1
+ package jfyg.data.transaction
2
+
3
+ import com.google.gson.Gson
4
+ import com.google.gson.GsonBuilder
5
+ import jfyg.network.response.BaseResponse
6
+ import jfyg.network.response.transaction.TxContractExecutionResponse
7
+ import jfyg.network.response.transaction.TxContractReceiptResponse
8
+ import org.junit.Assert
9
+ import org.junit.Test
10
+
11
+ import org.junit.Before
12
+
13
+ /* *
14
+ * https://etherscan.io/apis#transactions
15
+ */
16
+ class TransactionsTest {
17
+ lateinit var gson: Gson
18
+
19
+ private val inputBadResponse = """
20
+ {
21
+ "status": "0",
22
+ "message": "NOTOK",
23
+ "result": "Error!"
24
+ }"""
25
+
26
+ private val txExecutionStatus = """
27
+ {
28
+ "status": "1",
29
+ "message": "OK",
30
+ "result": {
31
+ "isError": "1",
32
+ "errDescription": "Bad jump destination"
33
+ }}"""
34
+
35
+ private val txReceiptStatus = """
36
+ {
37
+ "status": "1",
38
+ "message": "OK",
39
+ "result": {
40
+ "status": "1"
41
+ }}"""
42
+
43
+ @Before
44
+ fun setUp () {
45
+ val gb = GsonBuilder ()
46
+ gson = gb.create()
47
+ }
48
+
49
+ @Test
50
+ fun getTxExecutionStatus () {
51
+ val response = gson.fromJson(txExecutionStatus, TxContractExecutionResponse ::class .java)
52
+ Assert .assertEquals(" 1" , response.result.isError)
53
+ Assert .assertEquals(" Bad jump destination" , response.result.errDescription)
54
+
55
+ }
56
+
57
+ @Test
58
+ fun getTxReceiptStatus () {
59
+ val response = gson.fromJson(txReceiptStatus, TxContractReceiptResponse ::class .java)
60
+ Assert .assertEquals(" 1" , response.result.status)
61
+ }
62
+
63
+ @Test
64
+ fun networkStatusIsDown () {
65
+ val response = gson.fromJson(inputBadResponse, BaseResponse ::class .java)
66
+ Assert .assertEquals(" 0" , response.status)
67
+ }
68
+
69
+ @Test
70
+ fun networkStatusIsUp () {
71
+ val response = gson.fromJson(inputBadResponse, BaseResponse ::class .java)
72
+ Assert .assertNotEquals(" 1" , response.status)
73
+ }
74
+
75
+ @Test
76
+ fun networkMessageNotOk () {
77
+ val response = gson.fromJson(inputBadResponse, BaseResponse ::class .java)
78
+ Assert .assertEquals(" NOTOK" , response.message)
79
+ }
80
+
81
+ @Test
82
+ fun networkMessageOk () {
83
+ val response = gson.fromJson(inputBadResponse, BaseResponse ::class .java)
84
+ Assert .assertNotEquals(" OK" , response.message)
85
+ }
86
+ }
0 commit comments