-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
helper_test.go
52 lines (42 loc) · 1.15 KB
/
helper_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
/*
* Copyright (c) 2018 LI Zhennan
*
* Use of this work is governed by a MIT License.
* You may find a license copy in project root.
*/
package etherscan
import (
"math/big"
"testing"
"time"
)
func TestBigInt(t *testing.T) {
const ansStr = "255"
var ans = big.NewInt(255)
b := new(BigInt)
err := b.UnmarshalText([]byte(ansStr))
noError(t, err, "BigInt.UnmarshalText")
if b.Int().Cmp(ans) != 0 {
t.Fatalf("BigInt.UnmarshalText not working, got %v, want %v", b.Int(), ans)
}
textBytes, err := b.MarshalText()
noError(t, err, "BigInt.MarshalText")
if string(textBytes) != ansStr {
t.Fatalf("BigInt.MarshalText not working, got %s, want %s", textBytes, ansStr)
}
}
func TestTime(t *testing.T) {
const ansStr = "1533396289"
var ans = time.Unix(1533396289, 0)
b := new(Time)
err := b.UnmarshalText([]byte(ansStr))
noError(t, err, "Time.UnmarshalText")
if !b.Time().Equal(ans) {
t.Fatalf("Time.UnmarshalText not working, got %v, want %v", b, ans)
}
textBytes, err := b.MarshalText()
noError(t, err, "BigInt.MarshalText")
if string(textBytes) != ansStr {
t.Fatalf("Time.MarshalText not working, got %s, want %s", textBytes, ansStr)
}
}