-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_test.go
156 lines (141 loc) · 3.99 KB
/
e2e_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package tests
import (
"context"
"encoding/hex"
"errors"
"fmt"
"os"
"os/exec"
"os/signal"
"syscall"
"testing"
testUtils "github.com/ava-labs/awm-relayer/tests/utils"
"github.com/ava-labs/awm-relayer/utils"
"github.com/ava-labs/teleporter/tests/local"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
const (
warpGenesisTemplateFile = "./tests/utils/warp-genesis-template.json"
)
var (
localNetworkInstance *local.LocalNetwork
decider *exec.Cmd
cancelDecider context.CancelFunc
)
func TestE2E(t *testing.T) {
if os.Getenv("RUN_E2E") == "" {
t.Skip("Environment variable RUN_E2E not set; skipping E2E tests")
}
RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "Relayer e2e test")
}
// Define the Relayer before and after suite functions.
var _ = ginkgo.BeforeSuite(func() {
localNetworkInstance = local.NewLocalNetwork(
"awm-relayer-e2e-test",
warpGenesisTemplateFile,
[]local.SubnetSpec{
{
Name: "A",
EVMChainID: 12345,
NodeCount: 2,
},
{
Name: "B",
EVMChainID: 54321,
NodeCount: 2,
},
},
0,
)
// Generate the Teleporter deployment values
teleporterContractAddress := common.HexToAddress(
testUtils.ReadHexTextFile("./tests/utils/UniversalTeleporterMessengerContractAddress.txt"),
)
teleporterDeployerAddress := common.HexToAddress(
testUtils.ReadHexTextFile("./tests/utils/UniversalTeleporterDeployerAddress.txt"),
)
teleporterDeployerTransactionStr := testUtils.ReadHexTextFile(
"./tests/utils/UniversalTeleporterDeployerTransaction.txt",
)
teleporterDeployerTransaction, err := hex.DecodeString(
utils.SanitizeHexString(teleporterDeployerTransactionStr),
)
Expect(err).Should(BeNil())
_, fundedKey := localNetworkInstance.GetFundedAccountInfo()
localNetworkInstance.DeployTeleporterContracts(
teleporterDeployerTransaction,
teleporterDeployerAddress,
teleporterContractAddress,
fundedKey,
true,
)
log.Info("Deployed Teleporter contracts")
localNetworkInstance.DeployTeleporterRegistryContracts(
teleporterContractAddress,
fundedKey,
)
var ctx context.Context
ctx, cancelDecider = context.WithCancel(context.Background())
// we'll call cancelDecider in AfterSuite, but also call it if this
// process is killed, because AfterSuite won't always run then:
signalChan := make(chan os.Signal, 2)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-signalChan
cancelDecider()
}()
decider = exec.CommandContext(ctx, "./tests/cmd/decider/decider")
decider.Start()
go func() { // panic if the decider exits abnormally
err := decider.Wait()
// Context cancellation is the only expected way for the
// process to exit, otherwise panic
if !errors.Is(ctx.Err(), context.Canceled) {
panic(fmt.Errorf("decider exited abnormally: %w", err))
}
}()
log.Info("Started decider service")
log.Info("Set up ginkgo before suite")
ginkgo.AddReportEntry(
"network directory with node logs & configs; useful in the case of failures",
localNetworkInstance.Dir(),
ginkgo.ReportEntryVisibilityFailureOrVerbose,
)
})
var _ = ginkgo.AfterSuite(func() {
if localNetworkInstance != nil {
localNetworkInstance.TearDownNetwork()
}
if decider != nil {
cancelDecider()
}
})
var _ = ginkgo.Describe("[AWM Relayer Integration Tests", func() {
ginkgo.It("Manually Provided Message", func() {
ManualMessage(localNetworkInstance)
})
ginkgo.It("Basic Relay", func() {
BasicRelay(localNetworkInstance)
})
ginkgo.It("Shared Database", func() {
SharedDatabaseAccess(localNetworkInstance)
})
ginkgo.It("Allowed Addresses", func() {
AllowedAddresses(localNetworkInstance)
})
ginkgo.It("Batch Message", func() {
BatchRelay(localNetworkInstance)
})
ginkgo.It("Relay Message API", func() {
RelayMessageAPI(localNetworkInstance)
})
ginkgo.It("Warp API", func() {
WarpAPIRelay(localNetworkInstance)
})
})