How to run near-js-sdk tests against a localnet with multiple contracts

I have set up node:

nearup run localnet --binary-path ~/code/nearcore/target/release

I am trying to run a jest test case:

beforeAll(async function () {
  // NOTE: nearlib and nearConfig are made available by near-cli/test_environment
  const near = await nearlib.connect(nearConfig)
})

However there is obvious step missing how to create test accounts on your local node. This is the error:

 ● Test suite failed to run

    Can not sign transactions for account test.near, no matching key pair found in Signer.

      at node_modules/near-api-js/lib/account.js:83:23
      at Object.exponentialBackoff [as default] (node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24)
      at Account.signAndSendTransaction (node_modules/near-api-js/lib/account.js:80:24)
      at Account.createAndDeployContract (node_modules/near-api-js/lib/account.js:176:9)
      at LocalTestEnvironment.setup (node_modules/near-cli/test_environment.js:39:9)

Also looks like near-js-sdk is hardcoded to deploy only one contract. I need to test multiple contracts. How can I deploy multiple contracts? From near-js-sdk test_environment.js

class LocalTestEnvironment extends NodeEnvironment {
    constructor(config) {
        super(config);
    }

    async setup() {
        this.global.nearlib = require('near-api-js');
        this.global.nearAPI = require('near-api-js');
        this.global.window = {};
        let config = require('./get-config')();
        this.global.testSettings = this.global.nearConfig = config;
        const now = Date.now();
        // create random number with at least 7 digits
        const randomNumber = Math.floor(Math.random() * (9999999 - 1000000) + 1000000);
        config = Object.assign(config, {
            contractName: 'test-account-' + now + '-' + randomNumber,
            accountId: 'test-account-' + now + '-' + randomNumber
        });
        const keyStore = new nearAPI.keyStores.UnencryptedFileSystemKeyStore(PROJECT_KEY_DIR);
        config.deps = Object.assign(config.deps || {}, {
            storage:  this.createFakeStorage(),
            keyStore,
        });
        const near = await nearAPI.connect(config);

        const masterAccount = await near.account(testAccountName);
        const randomKey = await nearAPI.KeyPair.fromRandom('ed25519');
        const data = [...fs.readFileSync('./out/main.wasm')];
        await config.deps.keyStore.setKey(config.networkId, config.contractName, randomKey);
        await masterAccount.createAndDeployContract(config.contractName, randomKey.getPublicKey(), data, INITIAL_BALANCE);

        await super.setup();
    }

near-js-sdk itself is deploying against mysterious shared-test

    case 'ci':
        return {
            networkId: 'shared-test',
            nodeUrl: 'https://rpc.ci-testnet.near.org',
            masterAccount: 'test.near',
        };


from Recent Questions - Stack Overflow https://ift.tt/3cEB6Rk
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations