-
Notifications
You must be signed in to change notification settings - Fork 179
/
extrinsic_retriever_live_test.go
102 lines (74 loc) · 2.29 KB
/
extrinsic_retriever_live_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
//go:build live
package retriever
import (
gsrpc "github.com/centrifuge/go-substrate-rpc-client/v4"
"log"
"os"
"strconv"
"sync"
"testing"
)
var (
extrinsicTestURLs = []string{
"wss://fullnode.parachain.centrifuge.io",
"wss://rpc.polkadot.io",
"wss://acala-rpc-0.aca-api.network",
"wss://wss.api.moonbeam.network",
}
)
func TestLive_ExtrinsicRetriever_GetExtrinsics(t *testing.T) {
t.Parallel()
var wg sync.WaitGroup
extrinsicsThreshold, err := strconv.Atoi(os.Getenv("GSRPC_LIVE_TEST_EXTRINSICS_THRESHOLD"))
if err != nil {
extrinsicsThreshold = 50
log.Printf("Env Var GSRPC_LIVE_TEST_EXTRINSICS_THRESHOLD not set, defaulting to %d", extrinsicsThreshold)
}
for _, testURL := range extrinsicTestURLs {
testURL := testURL
wg.Add(1)
go func() {
defer wg.Done()
api, err := gsrpc.NewSubstrateAPI(testURL)
if err != nil {
log.Printf("Couldn't connect to '%s': %s\n", testURL, err)
return
}
retriever, err := NewDefaultExtrinsicRetriever(api.RPC.Chain, api.RPC.State)
if err != nil {
log.Printf("Couldn't create extrinsic retriever: %s", err)
return
}
header, err := api.RPC.Chain.GetHeaderLatest()
if err != nil {
log.Printf("Couldn't get latest header for '%s': %s\n", testURL, err)
return
}
extrinsicCount := 0
for {
blockHash, err := api.RPC.Chain.GetBlockHash(uint64(header.Number))
if err != nil {
log.Printf("Couldn't retrieve blockHash for '%s', block number %d: %s\n", testURL, header.Number, err)
return
}
extrinsics, err := retriever.GetExtrinsics(blockHash)
if err != nil {
log.Printf("Couldn't retrieve extrinsics for '%s', block number %d: %s\n", testURL, header.Number, err)
return
}
log.Printf("Found %d extrinsics for '%s', at block number %d.\n", len(extrinsics), testURL, header.Number)
extrinsicCount += len(extrinsics)
if extrinsicCount > extrinsicsThreshold {
log.Printf("Retrieved a total of %d extrinsics for '%s', last block number %d. Stopping now.\n", extrinsicCount, testURL, header.Number)
return
}
header, err = api.RPC.Chain.GetHeader(header.ParentHash)
if err != nil {
log.Printf("Couldn't retrieve header for block number '%d' for '%s': %s\n", header.Number, testURL, err)
return
}
}
}()
}
wg.Wait()
}