-
Notifications
You must be signed in to change notification settings - Fork 1
/
structs_marshal_test.go
66 lines (60 loc) · 1.4 KB
/
structs_marshal_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
package web3
import (
"encoding/json"
"math/big"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
const (
addr0 = "0x0000000000000000000000000000000000000000"
)
func cleanStr(str string) string {
str = strings.Replace(str, " ", "", -1)
str = strings.Replace(str, "\n", "", -1)
str = strings.Replace(str, "\t", "", -1)
return str
}
func TestMarshal(t *testing.T) {
cases := []struct {
Input json.Marshaler
Result string
}{
{
Input: &Transaction{},
Result: `{
"from": "` + addr0 + `",
"hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasPrice": "0x0",
"gas": "0x0",
"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber":"0x0",
"nonce":"0x0",
"transactionIndex":"0x0"
}`,
},
{
Input: &Transaction{
GasPrice: 100,
Gas: 50,
Value: big.NewInt(100),
},
Result: `{
"from": "` + addr0 + `",
"hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasPrice": "0x64",
"gas": "0x32",
"value": "0x64",
"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber":"0x0",
"nonce":"0x0",
"transactionIndex":"0x0"
}`,
},
}
for _, c := range cases {
raw, err := c.Input.MarshalJSON()
assert.NoError(t, err)
assert.Equal(t, string(raw), cleanStr(c.Result))
}
}