forked from umbracle/ethgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs_test.go
120 lines (108 loc) · 2.64 KB
/
structs_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
package ethgo
import (
_ "embed"
"encoding/json"
"math/big"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAddress_Checksum(t *testing.T) {
cases := []struct {
src, dst string
}{
{
"0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed",
"0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed",
},
{
"0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359",
"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359",
},
{
"0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb",
"0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB",
},
{
"0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb",
"0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
},
}
for _, c := range cases {
addr := HexToAddress(c.src)
assert.Equal(t, addr.String(), c.dst)
}
}
func TestAddress_HexToString(t *testing.T) {
assert.Equal(t, HexToAddress("0x1").String(), "0x0000000000000000000000000000000000000001")
assert.Equal(t, HexToAddress("00000000000000000000000000000000000000001").String(), "0x0000000000000000000000000000000000000001")
assert.Equal(t, HexToAddress("0000000000000000000000000000000000000001").String(), "0x0000000000000000000000000000000000000001")
}
func TestHash_HexToString(t *testing.T) {
assert.Equal(t, HexToHash("1").String(), "0x0000000000000000000000000000000000000000000000000000000000000001")
}
func TestBlock_Copy(t *testing.T) {
b := &Block{
Difficulty: big.NewInt(1),
Transactions: []*Transaction{},
ExtraData: []byte{0x1, 0x2},
}
b1 := b.Copy()
if !reflect.DeepEqual(b, b1) {
t.Fatal("incorrect block copy")
}
}
func TestTransaction_Copy(t *testing.T) {
txn := &Transaction{
GasPrice: 10,
Input: []byte{0x1, 0x2},
V: []byte{0x1, 0x2},
R: []byte{0x1, 0x2},
S: []byte{0x1, 0x2},
AccessList: AccessList{
AccessEntry{
Address: Address{0x1},
Storage: []Hash{
{0x1},
},
},
},
}
txn1 := txn.Copy()
if !reflect.DeepEqual(txn, txn1) {
t.Fatal("incorrect transaction")
}
}
func TestReceipt_Copy(t *testing.T) {
r := &Receipt{
LogsBloom: []byte{0x1, 0x2},
Logs: []*Log{
{LogIndex: 1, Topics: []Hash{{0x1}}},
},
GasUsed: 10,
}
rr := r.Copy()
if !reflect.DeepEqual(r, rr) {
t.Fatal("incorrect receipt")
}
}
func TestLog_Copy(t *testing.T) {
l := &Log{
Data: []byte{0x1, 0x2},
BlockHash: Hash{0x1},
}
ll := l.Copy()
if !reflect.DeepEqual(l, ll) {
t.Fatal("incorrect receipt")
}
}
//go:embed testsuite/receipts.json
var receiptsFixtures []byte
func TestReceipt_Unmarshal(t *testing.T) {
var cases []json.RawMessage
assert.NoError(t, json.Unmarshal(receiptsFixtures, &cases))
for _, c := range cases {
receipt := &Receipt{}
assert.NoError(t, receipt.UnmarshalJSON(c))
}
}