-
Notifications
You must be signed in to change notification settings - Fork 1
/
tron_test.go
161 lines (121 loc) · 3.84 KB
/
tron_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package ethcli_test
import (
"github.com/medeirosfalante/ethcli/tron"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"math/big"
"testing"
)
const (
TestGrpcAddress = "47.252.19.181:50051"
TestMnemonic = "crunch goat helmet buddy metal crowd fish rack entire glare job milk call wish protect"
)
func TestTronClient_IsTRC10(t *testing.T) {
client, err := tron.NewTronClient(TestGrpcAddress, grpc.WithInsecure())
if err != nil {
t.Fatalf("err %s", err.Error())
}
t.Run("must not return an error", func(t *testing.T) {
ok := client.IsTRC10("1000016")
assert.Equal(t, true, ok)
})
t.Run("must return an error", func(t *testing.T) {
ok := client.IsTRC10("TRYCsQN7mfyCVYvXQuc2LTAUC4EDxDMoMJ")
assert.Equal(t, false, ok)
})
}
func TestTronClient_Transfer(t *testing.T) {
client, err := tron.NewTronClient(TestGrpcAddress, grpc.WithInsecure())
if err != nil {
t.Fatalf("err %s", err.Error())
}
tronAccount, err := tron.NewTronAccount(TestMnemonic, "0")
assert.NoError(t, err)
assert.NotEmpty(t, tronAccount)
t.Run("Must not return an error on send Native coin", func(t *testing.T) {
tx, err := client.Transfer(&tron.TransferOpts{
From: tronAccount.PublicKey(),
PrivKey: tronAccount.PrivateKey(),
To: "TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX",
Amount: big.NewInt(1e2),
})
assert.NoError(t, err)
assert.NotEqual(t, "", tx)
})
t.Run("Must not return an error on send TRC10", func(t *testing.T) {
tokenID := "1000016"
tx, err := client.Transfer(&tron.TransferOpts{
From: tronAccount.PublicKey(),
PrivKey: tronAccount.PrivateKey(),
To: "TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX",
Amount: big.NewInt(1e2),
TokenID: &tokenID,
})
assert.NoError(t, err)
assert.NotEqual(t, "", tx)
})
t.Run("Must not return an error on send TRC20", func(t *testing.T) {
tokenID := "TU2T8vpHZhCNY8fXGVaHyeZrKm8s6HEXWe"
tx, err := client.Transfer(&tron.TransferOpts{
From: tronAccount.PublicKey(),
PrivKey: tronAccount.PrivateKey(),
To: "TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX",
Amount: big.NewInt(1e1),
TokenID: &tokenID,
})
assert.NoError(t, err)
assert.NotEqual(t, "", tx)
})
t.Run("Must return an error because token id is invalid", func(t *testing.T) {
tokenID := "10000164654654"
tx, err := client.Transfer(&tron.TransferOpts{
From: tronAccount.PublicKey(),
PrivKey: tronAccount.PrivateKey(),
To: "TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX",
Amount: big.NewInt(1e1),
TokenID: &tokenID,
})
assert.Error(t, err)
assert.Empty(t, tx)
})
t.Run("Must return an error because token contract address is invalid", func(t *testing.T) {
tokenID := "10000164654654"
tx, err := client.Transfer(&tron.TransferOpts{
From: tronAccount.PublicKey(),
PrivKey: tronAccount.PrivateKey(),
To: "TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX",
Amount: big.NewInt(1e1),
TokenID: &tokenID,
})
assert.Error(t, err)
assert.Empty(t, tx)
})
}
func TestTronClient_Balance(t *testing.T) {
client, err := tron.NewTronClient(TestGrpcAddress, grpc.WithInsecure())
if err != nil {
t.Fatalf("err %s", err.Error())
}
balance, err := client.Balance("TVvxthSkGf4FGd8B5C2JQdQYPprSQgSvJX")
assert.NoError(t, err)
assert.NotNil(t, balance)
}
func TestTronClient_TokenBalance(t *testing.T) {
client, err := tron.NewTronClient(TestGrpcAddress, grpc.WithInsecure())
if err != nil {
t.Fatalf("err %s", err.Error())
}
balance, err := client.TokenBalance("TYyxg8cPoR1uWh7aJUqShikruPvnJfv1e9",
"1002413")
assert.NoError(t, err)
assert.NotNil(t, balance)
}
func TestTronClient_AccountBalance(t *testing.T) {
client, err := tron.NewTronClient(TestGrpcAddress, grpc.WithInsecure())
if err != nil {
t.Fatalf("err %s", err.Error())
}
balance, err := client.AccountBalance("TYyxg8cPoR1uWh7aJUqShikruPvnJfv1e9")
assert.NoError(t, err)
assert.NotNil(t, balance)
}