near / near-workspaces-js

Write tests once, run them both on NEAR TestNet and a controlled NEAR Sandbox local environment
https://near.github.io/near-workspaces-js/
GNU General Public License v3.0
42 stars 22 forks source link

Can not sign transactions for account test.near on network sandbox, no matching key pair found in InMemorySigner #211

Open toteto opened 1 year ago

toteto commented 1 year ago

I am having issue while using the library. Uppon invoking rootAccount.createAccount(...) (or any of the other create account methods) I get error of: Can not sign transactions for account test.near on network sandbox, no matching key pair found in InMemorySigner(UnencryptedFileSystemKeyStore(/private/var/folders/_3/ggprgl2s3dg02ll3pgymf2280000gn/T/sandbox/81264186-ccb1-4f88-80c7-b932a3b1a62b))

This is the code snippet producing this

const nearRpcUrl = `http://127.0.0.1:${port}`;
const worker = await Worker.init({
// config needed until https://github.com/near/workspaces-js/pull/200 merged
port,
rpcAddr: nearRpcUrl,
});

console.log('accountId', worker.rootAccount.accountId); //  accountId test.near
console.log('availableBalance', await worker.rootAccount.availableBalance()); // availableBalance <BN: 314dc5f1d5bbc198ca396ebf3800>
console.log('exists', await worker.rootAccount.exists()); //  exists true

await worker.rootAccount.createAccount('alice'); // throws

My environment:

What I have tried

toteto commented 1 year ago

Only thing that has worked so far is changing the port number on each test run. If the test run uses port number that is previous used, it will fail with the above error.

fospring commented 10 months ago

Only thing that has worked so far is changing the port number on each test run. If the test run uses port number that is previous used, it will fail with the above error. @toteto every running task should use different port, for each default config it will get port by nextPort:

  static async defaultConfig(): Promise<Config> {
    const port = await SandboxServer.nextPort();
    return {
      ...this.clientConfig,
      homeDir: SandboxServer.randomHomeDir(),
      port,
      rm: false,
      refDir: null,
      rpcAddr: `http://localhost:${port}`,
    };
  }

https://github.com/near/workspaces-js/blob/main/packages/js/src/worker.ts#L108C7-L108C7 I think you just need to init worker without params:

const worker = await Worker.init();