-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics_test.go
57 lines (44 loc) · 1.29 KB
/
metrics_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
package invariants
import (
"context"
"fmt"
"log"
"os"
"strconv"
"testing"
"github.com/glifio/invariants/singleton"
"github.com/stretchr/testify/assert"
)
var eventsURL string
func init() {
eventsURL = os.Getenv("EVENTS_API")
}
func init() {
chainID, err := strconv.Atoi(os.Getenv("CHAIN_ID"))
if err != nil {
log.Fatal(err)
}
singleton.InitPoolsSDK(
context.Background(),
int64(chainID),
os.Getenv("LOTUS_PRIVATE_ADDR"),
os.Getenv("LOTUS_PRIVATE_TOKEN"),
)
}
// TestMetrics calls the REST API, and compares against on-chain
func TestMetrics(t *testing.T) {
ctx := context.Background()
metricsFromAPI, err := GetMetricsFromAPI(ctx, eventsURL)
assert.Nil(t, err)
fmt.Printf("Jim rest %+v\n", metricsFromAPI)
if metricsFromAPI.Height == 0 {
t.Fatal("Height is zero")
}
height := metricsFromAPI.Height
metricsFromNode, err := GetMetricsFromNode(ctx, height)
assert.Nil(t, err)
fmt.Printf("Jim chain %+v\n", metricsFromNode)
assert.Equal(t, metricsFromAPI.PoolTotalAssets, metricsFromNode.PoolTotalAssets, "Total assets should be equal")
assert.Equal(t, metricsFromAPI.PoolTotalBorrowed, metricsFromNode.PoolTotalBorrowed, "Total borrowed should be equal")
assert.Equal(t, metricsFromAPI.TotalAgentCount, metricsFromNode.TotalAgentCount, "Agent count should be equal")
}