Skip to content

Commit 0e42a2a

Browse files
committed
[dev] add test case
1 parent c677ea8 commit 0e42a2a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

error_wrap_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018 LI Zhennan
3+
*
4+
* Use of this work is governed by a MIT License.
5+
* You may find a license copy in project root.
6+
*/
7+
8+
package etherscan
9+
10+
import (
11+
"errors"
12+
"testing"
13+
)
14+
15+
func Test_wrapfErr(t *testing.T) {
16+
const ans = "status 100: continue test"
17+
18+
err := errors.New("continue test")
19+
err = wrapfErr(err, "%s %v", "status", "100")
20+
21+
if err.Error() != ans {
22+
t.Fatalf("got %v, want %s", err, ans)
23+
}
24+
}

helper_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2018 LI Zhennan
3+
*
4+
* Use of this work is governed by a MIT License.
5+
* You may find a license copy in project root.
6+
*/
7+
8+
package etherscan
9+
10+
import (
11+
"math/big"
12+
"testing"
13+
"time"
14+
)
15+
16+
func TestBigInt(t *testing.T) {
17+
const ansStr = "255"
18+
var ans = big.NewInt(255)
19+
20+
b := new(BigInt)
21+
err := b.UnmarshalText([]byte(ansStr))
22+
noError(t, err, "BigInt.UnmarshalText")
23+
24+
if b.Int().Cmp(ans) != 0 {
25+
t.Fatalf("BigInt.UnmarshalText not working, got %v, want %v", b.Int(), ans)
26+
}
27+
textBytes, err := b.MarshalText()
28+
noError(t, err, "BigInt.MarshalText")
29+
30+
if string(textBytes) != ansStr {
31+
t.Fatalf("BigInt.MarshalText not working, got %s, want %s", textBytes, ansStr)
32+
}
33+
}
34+
35+
func TestTime(t *testing.T) {
36+
const ansStr = "1533396289"
37+
var ans = time.Unix(1533396289, 0)
38+
39+
b := new(Time)
40+
err := b.UnmarshalText([]byte(ansStr))
41+
noError(t, err, "Time.UnmarshalText")
42+
43+
if !b.Time().Equal(ans) {
44+
t.Fatalf("Time.UnmarshalText not working, got %v, want %v", b, ans)
45+
}
46+
textBytes, err := b.MarshalText()
47+
noError(t, err, "BigInt.MarshalText")
48+
49+
if string(textBytes) != ansStr {
50+
t.Fatalf("Time.MarshalText not working, got %s, want %s", textBytes, ansStr)
51+
}
52+
}

0 commit comments

Comments
 (0)