Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 26, 2024. It is now read-only.
/etherscan-apiPublic archive

Commitb7b993c

Browse files
committed
Test paging on accounbt/txlist with the right parameters
1 parent7774204 commitb7b993c

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

‎src/client/ClientAccountBalancemulti.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { Address } from '../entities/Address'
33
import{ApiKey}from'../entities/Apikey'
44
import{IClientAccountBalanceMultiRequest}from'../interfaces/Account'
55
import{requestBuilder}from'../requestBuilder'
6-
6+
import{ClientBase}from'./ClientBase'
77
/**
88
* Client for the account balance
99
*/
10-
exportclassClientAccountBalancemultiimplementsIClientAccountBalanceMultiRequest{
10+
exportclassClientAccountBalancemultiextendsClientBaseimplementsIClientAccountBalanceMultiRequest{
1111
/**
1212
* Api key to send with the request
1313
*/
@@ -30,6 +30,7 @@ export class ClientAccountBalancemulti implements IClientAccountBalanceMultiRequ
3030
tag:string
3131

3232
constructor(apiKey:ApiKey,module:string,action:string,address:Address[],tag:string){
33+
super()
3334
this.apiKey=apiKey
3435
this.module=module
3536
this.action=action
@@ -54,6 +55,7 @@ export class ClientAccountBalancemulti implements IClientAccountBalanceMultiRequ
5455
constoptions={
5556
uri:this.toUrl(),
5657
}
57-
returnrequest.get(options)
58+
constresult=awaitrequest.get(options)
59+
returnthis.processResult(result)
5860
}
5961
}

‎src/client/ClientAccountTxlist.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { Address } from '../entities/Address'
33
import{ApiKey}from'../entities/Apikey'
44
import{IClientAccountTxlistRequest}from'../interfaces/Account'
55
import{requestBuilder}from'../requestBuilder'
6+
import{ClientBase}from'./ClientBase'
67

78
/**
89
* Client for the account balance
910
*/
10-
exportclassClientAccountTxlistimplementsIClientAccountTxlistRequest{
11+
exportclassClientAccountTxlistextendsClientBaseimplementsIClientAccountTxlistRequest{
1112
/**
1213
* Api key to send with the request
1314
*/
@@ -55,7 +56,7 @@ export class ClientAccountTxlist implements IClientAccountTxlistRequest {
5556
sort?:string,
5657
page?:string,
5758
offset?:string){
58-
59+
super()
5960
this.apiKey=apiKey
6061
this.module=module
6162
this.action=action
@@ -105,6 +106,7 @@ export class ClientAccountTxlist implements IClientAccountTxlistRequest {
105106
constoptions={
106107
uri:this.toUrl(),
107108
}
108-
returnrequest.get(options)
109+
constres=awaitrequest.get(options)
110+
returnthis.processResult(res)
109111
}
110112
}

‎src/client/ClientBase.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
/**
3+
* Basic functions shared by all clients
4+
*/
5+
exportclassClientBase{
6+
/**
7+
* Processes the result and return it
8+
*@param result String result of a request
9+
*/
10+
protectedprocessResult(result:string):object{
11+
returnJSON.parse(result)
12+
}
13+
}

‎test/clients/ClientAccountTxlistTest.ts‎

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const address = '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'
1414
conststartblock='0'
1515
constendblock='99999999'
1616
constexpectedUrl='http://api.etherscan.io/api?module=account&action=txlist&address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken'
17-
constfixtureLocation='./test/fixtures/account/txlist/address-startblock-endblock.json'
1817

1918
test('exists',t=>{
2019
t.truthy(ClientAccountTxlist)
@@ -27,7 +26,6 @@ test('can be instantiated', t => {
2726
t.pass()
2827
})
2928

30-
3129
test('generates the right url',t=> {
3230
constoAddress=newAddress(address)
3331
constoApiKey=newApiKey(apiKey)
@@ -60,11 +58,13 @@ test('start end endblock', t => {
6058
t.is(parsedUrl.page,'10')
6159
})
6260

61+
test('actually request and get an response ordering',asynct=>{
62+
constexpectedUrl='http://api.etherscan.io/api?module=account&action=txlist&address=0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a&startblock=0&endblock=99999999&sort=asc&apikey=YourApiKeyToken'
63+
constfixtureLocation='./test/fixtures/account/txlist/address-startblock-endblock.json'
6364

64-
test('actually request and get an response',asynct=>{
6565
constoAddress=newAddress(address)
6666
constoApiKey=newApiKey(apiKey)
67-
constc=newClientAccountTxlist(oApiKey,'account','txlist',oAddress,startblock,endblock,'desc','10')
67+
constc=newClientAccountTxlist(oApiKey,'account','txlist',oAddress,startblock,endblock)
6868

6969
constresultFixture=await_readFile(fixtureLocation,'utf-8')
7070
constparsedUrl=parse(c.toUrl())
@@ -76,3 +76,42 @@ test('actually request and get an response', async t => {
7676
constresult=awaitc.request()
7777
t.truthy(result)
7878
})
79+
80+
test('actually request and get an response with ordering but without paging',asynct=>{
81+
constfixtureLocation='./test/fixtures/account/txlist/address-startblock-endblock.json'
82+
83+
constoAddress=newAddress(address)
84+
constoApiKey=newApiKey(apiKey)
85+
constc=newClientAccountTxlist(oApiKey,'account','txlist',oAddress,startblock,endblock,'desc')
86+
87+
constresultFixture=await_readFile(fixtureLocation,'utf-8')
88+
constparsedUrl=parse(c.toUrl())
89+
90+
nock(`${parsedUrl.protocol}//${parsedUrl.host}`)
91+
.get(parsedUrl.path)
92+
.reply(200,resultFixture)
93+
94+
constresult=awaitc.request()
95+
t.truthy(result)
96+
})
97+
98+
test('actually request and get an response with ordering and paging',asynct=>{
99+
constfixtureLocation='./test/fixtures/account/txlist/address-startblock-endblock-paging.json'
100+
constoAddress=newAddress(address)
101+
constoApiKey=newApiKey(apiKey)
102+
103+
constc=newClientAccountTxlist(oApiKey,'account','txlist',oAddress,startblock,endblock,'desc','1','10')
104+
105+
constresultFixture=await_readFile(fixtureLocation,'utf-8')
106+
constparsedUrl=parse(c.toUrl())
107+
108+
nock(`${parsedUrl.protocol}//${parsedUrl.host}`)
109+
.get(parsedUrl.path)
110+
.reply(200,resultFixture)
111+
112+
constresult=awaitc.request()
113+
t.is(typeofresult,'object')
114+
t.truthy(result)
115+
116+
});
117+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"1","message":"OK","result":[{"blockNumber":"0","timeStamp":"1438269973","hash":"GENESIS_ddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","nonce":"","blockHash":"","transactionIndex":"0","from":"GENESIS","to":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","value":"10000000000000000000000","gas":"0","gasPrice":"0","isError":"0","txreceipt_status":"","input":"","contractAddress":"","cumulativeGasUsed":"0","gasUsed":"0","confirmations":"8355212"},{"blockNumber":"47884","timeStamp":"1438947953","hash":"0xad1c27dd8d0329dbc400021d7477b34ac41e84365bd54b45a4019a15deb10c0d","nonce":"0","blockHash":"0xf2988b9870e092f2898662ccdbc06e0e320a08139e9c6be98d0ce372f8611f22","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x2910543af39aba0cd09dbb2d50200b3e800a63d2","value":"5000000000000000000","gas":"23000","gasPrice":"400000000000","isError":"0","txreceipt_status":"","input":"0x454e34354139455138","contractAddress":"","cumulativeGasUsed":"21612","gasUsed":"21612","confirmations":"8307328"},{"blockNumber":"47894","timeStamp":"1438948043","hash":"0x7e1503d2001cab2f432b56a62a3ee874782c8e33cbd79a664d155a758c1784a2","nonce":"1","blockHash":"0x2d0a9228f22fe85596d246040d4fd7dc6b1a55920bae02b68e731d55a890b315","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x2910543af39aba0cd09dbb2d50200b3e800a63d2","value":"9001000000000000000000","gas":"23000","gasPrice":"400000000000","isError":"0","txreceipt_status":"","input":"0x454e34354139455138","contractAddress":"","cumulativeGasUsed":"21612","gasUsed":"21612","confirmations":"8307318"},{"blockNumber":"49099","timeStamp":"1438968015","hash":"0xfa73feae5798f97ad1f2c01fa70424f90f2f4fa81d6fe9698bc4db2690b635fe","nonce":"2","blockHash":"0xc7e6738277354d82421c8430929c8566c4cac80ce8b2c15512dd226b1f47f146","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x2910543af39aba0cd09dbb2d50200b3e800a63d2","value":"5000000000000000000","gas":"23000","gasPrice":"500000000000","isError":"0","txreceipt_status":"","input":"0x454e34354139455138","contractAddress":"","cumulativeGasUsed":"21612","gasUsed":"21612","confirmations":"8306113"},{"blockNumber":"49109","timeStamp":"1438968167","hash":"0xb4b836183334510812525c79ee13722783452716f77b3fd5e4b1ec5a21f7a81e","nonce":"3","blockHash":"0x7549887277630a31450d802a944e8f28397b1e1f15867b6c75633675323633e4","transactionIndex":"2","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x2910543af39aba0cd09dbb2d50200b3e800a63d2","value":"988950000000000000000","gas":"23000","gasPrice":"500000000000","isError":"0","txreceipt_status":"","input":"0x454e34354139455138","contractAddress":"","cumulativeGasUsed":"64836","gasUsed":"21612","confirmations":"8306103"},{"blockNumber":"101773","timeStamp":"1439827863","hash":"0x70bc1a43c9e80caae6b69fe845ba1567826413a8e42d020837c3b09f9cad11c2","nonce":"5","blockHash":"0xe802363e95a7e4700058c64f308ff726eba63ec7a40083e65a0c8dd9124578fe","transactionIndex":"5","from":"0x1a56a50c378d21d0aa544ed9a482300c7f6e78ec","to":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","value":"84512559000000000000000","gas":"21000","gasPrice":"100000000000","isError":"0","txreceipt_status":"","input":"0x","contractAddress":"","cumulativeGasUsed":"126000","gasUsed":"21000","confirmations":"8253439"},{"blockNumber":"269968","timeStamp":"1442872420","hash":"0xf0ee803e146465fcebfe092041e187920832a474b1c989b36eee7e0dc6b3f09c","nonce":"4","blockHash":"0x4b55bddbcea00085a00903c0ddb31c2933923054a5f8ff080ec8a8bab2a33e1d","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0xc98756f014149787cee4f74328c4925dc0ce9779","value":"700000000000000000000","gas":"21000","gasPrice":"300000000000","isError":"0","txreceipt_status":"","input":"0x","contractAddress":"","cumulativeGasUsed":"21000","gasUsed":"21000","confirmations":"8085244"},{"blockNumber":"288379","timeStamp":"1443187492","hash":"0xda7d393b4995cec859e1fbcdb39dfc756e08b7efb17a658988bc6688fbccbc51","nonce":"5","blockHash":"0x65aaef94de624a53bc14c87d9a8aa668e50413ccfa2b3c9049befbba2084121b","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x4b321f615455ca04969c5057f459a4dad42781ab","value":"5001000000000000000000","gas":"21000","gasPrice":"300000000000","isError":"0","txreceipt_status":"","input":"0x","contractAddress":"","cumulativeGasUsed":"21000","gasUsed":"21000","confirmations":"8066833"},{"blockNumber":"301131","timeStamp":"1443411359","hash":"0x66c11e721b0651c51524f63c085b342efa4a588b4a020530b44e2040242b95bd","nonce":"6","blockHash":"0x0fa3050e11114f71e88182877adf98c1c32ef714ff4dee2bd9c520d09fc5b65a","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x4c3e0e3c46a5b7222060b774206c92f9cd60d338","value":"7000000000000000000000","gas":"21000","gasPrice":"300000000000","isError":"0","txreceipt_status":"","input":"0x","contractAddress":"","cumulativeGasUsed":"21000","gasUsed":"21000","confirmations":"8054081"},{"blockNumber":"305627","timeStamp":"1443493144","hash":"0xfba2e114f7c0d2b365c8af80e5206c6554e4a48e2001f61eaa4bf34ee79d9c30","nonce":"7","blockHash":"0xbbd6eea24bb6fd1fe7359a937c216665e396c5c80acadf833d50e0f622d0272e","transactionIndex":"0","from":"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a","to":"0x7e2592a940d9e751a98dd2dcc80d65935ec5b6c7","value":"5000000000000000000000","gas":"21000","gasPrice":"300000000000","isError":"0","txreceipt_status":"","input":"0x","contractAddress":"","cumulativeGasUsed":"21000","gasUsed":"21000","confirmations":"8049585"}]}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp