|
| 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