diff --git a/tests/flows/teleporter_registry.go b/tests/flows/teleporter_registry.go index 931dc595b..da7bf91a9 100644 --- a/tests/flows/teleporter_registry.go +++ b/tests/flows/teleporter_registry.go @@ -85,7 +85,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { subnetBInfo, newTeleporterAddress, fundedKey, - offchainMessageB) + offchainMessageB, + ) // Send a message using old Teleporter version to test messenger using new Teleporter version. // Message should be received successfully since we haven't updated mininum Teleporter version yet. @@ -99,7 +100,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { testMessengerB, fundedKey, "message_1", - true) + true, + ) // Update minimum Teleporter version on destination chain opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetBInfo.EVMChainID) @@ -117,7 +119,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { // Verify that minTeleporterVersion updated minTeleporterVersionUpdatedEvent, err := utils.GetEventFromLogs( receipt.Logs, - testMessengerB.ParseMinTeleporterVersionUpdated) + testMessengerB.ParseMinTeleporterVersionUpdated, + ) Expect(err).Should(BeNil()) Expect(minTeleporterVersionUpdatedEvent.OldMinTeleporterVersion.Cmp(minTeleporterVersion)).Should(Equal(0)) Expect(minTeleporterVersionUpdatedEvent.NewMinTeleporterVersion.Cmp(latestVersionB)).Should(Equal(0)) @@ -134,12 +137,14 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { testMessengerB, fundedKey, "message_2", - false) + false, + ) // Update the subnets to use new Teleporter messengers network.SetTeleporterContractAddress(newTeleporterAddress) cChainInfo = network.GetPrimaryNetworkInfo() subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network) + utils.SendExampleCrossChainMessageAndVerify( ctx, network, @@ -150,7 +155,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { testMessengerC, fundedKey, "message_3", - false) + false, + ) // Call addProtocolVersion on subnetA to register the new Teleporter version utils.AddProtocolVersionAndWaitForAcceptance( @@ -159,11 +165,13 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { cChainInfo, newTeleporterAddress, fundedKey, - offchainMessageC) + offchainMessageC, + ) // Send a message from A->B, which previously failed, but now using the new Teleporter version. // Teleporter versions should match, so message should be received successfully. - utils.SendExampleCrossChainMessageAndVerify(ctx, + utils.SendExampleCrossChainMessageAndVerify( + ctx, network, subnetBInfo, testMessengerB, @@ -172,7 +180,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { testMessengerC, fundedKey, "message_4", - true) + true, + ) // To make sure all subnets are using the same Teleporter version, call addProtocolVersion on subnetA // to register the new Teleporter version @@ -182,7 +191,8 @@ func TeleporterRegistry(network interfaces.LocalNetwork) { subnetAInfo, newTeleporterAddress, fundedKey, - offchainMessageA) + offchainMessageA, + ) latestVersionA, err := subnetAInfo.TeleporterRegistry.LatestVersion(&bind.CallOpts{}) Expect(err).Should(BeNil()) diff --git a/tests/interfaces/local_network.go b/tests/interfaces/local_network.go index c2f897ac3..12cdb4b9b 100644 --- a/tests/interfaces/local_network.go +++ b/tests/interfaces/local_network.go @@ -27,7 +27,8 @@ type LocalNetwork interface { deployerAddress common.Address, contractAddress common.Address, fundedKey *ecdsa.PrivateKey, - updateNetworkTeleporter bool) + updateNetworkTeleporter bool, + ) GetNetworkID() uint32 Dir() string } diff --git a/tests/local/network.go b/tests/local/network.go index 2ae69628c..ea8396543 100644 --- a/tests/local/network.go +++ b/tests/local/network.go @@ -7,6 +7,7 @@ import ( "math/big" "os" "slices" + "sort" "time" "github.com/ava-labs/avalanchego/api/info" @@ -44,7 +45,7 @@ type LocalNetwork struct { primaryNetworkInfo *interfaces.SubnetTestInfo subnetsInfo map[ids.ID]*interfaces.SubnetTestInfo - extraNodes []*tmpnet.Node // to add as more subnet vaidators in the tests + extraNodes []*tmpnet.Node // to add as more subnet validators in the tests globalFundedKey *ecdsa.PrivateKey @@ -90,7 +91,8 @@ func NewLocalNetwork( Expect(err).Should(BeNil()) warpChainConfigPath := f.Name() - allNodes := extraNodes // to be appended w/ subnet validators + var allNodes []*tmpnet.Node + allNodes = append(allNodes, extraNodes...) // to be appended w/ subnet validators var subnets []*tmpnet.Subnet for _, subnetSpec := range subnetSpecs { @@ -140,7 +142,7 @@ func NewLocalNetwork( setupProposerVM(ctx, globalFundedKey, network, subnet.SubnetID) } - res := &LocalNetwork{ + localNetwork := &LocalNetwork{ primaryNetworkInfo: &interfaces.SubnetTestInfo{}, subnetsInfo: make(map[ids.ID]*interfaces.SubnetTestInfo), extraNodes: extraNodes, @@ -149,10 +151,10 @@ func NewLocalNetwork( warpChainConfigPath: warpChainConfigPath, } for _, subnet := range network.Subnets { - res.setSubnetValues(subnet) + localNetwork.setSubnetValues(subnet) } - res.setPrimaryNetworkValues() - return res + localNetwork.setPrimaryNetworkValues() + return localNetwork } // Should be called after setSubnetValues for all subnets @@ -331,17 +333,22 @@ func (n *LocalNetwork) DeployTeleporterRegistryContracts( log.Info("Deployed TeleporterRegistry contract", "subnet", subnetInfo.SubnetID.Hex(), - "address", teleporterRegistryAddress.Hex()) + "address", teleporterRegistryAddress.Hex(), + ) } log.Info("Deployed TeleporterRegistry contracts to all subnets") } +// Returns all subnet info sorted in lexicographic order of SubnetName. func (n *LocalNetwork) GetSubnetsInfo() []interfaces.SubnetTestInfo { subnetsInfo := make([]interfaces.SubnetTestInfo, 0, len(n.subnetsInfo)) for _, subnetInfo := range n.subnetsInfo { subnetsInfo = append(subnetsInfo, *subnetInfo) } + sort.Slice(subnetsInfo, func(i, j int) bool { + return subnetsInfo[i].SubnetName < subnetsInfo[j].SubnetName + }) return subnetsInfo } @@ -436,7 +443,7 @@ func (n *LocalNetwork) setAllSubnetValues() { for _, subnetInfo := range n.subnetsInfo { subnet := n.tmpnet.GetSubnet(subnetInfo.SubnetName) Expect(subnet).ShouldNot(BeNil()) - n.setSubnetValues(n.tmpnet.GetSubnet(subnetInfo.SubnetName)) + n.setSubnetValues(subnet) } n.setPrimaryNetworkValues() @@ -463,8 +470,9 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, )] // consume some of the extraNodes - newValidatorNodes := n.extraNodes[0:count] - defer slices.Delete(n.extraNodes, 0, int(count)) + var newValidatorNodes []*tmpnet.Node + newValidatorNodes = append(newValidatorNodes, n.extraNodes[0:count]...) + n.extraNodes = n.extraNodes[count:] apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0]) Expect(err).Should(BeNil()) diff --git a/tests/utils/utils.go b/tests/utils/utils.go index 01ba1c0de..b73728763 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -70,7 +70,9 @@ func SendAddFeeAmountAndWaitForAcceptance( transactor *teleportermessenger.TeleporterMessenger, ) *types.Receipt { opts, err := bind.NewKeyedTransactorWithChainID( - senderKey, source.EVMChainID) + senderKey, + source.EVMChainID, + ) Expect(err).Should(BeNil()) tx, err := transactor.AddFeeAmount(opts, messageID, feeContractAddress, amount) @@ -85,7 +87,8 @@ func SendAddFeeAmountAndWaitForAcceptance( log.Info("Send AddFeeAmount transaction on source chain", "messageID", messageID, "sourceChainID", source.BlockchainID, - "destinationBlockchainID", destination.BlockchainID) + "destinationBlockchainID", destination.BlockchainID, + ) return receipt } @@ -900,7 +903,9 @@ func DeployTestMessenger( subnet interfaces.SubnetTestInfo, ) (common.Address, *testmessenger.TestMessenger) { opts, err := bind.NewKeyedTransactorWithChainID( - senderKey, subnet.EVMChainID) + senderKey, + subnet.EVMChainID, + ) Expect(err).Should(BeNil()) address, tx, exampleMessenger, err := testmessenger.DeployTestMessenger( opts, @@ -1004,7 +1009,8 @@ func SendExampleCrossChainMessageAndVerify( // Check that message execution failed messageExecutionFailedEvent, err := GetEventFromLogs( receipt.Logs, - destination.TeleporterMessenger.ParseMessageExecutionFailed) + destination.TeleporterMessenger.ParseMessageExecutionFailed, + ) Expect(err).Should(BeNil()) Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) } @@ -1036,7 +1042,8 @@ func InitOffChainMessageChainConfig( }) log.Info("Adding off-chain message to Warp chain config", "messageID", unsignedMessage.ID(), - "blockchainID", subnet.BlockchainID.String()) + "blockchainID", subnet.BlockchainID.String(), + ) return unsignedMessage, GetChainConfigWithOffChainMessages([]avalancheWarp.UnsignedMessage{*unsignedMessage}) } @@ -1057,7 +1064,8 @@ func CreateOffChainRegistryMessage( unsignedMessage, err := avalancheWarp.NewUnsignedMessage( networkID, subnet.BlockchainID, - addressedPayload.Bytes()) + addressedPayload.Bytes(), + ) Expect(err).Should(BeNil()) return unsignedMessage @@ -1097,7 +1105,8 @@ func CreateOffChainValidatorSetSigMessage( unsignedMessage, err := avalancheWarp.NewUnsignedMessage( networkID, subnet.BlockchainID, - addressedPayload.Bytes()) + addressedPayload.Bytes(), + ) Expect(err).Should(BeNil()) return unsignedMessage @@ -1127,7 +1136,8 @@ func DeployNewTeleporterVersion( teleporterDeployerAddress, teleporterContractAddress, fundedKey, - false) + false, + ) return teleporterContractAddress }