Skip to content

Commit e2874b0

Browse files
authored
move setup to beforesuite (#940)
1 parent 7221812 commit e2874b0

File tree

1 file changed

+45
-58
lines changed

1 file changed

+45
-58
lines changed

tests/warp/warp_test.go

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,20 @@ import (
3939
const fundedKeyStr = "56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
4040

4141
var (
42-
config = runner.NewDefaultANRConfig()
43-
manager = runner.NewNetworkManager(config)
44-
warpChainConfigPath string
42+
config = runner.NewDefaultANRConfig()
43+
manager = runner.NewNetworkManager(config)
44+
warpChainConfigPath string
45+
unsignedWarpMsg *avalancheWarp.UnsignedMessage
46+
unsignedWarpMessageID ids.ID
47+
signedWarpMsg *avalancheWarp.Message
48+
blockchainIDA, blockchainIDB ids.ID
49+
chainAURIs, chainBURIs []string
50+
chainAWSClient, chainBWSClient ethclient.Client
51+
chainID = big.NewInt(99999)
52+
fundedKey *ecdsa.PrivateKey
53+
fundedAddress common.Address
54+
payload = []byte{1, 2, 3}
55+
txSigner = types.LatestSignerForChainID(chainID)
4556
)
4657

4758
func TestE2E(t *testing.T) {
@@ -108,7 +119,8 @@ var _ = ginkgo.BeforeSuite(func() {
108119

109120
// Issue transactions to activate the proposerVM fork on the receiving chain
110121
chainID := big.NewInt(99999)
111-
fundedKey, err := crypto.HexToECDSA(fundedKeyStr)
122+
fundedKey, err = crypto.HexToECDSA(fundedKeyStr)
123+
fundedAddress = crypto.PubkeyToAddress(fundedKey.PublicKey)
112124
gomega.Expect(err).Should(gomega.BeNil())
113125
subnetB := manager.GetSubnets()[1]
114126
subnetBDetails, ok := manager.GetSubnet(subnetB)
@@ -121,6 +133,35 @@ var _ = ginkgo.BeforeSuite(func() {
121133

122134
err = utils.IssueTxsToActivateProposerVMFork(ctx, chainID, fundedKey, client)
123135
gomega.Expect(err).Should(gomega.BeNil())
136+
137+
subnetIDs := manager.GetSubnets()
138+
gomega.Expect(len(subnetIDs)).Should(gomega.Equal(2))
139+
140+
subnetA := subnetIDs[0]
141+
subnetADetails, ok := manager.GetSubnet(subnetA)
142+
gomega.Expect(ok).Should(gomega.BeTrue())
143+
blockchainIDA = subnetADetails.BlockchainID
144+
gomega.Expect(len(subnetADetails.ValidatorURIs)).Should(gomega.Equal(5))
145+
chainAURIs = append(chainAURIs, subnetADetails.ValidatorURIs...)
146+
147+
subnetB = subnetIDs[1]
148+
subnetBDetails, ok = manager.GetSubnet(subnetB)
149+
gomega.Expect(ok).Should(gomega.BeTrue())
150+
blockchainIDB = subnetBDetails.BlockchainID
151+
gomega.Expect(len(subnetBDetails.ValidatorURIs)).Should(gomega.Equal(5))
152+
chainBURIs = append(chainBURIs, subnetBDetails.ValidatorURIs...)
153+
154+
log.Info("Created URIs for both subnets", "ChainAURIs", chainAURIs, "ChainBURIs", chainBURIs, "blockchainIDA", blockchainIDA, "blockchainIDB", blockchainIDB)
155+
156+
chainAWSURI := toWebsocketURI(chainAURIs[0], blockchainIDA.String())
157+
log.Info("Creating ethclient for blockchainA", "wsURI", chainAWSURI)
158+
chainAWSClient, err = ethclient.Dial(chainAWSURI)
159+
gomega.Expect(err).Should(gomega.BeNil())
160+
161+
chainBWSURI := toWebsocketURI(chainBURIs[0], blockchainIDB.String())
162+
log.Info("Creating ethclient for blockchainB", "wsURI", chainBWSURI)
163+
chainBWSClient, err = ethclient.Dial(chainBWSURI)
164+
gomega.Expect(err).Should(gomega.BeNil())
124165
})
125166

126167
var _ = ginkgo.AfterSuite(func() {
@@ -131,64 +172,10 @@ var _ = ginkgo.AfterSuite(func() {
131172
})
132173

133174
var _ = ginkgo.Describe("[Warp]", ginkgo.Ordered, func() {
134-
var (
135-
unsignedWarpMsg *avalancheWarp.UnsignedMessage
136-
unsignedWarpMessageID ids.ID
137-
signedWarpMsg *avalancheWarp.Message
138-
blockchainIDA, blockchainIDB ids.ID
139-
chainAURIs, chainBURIs []string
140-
chainAWSClient, chainBWSClient ethclient.Client
141-
chainID = big.NewInt(99999)
142-
fundedKey *ecdsa.PrivateKey
143-
fundedAddress common.Address
144-
payload = []byte{1, 2, 3}
145-
txSigner = types.LatestSignerForChainID(chainID)
146-
err error
147-
)
148-
149-
fundedKey, err = crypto.HexToECDSA(fundedKeyStr)
150-
if err != nil {
151-
panic(err)
152-
}
153-
fundedAddress = crypto.PubkeyToAddress(fundedKey.PublicKey)
154-
155-
ginkgo.It("Setup URIs", ginkgo.Label("Warp", "SetupWarp"), func() {
156-
subnetIDs := manager.GetSubnets()
157-
gomega.Expect(len(subnetIDs)).Should(gomega.Equal(2))
158-
159-
subnetA := subnetIDs[0]
160-
subnetADetails, ok := manager.GetSubnet(subnetA)
161-
gomega.Expect(ok).Should(gomega.BeTrue())
162-
blockchainIDA = subnetADetails.BlockchainID
163-
gomega.Expect(len(subnetADetails.ValidatorURIs)).Should(gomega.Equal(5))
164-
chainAURIs = append(chainAURIs, subnetADetails.ValidatorURIs...)
165-
166-
subnetB := subnetIDs[1]
167-
subnetBDetails, ok := manager.GetSubnet(subnetB)
168-
gomega.Expect(ok).Should(gomega.BeTrue())
169-
blockchainIDB = subnetBDetails.BlockchainID
170-
gomega.Expect(len(subnetBDetails.ValidatorURIs)).Should(gomega.Equal(5))
171-
chainBURIs = append(chainBURIs, subnetBDetails.ValidatorURIs...)
172-
173-
log.Info("Created URIs for both subnets", "ChainAURIs", chainAURIs, "ChainBURIs", chainBURIs, "blockchainIDA", blockchainIDA, "blockchainIDB", blockchainIDB)
174-
175-
chainAWSURI := toWebsocketURI(chainAURIs[0], blockchainIDA.String())
176-
log.Info("Creating ethclient for blockchainA", "wsURI", chainAWSURI)
177-
chainAWSClient, err = ethclient.Dial(chainAWSURI)
178-
gomega.Expect(err).Should(gomega.BeNil())
179-
180-
chainBWSURI := toWebsocketURI(chainBURIs[0], blockchainIDB.String())
181-
log.Info("Creating ethclient for blockchainB", "wsURI", chainBWSURI)
182-
chainBWSClient, err = ethclient.Dial(chainBWSURI)
183-
gomega.Expect(err).Should(gomega.BeNil())
184-
})
185-
186175
// Send a transaction to Subnet A to issue a Warp Message to Subnet B
187176
ginkgo.It("Send Message from A to B", ginkgo.Label("Warp", "SendWarp"), func() {
188177
ctx := context.Background()
189178

190-
gomega.Expect(err).Should(gomega.BeNil())
191-
192179
log.Info("Subscribing to new heads")
193180
newHeads := make(chan *types.Header, 10)
194181
sub, err := chainAWSClient.SubscribeNewHead(ctx, newHeads)

0 commit comments

Comments
 (0)