From e25618bce27efd2b1e12fb259310c7cf74a59719 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 31 Jul 2024 10:57:53 -0400 Subject: [PATCH 1/4] Fix tests? --- tests/flows/teleporter_registry.go | 28 +++++++++++++++++++--------- tests/flows/validator_churn.go | 3 --- tests/interfaces/local_network.go | 3 ++- tests/local/network.go | 18 +++++++++--------- tests/utils/utils.go | 26 ++++++++++++++++++-------- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/tests/flows/teleporter_registry.go b/tests/flows/teleporter_registry.go index edd1a0d24..b7019db47 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/flows/validator_churn.go b/tests/flows/validator_churn.go index 316c4c8b9..df0cd630b 100644 --- a/tests/flows/validator_churn.go +++ b/tests/flows/validator_churn.go @@ -61,9 +61,6 @@ func ValidatorChurn(network interfaces.LocalNetwork) { // Add new nodes to the validator set network.AddSubnetValidators(ctx, subnetAInfo.SubnetID, newNodeCount) - // Refresh the subnet info - subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network) - // Trigger the proposer VM to update its height so that the inner VM can see the new validator set // We have to update all subnets, not just the ones directly involved in this test to ensure that the // proposer VM is updated on all subnets. 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..ad954551e 100644 --- a/tests/local/network.go +++ b/tests/local/network.go @@ -90,7 +90,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 +141,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 +150,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,7 +332,8 @@ 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") @@ -464,7 +466,7 @@ 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)) + copy(n.extraNodes, n.extraNodes[count:]) apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0]) Expect(err).Should(BeNil()) @@ -535,8 +537,6 @@ func (n *LocalNetwork) RestartNodes(ctx context.Context, nodeIDs []ids.NodeID) { err := tmpnet.WaitForHealthy(ctx, node) Expect(err).Should(BeNil()) } - - n.setAllSubnetValues() } func (n *LocalNetwork) SetChainConfigs(chainConfigs map[string]string) { 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 } From efe0554d47183a2fb89177e7452bbfded7983048 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 31 Jul 2024 11:57:05 -0400 Subject: [PATCH 2/4] Fix tests? --- tests/flows/validator_churn.go | 3 +++ tests/local/network.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/flows/validator_churn.go b/tests/flows/validator_churn.go index df0cd630b..316c4c8b9 100644 --- a/tests/flows/validator_churn.go +++ b/tests/flows/validator_churn.go @@ -61,6 +61,9 @@ func ValidatorChurn(network interfaces.LocalNetwork) { // Add new nodes to the validator set network.AddSubnetValidators(ctx, subnetAInfo.SubnetID, newNodeCount) + // Refresh the subnet info + subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network) + // Trigger the proposer VM to update its height so that the inner VM can see the new validator set // We have to update all subnets, not just the ones directly involved in this test to ensure that the // proposer VM is updated on all subnets. diff --git a/tests/local/network.go b/tests/local/network.go index ad954551e..aa6aff38b 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 @@ -339,11 +340,15 @@ func (n *LocalNetwork) DeployTeleporterRegistryContracts( 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 } @@ -438,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() @@ -537,6 +542,8 @@ func (n *LocalNetwork) RestartNodes(ctx context.Context, nodeIDs []ids.NodeID) { err := tmpnet.WaitForHealthy(ctx, node) Expect(err).Should(BeNil()) } + + n.setAllSubnetValues() } func (n *LocalNetwork) SetChainConfigs(chainConfigs map[string]string) { From 881762025f780e3624fe1eb5b4d4e53485c23c56 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 31 Jul 2024 14:34:29 -0400 Subject: [PATCH 3/4] Fix slice manipulation --- tests/local/network.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/local/network.go b/tests/local/network.go index aa6aff38b..01255b1de 100644 --- a/tests/local/network.go +++ b/tests/local/network.go @@ -470,8 +470,9 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, )] // consume some of the extraNodes - newValidatorNodes := n.extraNodes[0:count] - copy(n.extraNodes, n.extraNodes[count:]) + var newValidatorNodes []*tmpnet.Node + copy(newValidatorNodes, n.extraNodes[0:count]) + n.extraNodes = n.extraNodes[count:] apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0]) Expect(err).Should(BeNil()) From e2ea3f5dfd120545f806a1c2b7928cb6a321b314 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 31 Jul 2024 14:50:56 -0400 Subject: [PATCH 4/4] Fix --- tests/local/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/local/network.go b/tests/local/network.go index 01255b1de..ea8396543 100644 --- a/tests/local/network.go +++ b/tests/local/network.go @@ -471,7 +471,7 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, // consume some of the extraNodes var newValidatorNodes []*tmpnet.Node - copy(newValidatorNodes, n.extraNodes[0:count]) + newValidatorNodes = append(newValidatorNodes, n.extraNodes[0:count]...) n.extraNodes = n.extraNodes[count:] apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0])