forked from aptos-labs/aptos-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
75 lines (61 loc) · 1.83 KB
/
util_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
package aptos
import (
"github.com/stretchr/testify/assert"
"math/big"
"testing"
)
var testConfig = LocalnetConfig
// createTestClient to use for testing for only one place to configure the network
// TODO: Allow overrides with environment variable?
func createTestClient() (*Client, error) {
return NewClient(testConfig)
}
func TestSHA3_256Hash(t *testing.T) {
input := [][]byte{{0x1}, {0x2}, {0x3}}
expected, err := ParseHex("fd1780a6fc9ee0dab26ceb4b3941ab03e66ccd970d1db91612c66df4515b0a0a")
assert.NoError(t, err)
assert.Equal(t, expected, Sha3256Hash(input))
}
func TestParseHex(t *testing.T) {
// Last case is needed from the JSON API, as an empty array comes out as just 0x
inputs := []string{"0x012345", "012345", "0x"}
expected := [][]byte{{0x01, 0x23, 0x45}, {0x01, 0x23, 0x45}, {}}
for i, input := range inputs {
val, err := ParseHex(input)
assert.NoError(t, err)
assert.Equal(t, expected[i], val)
}
}
func TestBytesToHex(t *testing.T) {
inputs := [][]byte{{0x01, 0x23, 0x45}, {0x01}, {}}
expected := []string{"0x012345", "0x01", "0x"}
for i, input := range inputs {
val := BytesToHex(input)
assert.Equal(t, expected[i], val)
}
}
func TestStrToUint64(t *testing.T) {
inputs := []string{"0", "1", "100"}
expected := []uint64{0, 1, 100}
for i, input := range inputs {
val, err := StrToUint64(input)
assert.NoError(t, err)
assert.Equal(t, expected[i], val)
}
}
func TestStrToBigInt(t *testing.T) {
inputs := []string{"0", "1", "100"}
expected := []*big.Int{big.NewInt(0), big.NewInt(1), big.NewInt(100)}
for i, input := range inputs {
val, err := StrToBigInt(input)
assert.NoError(t, err)
assert.Equal(t, expected[i], val)
}
}
func TestStrToBigIntError(t *testing.T) {
inputs := []string{"hello", "1a", "", "0.01"}
for _, input := range inputs {
_, err := StrToBigInt(input)
assert.Error(t, err)
}
}