-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathegpp_test.go
88 lines (75 loc) · 1.94 KB
/
egpp_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
package egpp_test
import (
"testing"
"github.com/OsoianMarcel/egpp"
"github.com/OsoianMarcel/egpp/common"
"github.com/OsoianMarcel/egpp/providers/ethergasstation"
"github.com/OsoianMarcel/egpp/providers/tester"
)
func TestGetGasPriceWithFallback_FallbackSuccess(t *testing.T) {
providers := []common.Provider{
tester.NewProvider(false, common.GasPrice{}),
ethergasstation.NewProvider(),
}
gasPrice, err := egpp.GetGasPriceWithFallback(providers)
if err != nil {
t.Error(err)
return
}
if gasPrice.Provider != "Ether Gas Station" {
t.Error("fetched provider name should be different")
}
}
func TestGetGasPriceWithFallback_AllFails(t *testing.T) {
providers := []common.Provider{
tester.NewProvider(false, common.GasPrice{}),
tester.NewProvider(false, common.GasPrice{}),
}
_, err := egpp.GetGasPriceWithFallback(providers)
if err == nil {
t.Error("the method should return an error")
}
}
func TestGetGasPriceAverage_Success(t *testing.T) {
providers := []common.Provider{
tester.NewProvider(true, common.GasPrice{
Provider: "1",
Standard: 30,
SafeLow: 10,
Fast: 50,
Fastest: 200,
}),
tester.NewProvider(true, common.GasPrice{
Provider: "1",
Standard: 20,
SafeLow: 10,
Fast: 0,
Fastest: 150,
}),
}
avgGasPrice, err := egpp.GetGasPriceAverage(providers)
if err != nil {
t.Error(err)
return
}
if avgGasPrice.Provider != "Average Gas Price" {
t.Error("average gas price provider is wrong")
return
}
if avgGasPrice.Standard != 25 ||
avgGasPrice.SafeLow != 10 ||
avgGasPrice.Fast != 50 ||
avgGasPrice.Fastest != 175 {
t.Error("average gas price values are wrong")
}
}
func TestGetGasPriceAverage_AllFail(t *testing.T) {
providers := []common.Provider{
tester.NewProvider(false, common.GasPrice{}),
tester.NewProvider(false, common.GasPrice{}),
}
_, err := egpp.GetGasPriceAverage(providers)
if err == nil {
t.Error("get gas price average should return an error")
}
}