diff --git a/packages/accounts/test/config.js b/packages/accounts/test/config.js index 23f994a1dd..4afbbc6ef5 100644 --- a/packages/accounts/test/config.js +++ b/packages/accounts/test/config.js @@ -37,16 +37,27 @@ module.exports = async function getConfig(env) { case 'test': case 'ci': { if (!worker) worker = await Worker.init(); - const keyFile = fs.readFileSync(`${worker.rootAccount.manager.config.homeDir}/validator_key.json`); + const keyFile = fs.readFileSync( + `${worker.rootAccount.manager.config.homeDir}/validator_key.json` + ); const keyPair = JSON.parse(keyFile.toString()); return { networkId: worker.config.network, nodeUrl: worker.manager.config.rpcAddr, masterAccount: worker.rootAccount._accountId, - secretKey: keyPair.secret_key || keyPair.private_key + secretKey: keyPair.secret_key || keyPair.private_key, + }; + } + case 'remote_ci': { + return { + networkId: 'shared-test', + nodeUrl: 'https://rpc.ci-testnet.near.org', + masterAccount: 'test.near', }; } default: - throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`); + throw Error( + `Unconfigured environment '${env}'. Can be configured in src/config.js.` + ); } }; diff --git a/packages/near-api-js/test/config.js b/packages/near-api-js/test/config.js index 7bbf1bfc0c..9bbfab99c2 100644 --- a/packages/near-api-js/test/config.js +++ b/packages/near-api-js/test/config.js @@ -45,6 +45,13 @@ module.exports = async function getConfig(env) { masterAccount: worker.rootAccount._accountId, secretKey: keyPair.secret_key || keyPair.private_key }; + case 'remote_ci': { + return { + networkId: 'shared-test', + nodeUrl: 'https://rpc.ci-testnet.near.org', + masterAccount: 'test.near', + }; + } default: throw Error(`Unconfigured environment '${env}'. Can be configured in src/config.js.`); } diff --git a/packages/providers/package.json b/packages/providers/package.json index 9a773fbeeb..bf12b8ac86 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@types/node": "18.11.18", + "@near-js/keystores": "workspace:*", "jest": "26.0.1", "near-workspaces": "3.4.0", "ts-jest": "26.5.6", diff --git a/packages/providers/test/config.js b/packages/providers/test/config.js new file mode 100644 index 0000000000..4afbbc6ef5 --- /dev/null +++ b/packages/providers/test/config.js @@ -0,0 +1,63 @@ +const { Worker } = require('near-workspaces'); +const fs = require('fs'); +let worker; +module.exports = async function getConfig(env) { + switch (env) { + case 'production': + case 'mainnet': + return { + networkId: 'mainnet', + nodeUrl: 'https://rpc.mainnet.near.org', + walletUrl: 'https://wallet.near.org', + helperUrl: 'https://helper.mainnet.near.org', + }; + case 'development': + case 'testnet': + return { + networkId: 'default', + nodeUrl: 'https://rpc.testnet.near.org', + walletUrl: 'https://wallet.testnet.near.org', + helperUrl: 'https://helper.testnet.near.org', + masterAccount: 'test.near', + }; + case 'betanet': + return { + networkId: 'betanet', + nodeUrl: 'https://rpc.betanet.near.org', + walletUrl: 'https://wallet.betanet.near.org', + helperUrl: 'https://helper.betanet.near.org', + }; + case 'local': + return { + networkId: 'local', + nodeUrl: 'http://localhost:3030', + keyPath: `${process.env.HOME}/.near/validator_key.json`, + walletUrl: 'http://localhost:4000/wallet', + }; + case 'test': + case 'ci': { + if (!worker) worker = await Worker.init(); + const keyFile = fs.readFileSync( + `${worker.rootAccount.manager.config.homeDir}/validator_key.json` + ); + const keyPair = JSON.parse(keyFile.toString()); + return { + networkId: worker.config.network, + nodeUrl: worker.manager.config.rpcAddr, + masterAccount: worker.rootAccount._accountId, + secretKey: keyPair.secret_key || keyPair.private_key, + }; + } + case 'remote_ci': { + return { + networkId: 'shared-test', + nodeUrl: 'https://rpc.ci-testnet.near.org', + masterAccount: 'test.near', + }; + } + default: + throw Error( + `Unconfigured environment '${env}'. Can be configured in src/config.js.` + ); + } +}; diff --git a/packages/providers/test/providers.test.js b/packages/providers/test/providers.test.js index f66a34c5a1..4a2dc559da 100644 --- a/packages/providers/test/providers.test.js +++ b/packages/providers/test/providers.test.js @@ -1,23 +1,23 @@ const { getTransactionLastResult } = require('@near-js/utils'); -const { Worker } = require('near-workspaces'); +const { InMemoryKeyStore } = require('@near-js/keystores'); const { JsonRpcProvider } = require('../lib'); jest.setTimeout(20000); describe('providers', () => { - let worker; let provider; beforeAll(async () => { - worker = await Worker.init(); - provider = new JsonRpcProvider({ url: worker.manager.config.rpcAddr }); + const networkId = 'unittest'; + const keyStore = new InMemoryKeyStore(); + const config = Object.assign(await require('./config')(process.env.NODE_ENV || 'test'), { + networkId, + keyStore + }); + provider = new JsonRpcProvider({ url: config.nodeUrl }); await new Promise(resolve => setTimeout(resolve, 2000)); }); - afterAll(async () => { - await worker.tearDown(); - }); - test('json rpc fetch node status', async () => { let response = await provider.status(); expect(response.chain_id).toBeTruthy(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ce6e85b14..19cbf50eb2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -402,6 +402,9 @@ importers: specifier: 2.6.7 version: 2.6.7 devDependencies: + '@near-js/keystores': + specifier: workspace:* + version: link:../keystores '@types/node': specifier: 18.11.18 version: 18.11.18