Skip to content

Commit c032a58

Browse files
authored
Merge pull request #462 from ava-labs/gstuart/test-fix-2
E2E flaky test fix
2 parents e9b5f51 + 7a89b56 commit c032a58

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

tests/flows/teleporter_registry.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
8585
subnetBInfo,
8686
newTeleporterAddress,
8787
fundedKey,
88-
offchainMessageB)
88+
offchainMessageB,
89+
)
8990

9091
// Send a message using old Teleporter version to test messenger using new Teleporter version.
9192
// Message should be received successfully since we haven't updated mininum Teleporter version yet.
@@ -99,7 +100,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
99100
testMessengerB,
100101
fundedKey,
101102
"message_1",
102-
true)
103+
true,
104+
)
103105

104106
// Update minimum Teleporter version on destination chain
105107
opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetBInfo.EVMChainID)
@@ -117,7 +119,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
117119
// Verify that minTeleporterVersion updated
118120
minTeleporterVersionUpdatedEvent, err := utils.GetEventFromLogs(
119121
receipt.Logs,
120-
testMessengerB.ParseMinTeleporterVersionUpdated)
122+
testMessengerB.ParseMinTeleporterVersionUpdated,
123+
)
121124
Expect(err).Should(BeNil())
122125
Expect(minTeleporterVersionUpdatedEvent.OldMinTeleporterVersion.Cmp(minTeleporterVersion)).Should(Equal(0))
123126
Expect(minTeleporterVersionUpdatedEvent.NewMinTeleporterVersion.Cmp(latestVersionB)).Should(Equal(0))
@@ -134,12 +137,14 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
134137
testMessengerB,
135138
fundedKey,
136139
"message_2",
137-
false)
140+
false,
141+
)
138142

139143
// Update the subnets to use new Teleporter messengers
140144
network.SetTeleporterContractAddress(newTeleporterAddress)
141145
cChainInfo = network.GetPrimaryNetworkInfo()
142146
subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network)
147+
143148
utils.SendExampleCrossChainMessageAndVerify(
144149
ctx,
145150
network,
@@ -150,7 +155,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
150155
testMessengerC,
151156
fundedKey,
152157
"message_3",
153-
false)
158+
false,
159+
)
154160

155161
// Call addProtocolVersion on subnetA to register the new Teleporter version
156162
utils.AddProtocolVersionAndWaitForAcceptance(
@@ -159,11 +165,13 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
159165
cChainInfo,
160166
newTeleporterAddress,
161167
fundedKey,
162-
offchainMessageC)
168+
offchainMessageC,
169+
)
163170

164171
// Send a message from A->B, which previously failed, but now using the new Teleporter version.
165172
// Teleporter versions should match, so message should be received successfully.
166-
utils.SendExampleCrossChainMessageAndVerify(ctx,
173+
utils.SendExampleCrossChainMessageAndVerify(
174+
ctx,
167175
network,
168176
subnetBInfo,
169177
testMessengerB,
@@ -172,7 +180,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
172180
testMessengerC,
173181
fundedKey,
174182
"message_4",
175-
true)
183+
true,
184+
)
176185

177186
// To make sure all subnets are using the same Teleporter version, call addProtocolVersion on subnetA
178187
// to register the new Teleporter version
@@ -182,7 +191,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) {
182191
subnetAInfo,
183192
newTeleporterAddress,
184193
fundedKey,
185-
offchainMessageA)
194+
offchainMessageA,
195+
)
186196

187197
latestVersionA, err := subnetAInfo.TeleporterRegistry.LatestVersion(&bind.CallOpts{})
188198
Expect(err).Should(BeNil())

tests/interfaces/local_network.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ type LocalNetwork interface {
2727
deployerAddress common.Address,
2828
contractAddress common.Address,
2929
fundedKey *ecdsa.PrivateKey,
30-
updateNetworkTeleporter bool)
30+
updateNetworkTeleporter bool,
31+
)
3132
GetNetworkID() uint32
3233
Dir() string
3334
}

tests/local/network.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"math/big"
88
"os"
99
"slices"
10+
"sort"
1011
"time"
1112

1213
"github.com/ava-labs/avalanchego/api/info"
@@ -44,7 +45,7 @@ type LocalNetwork struct {
4445
primaryNetworkInfo *interfaces.SubnetTestInfo
4546
subnetsInfo map[ids.ID]*interfaces.SubnetTestInfo
4647

47-
extraNodes []*tmpnet.Node // to add as more subnet vaidators in the tests
48+
extraNodes []*tmpnet.Node // to add as more subnet validators in the tests
4849

4950
globalFundedKey *ecdsa.PrivateKey
5051

@@ -90,7 +91,8 @@ func NewLocalNetwork(
9091
Expect(err).Should(BeNil())
9192
warpChainConfigPath := f.Name()
9293

93-
allNodes := extraNodes // to be appended w/ subnet validators
94+
var allNodes []*tmpnet.Node
95+
allNodes = append(allNodes, extraNodes...) // to be appended w/ subnet validators
9496

9597
var subnets []*tmpnet.Subnet
9698
for _, subnetSpec := range subnetSpecs {
@@ -140,7 +142,7 @@ func NewLocalNetwork(
140142
setupProposerVM(ctx, globalFundedKey, network, subnet.SubnetID)
141143
}
142144

143-
res := &LocalNetwork{
145+
localNetwork := &LocalNetwork{
144146
primaryNetworkInfo: &interfaces.SubnetTestInfo{},
145147
subnetsInfo: make(map[ids.ID]*interfaces.SubnetTestInfo),
146148
extraNodes: extraNodes,
@@ -149,10 +151,10 @@ func NewLocalNetwork(
149151
warpChainConfigPath: warpChainConfigPath,
150152
}
151153
for _, subnet := range network.Subnets {
152-
res.setSubnetValues(subnet)
154+
localNetwork.setSubnetValues(subnet)
153155
}
154-
res.setPrimaryNetworkValues()
155-
return res
156+
localNetwork.setPrimaryNetworkValues()
157+
return localNetwork
156158
}
157159

158160
// Should be called after setSubnetValues for all subnets
@@ -331,17 +333,22 @@ func (n *LocalNetwork) DeployTeleporterRegistryContracts(
331333

332334
log.Info("Deployed TeleporterRegistry contract",
333335
"subnet", subnetInfo.SubnetID.Hex(),
334-
"address", teleporterRegistryAddress.Hex())
336+
"address", teleporterRegistryAddress.Hex(),
337+
)
335338
}
336339

337340
log.Info("Deployed TeleporterRegistry contracts to all subnets")
338341
}
339342

343+
// Returns all subnet info sorted in lexicographic order of SubnetName.
340344
func (n *LocalNetwork) GetSubnetsInfo() []interfaces.SubnetTestInfo {
341345
subnetsInfo := make([]interfaces.SubnetTestInfo, 0, len(n.subnetsInfo))
342346
for _, subnetInfo := range n.subnetsInfo {
343347
subnetsInfo = append(subnetsInfo, *subnetInfo)
344348
}
349+
sort.Slice(subnetsInfo, func(i, j int) bool {
350+
return subnetsInfo[i].SubnetName < subnetsInfo[j].SubnetName
351+
})
345352
return subnetsInfo
346353
}
347354

@@ -436,7 +443,7 @@ func (n *LocalNetwork) setAllSubnetValues() {
436443
for _, subnetInfo := range n.subnetsInfo {
437444
subnet := n.tmpnet.GetSubnet(subnetInfo.SubnetName)
438445
Expect(subnet).ShouldNot(BeNil())
439-
n.setSubnetValues(n.tmpnet.GetSubnet(subnetInfo.SubnetName))
446+
n.setSubnetValues(subnet)
440447
}
441448

442449
n.setPrimaryNetworkValues()
@@ -463,8 +470,9 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID,
463470
)]
464471

465472
// consume some of the extraNodes
466-
newValidatorNodes := n.extraNodes[0:count]
467-
defer slices.Delete(n.extraNodes, 0, int(count))
473+
var newValidatorNodes []*tmpnet.Node
474+
newValidatorNodes = append(newValidatorNodes, n.extraNodes[0:count]...)
475+
n.extraNodes = n.extraNodes[count:]
468476

469477
apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0])
470478
Expect(err).Should(BeNil())

tests/utils/utils.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ func SendAddFeeAmountAndWaitForAcceptance(
7070
transactor *teleportermessenger.TeleporterMessenger,
7171
) *types.Receipt {
7272
opts, err := bind.NewKeyedTransactorWithChainID(
73-
senderKey, source.EVMChainID)
73+
senderKey,
74+
source.EVMChainID,
75+
)
7476
Expect(err).Should(BeNil())
7577

7678
tx, err := transactor.AddFeeAmount(opts, messageID, feeContractAddress, amount)
@@ -85,7 +87,8 @@ func SendAddFeeAmountAndWaitForAcceptance(
8587
log.Info("Send AddFeeAmount transaction on source chain",
8688
"messageID", messageID,
8789
"sourceChainID", source.BlockchainID,
88-
"destinationBlockchainID", destination.BlockchainID)
90+
"destinationBlockchainID", destination.BlockchainID,
91+
)
8992

9093
return receipt
9194
}
@@ -900,7 +903,9 @@ func DeployTestMessenger(
900903
subnet interfaces.SubnetTestInfo,
901904
) (common.Address, *testmessenger.TestMessenger) {
902905
opts, err := bind.NewKeyedTransactorWithChainID(
903-
senderKey, subnet.EVMChainID)
906+
senderKey,
907+
subnet.EVMChainID,
908+
)
904909
Expect(err).Should(BeNil())
905910
address, tx, exampleMessenger, err := testmessenger.DeployTestMessenger(
906911
opts,
@@ -1004,7 +1009,8 @@ func SendExampleCrossChainMessageAndVerify(
10041009
// Check that message execution failed
10051010
messageExecutionFailedEvent, err := GetEventFromLogs(
10061011
receipt.Logs,
1007-
destination.TeleporterMessenger.ParseMessageExecutionFailed)
1012+
destination.TeleporterMessenger.ParseMessageExecutionFailed,
1013+
)
10081014
Expect(err).Should(BeNil())
10091015
Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:]))
10101016
}
@@ -1036,7 +1042,8 @@ func InitOffChainMessageChainConfig(
10361042
})
10371043
log.Info("Adding off-chain message to Warp chain config",
10381044
"messageID", unsignedMessage.ID(),
1039-
"blockchainID", subnet.BlockchainID.String())
1045+
"blockchainID", subnet.BlockchainID.String(),
1046+
)
10401047

10411048
return unsignedMessage, GetChainConfigWithOffChainMessages([]avalancheWarp.UnsignedMessage{*unsignedMessage})
10421049
}
@@ -1057,7 +1064,8 @@ func CreateOffChainRegistryMessage(
10571064
unsignedMessage, err := avalancheWarp.NewUnsignedMessage(
10581065
networkID,
10591066
subnet.BlockchainID,
1060-
addressedPayload.Bytes())
1067+
addressedPayload.Bytes(),
1068+
)
10611069
Expect(err).Should(BeNil())
10621070

10631071
return unsignedMessage
@@ -1097,7 +1105,8 @@ func CreateOffChainValidatorSetSigMessage(
10971105
unsignedMessage, err := avalancheWarp.NewUnsignedMessage(
10981106
networkID,
10991107
subnet.BlockchainID,
1100-
addressedPayload.Bytes())
1108+
addressedPayload.Bytes(),
1109+
)
11011110
Expect(err).Should(BeNil())
11021111

11031112
return unsignedMessage
@@ -1127,7 +1136,8 @@ func DeployNewTeleporterVersion(
11271136
teleporterDeployerAddress,
11281137
teleporterContractAddress,
11291138
fundedKey,
1130-
false)
1139+
false,
1140+
)
11311141
return teleporterContractAddress
11321142
}
11331143

0 commit comments

Comments
 (0)