forked from umbracle/ethgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs_unmarshal_test.go
71 lines (65 loc) · 1.41 KB
/
structs_unmarshal_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
package web3
import (
"encoding/json"
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
var (
hash1 = Hash{0x1}
hash2 = Hash{0x2}
hash3 = Hash{0x3}
addr1 = Address{0x1}
)
func TestUnmarshalBlock(t *testing.T) {
cases := []struct {
Input string
Result interface{}
}{
{
Input: `{
"hash": "` + hash1.String() + `",
"parentHash": "` + hash2.String() + `",
"sha3Uncles": "` + hash3.String() + `",
"transactionsRoot": "` + hash1.String() + `",
"receiptsRoot": "` + hash2.String() + `",
"stateRoot": "` + hash3.String() + `",
"miner": "` + addr1.String() + `",
"number": "0x1",
"gasLimit": "0x2",
"gasUsed": "0x3",
"timestamp": "0x4",
"difficulty": "0x5",
"extraData": "0x01",
"uncles": [
"` + hash1.String() + `",
"` + hash2.String() + `"
]
}`,
Result: &Block{
Hash: hash1,
ParentHash: hash2,
Sha3Uncles: hash3,
TransactionsRoot: hash1,
ReceiptsRoot: hash2,
StateRoot: hash3,
Miner: addr1,
Number: 1,
GasLimit: 2,
GasUsed: 3,
Timestamp: 4,
Difficulty: big.NewInt(5),
ExtraData: []byte{0x1},
Uncles: []Hash{
hash1,
hash2,
},
},
},
}
for _, c := range cases {
var b *Block
assert.NoError(t, json.Unmarshal([]byte(c.Input), &b))
assert.Equal(t, b, c.Result)
}
}