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

Unable to run on Node.js 17.9.0/18.2.0 #168

Closed itegulov closed 1 month ago

itegulov commented 2 years ago

If you install node 17.9.0/18.2.0 (using nvm or through other means) and run yarn test in the workspaces-js root directory all tests will fail with the following error:

Rejected promise returned by test. Reason:

Error (TypedError)

{ context: undefined, type: 'RetriesExceeded', message: 'Exceeded 10 attempts for http://localhost:1026.', }

› Object.fetchJson (node_modules/near-api-js/lib/utils/web.js:47:15) › async node_modules/near-api-js/lib/providers/json-rpc-provider.js:312:34 › async Object.exponentialBackoff [as default] (node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24) › async JsonRpcProvider.sendJsonRpc (node_modules/near-api-js/lib/providers/json-rpc-provider.js:304:26) › async JsonRpcProvider.query (node_modules/near-api-js/lib/providers/json-rpc-provider.js:116:22) › async Account.findAccessKey (node_modules/near-api-js/lib/account.js:186:31) › async Account.signTransaction (node_modules/near-api-js/lib/account.js:91:31) › async node_modules/near-api-js/lib/account.js:118:34 › async Object.exponentialBackoff [as default] (node_modules/near-api-js/lib/utils/exponential-backoff.js:7:24) › async Account.signAndSendTransactionV2 (node_modules/near-api-js/lib/account.js:117:24)

The last Node.js that works for me is 16.15.0

idea404 commented 2 years ago

This also has memory leakage as a side effect:

image

To replicate: use Node v18.6, attempt to run workspaces-js tests for https://github.com/near-examples/FT

ad0ll commented 2 years ago

I'm encountering a similar issue when trying to run integration tests from create-near-app.

Sample code that results in a kill Node 18:

import anyTest, { TestFn } from 'ava';
import * as path from "path";

const test = anyTest as TestFn<{
  worker: Worker;
  accounts: Record<string, NearAccount>;
}>;

test( "create sub-account", async (t) => {
  const worker = await Worker.init();
  const root = worker.rootAccount;
  // Hangs on this line w/ Node 18. Also hangs on deploy contract and others.
  const contract = await root.createSubAccount("test-account");
  t.context.worker = worker;
  t.context.accounts = { root, contract };
});
no2chem commented 1 year ago

This bug turns out to be due to an issue with node name resolution in Node18. I'll push a PR which addresses it.

gagdiez commented 1 year ago

@volovyks @ailisp we have come across this same issue today using node 19.8.0.

ghost commented 1 year ago

This issue is affecting at least the example repos referenced by https://docs.near.org/develop/quickstart-guide , whose integration tests uses workspaces-js

Exact line it's getting stuck is:

For those who are new to node.js/ javascript/typescript, a temporary workaround is to downgrade node:

First, install nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
export NVM_DIR="$HOME/.nvm" 
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm --version # Verify installation

Then, downgrade node

nvm install v16.17.1
nvm use v16.17.1

Now, integration tests will run fine with downgraded node.

git clone https://github.com/near-examples/hello-near-rust
cd  hello-near-rust
npm install
npm run test:integration