-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_assets_test.go
164 lines (139 loc) · 5 KB
/
api_assets_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
152
153
154
155
156
157
158
159
160
161
162
163
164
package blockfrost_test
import (
"context"
"encoding/json"
"path/filepath"
"reflect"
"strings"
"testing"
"github.com/blockfrost/blockfrost-go"
)
func TestAssetUnmarshal(t *testing.T) {
var onchainMetadata interface{} = map[string]interface{}{
"image": "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226",
"name": "My NFT token",
"description": "optional",
}
fp := filepath.Join(testdata, "json", "assets", "asset.json")
want := blockfrost.Asset{
Asset: "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
AssetName: "6e7574636f696e",
PolicyId: "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a7",
Fingerprint: "asset1pkpwyknlvul7az0xx8czhl60pyel45rpje4z8w",
InitialMintTxHash: "6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad",
MintOrBurnCount: 1,
Quantity: "12000",
OnchainMetadata: &onchainMetadata,
Metadata: &blockfrost.AssetMetadata{
Name: "nutcoin",
Description: "The Nut Coin",
Ticker: "nutc",
Decimals: 6,
URL: "https://www.stakenuts.com/",
Logo: "42",
},
}
got := blockfrost.Asset{}
testStructGotWant(t, fp, &got, &want)
}
func TestResourceAssetsIntegration(t *testing.T) {
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.Assets(context.TODO(), blockfrost.APIQueryParams{})
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := []blockfrost.AssetByPolicy{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetIntegration(t *testing.T) {
asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.Asset(context.TODO(), asset)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := blockfrost.Asset{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetMetadataIntegration(t *testing.T) {
asset := "14696a4676909f4e3cb1f2e60e2e08e5abed70caf5c02699be97113943554259"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.Asset(context.TODO(), asset)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := blockfrost.Asset{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetHistoryIntegration(t *testing.T) {
asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.AssetHistory(context.TODO(), asset)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := []blockfrost.AssetHistory{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetTransactionIntegration(t *testing.T) {
asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.AssetTransactions(context.TODO(), asset)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := []blockfrost.AssetTransaction{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetddressesIntegration(t *testing.T) {
asset := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e4669727374636f696e"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.AssetAddresses(context.TODO(), asset, blockfrost.APIQueryParams{})
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := []blockfrost.AssetAddress{}
testIntUtil(t, fp, &got, &want)
}
func TestResourceAssetsByPolicyIntegration(t *testing.T) {
policy := "3a9241cd79895e3a8d65261b40077d4437ce71e9d7c8c6c00e3f658e"
api := blockfrost.NewAPIClient(blockfrost.APIClientOptions{})
got, err := api.AssetsByPolicy(context.TODO(), policy)
if err != nil {
t.Fatal(err)
}
fp := filepath.Join(testdata, strings.ToLower(strings.TrimLeft(t.Name(), "Test"))+".golden")
want := []blockfrost.AssetByPolicy{}
testIntUtil(t, fp, &got, &want)
}
type withCustomTest func() func(got interface{}, want interface{})
func testIntUtil(t *testing.T, fp string, got interface{}, want interface{}, opts ...withCustomTest) {
if *update {
data, err := json.Marshal(got)
if err != nil {
t.Fatal(err)
}
WriteGoldenFile(t, fp, data)
}
bytes := ReadOrGenerateGoldenFile(t, fp, got)
if err := json.Unmarshal(bytes, want); err != nil {
t.Fatal(err)
}
for _, opt := range opts {
opt()(&got, &want)
}
if !reflect.DeepEqual(got, want) {
gotJSON, err := json.Marshal(got)
wantJSON, err := json.Marshal(want)
if err != nil {
t.Fatalf("\nexpected %v \ngot %v", want, got)
}
t.Fatalf("\nexpected %s \ngot %s", string(wantJSON), string(gotJSON))
}
}