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

Bug: KeyNotFound, but it's there #128

Open tifrel opened 2 years ago

tifrel commented 2 years ago

I can currently not sign a transaction due to a missing key:

 Rejected promise returned by test. Reason:

 Error (TypedError) 

 { context: undefined, type: 'KeyNotFound', message: 'Can not sign transactions for account alice.factory.test.near on network sandbox, no matching key pair found in InMemorySigner(UnencryptedFileSystemKeyStore(/private/var/folders/pl/t18g62c96jdd1fcl5zmdgg680000gn/T/sandbox/9106bd6a-9750-4117-abf6-f2d07ac6a4f6)).', } 

Taking a look into that directory, the key pair does actually exist, as I have copied it over from the factory account as part of the tests. The test output confirms that. You can [check it out](https://github.com/Mintbase/mintbase-core/blob/0b6c0e388b35da3f6517cd41d085b80f6db29694/testing/tests/nft.upgrade.ava.ts), but I can not open-source the whole repo. I have also replaced the the UnencryptedFileSystemKeyStore for the offending account, but that doesn't work (see l. 197 in linked code). My best idea right now is that the InMemorySigner keeps an outdated version of UnencryptedFileSystemKeyStore, but I cannot find where to replace that signer.

ailisp commented 2 years ago

We were able to reliably reproduce the same error in testnet, but sandbox were passed. The tests are: https://github.com/near-examples/nft-tutorial/tree/feat-testing/onchain_tests. We're working on a fix, and will see if that solves your problem.

ailisp commented 2 years ago

For now you do a very quick workaround to sequentially run tests, which fixes the tests for me. Edit this file, node_modules/near-workspaces-ava/dist/index.js, change this line:

            (0, ava_1.default)(description, async (t) => {

to:

            (0, ava_1.serial)(description, async (t) => {

The problem is UnencryptedFileSystemKeyStore doesn't handle concurrent access of key files well. We're still investigating a fix, maybe in near-api-js.

idea404 commented 2 years ago

I would add to this issue:

ailisp commented 2 years ago

@tifrel In our fails, this failure is due to the account creation failed (alice.factory.test.near). The keypair is there but the account wasn't successfully created will also give this error message (our bad :(), and it's much more frequent than the key really doesn't exist.

Please try:

const balance = await alice.availableBalance();
console.log(balance);

If it errors, we can confirm alice doesn't exist. Call availableBalance doesn't need key.

tifrel commented 2 years ago

@ailisp Thanks a lot for your support. In my case, I have fixed the issue by not using the factory to deploy the contract, and instead testing the upgrade on a directly deployed store. I did however take the time to check this. alice exists on my sandbox node. Furthermore I tried the same with store, as that is the variable for account alice.factory.test.near. I checked everything in a repo where I didn't download the closed-source parts, to eliminate the chances of those interfering.

I'd like to add to this that all my other tests pass, and all of them require account creation. The only part where I am facing troubles is the key copying.