@@ -4,118 +4,123 @@ import com.google.gson.Gson
44import com.google.gson.GsonBuilder
55import jfyg.response.BaseResponse
66import jfyg.response.account.AccountBalanceResponse
7+ import jfyg.response.account.AccountBlockResponse
78import jfyg.response.account.AccountMultiBalanceResponse
9+ import jfyg.response.account.AccountTransactionResponse
810import org.junit.Assert.assertEquals
911import org.junit.Assert
1012import org.junit.Before
1113import org.junit.Test
1214
1315class AccountTest {
1416
15- val accountBalance = """
17+ lateinit var gson: Gson
18+
19+ private val accountBalance = """
20+ {
21+ "status": "1",
22+ "message": "OK",
23+ "result": "670456215218885498951364"
24+ }"""
25+
26+ private val accountMultiBalance = """
27+ {
28+ "status": "1",
29+ "message": "OK",
30+ "result": [
31+ {
32+ "account": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
33+ "balance": "40807168564070000000000"
34+ },
35+ {
36+ "account": "0x63a9975ba31b0b9626b34300f7f627147df1f526",
37+ "balance": "332567136222827062478"
38+ },
39+ {
40+ "account": "0x198ef1ec325a96cc354c7266a038be8b5c558f67",
41+ "balance": "0"
42+ }
43+ ]
44+ }"""
45+ private val accountBlocksMined = """
1646 {
17- "status": "1",
18- "message": "OK",
19- "result": "670456215218885498951364"
20- }"""
21-
22- val accountMultiBalance = """ {
23- "status": "1",
24- "message": "OK",
25- "result": [
26- {
27- "account": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
28- "balance": "40807168564070000000000"
29- },
30- {
31- "account": "0x63a9975ba31b0b9626b34300f7f627147df1f526",
32- "balance": "332567136222827062478"
33- },
34- {
35- "account": "0x198ef1ec325a96cc354c7266a038be8b5c558f67",
36- "balance": "0"
37- }
38- ]
39- }"""
40- val accountTransactions = """ {
41- "status": "1",
42- "message": "OK",
43- "result": [
44- {
45- "blockNumber": "5273167",
46- "timeStamp": "1521316197",
47- "hash": "0x308d39f4223154fdf2db3b803400dea0da7468592aded1c6e9c01fd35835f23f",
48- "nonce": "0",
49- "blockHash": "0x315ee5a947d4c7519bd817465711fbb0b56c8ecafc8d9766aef1350e83c41521",
50- "transactionIndex": "28",
51- "from": "0x047250bd5ac59e6c45473cc0036d71737c885f6a",
52- "to": "0x82e4499d4b2a669831a3881d61bb24f7b620c61a",
53- "value": "18034800000000000",
54- "gas": "21000",
55- "gasPrice": "4000000000",
56- "isError": "0",
57- "txreceipt_status": "1",
58- "input": "0x",
59- "contractAddress": "",
60- "cumulativeGasUsed": "1376343",
61- "gasUsed": "21000",
62- "confirmations": "150836"
63- },
64- {
65- "blockNumber": "5273704",
66- "timeStamp": "1521323646",
67- "hash": "0x55a6922f90f0fce43896b9b2239ddddd3f829fb06291724bfb4be6fcc895d202",
68- "nonce": "0",
69- "blockHash": "0xeb96c9b68ae66c42dbf35f323e66534858d88dd1b107f77bb2c65504140e9752",
70- "transactionIndex": "14",
71- "from": "0x4a7341f16107521adca5d24009e7c2d8829787d3",
72- "to": "0x82e4499d4b2a669831a3881d61bb24f7b620c61a",
73- "value": "53297010000000000",
74- "gas": "21000",
75- "gasPrice": "4000000000",
76- "isError": "0",
77- "txreceipt_status": "1",
78- "input": "0x",
79- "contractAddress": "",
80- "cumulativeGasUsed": "391843",
81- "gasUsed": "21000",
82- "confirmations": "150299"
83- }
84- ]
85- }"""
86- val accountBlocksMined = """ {
87- "status": "1",
88- "message": "OK",
89- "result": [
90- {
91- "blockNumber": "3462296",
92- "timeStamp": "1491118514",
93- "blockReward": "5194770940000000000"
94- },
95- {
96- "blockNumber": "2691400",
97- "timeStamp": "1480072029",
98- "blockReward": "5086562212310617100"
99- },
100- {
101- "blockNumber": "70606",
102- "timeStamp": "1439322608",
103- "blockReward": "5001164799033398000"
104- }
105- ]
106- }"""
107-
108- val inputBadResponse = """
47+ "status": "1",
48+ "message": "OK",
49+ "result": [
50+ {
51+ "blockNumber": "3462296",
52+ "timeStamp": "1491118514",
53+ "blockReward": "5194770940000000000"
54+ },
55+ {
56+ "blockNumber": "2691400",
57+ "timeStamp": "1480072029",
58+ "blockReward": "5086562212310617100"
59+ },
60+ {
61+ "blockNumber": "70606",
62+ "timeStamp": "1439322608",
63+ "blockReward": "5001164799033398000"
64+ }
65+ ]
66+ }"""
67+
68+ private val accountTransactions = """
69+ {
70+ "status": "1",
71+ "message": "OK",
72+ "result": [
73+ {
74+ "blockNumber": "5273167",
75+ "timeStamp": "1521316197",
76+ "hash": "0x308d39f4223154fdf2db3b803400dea0da7468592aded1c6e9c01fd35835f23f",
77+ "nonce": "0",
78+ "blockHash": "0x315ee5a947d4c7519bd817465711fbb0b56c8ecafc8d9766aef1350e83c41521",
79+ "transactionIndex": "28",
80+ "from": "0x047250bd5ac59e6c45473cc0036d71737c885f6a",
81+ "to": "0x82e4499d4b2a669831a3881d61bb24f7b620c61a",
82+ "value": "18034800000000000",
83+ "gas": "21000",
84+ "gasPrice": "4000000000",
85+ "isError": "0",
86+ "txreceipt_status": "1",
87+ "input": "0x",
88+ "contractAddress": "",
89+ "cumulativeGasUsed": "1376343",
90+ "gasUsed": "21000",
91+ "confirmations": "150836"
92+ },
93+ {
94+ "blockNumber": "5273704",
95+ "timeStamp": "1521323646",
96+ "hash": "0x55a6922f90f0fce43896b9b2239ddddd3f829fb06291724bfb4be6fcc895d202",
97+ "nonce": "0",
98+ "blockHash": "0xeb96c9b68ae66c42dbf35f323e66534858d88dd1b107f77bb2c65504140e9752",
99+ "transactionIndex": "14",
100+ "from": "0x4a7341f16107521adca5d24009e7c2d8829787d3",
101+ "to": "0x82e4499d4b2a669831a3881d61bb24f7b620c61a",
102+ "value": "53297010000000000",
103+ "gas": "21000",
104+ "gasPrice": "4000000000",
105+ "isError": "0",
106+ "txreceipt_status": "1",
107+ "input": "0x",
108+ "contractAddress": "",
109+ "cumulativeGasUsed": "391843",
110+ "gasUsed": "21000",
111+ "confirmations": "150299"
112+ }
113+ ]
114+ }"""
115+
116+ private val inputBadResponse = """
109117 {
110118 "status": "0",
111119 "message": "NOTOK",
112120 "result": "Error!"
113121 }"""
114122
115123
116- lateinit var gson: Gson
117-
118-
119124 @Before
120125 fun setUp () {
121126 val gb = GsonBuilder ()
@@ -132,16 +137,34 @@ class AccountTest {
132137 @Test
133138 fun getMultiBalance () {
134139 val response = gson.fromJson(accountMultiBalance, AccountMultiBalanceResponse ::class .java)
135- assertEquals(" 3" ,response.result?.size)
136- assertEquals(" 3" ,response.result)
140+ assertEquals(" 0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a" , response.result?.get(0 )?.account)
141+ assertEquals(" 40807168564070000000000" , response.result?.get(0 )?.balance)
142+ assertEquals(" 0x63a9975ba31b0b9626b34300f7f627147df1f526" , response.result?.get(1 )?.account)
143+ assertEquals(" 332567136222827062478" , response.result?.get(1 )?.balance)
144+ assertEquals(" 0x198ef1ec325a96cc354c7266a038be8b5c558f67" , response.result?.get(2 )?.account)
145+ assertEquals(" 0" , response.result?.get(2 )?.balance)
137146 }
138147
139148 @Test
140149 fun getBlocks () {
150+ val response = gson.fromJson(accountBlocksMined, AccountBlockResponse ::class .java)
151+ assertEquals(" 3462296" , response.result?.get(0 )?.blockNumber)
152+ assertEquals(" 1491118514" , response.result?.get(0 )?.timeStamp)
153+ assertEquals(" 5194770940000000000" , response.result?.get(0 )?.blockReward)
154+ assertEquals(" 2691400" , response.result?.get(1 )?.blockNumber)
155+ assertEquals(" 1480072029" , response.result?.get(1 )?.timeStamp)
156+ assertEquals(" 5086562212310617100" , response.result?.get(1 )?.blockReward)
141157 }
142158
143159 @Test
144160 fun getTransactions () {
161+ val response = gson.fromJson(accountTransactions, AccountTransactionResponse ::class .java)
162+ assertEquals(" 0x047250bd5ac59e6c45473cc0036d71737c885f6a" , response.result?.get(0 )?.transactionFrom)
163+ assertEquals(" 0x82e4499d4b2a669831a3881d61bb24f7b620c61a" , response.result?.get(0 )?.transactionTo)
164+ assertEquals(" 18034800000000000" , response.result?.get(0 )?.value)
165+ assertEquals(" 21000" , response.result?.get(1 )?.gas)
166+ assertEquals(" 4000000000" , response.result?.get(1 )?.gasPrice)
167+ assertEquals(" 0" , response.result?.get(1 )?.isError)
145168 }
146169
147170 @Test
0 commit comments