forked from savaki/ogmigo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
state_query_test.go
140 lines (121 loc) · 3.34 KB
/
state_query_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
// Copyright 2021 Matt Ho
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ogmigo
import (
"context"
"encoding/json"
"fmt"
"os"
"testing"
"time"
)
func TestClient_ChainTip(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
point, err := client.ChainTip(ctx)
if err != nil {
t.Fatalf("got %v; want nil", err)
}
ps, ok := point.PointStruct()
if !ok {
t.Fatalf("got false; want true")
}
if ps.Hash == "" {
t.Fatalf("got blank; want not blank")
}
if ps.Slot == 0 {
t.Fatalf("got zero; want not zero")
}
}
func TestClient_EraSummaries(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
history, err := client.EraSummaries(ctx)
if err != nil {
t.Fatalf("got %#v; want nil", err)
}
if len(history.Summaries) == 0 {
t.Fatalf("got empty era history; want nonempty")
}
}
func TestClient_CurrentEpoch(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
params, err := client.CurrentEpoch(ctx)
if err != nil {
t.Fatalf("got %#v; want nil", err)
}
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
_ = encoder.Encode(params)
}
func TestClient_CurrentProtocolParameters(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
params, err := client.CurrentProtocolParameters(ctx)
if err != nil {
t.Fatalf("got %#v; want nil", err)
}
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
_ = encoder.Encode(params)
}
func TestClient_EraStart(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
eraStart, err := client.EraStart(ctx)
if err != nil {
t.Fatalf("got %#v; want nil", err)
}
start := time.Now().Add(-eraStart.Time)
fmt.Println(start)
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
_ = encoder.Encode(eraStart)
}
func TestClient_UtxosByAddress(t *testing.T) {
endpoint := os.Getenv("OGMIOS")
if endpoint == "" {
t.SkipNow()
}
ctx := context.Background()
client := New(WithEndpoint(endpoint), WithLogger(DefaultLogger))
utxos, err := client.UtxosByAddress(ctx, "addr_test1qz6m03tdfm5raxr00fsw7p8v79ptfveaptar9a56zqz09kqkazwhq98h9v8gnk3wm5uvevzvd642zm7778afv0evwqgqfuy84f")
if err != nil {
t.Fatalf("got %#v; want nil", err)
}
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
_ = encoder.Encode(utxos)
}