Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote RPC for backward compatibility of testing #1283

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/accounts/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
);
}
};
7 changes: 7 additions & 0 deletions packages/near-api-js/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions packages/providers/test/config.js
Original file line number Diff line number Diff line change
@@ -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.`
);
}
};
16 changes: 8 additions & 8 deletions packages/providers/test/providers.test.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading