forked from metachris/flashbotsrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types_test.go
174 lines (149 loc) · 7.62 KB
/
types_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package flashxroute
import (
"encoding/json"
"math/big"
"testing"
"github.com/stretchr/testify/require"
)
func TestHexIntUnmarshal(t *testing.T) {
test := struct {
ID hexInt `json:"id"`
}{}
data := []byte(`{"id": "0x1cc348"}`)
err := json.Unmarshal(data, &test)
require.Nil(t, err)
require.Equal(t, hexInt(1885000), test.ID)
}
func TestHexBigUnmarshal(t *testing.T) {
test := struct {
ID hexBig `json:"id"`
}{}
data := []byte(`{"id": "0x51248487c7466b7062d"}`)
err := json.Unmarshal(data, &test)
require.Nil(t, err)
b := big.Int{}
b.SetString("23949082357483433297453", 10)
require.Equal(t, hexBig(b), test.ID)
}
func TestSyncingUnmarshal(t *testing.T) {
syncing := new(Syncing)
err := json.Unmarshal([]byte("0"), syncing)
require.NotNil(t, err)
data := []byte(`{
"startingBlock": "0x384",
"currentBlock": "0x386",
"highestBlock": "0x454"
}`)
err = json.Unmarshal(data, syncing)
require.Nil(t, err)
require.True(t, syncing.IsSyncing)
require.Equal(t, 900, syncing.StartingBlock)
require.Equal(t, 902, syncing.CurrentBlock)
require.Equal(t, 1108, syncing.HighestBlock)
}
func TestTransactionUnmarshal(t *testing.T) {
tx := new(Transaction)
err := json.Unmarshal([]byte("111"), tx)
require.NotNil(t, err)
data := []byte(`{
"blockHash": "0x3003694478c108eaec173afcb55eafbb754a0b204567329f623438727ffa90d8",
"blockNumber": "0x83319",
"from": "0x201354729f8d0f8b64e9a0c353c672c6a66b3857",
"gas": "0x15f90",
"gasPrice": "0x4a817c800",
"hash": "0xfc7dcd42eb0b7898af2f52f7c5af3bd03cdf71ab8b3ed5b3d3a3ff0d91343cbe",
"input": "0xe1fa8e8425f1af44eb895e4900b8be35d9fdc28744a6ef491c46ec8601990e12a58af0ed",
"nonce": "0x6ba1",
"to": "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf",
"transactionIndex": "0x3",
"value": "0x0"
}`)
err = json.Unmarshal(data, tx)
require.Nil(t, err)
require.Equal(t, "0x3003694478c108eaec173afcb55eafbb754a0b204567329f623438727ffa90d8", tx.BlockHash)
require.Equal(t, 537369, *tx.BlockNumber)
require.Equal(t, "0x201354729f8d0f8b64e9a0c353c672c6a66b3857", tx.From)
require.Equal(t, 90000, tx.Gas)
require.Equal(t, *big.NewInt(20000000000), tx.GasPrice)
require.Equal(t, "0xfc7dcd42eb0b7898af2f52f7c5af3bd03cdf71ab8b3ed5b3d3a3ff0d91343cbe", tx.Hash)
require.Equal(t, "0xe1fa8e8425f1af44eb895e4900b8be35d9fdc28744a6ef491c46ec8601990e12a58af0ed", tx.Input)
require.Equal(t, 27553, tx.Nonce)
require.Equal(t, "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf", tx.To)
require.Equal(t, 3, *tx.TransactionIndex)
require.Equal(t, *big.NewInt(0), tx.Value)
}
func TestLogUnmarshal(t *testing.T) {
log := new(Log)
err := json.Unmarshal([]byte("111"), log)
require.NotNil(t, err)
data := []byte(`{
"address": "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf",
"topics": ["0x78e4fc71ff7e525b3b4660a76336a2046232fd9bba9c65abb22fa3d07d6e7066"],
"data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x7f2cd",
"blockHash": "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7",
"transactionIndex": "0x1",
"transactionHash": "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69",
"logIndex": "0x6",
"removed": false
}`)
err = json.Unmarshal(data, log)
require.Nil(t, err)
require.Equal(t, "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf", log.Address)
require.Equal(t, []string{"0x78e4fc71ff7e525b3b4660a76336a2046232fd9bba9c65abb22fa3d07d6e7066"}, log.Topics)
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", log.Data)
require.Equal(t, 520909, log.BlockNumber)
require.Equal(t, "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7", log.BlockHash)
require.Equal(t, 1, log.TransactionIndex)
require.Equal(t, "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69", log.TransactionHash)
require.Equal(t, 6, log.LogIndex)
require.Equal(t, false, log.Removed)
}
func TestTransactionReceiptUnmarshal(t *testing.T) {
receipt := new(TransactionReceipt)
err := json.Unmarshal([]byte("[1]"), receipt)
require.NotNil(t, err)
data := []byte(`{
"blockHash": "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7",
"blockNumber": "0x7f2cd",
"contractAddress": null,
"cumulativeGasUsed": "0x13356",
"gasUsed": "0x6384",
"logs": [{
"address": "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf",
"topics": ["0x78e4fc71ff7e525b3b4660a76336a2046232fd9bba9c65abb22fa3d07d6e7066"],
"data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber": "0x7f2cd",
"blockHash": "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7",
"transactionIndex": "0x1",
"transactionHash": "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69",
"logIndex": "0x6",
"removed": false
}],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000020000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000",
"root": "0xe367ea197d629892e7b25ea246fba93cd8ae053d468cc5997a816cc85d660321",
"transactionHash": "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69",
"transactionIndex": "0x1"
}`)
err = json.Unmarshal(data, receipt)
require.Nil(t, err)
require.Equal(t, 1, len(receipt.Logs))
require.Equal(t, "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7", receipt.BlockHash)
require.Equal(t, 520909, receipt.BlockNumber)
require.Equal(t, "", receipt.ContractAddress)
require.Equal(t, 78678, receipt.CumulativeGasUsed)
require.Equal(t, 25476, receipt.GasUsed)
require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000020000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000", receipt.LogsBloom)
require.Equal(t, "0xe367ea197d629892e7b25ea246fba93cd8ae053d468cc5997a816cc85d660321", receipt.Root)
require.Equal(t, "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69", receipt.TransactionHash)
require.Equal(t, 1, receipt.TransactionIndex)
require.Equal(t, "0xd10e3be2bc8f959bc8c41cf65f60de721cf89adf", receipt.Logs[0].Address)
require.Equal(t, []string{"0x78e4fc71ff7e525b3b4660a76336a2046232fd9bba9c65abb22fa3d07d6e7066"}, receipt.Logs[0].Topics)
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", receipt.Logs[0].Data)
require.Equal(t, 520909, receipt.Logs[0].BlockNumber)
require.Equal(t, "0x3757b6efd7f82e3a832f0ec229b2fa36e622033ae7bad76b95763055a69374f7", receipt.Logs[0].BlockHash)
require.Equal(t, 1, receipt.Logs[0].TransactionIndex)
require.Equal(t, "0xecd8a21609fa852c08249f6c767b7097481da34b9f8d2aae70067918955b4e69", receipt.Logs[0].TransactionHash)
require.Equal(t, 6, receipt.Logs[0].LogIndex)
require.Equal(t, false, receipt.Logs[0].Removed)
}