-
Notifications
You must be signed in to change notification settings - Fork 1
/
token_test.go
101 lines (88 loc) · 2.52 KB
/
token_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
package client
import (
"context"
"fmt"
"github.com/google/go-cmp/cmp"
"net/http"
"testing"
)
func TestTokensService(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/tokens", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
query := r.URL.Query()
if len(query.Get("addresses")) > 0 || len(query.Get("symbols")) > 0 || len(query.Get("projects")) > 0 {
_, _ = fmt.Fprint(w, `{ "data":[ { "name":"GovWorld" }, { "name":"Dino Land" } ], "error_code": 0 }`)
} else {
_, _ = fmt.Fprint(w, `{ "data":[ { "name":"DePo" } ], "error_code": 0 }`)
}
})
t.Run("ListAll", func(t *testing.T) {
opt := &TokenListOptions{
ListOptions: ListOptions{
Chain: "bsc",
},
}
ctx := context.Background()
tokens, _, err := client.Tokens.List(ctx, opt)
if err != nil {
t.Errorf("Tokens.List returned error: %v", err)
}
want := []*Token{{Name: "DePo"}}
if !cmp.Equal(tokens, want) {
t.Errorf("Token.List returned %+v, want %+v", tokens, want)
}
})
t.Run("ListByAddresses", func(t *testing.T) {
opt := &TokenListOptions{
ListOptions: ListOptions{
Chain: "bsc",
},
Addresses: []string{"0xcc7a91413769891de2e9ebbfc96d2eb1874b5760", "0x6b9481fb5465ef9ab9347b332058d894ab09b2f6"},
}
ctx := context.Background()
tokens, _, err := client.Tokens.List(ctx, opt)
if err != nil {
t.Errorf("Tokens.List returned error: %v", err)
}
want := []*Token{{Name: "GovWorld"}, {Name: "Dino Land"}}
if !cmp.Equal(tokens, want) {
t.Errorf("Token.List returned %+v, want %+v", tokens, want)
}
})
t.Run("ListBySymbols", func(t *testing.T) {
opt := &TokenListOptions{
ListOptions: ListOptions{
Chain: "bsc",
},
Symbols: []string{"GOV", "DNL"},
}
ctx := context.Background()
tokens, _, err := client.Tokens.List(ctx, opt)
if err != nil {
t.Errorf("Tokens.List returned error: %v", err)
}
want := []*Token{{Name: "GovWorld"}, {Name: "Dino Land"}}
if !cmp.Equal(tokens, want) {
t.Errorf("Token.List returned %+v, want %+v", tokens, want)
}
})
t.Run("ListByProjects", func(t *testing.T) {
opt := &TokenListOptions{
ListOptions: ListOptions{
Chain: "bsc",
},
Symbols: []string{"GOV", "DNL"},
}
ctx := context.Background()
tokens, _, err := client.Tokens.List(ctx, opt)
if err != nil {
t.Errorf("Tokens.List returned error: %v", err)
}
want := []*Token{{Name: "GovWorld"}, {Name: "Dino Land"}}
if !cmp.Equal(tokens, want) {
t.Errorf("Token.List returned %+v, want %+v", tokens, want)
}
})
}