-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
tokenbalance_test.go
96 lines (83 loc) · 2.57 KB
/
tokenbalance_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package tokenbalance
import (
"github.com/stretchr/testify/assert"
"math/big"
"os"
"testing"
)
func TestFailedConnection(t *testing.T) {
c := &Config{
GethLocation: "https://google.com",
Logs: true,
}
err := c.Connect()
assert.Error(t, err)
}
func TestFailingNoConfig(t *testing.T) {
_, err := New("0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", "0x42d4722b804585cdf6406fa7739e794b0aa8b1ff")
assert.Error(t, err)
}
func TestConnection(t *testing.T) {
c := &Config{
GethLocation: os.Getenv("ETH"),
Logs: true,
}
err := c.Connect()
assert.Nil(t, err)
}
func TestZeroDecimal(t *testing.T) {
number := big.NewInt(123456789)
tokenCorrected := bigIntString(number, 0)
assert.Equal(t, "123456789", tokenCorrected)
}
func TestZeroBalance(t *testing.T) {
number := big.NewInt(0)
tokenCorrected := bigIntString(number, 18)
assert.Equal(t, "0.0", tokenCorrected)
}
func TestFormatDecimal(t *testing.T) {
number := big.NewInt(0)
number.SetString("72094368689712", 10)
tokenCorrected := bigIntString(number, 18)
assert.Equal(t, "0.000072094368689712", tokenCorrected)
}
func TestFormatSmallDecimal(t *testing.T) {
number := big.NewInt(0)
number.SetString("123", 10)
tokenCorrected := bigIntString(number, 18)
assert.Equal(t, "0.000000000000000123", tokenCorrected)
}
func TestFormatVerySmallDecimal(t *testing.T) {
number := big.NewInt(0)
number.SetString("1142400000000001", 10)
tokenCorrected := bigIntString(number, 18)
assert.Equal(t, "0.001142400000000001", tokenCorrected)
}
func TestFailedNewTokenBalance(t *testing.T) {
_, err := New("0x42D4722B804585CDf6406fa7739e794b0Aa8b1FF", "0x42d4722b804585cdf6406fa7739e794b0aa8b1ff")
assert.Error(t, err)
}
func TestSymbolFix(t *testing.T) {
symbol := symbolFix("0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0")
assert.Equal(t, "EOS", symbol)
}
func TestTokenBalance_ToJSON(t *testing.T) {
symbol := symbolFix("0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0")
assert.Equal(t, "EOS", symbol)
}
func TestNewTokenBalance(t *testing.T) {
c := &Config{
GethLocation: os.Getenv("ETH"),
Logs: true,
}
err := c.Connect()
assert.Nil(t, err)
tb, err := New("0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", "0x42d4722b804585cdf6406fa7739e794b0aa8b1ff")
assert.Nil(t, err)
assert.Equal(t, "0x42D4722B804585CDf6406fa7739e794b0Aa8b1FF", tb.Wallet.String())
assert.Equal(t, "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", tb.Contract.String())
assert.Equal(t, "600000.0", tb.BalanceString())
assert.Equal(t, "1.020095885777777767", tb.ETHString())
assert.Equal(t, int64(18), tb.Decimals)
assert.Equal(t, "OMG", tb.Symbol)
}