-
Notifications
You must be signed in to change notification settings - Fork 1
/
finney_test.go
134 lines (125 loc) · 3.25 KB
/
finney_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
package unit
import (
"math/big"
"reflect"
"testing"
)
func TestNewFinney(t *testing.T) {
type args struct {
value *big.Float
}
ether10, _ := new(big.Int).SetString("10000000000000000000", 10)
ether100, _ := new(big.Int).SetString("100000000000000000000", 10)
ether1000, _ := new(big.Int).SetString("1000000000000000000000", 10)
ether10000000, _ := new(big.Int).SetString("10000000000000000000000000", 10)
tests := []struct {
name string
args args
want *Unit
}{
{
name: "0.0001 ether",
args: args{value: big.NewFloat(0.1)},
want: &Unit{Value: big.NewInt(100000000000000)},
},
{
name: "0.1 ether",
args: args{value: big.NewFloat(100)},
want: &Unit{Value: big.NewInt(100000000000000000)},
},
{
name: "1 ether",
args: args{value: big.NewFloat(1000)},
want: &Unit{Value: big.NewInt(1000000000000000000)},
},
{
name: "10 ether",
args: args{value: big.NewFloat(10000)},
want: &Unit{Value: ether10},
},
{
name: "100 ether",
args: args{value: big.NewFloat(100000)},
want: &Unit{Value: ether100},
},
{
name: "1000 ether",
args: args{value: big.NewFloat(1000000)},
want: &Unit{Value: ether1000},
},
{
name: "10000000 ether",
args: args{value: big.NewFloat(10000000000)},
want: &Unit{Value: ether10000000},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewFinney(tt.args.value); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewFinney() = %v, want %v", got, tt.want)
}
})
}
}
func TestUnit_Finney(t *testing.T) {
type fields struct {
Value *big.Int
}
ether10, _ := new(big.Int).SetString("10000000000000000000", 10)
ether100, _ := new(big.Int).SetString("100000000000000000000", 10)
ether1000, _ := new(big.Int).SetString("1000000000000000000000", 10)
ether10000000, _ := new(big.Int).SetString("10000000000000000000000000", 10)
decEther, _ := new(big.Int).SetString("91231929312891218293912932993", 10)
veryBigEther, _ := new(big.Int).SetString("99999999999999999899879999999999999999999999999999999999999999999999999999999000000000000000000", 10)
tests := []struct {
name string
fields fields
want *big.Float
}{
{
name: "1 ether",
fields: fields{Value: big.NewInt(1000000000000000000)},
want: big.NewFloat(1000),
},
{
name: "10 ether",
fields: fields{Value: ether10},
want: big.NewFloat(10000),
},
{
name: "100 ether",
fields: fields{Value: ether100},
want: big.NewFloat(100000),
},
{
name: "1000 ether",
fields: fields{Value: ether1000},
want: big.NewFloat(1000000),
},
{
name: "10000000 ether",
fields: fields{Value: ether10000000},
want: big.NewFloat(10000000000),
},
{
name: "91231929312.891218293912932993 ether",
fields: fields{Value: decEther},
want: big.NewFloat(91231929312891.218293912932993),
},
{
name: "a lot ether",
fields: fields{Value: veryBigEther},
want: big.NewFloat(99999999999999999899879999999999999999999999999999999999999999999999999999999000),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
u := Unit{
Value: tt.fields.Value,
}
if got := u.Finney(); got.String() != tt.want.String() {
t.Errorf("Finney() = %s, want %s", got.String(), tt.want.String())
}
})
}
}