From e73ccbc4156b5a0bb977201a0b88b3b71e18ade5 Mon Sep 17 00:00:00 2001 From: tony Date: Fri, 22 Nov 2019 11:08:00 +0800 Subject: [PATCH 1/5] improve npm ignore --- .npmignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.npmignore b/.npmignore index 725c604..fd5d881 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,8 @@ .vscode/ src/ test/ +.github +docs/ *.tgz tsconfig.json tslint.json From de5778ef2d1654584ad5c16ed82a809812e338b5 Mon Sep 17 00:00:00 2001 From: tony Date: Fri, 17 Jan 2020 17:22:39 +0800 Subject: [PATCH 2/5] change event query url to latest --- src/provider/rpc-methods.ts | 2 +- test/extend/contract.test.ts | 4 ++-- test/provider/rpc-methods.test.ts | 6 +++--- test/web3/eth.test.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/provider/rpc-methods.ts b/src/provider/rpc-methods.ts index c51f736..d88feb9 100644 --- a/src/provider/rpc-methods.ts +++ b/src/provider/rpc-methods.ts @@ -223,7 +223,7 @@ RPCMethodMap.set('eth_getLogs', async function(rpc: JSONRPC, host: string, timeo query += '&order=' + rpc.params[0].order.toUpperCase() } query = query.replace('&', '?') - const URL = host + '/logs/events' + query + const URL = host + '/logs/event' + query const reqBody = utils.formatLogQuery(rpc.params[0]) diff --git a/test/extend/contract.test.ts b/test/extend/contract.test.ts index 88908a4..0a395ce 100644 --- a/test/extend/contract.test.ts +++ b/test/extend/contract.test.ts @@ -16,7 +16,7 @@ describe('web3.contract', () => { await contract.getPastEvents('Transfer') const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000000000456e65726779') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000000000456e65726779') expect(body).to.not.have.property('range') expect(body).to.not.have.property('options') }) @@ -26,7 +26,7 @@ describe('web3.contract', () => { const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000000000456e65726779&order=ASC') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000000000456e65726779&order=ASC') }) }) diff --git a/test/provider/rpc-methods.test.ts b/test/provider/rpc-methods.test.ts index 2ee87cf..051a522 100644 --- a/test/provider/rpc-methods.test.ts +++ b/test/provider/rpc-methods.test.ts @@ -475,7 +475,7 @@ describe('rpc methods', () => { const ret = await executor(rpc, host, timeout) const {url} = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000417574686f72697479&order=ASC') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000417574686f72697479&order=ASC') expect(ret.result).to.have.lengthOf(1) expect(ret.result[0]).to.have.property('blockNumber', 100) expect(ret.result[0]).to.have.property('blockHash', 'block-id') @@ -492,7 +492,7 @@ describe('rpc methods', () => { await executor(rpc, host, timeout) const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000417574686f72697479&order=DESC') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000417574686f72697479&order=DESC') }) it('minimum request param should get the minimum url', async () => { @@ -502,7 +502,7 @@ describe('rpc methods', () => { await executor(rpc, host, timeout) const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events') + expect(url).to.be.equal('/logs/event') }) it('return null', async () => { diff --git a/test/web3/eth.test.ts b/test/web3/eth.test.ts index 5e77bd0..6d0853f 100644 --- a/test/web3/eth.test.ts +++ b/test/web3/eth.test.ts @@ -392,7 +392,7 @@ describe('web3.eth', () => { }) const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000000000456e65726779') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000000000456e65726779') expect(result.length).to.be.equal(1) }) @@ -480,7 +480,7 @@ describe('web3.eth.Contract', () => { const result = await contract.getPastEvents('Transfer', { filter: { _from: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed' } }) const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/logs/events?address=0x0000000000000000000000000000456e65726779') + expect(url).to.be.equal('/logs/event?address=0x0000000000000000000000000000456e65726779') expect(result.length).to.be.equal(1) expect(result[0]).to.have.all.keys('address', 'blockHash', 'blockNumber', 'event', 'meta', 'raw', 'returnValues', 'signature', 'transactionHash') }) From 494f5436480269fae5bb97363b9109649d994869 Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 19 Jan 2020 12:17:20 +0800 Subject: [PATCH 3/5] change to add 15000 gas instead of increase 20% --- src/provider/rpc-methods.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/provider/rpc-methods.ts b/src/provider/rpc-methods.ts index d88feb9..c19f815 100644 --- a/src/provider/rpc-methods.ts +++ b/src/provider/rpc-methods.ts @@ -205,11 +205,8 @@ RPCMethodMap.set('eth_estimateGas', async function(rpc: JSONRPC, host: string, t debug('VM gas:', res.gasUsed) // ignore the overflow since block gas limit is uint64 and JavaScript's max number is 2^53 const intrinsicGas = utils.calcIntrinsicGas(Object.assign(reqBody, { to: rpc.params[0].to })) - if (res.gasUsed === 0 && (reqBody.data === '0x')) { - return rpc.makeResult(intrinsicGas) - } else { - return rpc.makeResult(Math.floor(res.gasUsed * 1.2) + intrinsicGas) // increase vm gas with 20% for safe since it's estimated from current block state, final state for the transaction is not determined for now - } + // increase vm gas by 15000 for safe since it's estimated from current block state, final state for the transaction is not determined for now + return rpc.makeResult(intrinsicGas + (result.gasUsed ? (result.gasUsed + 15000) : 0)) } } }) From 0cd75845df33ba3dac378ea664535f53932a752c Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 19 Jan 2020 12:17:55 +0800 Subject: [PATCH 4/5] change the API of call/estimateGas --- src/provider/rpc-methods.ts | 60 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/provider/rpc-methods.ts b/src/provider/rpc-methods.ts index c19f815..9b89b8e 100644 --- a/src/provider/rpc-methods.ts +++ b/src/provider/rpc-methods.ts @@ -125,17 +125,16 @@ RPCMethodMap.set('eth_getTransactionReceipt', async function(rpc: JSONRPC, host: }) RPCMethodMap.set('eth_call', async function(rpc: JSONRPC, host: string, timeout: number) { - let extraURI = '' - if (rpc.params[0].to) { - extraURI = '/' + rpc.params[0].to - } - extraURI += '?revision=' + utils.fromETHBlockNumberOrHash(rpc.params[1]) - const URL = host + '/accounts' + extraURI + const extraURI = '?revision=' + utils.fromETHBlockNumberOrHash(rpc.params[1]) + const URL = host + '/accounts/*' + extraURI const reqBody: any = { - value: rpc.params[0].value || '', - data: rpc.params[0].data || '0x', - gasPrice: rpc.params[0].gasPrice || '', + clauses: [{ + to: rpc.params[0].to || null, + value: rpc.params[0].value || '', + data: rpc.params[0].data || '0x', + }], + gasPrice: rpc.params[0].gasPrice || undefined, } if (rpc.params[0].gas) { if (typeof rpc.params[0].gas === 'number') { @@ -151,33 +150,33 @@ RPCMethodMap.set('eth_call', async function(rpc: JSONRPC, host: string, timeout: const res = await HTTP.post(URL, reqBody, timeout).then(HTTPPostProcessor) debug('eth_call returns', res) - if (!res) { + if (!res || res.length === 0) { return rpc.makeResult(null) } else { - if (res.reverted || res.vmError) { - if (res.data && (res.data as string).startsWith('0x08c379a0')) { - return rpc.makeError('VM reverted: ' + require('web3-eth-abi').decodeParameter('string', res.data.replace(/^0x08c379a0/i, ''))) + const result = res[0] + if (result.reverted || result.vmError) { + if (result.data && (result.data as string).startsWith('0x08c379a0')) { + return rpc.makeError('VM reverted: ' + require('web3-eth-abi').decodeParameter('string', result.data.replace(/^0x08c379a0/i, ''))) } else { - return rpc.makeError('VM executing failed' + (res.vmError ? ': ' + res.vmError : '')) + return rpc.makeError('VM executing failed' + (result.vmError ? ': ' + result.vmError : '')) } } else { - return rpc.makeResult(res.data === '0x' ? '' : res.data) + return rpc.makeResult(result.data === '0x' ? '' : result.data) } } }) RPCMethodMap.set('eth_estimateGas', async function(rpc: JSONRPC, host: string, timeout: number) { - let extraURI = '' - if (rpc.params[0].to) { - extraURI = '/' + rpc.params[0].to - } - extraURI += '?revision=' + utils.fromETHBlockNumberOrHash(rpc.params[1]) - const URL = host + '/accounts' + extraURI + const extraURI = '?revision=' + utils.fromETHBlockNumberOrHash(rpc.params[1]) + const URL = host + '/accounts/*' + extraURI const reqBody: any = { - value: rpc.params[0].value || '', - data: rpc.params[0].data || '0x', - gasPrice: rpc.params[0].gasPrice || '', + clauses: [{ + to: rpc.params[0].to || null, + value: rpc.params[0].value || '', + data: rpc.params[0].data || '0x', + }], + gasPrice: rpc.params[0].gasPrice || undefined, } if (rpc.params[0].gas) { if (typeof rpc.params[0].gas === 'number') { @@ -192,17 +191,18 @@ RPCMethodMap.set('eth_estimateGas', async function(rpc: JSONRPC, host: string, t const res = await HTTP.post(URL, reqBody, timeout).then(HTTPPostProcessor) - if (!res) { + if (!res || res.length === 0) { return rpc.makeResult(null) } else { - if (res.reverted || res.vmError) { - if (res.data && (res.data as string).startsWith('0x08c379a0')) { - return rpc.makeError('Gas estimation failed with VM reverted: ' + require('web3-eth-abi').decodeParameter('string', res.data.replace(/^0x08c379a0/i, ''))) + const result = res[0] + if (result.reverted || result.vmError) { + if (result.data && (result.data as string).startsWith('0x08c379a0')) { + return rpc.makeError('Gas estimation failed with VM reverted: ' + require('web3-eth-abi').decodeParameter('string', result.data.replace(/^0x08c379a0/i, ''))) } else { - return rpc.makeError('Gas estimation failed' + (res.vmError ? ': ' + res.vmError : '')) + return rpc.makeError('Gas estimation failed' + (result.vmError ? ': ' + result.vmError : '')) } } else { - debug('VM gas:', res.gasUsed) + debug('VM gas:', result.gasUsed) // ignore the overflow since block gas limit is uint64 and JavaScript's max number is 2^53 const intrinsicGas = utils.calcIntrinsicGas(Object.assign(reqBody, { to: rpc.params[0].to })) // increase vm gas by 15000 for safe since it's estimated from current block state, final state for the transaction is not determined for now From 7b72f048b398bd75e861ba612822eace152642d8 Mon Sep 17 00:00:00 2001 From: tony Date: Sun, 19 Jan 2020 12:18:24 +0800 Subject: [PATCH 5/5] test cases: call/estimate gas --- test/extend/accounts.test.ts | 12 ++--- test/provider/rpc-methods.test.ts | 88 +++++++++++++++++++++---------- test/web3/eth.test.ts | 45 ++++++++++------ 3 files changed, 95 insertions(+), 50 deletions(-) diff --git a/test/extend/accounts.test.ts b/test/extend/accounts.test.ts index 673d4fb..e0848cc 100644 --- a/test/extend/accounts.test.ts +++ b/test/extend/accounts.test.ts @@ -27,9 +27,9 @@ describe('extend:accounts', () => { xhrUtility.setCachedResponse('/blocks/best', { id: '0x000000352985d99d', }) - xhrUtility.setCachedResponse('/accounts/0xd3ae78222beadb038203be21ed5ce7c9b1bff602?revision=best', { + xhrUtility.setCachedResponse('/accounts/*?revision=best', [{ gasUsed: 53000, - }) + }]) const ret = await web3.eth.accounts.signTransaction({ to: '0xD3ae78222BEADB038203bE21eD5ce7C9B1BfF602', @@ -133,10 +133,10 @@ describe('extend:accounts', () => { it('sign Transaction without gas', (done) => { // if reverted estimateGas will return null - xhrUtility.setCachedResponse('/accounts/0xd3ae78222beadb038203be21ed5ce7c9b1bff602?revision=best', { + xhrUtility.setCachedResponse('/accounts/*?revision=best', [{ reverted: true, data: '0x08c379a00x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f736f6d657468696e672077726f6e670000000000000000000000000000000000', - }) + }]) web3.eth.accounts.signTransaction({ to: '0xd3ae78222beadb038203be21ed5ce7c9b1bff602', value: '0x3e8', @@ -184,9 +184,9 @@ describe('extend:accounts', () => { }) it('sign Transaction without gas and 0-length clause should not throw error', async () => { - xhrUtility.setCachedResponse('/accounts?revision=best', { + xhrUtility.setCachedResponse('/accounts/*?revision=best', [{ gasUsed: 53000, - }) + }]) await web3.eth.accounts.signTransaction({ expiration: 720, diff --git a/test/provider/rpc-methods.test.ts b/test/provider/rpc-methods.test.ts index 051a522..350ced6 100644 --- a/test/provider/rpc-methods.test.ts +++ b/test/provider/rpc-methods.test.ts @@ -223,7 +223,7 @@ describe('rpc methods', () => { describe('eth_call', () => { it('valid response', async () => { - xhrUtility.setResponse({ reverted: false, data: '0xdata' }) + xhrUtility.setResponse([{ reverted: false, data: '0xdata' }]) const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -236,19 +236,21 @@ describe('rpc methods', () => { const ret = await executor(rpc, host, timeout) const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed?revision=best') - expect(body).to.have.property('value', '0x64') + expect(url).to.be.equal('/accounts/*?revision=best') expect(body).to.have.property('gas', 100) expect(body).to.have.property('gasPrice', '0x64') expect(body).to.have.property('caller', '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed') + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('value', '0x64') expect(ret.result).to.be.equal('0xdata') }) it('reverted should return rpc error', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ reverted: true, data: '0x08c379a00x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f736f6d657468696e672077726f6e670000000000000000000000000000000000', - }) + }]) const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -267,7 +269,7 @@ describe('rpc methods', () => { }) it('"0x" of data should return empty string', async () => { - xhrUtility.setResponse({ data: '0x' }) + xhrUtility.setResponse([{ data: '0x' }]) const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -278,7 +280,6 @@ describe('rpc methods', () => { }]) const ret = await executor(rpc, host, timeout) - const { body } = xhrUtility.extractRequest() expect(ret.result).to.be.equal('') }) @@ -296,7 +297,7 @@ describe('rpc methods', () => { describe('eth_call', () => { it('valid response', async () => { - xhrUtility.setResponse({ reverted: false, data: '0xdata' }) + xhrUtility.setResponse([{ reverted: false, data: '0xdata' }]) const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -309,16 +310,18 @@ describe('rpc methods', () => { const ret = await executor(rpc, host, timeout) const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed?revision=best') - expect(body).to.have.property('value', '0x64') + expect(url).to.be.equal('/accounts/*?revision=best') expect(body).to.have.property('gas', 100) expect(body).to.have.property('gasPrice', '0x64') expect(body).to.have.property('caller', '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed') + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('value', '0x64') expect(ret.result).to.be.equal('0xdata') }) it('request without from should not have caller in body', async () => { - xhrUtility.setResponse({ reverted: true }) + xhrUtility.setResponse([{ reverted: true }]) const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -334,15 +337,19 @@ describe('rpc methods', () => { expect(body).to.not.have.property('caller') }) - it('deploy contract should request the right url', async () => { + it('deploy contract should set "to" to null', async () => { const executor = RPCMethodMap.get('eth_call') const rpc = makeRPCRequest('eth_call', [{ from: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', }]) await executor(rpc, host, timeout) - const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts?revision=best') + const { url, body } = xhrUtility.extractRequest() + expect(url).to.be.equal('/accounts/*?revision=best') + + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('to', null) }) it('return null', async () => { @@ -358,7 +365,7 @@ describe('rpc methods', () => { describe('eth_estimateGas', () => { it('valid response', async () => { - xhrUtility.setResponse({ gasUsed: 0 }) + xhrUtility.setResponse([{ gasUsed: 0 }]) const executor = RPCMethodMap.get('eth_estimateGas') const rpc = makeRPCRequest('eth_estimateGas', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -371,16 +378,20 @@ describe('rpc methods', () => { const ret = await executor(rpc, host, timeout) const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed?revision=best') - expect(body).to.have.property('value', '0x64') + expect(url).to.be.equal('/accounts/*?revision=best') expect(body).to.have.property('gas', 100) expect(body).to.have.property('gasPrice', '0x64') expect(body).to.have.property('caller', '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed') + + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('value', '0x64') + expect(ret.result).to.be.equal(21000) }) - it('gas Used should increase 20%', async () => { - xhrUtility.setResponse({ gasUsed: 10 }) + it('gas Used should increase 15000', async () => { + xhrUtility.setResponse([{ gasUsed: 10 }]) const executor = RPCMethodMap.get('eth_estimateGas') const rpc = makeRPCRequest('eth_estimateGas', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -391,14 +402,14 @@ describe('rpc methods', () => { }]) const ret = await executor(rpc, host, timeout) - expect(ret.result).to.be.equal(21012) + expect(ret.result).to.be.equal(21000 + 10 + 15000) }) it('reverted should return rpc error', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ reverted: true, data: '0x08c379a00x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f736f6d657468696e672077726f6e670000000000000000000000000000000000', - }) + }]) const executor = RPCMethodMap.get('eth_estimateGas') const rpc = makeRPCRequest('eth_estimateGas', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -414,11 +425,30 @@ describe('rpc methods', () => { }) + it('vmError present should return rpc error', async () => { + xhrUtility.setResponse([{ + vmError: 'invalid opcode 0xfe', + }]) + const executor = RPCMethodMap.get('eth_estimateGas') + const rpc = makeRPCRequest('eth_estimateGas', [{ + to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', + from: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', + gas: '0x64', + value: '0x64', + gasPrice: '0x64', + }]) + + const ret = await executor(rpc, host, timeout) + expect(ret).to.have.property('error') + expect(ret.error).to.have.property('message', 'Gas estimation failed: invalid opcode 0xfe') + + }) + it('request without from should not have caller in body', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ reverted: true, data: '0x08c379a00x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f736f6d657468696e672077726f6e670000000000000000000000000000000000', - }) + }]) const executor = RPCMethodMap.get('eth_estimateGas') const rpc = makeRPCRequest('eth_estimateGas', [{ to: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', @@ -435,15 +465,19 @@ describe('rpc methods', () => { }) - it('deploy contract should request the right url', async () => { + it('deploy contract should not set "to" to null', async () => { const executor = RPCMethodMap.get('eth_estimateGas') const rpc = makeRPCRequest('eth_estimateGas', [{ from: '0x7567D83b7b8d80ADdCb281A71d54Fc7B3364ffed', }]) await executor(rpc, host, timeout) - const { url } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts?revision=best') + const { url, body } = xhrUtility.extractRequest() + expect(url).to.be.equal('/accounts/*?revision=best') + + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('to', null) }) it('return null', async () => { diff --git a/test/web3/eth.test.ts b/test/web3/eth.test.ts index 6d0853f..d39bf23 100644 --- a/test/web3/eth.test.ts +++ b/test/web3/eth.test.ts @@ -332,9 +332,9 @@ describe('web3.eth', () => { }) it('call with valid response', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ data: '0x0000000000000000000000000000000000000000000000000000000000000001', - }) + }]) const result = await web3.eth.call({ from: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', to: '0x0000000000000000000000000000456e65726779', @@ -342,16 +342,19 @@ describe('web3.eth', () => { }) const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x0000000000000000000000000000456e65726779?revision=best') + expect(url).to.be.equal('/accounts/*?revision=best') expect(result).to.be.equal('0x0000000000000000000000000000000000000000000000000000000000000001') expect(body).to.have.property('caller', '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed') - expect(body).to.have.property('data', '0xa9059cbb000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff6020000000000000000000000000000000000000000000000000000000000000064') + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('to', '0x0000000000000000000000000000456e65726779') + expect((body as any).clauses[0]).to.have.property('data', '0xa9059cbb000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff6020000000000000000000000000000000000000000000000000000000000000064') }) it('estimateGas with valid response', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ gasUsed: 0, - }) + }]) const result = await web3.eth.estimateGas({ from: '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', to: '0x0000000000000000000000000000456e65726779', @@ -360,10 +363,12 @@ describe('web3.eth', () => { }) const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x0000000000000000000000000000456e65726779?revision=best') + expect(url).to.be.equal('/accounts/*?revision=best') expect(result).to.be.equal(21000) expect(body).to.have.property('caller', '0x7567d83b7b8d80addcb281a71d54fc7b3364ffed') - expect(body).to.have.property('value', '0x64') + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('value', '0x64') }) it('getPastLogs with valid response', async () => { @@ -434,27 +439,33 @@ describe('web3.eth', () => { describe('web3.eth.Contract', () => { it('call method', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ data: '0x000000000000000000000000000000000000000003663fde3f5cc2921e0d7593', - }) + }]) const result = await contract.methods.balanceOf('0xd3ae78222beadb038203be21ed5ce7c9b1bff602').call() const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x0000000000000000000000000000456e65726779?revision=best') + expect(url).to.be.equal('/accounts/*?revision=best') expect(result).to.be.equal('1052067071896070588235347347') - expect(body).to.have.property('data', '0x70a08231000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff602') + + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('data', '0x70a08231000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff602') }) it('estimateGas method', async () => { - xhrUtility.setResponse({ + xhrUtility.setResponse([{ gasUsed: 870, - }) + }]) const result = await contract.methods.balanceOf('0xd3ae78222beadb038203be21ed5ce7c9b1bff602').estimateGas() const { url, body } = xhrUtility.extractRequest() - expect(url).to.be.equal('/accounts/0x0000000000000000000000000000456e65726779?revision=best') - expect(body).to.have.property('data', '0x70a08231000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff602') - expect(result).to.be.equal(23724) + expect(url).to.be.equal('/accounts/*?revision=best') + expect(result).to.be.equal(36870) + + expect(body).to.have.property('clauses') + expect((body as any).clauses).to.be.an('array').to.have.lengthOf(1) + expect((body as any).clauses[0]).to.have.property('data', '0x70a08231000000000000000000000000d3ae78222beadb038203be21ed5ce7c9b1bff602') }) it('getPastLogs', async () => {