Skip to content

Commit

Permalink
Deduplicated the code in provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frol committed Oct 25, 2019
1 parent a687bb2 commit eb40098
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions test/providers.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@

const nearlib = require('../lib/index');

test('json rpc fetch node status', async () => {
const withProvider = (fn) => {
const config = Object.assign(require('./config')(process.env.NODE_ENV || 'test'));
const provider = new nearlib.providers.JsonRpcProvider(config.nodeUrl);
return () => fn(provider);
};

test('json rpc fetch node status', withProvider(async (provider) => {
let response = await provider.status();
expect(response.chain_id).toContain('test-chain');
});
}));

test('json rpc fetch block info', async () => {
const config = Object.assign(require('./config')(process.env.NODE_ENV || 'test'));
const provider = new nearlib.providers.JsonRpcProvider(config.nodeUrl);
test('json rpc fetch block info', withProvider(async (provider) => {
let response = await provider.block(1);
expect(response.header.height).toEqual(1);
let sameBlock = await provider.block(response.header.hash);
expect(sameBlock.header.height).toEqual(1);
});
}));

test('json rpc fetch chunk info', async () => {
const config = Object.assign(require('./config')(process.env.NODE_ENV || 'test'));
const provider = new nearlib.providers.JsonRpcProvider(config.nodeUrl);
test('json rpc fetch chunk info', withProvider(async (provider) => {
let response = await provider.chunk([1, 0]);
expect(response.header.shard_id).toEqual(0);
let sameChunk = await provider.chunk(response.header.chunk_hash);
expect(sameChunk.header.chunk_hash).toEqual(response.header.chunk_hash);
expect(sameChunk.header.shard_id).toEqual(0);
});
}));

test('json rpc query account', async () => {
const config = Object.assign(require('./config')(process.env.NODE_ENV || 'test'));
const provider = new nearlib.providers.JsonRpcProvider(config.nodeUrl);
test('json rpc query account', withProvider(async (provider) => {
let response = await provider.query('account/test.near', '');
expect(response.code_hash).toEqual('11111111111111111111111111111111');
});
}));

test('final tx result', async() => {
const result = {
Expand Down

0 comments on commit eb40098

Please sign in to comment.