-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils_test.go
151 lines (147 loc) · 3.69 KB
/
utils_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
package ethNotification
import (
"math/big"
"reflect"
"testing"
"time"
)
func TestParseInputTx(t *testing.T) {
type args struct {
input string
decimals int8
}
tests := []struct {
name string
args args
want *InputData
}{
{
"Test case 1: Transaction VECHAIN",
args{
input: "0xa9059cbb00000000000000000000000019bbb1c4407dcee04059682949f32cb3b513bf7600000000000000000000000000000000000000000000043c2b2187680e25a000",
decimals: 18,
},
&InputData{
ToAddress: "19bbb1c4407dcee04059682949f32cb3b513bf76",
Value: "19999378490000000000000",
ValueWithDecimals: "19999.37849",
MethodID: "0xa9059cbb",
},
},
{
"Test case 2: Transaction Bytom",
args{
input: "0xa9059cbb000000000000000000000000f8e2f119e4c9f5bd939cad8ba59dbbf68af109490000000000000000000000000000000000000000000000000000022d191fac50",
decimals: 8,
},
&InputData{
ToAddress: "f8e2f119e4c9f5bd939cad8ba59dbbf68af10949",
Value: "2392718290000",
ValueWithDecimals: "23927.1829",
MethodID: "0xa9059cbb",
},
},
{
"Test case 3: Transaction",
args{
input: "0xa9059cbb000000000000000000000000af654d6b7254746edb974fe292d36fc8f9da10eb000000000000000000000000000000000000000000000000117c6b5300fe0000",
decimals: 18,
},
&InputData{
ToAddress: "af654d6b7254746edb974fe292d36fc8f9da10eb",
Value: "1260000000000000000",
ValueWithDecimals: "1.26",
MethodID: "0xa9059cbb",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseInputTx(tt.args.input, tt.args.decimals); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseInputTx() = %v, want %v", got, tt.want)
}
})
}
}
func TestCoinToNumberInString(t *testing.T) {
bigIntTest0 := big.NewInt(19831202373)
bigIntTest1, _ := new(big.Int).SetString("198312023182371823973", 10)
bigIntTest2, _ := new(big.Int).SetString("49820000000000000000", 10)
BigIntTest := []*big.Int{
bigIntTest0,
bigIntTest1,
bigIntTest2,
}
type args struct {
value *big.Int
decimal int
number_precision int
}
tests := []struct {
name string
args args
want string
}{
{"Test case 0",
args{
value: BigIntTest[0],
decimal: 8,
number_precision: 5,
},
"198.31",
},
{"Test case 1",
args{
value: BigIntTest[1],
decimal: 18,
number_precision: 5,
},
"198.31",
},
{"Test case 2",
args{
value: BigIntTest[2],
decimal: 18,
number_precision: 4,
},
"49.82",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
start := time.Now()
got := CoinToNumberInString(tt.args.value, tt.args.decimal, tt.args.number_precision)
t.Log(time.Now().Sub(start))
if got != tt.want {
t.Errorf("CoinToNumberInString() = %v, want %v", got, tt.want)
}
t.Log(got)
})
}
}
func TestConvertInputValueWithDecimal(t *testing.T) {
type args struct {
valStr string
decimals int8
}
tests := []struct {
name string
args args
want string
}{
{"Test case 1", args{"19999378490000000000000", 18}, "19999.37849"},
{"Test case 2", args{"0.000", 3}, "0"},
{"Test case 3", args{"0", 5}, "0"},
{"Test case 4", args{"8000", 8}, "0.0008"},
{"Test case 5", args{"9000", 4}, "0.9"},
{"Test case 6", args{"91237123", 0}, "91237123"},
{"Test case 7", args{"72000", 3}, "72"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ConvertInputValueWithDecimal(tt.args.valStr, tt.args.decimals); got != tt.want {
t.Errorf("ConvertInputValueWithDecimal() = %v, want %v", got, tt.want)
}
})
}
}