This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
/
init.go
44 lines (37 loc) 路 1.56 KB
/
init.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
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
package subtest
import (
"fmt"
"testing"
utils "github.com/ChainSafe/ChainBridge/shared/substrate"
"github.com/ChainSafe/chainbridge-utils/msg"
"github.com/centrifuge/go-substrate-rpc-client/types"
)
// WARNING: THIS METHOD IS UNSAFE AND MAY PANIC
func EnsureInitializedChain(t *testing.T, client *utils.Client, relayers []types.AccountID, chains []msg.ChainId, resources map[msg.ResourceId]utils.Method, threshold uint32) {
var count types.U32
_, err := utils.QueryStorage(client, utils.BridgeStoragePrefix, "RelayerCount", nil, nil, &count)
if err != nil {
t.Fatal(err)
}
// Only perform setup if no relayers exist already (ie. state is uninitialized)
if count == 0 {
err = utils.InitializeChain(client, relayers, chains, resources, threshold)
if err != nil {
t.Fatal(err)
}
fmt.Println("======================== Substrate Initialized ========================")
fmt.Printf("Relayers: %x\n", relayers)
fmt.Printf("Whitelisted Chain IDs: %x\n", chains)
fmt.Printf("Relayer Threshold: %x\n", threshold)
for id, method := range resources {
fmt.Printf("Resource - Id: %x, %s\n", id, method)
}
fmt.Println("========================================================================")
} else {
fmt.Println("=========================================================================")
fmt.Println("! WARNING: Running tests against an initialized chain, results may vary !")
fmt.Println("=========================================================================")
}
}