From eb4009848e0aa758192cb2b3a840fb0f3d755b1d Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Wed, 23 Oct 2019 15:29:40 +0300 Subject: [PATCH] Deduplicated the code in provider tests --- test/providers.test.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/test/providers.test.js b/test/providers.test.js index 6749711fae..a3a3448c3b 100644 --- a/test/providers.test.js +++ b/test/providers.test.js @@ -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 = {