-
Notifications
You must be signed in to change notification settings - Fork 106
/
helpers_test.go
51 lines (39 loc) · 1.08 KB
/
helpers_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
package ethrpc
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseInt(t *testing.T) {
i, err := ParseInt("0x143")
assert.Nil(t, err)
assert.Equal(t, 323, i)
i, err = ParseInt("143")
assert.Nil(t, err)
assert.Equal(t, 323, i)
i, err = ParseInt("0xaaa")
assert.Nil(t, err)
assert.Equal(t, 2730, i)
i, err = ParseInt("1*29")
assert.NotNil(t, err)
assert.Equal(t, 0, i)
}
func TestParseBigInt(t *testing.T) {
i, err := ParseBigInt("0xabc")
assert.Nil(t, err)
assert.Equal(t, int64(2748), i.Int64())
i, err = ParseBigInt("$%1")
assert.NotNil(t, err)
}
func TestIntToHex(t *testing.T) {
assert.Equal(t, "0xde0b6b3a7640000", IntToHex(1000000000000000000))
assert.Equal(t, "0x6f", IntToHex(111))
}
func TestBigToHex(t *testing.T) {
i1, _ := big.NewInt(0).SetString("1000000000000000000", 10)
assert.Equal(t, "0xde0b6b3a7640000", BigToHex(*i1))
i2, _ := big.NewInt(0).SetString("100000000000000000000", 10)
assert.Equal(t, "0x56bc75e2d63100000", BigToHex(*i2))
i3, _ := big.NewInt(0).SetString("0", 10)
assert.Equal(t, "0x0", BigToHex(*i3))
}