-
Notifications
You must be signed in to change notification settings - Fork 80
/
fees_test.go
76 lines (67 loc) · 1.85 KB
/
fees_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
package spvwallet
import (
"bytes"
"github.com/OpenBazaar/wallet-interface"
"net/http"
"testing"
)
type ClosingBuffer struct {
*bytes.Buffer
}
func (cb *ClosingBuffer) Close() (err error) {
return
}
type mockHttpClient struct{}
func (m *mockHttpClient) Get(url string) (*http.Response, error) {
data := `{"priority":450,"normal":420,"economic":390}`
cb := &ClosingBuffer{bytes.NewBufferString(data)}
resp := &http.Response{
Body: cb,
}
return resp, nil
}
func TestFeeProvider_GetFeePerByte(t *testing.T) {
fp := NewFeeProvider(2000, 360, 320, 280, "https://btc.fees.openbazaar.org", nil)
fp.httpClient = new(mockHttpClient)
// Test fetch from API
if fp.GetFeePerByte(wallet.PRIOIRTY) != 450 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.NORMAL) != 420 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.ECONOMIC) != 390 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.FEE_BUMP) != 450 {
t.Error("Returned incorrect fee per byte")
}
// Test return over max
fp.maxFee = 100
if fp.GetFeePerByte(wallet.PRIOIRTY) != 100 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.NORMAL) != 100 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.ECONOMIC) != 100 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.FEE_BUMP) != 100 {
t.Error("Returned incorrect fee per byte")
}
// Test no API provided
fp.feeAPI = ""
if fp.GetFeePerByte(wallet.PRIOIRTY) != 360 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.NORMAL) != 320 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.ECONOMIC) != 280 {
t.Error("Returned incorrect fee per byte")
}
if fp.GetFeePerByte(wallet.FEE_BUMP) != 360 {
t.Error("Returned incorrect fee per byte")
}
}