forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_client.go
107 lines (97 loc) · 3.24 KB
/
test_client.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
package relayer
import (
context "context"
"log"
"math/rand"
"time"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/lavanet/lava/relayer/chainproxy"
"github.com/lavanet/lava/relayer/sentry"
"github.com/lavanet/lava/relayer/sigs"
"github.com/lavanet/lava/relayer/testclients"
"github.com/lavanet/lava/utils"
"github.com/spf13/pflag"
)
func TestClient(
ctx context.Context,
txFactory tx.Factory,
clientCtx client.Context,
chainID string,
apiInterface string,
duration int64,
flagSet *pflag.FlagSet,
) {
// Every client must preseed
rand.Seed(time.Now().UnixNano())
//
sk, _, err := utils.GetOrCreateVRFKey(clientCtx)
if err != nil {
log.Fatalln("error: GetOrCreateVRFKey", err)
}
// Start sentry
sentry := sentry.NewSentry(clientCtx, txFactory, chainID, true, nil, nil, apiInterface, sk, flagSet, 0)
err = sentry.Init(ctx)
if err != nil {
log.Fatalln("error sentry.Init", err)
}
go sentry.Start(ctx)
for sentry.GetBlockHeight() == 0 {
time.Sleep(1 * time.Second)
}
//
// Node
chainProxy, err := chainproxy.GetChainProxy("", chainproxy.NumberOfParallelConnections, sentry, nil, nil)
if err != nil {
log.Fatalln("error: GetChainProxy", err)
}
err = sentry.SetupConsumerSessionManager(ctx, chainProxy.GetConsumerSessionManager())
if err != nil {
log.Fatalln("error: SetupConsumerSessionManager", err)
}
//
// Set up a connection to the server.
log.Println("TestClient connecting")
keyName, err := sigs.GetKeyName(clientCtx)
if err != nil {
log.Fatalln("error: getKeyName", err)
}
privKey, err := sigs.GetPrivKey(clientCtx, keyName)
if err != nil {
log.Fatalln("error: getPrivKey", err)
}
clientKey, _ := clientCtx.Keyring.Key(keyName)
log.Println("Client pubkey", clientKey.GetPubKey().Address())
testDuration := time.Second * time.Duration(duration)
// Run tests
var testErrors error = nil
switch chainID {
case "ETH1":
testErrors = testclients.EthTests(ctx, chainID, "http://127.0.0.1:3333/1", testDuration)
case "GTH1":
testErrors = testclients.EthTests(ctx, chainID, "http://127.0.0.1:3339/1", testDuration)
case "FTM250":
testErrors = testclients.EthTests(ctx, chainID, "http://127.0.0.1:3336/1", testDuration)
case "COS1":
testErrors = testclients.TerraTests(ctx, chainProxy, privKey, apiInterface)
case "COS3", "COS4":
testErrors = testclients.OsmosisTests(ctx, chainProxy, privKey, apiInterface)
case "LAV1":
testErrors = testclients.LavaTests(ctx, chainProxy, privKey, apiInterface, sentry, clientCtx)
case "APT1":
testErrors = testclients.AptosTests(ctx, chainProxy, privKey, apiInterface, sentry, clientCtx)
case "JUN1":
testErrors = testclients.JunoTests(ctx, chainProxy, privKey, apiInterface)
case "COS5":
testErrors = testclients.CosmoshubTests(ctx, chainProxy, privKey, apiInterface, sentry, clientCtx)
case "STRK", "STRKT":
testErrors = testclients.StarknetTests(ctx, chainID, "http://127.0.0.1:3347/1", chainProxy, privKey, testDuration)
case "POLYGON1", "POLYGON1T":
testErrors = testclients.PolygonTests(ctx, chainID, "http://127.0.0.1:3351/1", chainProxy, privKey, testDuration)
}
if testErrors != nil {
log.Fatalf("%s Client test failed with errors %s\n", chainID, testErrors)
} else {
log.Printf("%s Client test complete \n", chainID)
}
}