diff --git a/tests/flows/governance/validator_set_sig.go b/tests/flows/governance/validator_set_sig.go index 33bec5062..270b22afa 100644 --- a/tests/flows/governance/validator_set_sig.go +++ b/tests/flows/governance/validator_set_sig.go @@ -150,7 +150,7 @@ func ValidatorSetSig(network *localnetwork.LocalNetwork) { // ************************************************************************************************ // Execute the ValidatorSetSig executeCall and wait for acceptance - receipt := network.ExecuteValidatorSetSigCallAndVerify( + receipt := utils.ExecuteValidatorSetSigCallAndVerify( ctx, subnetB, subnetA, @@ -172,7 +172,7 @@ func ValidatorSetSig(network *localnetwork.LocalNetwork) { // Resend the same message again and it should fail due to nonce being consumed - _ = network.ExecuteValidatorSetSigCallAndVerify( + _ = utils.ExecuteValidatorSetSigCallAndVerify( ctx, subnetB, subnetA, @@ -188,7 +188,7 @@ func ValidatorSetSig(network *localnetwork.LocalNetwork) { Expect(endingBalance).Should(Equal(big.NewInt(100))) // Send another valid transaction with the incremented nonce - receipt2 := network.ExecuteValidatorSetSigCallAndVerify( + receipt2 := utils.ExecuteValidatorSetSigCallAndVerify( ctx, subnetB, subnetA, @@ -219,7 +219,7 @@ func ValidatorSetSig(network *localnetwork.LocalNetwork) { // Send the third transaction where the validatorSetSig contract expects validator signatures // from the same chain that it is deployed on. - receipt3 := network.ExecuteValidatorSetSigCallAndVerify( + receipt3 := utils.ExecuteValidatorSetSigCallAndVerify( ctx, subnetB, subnetB, diff --git a/tests/flows/ictt/erc20_home_erc20_remote.go b/tests/flows/ictt/erc20_home_erc20_remote.go index 7a60776dd..80a9c007a 100644 --- a/tests/flows/ictt/erc20_home_erc20_remote.go +++ b/tests/flows/ictt/erc20_home_erc20_remote.go @@ -9,7 +9,6 @@ import ( erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" - teleporterUtils "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" ) @@ -135,7 +134,7 @@ func ERC20TokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, teleport // Transfer back to home chain // Fund recipient with gas tokens on subnet A - teleporterUtils.SendNativeTransfer( + utils.SendNativeTransfer( ctx, subnetAInfo, fundedKey, @@ -158,7 +157,7 @@ func ERC20TokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, teleport erc20TokenRemote, erc20TokenRemoteAddress, inputB, - teleporterUtils.BigIntSub(transferredAmount, inputB.PrimaryFee), + utils.BigIntSub(transferredAmount, inputB.PrimaryFee), recipientKey, ) diff --git a/tests/flows/ictt/native_home_erc20_remote.go b/tests/flows/ictt/native_home_erc20_remote.go index 2ca80710c..5bf88611c 100644 --- a/tests/flows/ictt/native_home_erc20_remote.go +++ b/tests/flows/ictt/native_home_erc20_remote.go @@ -9,7 +9,6 @@ import ( erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" - teleporterUtils "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" ) @@ -131,7 +130,7 @@ func NativeTokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, telepor Expect(balance).Should(Equal(transferredAmount)) // Fund recipient with gas tokens on subnet A - teleporterUtils.SendNativeTransfer( + utils.SendNativeTransfer( ctx, subnetAInfo, fundedKey, @@ -155,7 +154,7 @@ func NativeTokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, telepor erc20TokenRemote, erc20TokenRemoteAddress, inputA, - teleporterUtils.BigIntSub(transferredAmount, inputA.PrimaryFee), + utils.BigIntSub(transferredAmount, inputA.PrimaryFee), recipientKey, ) @@ -177,5 +176,5 @@ func NativeTokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, telepor transferredAmount, ) - teleporterUtils.CheckBalance(ctx, recipientAddress, transferredAmount, cChainInfo.RPCClient) + utils.CheckBalance(ctx, recipientAddress, transferredAmount, cChainInfo.RPCClient) } diff --git a/tests/flows/ictt/native_home_erc20_remote_multihop.go b/tests/flows/ictt/native_home_erc20_remote_multihop.go index d70dfb3d9..9b6a8fdd3 100644 --- a/tests/flows/ictt/native_home_erc20_remote_multihop.go +++ b/tests/flows/ictt/native_home_erc20_remote_multihop.go @@ -8,7 +8,6 @@ import ( nativetokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/NativeTokenHome" localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" - teleporterUtils "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -128,7 +127,7 @@ func NativeTokenHomeERC20TokenRemoteMultiHop(network *localnetwork.LocalNetwork, nativeTokenHomeAddress, wavax, input, - teleporterUtils.BigIntSub(amount, input.PrimaryFee), + utils.BigIntSub(amount, input.PrimaryFee), fundedKey, ) diff --git a/tests/flows/ictt/transparent_proxy_upgradeability.go b/tests/flows/ictt/transparent_proxy_upgradeability.go index e25cc4933..15132f009 100644 --- a/tests/flows/ictt/transparent_proxy_upgradeability.go +++ b/tests/flows/ictt/transparent_proxy_upgradeability.go @@ -10,7 +10,6 @@ import ( erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" - teleporterUtils "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" ) @@ -60,7 +59,7 @@ func TransparentUpgradeableProxy(network *localnetwork.LocalNetwork, teleporter uint8(1), ) Expect(err).Should(BeNil()) - teleporterUtils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) + utils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) // Deploy a TransparentUpgradeableProxy contract on primary network for the ERC20TokenHome logic contract erc20TokenHomeAddress, proxyAdmin, erc20TokenHome := utils.DeployTransparentUpgradeableProxy( @@ -80,7 +79,7 @@ func TransparentUpgradeableProxy(network *localnetwork.LocalNetwork, teleporter tokenDecimals, ) Expect(err).Should(BeNil()) - teleporterUtils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) + utils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) // Deploy the ERC20TokenRemote contract on Subnet A erc20TokenRemoteAddress, erc20TokenRemote := utils.DeployERC20TokenRemote( @@ -165,15 +164,15 @@ func TransparentUpgradeableProxy(network *localnetwork.LocalNetwork, teleporter uint8(1), ) Expect(err).Should(BeNil()) - teleporterUtils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) + utils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) // Upgrade the TransparentUpgradeableProxy contract to use the new logic contract tx, err = proxyAdmin.UpgradeAndCall(opts, erc20TokenHomeAddress, newLogic, []byte{}) Expect(err).Should(BeNil()) - teleporterUtils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) + utils.WaitForTransactionSuccess(ctx, cChainInfo, tx.Hash()) // Send a transfer from Subnet A back to primary network - teleporterUtils.SendNativeTransfer( + utils.SendNativeTransfer( ctx, subnetAInfo, fundedKey, @@ -196,7 +195,7 @@ func TransparentUpgradeableProxy(network *localnetwork.LocalNetwork, teleporter erc20TokenRemote, erc20TokenRemoteAddress, inputB, - teleporterUtils.BigIntSub(transferredAmount, inputB.PrimaryFee), + utils.BigIntSub(transferredAmount, inputB.PrimaryFee), recipientKey, ) diff --git a/tests/flows/teleporter/basic_send_receive.go b/tests/flows/teleporter/basic_send_receive.go index 7a9764cea..41ae53be2 100644 --- a/tests/flows/teleporter/basic_send_receive.go +++ b/tests/flows/teleporter/basic_send_receive.go @@ -25,7 +25,7 @@ func BasicSendReceive(network *localnetwork.LocalNetwork, teleporter utils.Telep // Clear the receipt queue from Subnet B -> Subnet A to have a clean slate for the test flow. // This is only done if the test non-external networks because external networks may have // an arbitrarily high number of receipts to be cleared from a given queue from unrelated messages. - network.ClearReceiptQueue(ctx, teleporter, fundedKey, subnetBInfo, subnetAInfo) + teleporter.ClearReceiptQueue(ctx, fundedKey, subnetBInfo, subnetAInfo) feeAmount := big.NewInt(1) feeTokenAddress, feeToken := utils.DeployExampleERC20( diff --git a/tests/flows/teleporter/registry/pause_teleporter.go b/tests/flows/teleporter/registry/pause_teleporter.go index 1f423660b..4f6fa2763 100644 --- a/tests/flows/teleporter/registry/pause_teleporter.go +++ b/tests/flows/teleporter/registry/pause_teleporter.go @@ -51,9 +51,8 @@ func PauseTeleporter(network *localnetwork.LocalNetwork, teleporter utils.Telepo Expect(isPaused).Should(BeTrue()) // Send a message from subnet A to subnet B, which should fail - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, subnetAInfo, testMessengerA, subnetBInfo, @@ -78,9 +77,8 @@ func PauseTeleporter(network *localnetwork.LocalNetwork, teleporter utils.Telepo Expect(isPaused).Should(BeFalse()) // Send a message from subnet A to subnet B again, which should now succeed - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, subnetAInfo, testMessengerA, subnetBInfo, diff --git a/tests/flows/teleporter/registry/teleporter_registry.go b/tests/flows/teleporter/registry/teleporter_registry.go index 43f328aa3..60bfb3431 100644 --- a/tests/flows/teleporter/registry/teleporter_registry.go +++ b/tests/flows/teleporter/registry/teleporter_registry.go @@ -52,7 +52,7 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel // Deploy the new version of Teleporter to both chains var newTeleporterAddress common.Address for _, subnet := range network.GetAllSubnetsInfo() { - newTeleporterAddress = utils.DeployNewTeleporterVersion(ctx, teleporter, subnet, fundedKey, teleporterByteCodeFile) + newTeleporterAddress = teleporter.DeployNewTeleporterVersion(ctx, subnet, fundedKey, teleporterByteCodeFile) } networkID := network.GetNetworkID() @@ -92,9 +92,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel network.RestartNodes(restartCtx, nil) // Call addProtocolVersion on subnetB to register the new Teleporter version - network.AddProtocolVersionAndWaitForAcceptance( + teleporter.AddProtocolVersionAndWaitForAcceptance( ctx, - teleporter, subnetBInfo, newTeleporterAddress, fundedKey, @@ -103,9 +102,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel // 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. - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, cChainInfo, testMessengerC, subnetBInfo, @@ -140,9 +138,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel // Send a message using old Teleporter version to test messenger with updated minimum Teleporter version. // Message should fail since we updated minimum Teleporter version. - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, cChainInfo, testMessengerC, subnetBInfo, @@ -159,9 +156,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel teleporter.InitializeBlockchainID(subnet, fundedKey) } - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, subnetBInfo, testMessengerB, cChainInfo, @@ -173,9 +169,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel ) // Call addProtocolVersion on subnetA to register the new Teleporter version - network.AddProtocolVersionAndWaitForAcceptance( + teleporter.AddProtocolVersionAndWaitForAcceptance( ctx, - teleporter, cChainInfo, newTeleporterAddress, fundedKey, @@ -184,9 +179,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel // 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. - network.SendExampleCrossChainMessageAndVerify( + teleporter.SendExampleCrossChainMessageAndVerify( ctx, - teleporter, subnetBInfo, testMessengerB, cChainInfo, @@ -199,9 +193,8 @@ func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.Tel // To make sure all subnets are using the same Teleporter version, call addProtocolVersion on subnetA // to register the new Teleporter version - network.AddProtocolVersionAndWaitForAcceptance( + teleporter.AddProtocolVersionAndWaitForAcceptance( ctx, - teleporter, subnetAInfo, newTeleporterAddress, fundedKey, diff --git a/tests/flows/teleporter/send_specific_receipts.go b/tests/flows/teleporter/send_specific_receipts.go index fff563247..386aee8e1 100644 --- a/tests/flows/teleporter/send_specific_receipts.go +++ b/tests/flows/teleporter/send_specific_receipts.go @@ -27,7 +27,7 @@ func SendSpecificReceipts(network *localnetwork.LocalNetwork, teleporter utils.T ctx := context.Background() // Clear the receipt queue from Subnet B -> Subnet A to have a clean slate for the test flow. - network.ClearReceiptQueue(ctx, teleporter, fundedKey, subnetBInfo, subnetAInfo) + teleporter.ClearReceiptQueue(ctx, fundedKey, subnetBInfo, subnetAInfo) // Use mock token as the fee token mockTokenAddress, mockToken := utils.DeployExampleERC20( diff --git a/tests/interfaces/subnet_test_info.go b/tests/interfaces/subnet_test_info.go index 0ab8e6807..73aa58d62 100644 --- a/tests/interfaces/subnet_test_info.go +++ b/tests/interfaces/subnet_test_info.go @@ -9,7 +9,6 @@ import ( // Tracks information about a test subnet used for executing tests against. type SubnetTestInfo struct { - SubnetName string SubnetID ids.ID BlockchainID ids.ID NodeURIs []string diff --git a/tests/network/network.go b/tests/network/network.go index 7f51add76..2580260f3 100644 --- a/tests/network/network.go +++ b/tests/network/network.go @@ -6,10 +6,8 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" - "math/big" "os" "slices" - "sort" "time" "github.com/ava-labs/avalanchego/api/info" @@ -17,19 +15,13 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" "github.com/ava-labs/avalanchego/upgrade" - "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/vms/platformvm" - avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/secp256k1fx" pwallet "github.com/ava-labs/avalanchego/wallet/chain/p/wallet" "github.com/ava-labs/avalanchego/wallet/subnet/primary" - "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/ethclient" subnetEvmTestUtils "github.com/ava-labs/subnet-evm/tests/utils" - teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - testmessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/tests/TestMessenger" "github.com/ava-labs/teleporter/tests/interfaces" "github.com/ava-labs/teleporter/tests/utils" @@ -41,16 +33,12 @@ import ( // Implements Network, pointing to the network setup in local_network_setup.go type LocalNetwork struct { - primaryNetworkInfo *interfaces.SubnetTestInfo - subnetsInfo map[ids.ID]*interfaces.SubnetTestInfo + tmpnet.Network - extraNodes []*tmpnet.Node // to add as more subnet validators in the tests - - globalFundedKey *ecdsa.PrivateKey - pChainWallet pwallet.Wallet - - // Internal vars only used to set up the local network - tmpnet *tmpnet.Network + extraNodes []*tmpnet.Node // to add as more subnet validators in the tests + primaryNetworkValidators []ids.NodeID + globalFundedKey *ecdsa.PrivateKey + pChainWallet pwallet.Wallet } const ( @@ -152,17 +140,18 @@ func NewLocalNetwork( utils.SetupProposerVM(ctx, globalFundedECDSAKey, network, subnet.SubnetID) } - localNetwork := &LocalNetwork{ - primaryNetworkInfo: &interfaces.SubnetTestInfo{}, - subnetsInfo: make(map[ids.ID]*interfaces.SubnetTestInfo), - extraNodes: extraNodes, - globalFundedKey: globalFundedECDSAKey, - tmpnet: network, + // All nodes are specified as bootstrap validators + var primaryNetworkValidators []ids.NodeID + for _, node := range network.Nodes { + primaryNetworkValidators = append(primaryNetworkValidators, node.NodeID) } - for _, subnet := range network.Subnets { - localNetwork.setSubnetValues(subnet) + + localNetwork := &LocalNetwork{ + Network: *network, + extraNodes: extraNodes, + globalFundedKey: globalFundedECDSAKey, + primaryNetworkValidators: primaryNetworkValidators, } - localNetwork.setPrimaryNetworkValues() // Create the P-Chain wallet to issue transactions kc := secp256k1fx.NewKeychain(globalFundedKey) @@ -183,103 +172,65 @@ func NewLocalNetwork( return localNetwork } -// Should be called after setSubnetValues for all subnets -func (n *LocalNetwork) setPrimaryNetworkValues() { - // Get the C-Chain node URIs. - // All subnet nodes validate the C-Chain, so we can include them all here +func (n *LocalNetwork) GetPrimaryNetworkInfo() interfaces.SubnetTestInfo { var nodeURIs []string - for _, subnetInfo := range n.subnetsInfo { - nodeURIs = append(nodeURIs, subnetInfo.NodeURIs...) - } - for _, extraNode := range n.extraNodes { - uri, err := n.tmpnet.GetURIForNodeID(extraNode.NodeID) + for _, nodeID := range n.primaryNetworkValidators { + uri, err := n.Network.GetURIForNodeID(nodeID) Expect(err).Should(BeNil()) + nodeURIs = append(nodeURIs, uri) } - - cChainBlockchainID, err := info.NewClient(nodeURIs[0]).GetBlockchainID(context.Background(), "C") + infoClient := info.NewClient(nodeURIs[0]) + cChainBlockchainID, err := infoClient.GetBlockchainID(context.Background(), "C") Expect(err).Should(BeNil()) - Expect(cChainBlockchainID).ShouldNot(Equal(ids.Empty)) - chainWSURI := utils.HttpToWebsocketURI(nodeURIs[0], cChainBlockchainID.String()) - chainRPCURI := utils.HttpToRPCURI(nodeURIs[0], cChainBlockchainID.String()) - if n.primaryNetworkInfo != nil && n.primaryNetworkInfo.WSClient != nil { - n.primaryNetworkInfo.WSClient.Close() - } - chainWSClient, err := ethclient.Dial(chainWSURI) - Expect(err).Should(BeNil()) - if n.primaryNetworkInfo != nil && n.primaryNetworkInfo.RPCClient != nil { - n.primaryNetworkInfo.RPCClient.Close() - } - chainRPCClient, err := ethclient.Dial(chainRPCURI) + wsClient, err := ethclient.Dial(utils.HttpToWebsocketURI(nodeURIs[0], cChainBlockchainID.String())) Expect(err).Should(BeNil()) - chainIDInt, err := chainRPCClient.ChainID(context.Background()) - Expect(err).Should(BeNil()) - - n.primaryNetworkInfo.SubnetID = constants.PrimaryNetworkID - n.primaryNetworkInfo.BlockchainID = cChainBlockchainID - n.primaryNetworkInfo.NodeURIs = nodeURIs - n.primaryNetworkInfo.WSClient = chainWSClient - n.primaryNetworkInfo.RPCClient = chainRPCClient - n.primaryNetworkInfo.EVMChainID = chainIDInt -} - -func (n *LocalNetwork) setSubnetValues(subnet *tmpnet.Subnet) { - blockchainID := subnet.Chains[0].ChainID - - var chainNodeURIs []string - for _, validatorID := range subnet.ValidatorIDs { - uri, err := n.tmpnet.GetURIForNodeID(validatorID) - Expect(err).Should(BeNil(), "failed to get URI for node ID %s", validatorID) - Expect(uri).ShouldNot(HaveLen(0)) - chainNodeURIs = append(chainNodeURIs, uri) - } - chainWSURI := utils.HttpToWebsocketURI(chainNodeURIs[0], blockchainID.String()) - chainRPCURI := utils.HttpToRPCURI(chainNodeURIs[0], blockchainID.String()) - - subnetID := subnet.SubnetID - - if n.subnetsInfo[subnetID] != nil && n.subnetsInfo[subnetID].WSClient != nil { - n.subnetsInfo[subnetID].WSClient.Close() - } - chainWSClient, err := ethclient.Dial(chainWSURI) - Expect(err).Should(BeNil()) - if n.subnetsInfo[subnetID] != nil && n.subnetsInfo[subnetID].RPCClient != nil { - n.subnetsInfo[subnetID].RPCClient.Close() - } - chainRPCClient, err := ethclient.Dial(chainRPCURI) - Expect(err).Should(BeNil()) - chainIDInt, err := chainRPCClient.ChainID(context.Background()) + rpcClient, err := ethclient.Dial(utils.HttpToRPCURI(nodeURIs[0], cChainBlockchainID.String())) Expect(err).Should(BeNil()) - // Set the new values in the subnetsInfo map - if n.subnetsInfo[subnetID] == nil { - n.subnetsInfo[subnetID] = &interfaces.SubnetTestInfo{} + evmChainID, err := rpcClient.ChainID(context.Background()) + Expect(err).Should(BeNil()) + return interfaces.SubnetTestInfo{ + SubnetID: ids.Empty, + BlockchainID: cChainBlockchainID, + NodeURIs: nodeURIs, + WSClient: wsClient, + RPCClient: rpcClient, + EVMChainID: evmChainID, } - n.subnetsInfo[subnetID].SubnetName = subnet.Name - n.subnetsInfo[subnetID].SubnetID = subnetID - n.subnetsInfo[subnetID].BlockchainID = blockchainID - n.subnetsInfo[subnetID].NodeURIs = chainNodeURIs - n.subnetsInfo[subnetID].WSClient = chainWSClient - n.subnetsInfo[subnetID].RPCClient = chainRPCClient - n.subnetsInfo[subnetID].EVMChainID = chainIDInt } // 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 -} + subnets := make([]interfaces.SubnetTestInfo, len(n.Network.Subnets)) + for i, subnet := range n.Network.Subnets { + var nodeURIs []string + for _, nodeID := range subnet.ValidatorIDs { + uri, err := n.Network.GetURIForNodeID(nodeID) + Expect(err).Should(BeNil()) + + nodeURIs = append(nodeURIs, uri) + } + blockchainID := subnet.Chains[0].ChainID + wsClient, err := ethclient.Dial(utils.HttpToWebsocketURI(nodeURIs[0], blockchainID.String())) + Expect(err).Should(BeNil()) -func (n *LocalNetwork) GetPrimaryNetworkInfo() interfaces.SubnetTestInfo { - return *n.primaryNetworkInfo + rpcClient, err := ethclient.Dial(utils.HttpToRPCURI(nodeURIs[0], blockchainID.String())) + Expect(err).Should(BeNil()) + evmChainID, err := rpcClient.ChainID(context.Background()) + Expect(err).Should(BeNil()) + subnets[i] = interfaces.SubnetTestInfo{ + SubnetID: subnet.SubnetID, + BlockchainID: blockchainID, + NodeURIs: nodeURIs, + WSClient: wsClient, + RPCClient: rpcClient, + EVMChainID: evmChainID, + } + } + return subnets } // Returns subnet info for all subnets, including the primary network @@ -293,24 +244,11 @@ func (n *LocalNetwork) GetFundedAccountInfo() (common.Address, *ecdsa.PrivateKey return fundedAddress, n.globalFundedKey } -func (n *LocalNetwork) setAllSubnetValues() { - subnetIDs := n.GetSubnetsInfo() - Expect(len(subnetIDs)).Should(Equal(2)) - - for _, subnetInfo := range n.subnetsInfo { - subnet := n.tmpnet.GetSubnet(subnetInfo.SubnetName) - Expect(subnet).ShouldNot(BeNil()) - n.setSubnetValues(subnet) - } - - n.setPrimaryNetworkValues() -} - func (n *LocalNetwork) TearDownNetwork() { log.Info("Tearing down network") Expect(n).ShouldNot(BeNil()) - Expect(n.tmpnet).ShouldNot(BeNil()) - Expect(n.tmpnet.Stop(context.Background())).Should(BeNil()) + Expect(n.Network).ShouldNot(BeNil()) + Expect(n.Network.Stop(context.Background())).Should(BeNil()) } func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, count uint) { @@ -320,8 +258,8 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, "not enough extra nodes to use", ) - subnet := n.tmpnet.Subnets[slices.IndexFunc( - n.tmpnet.Subnets, + subnet := n.Network.Subnets[slices.IndexFunc( + n.Network.Subnets, func(s *tmpnet.Subnet) bool { return s.SubnetID == subnetID }, )] @@ -330,7 +268,7 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, newValidatorNodes = append(newValidatorNodes, n.extraNodes[0:count]...) n.extraNodes = n.extraNodes[count:] - apiURI, err := n.tmpnet.GetURIForNodeID(subnet.ValidatorIDs[0]) + apiURI, err := n.Network.GetURIForNodeID(subnet.ValidatorIDs[0]) Expect(err).Should(BeNil()) ctx, cancel := context.WithCancel(ctx) @@ -348,15 +286,14 @@ func (n *LocalNetwork) AddSubnetValidators(ctx context.Context, subnetID ids.ID, node.Flags[config.TrackSubnetsKey] = subnetID.String() } - tmpnet.WaitForActiveValidators(ctx, os.Stdout, platformvm.NewClient(n.tmpnet.Nodes[0].URI), subnet) + tmpnet.WaitForActiveValidators(ctx, os.Stdout, platformvm.NewClient(n.Network.Nodes[0].URI), subnet) nodeIdsToRestart := make([]ids.NodeID, len(newValidatorNodes)) for i, node := range newValidatorNodes { + n.primaryNetworkValidators = append(n.primaryNetworkValidators, node.NodeID) nodeIdsToRestart[i] = node.NodeID } n.RestartNodes(ctx, nodeIdsToRestart) - - n.setAllSubnetValues() } // Restarts the nodes with the given nodeIDs. If nodeIDs is empty, restarts all nodes. @@ -364,10 +301,10 @@ func (n *LocalNetwork) RestartNodes(ctx context.Context, nodeIDs []ids.NodeID) { log.Info("Restarting nodes", "nodeIDs", nodeIDs) var nodes []*tmpnet.Node if len(nodeIDs) == 0 { - nodes = n.tmpnet.Nodes + nodes = n.Network.Nodes } else { for _, nodeID := range nodeIDs { - for _, node := range n.tmpnet.Nodes { + for _, node := range n.Network.Nodes { if node.NodeID == nodeID { nodes = append(nodes, node) } @@ -384,7 +321,7 @@ func (n *LocalNetwork) RestartNodes(ctx context.Context, nodeIDs []ids.NodeID) { err = node.Stop(ctx) Expect(err).Should(BeNil()) - err = n.tmpnet.StartNode(ctx, os.Stdout, node) + err = n.Network.StartNode(ctx, os.Stdout, node) Expect(err).Should(BeNil()) } @@ -395,8 +332,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) { @@ -411,11 +346,11 @@ func (n *LocalNetwork) SetChainConfigs(chainConfigs map[string]string) { "chainConfig", chainConfig, ) } - n.tmpnet.ChainConfigs[utils.CChainPathSpecifier] = cfg + n.Network.ChainConfigs[utils.CChainPathSpecifier] = cfg continue } - for _, subnet := range n.tmpnet.Subnets { + for _, subnet := range n.Network.Subnets { for _, chain := range subnet.Chains { if chain.ChainID.String() == chainIDStr { chain.Config = chainConfig @@ -423,12 +358,12 @@ func (n *LocalNetwork) SetChainConfigs(chainConfigs map[string]string) { } } } - err := n.tmpnet.Write() + err := n.Network.Write() if err != nil { log.Error("failed to write network", "error", err) } - for _, subnet := range n.tmpnet.Subnets { - err := subnet.Write(n.tmpnet.GetSubnetDir(), n.tmpnet.GetChainConfigDir()) + for _, subnet := range n.Network.Subnets { + err := subnet.Write(n.Network.GetSubnetDir(), n.Network.GetChainConfigDir()) if err != nil { log.Error("failed to write subnets", "error", err) } @@ -436,124 +371,17 @@ func (n *LocalNetwork) SetChainConfigs(chainConfigs map[string]string) { } func (n *LocalNetwork) GetNetworkID() uint32 { - return n.tmpnet.Genesis.NetworkID + return n.Network.Genesis.NetworkID } func (n *LocalNetwork) Dir() string { - return n.tmpnet.Dir + return n.Network.Dir } func (n *LocalNetwork) GetPChainWallet() pwallet.Wallet { return n.pChainWallet } -func (n *LocalNetwork) ClearReceiptQueue( - ctx context.Context, - teleporter utils.TeleporterTestInfo, - fundedKey *ecdsa.PrivateKey, - source interfaces.SubnetTestInfo, - destination interfaces.SubnetTestInfo, -) { - sourceTeleporterMessenger := teleporter.TeleporterMessenger(source) - outstandReceiptCount := utils.GetOutstandingReceiptCount( - teleporter.TeleporterMessenger(source), - destination.BlockchainID, - ) - for outstandReceiptCount.Cmp(big.NewInt(0)) != 0 { - log.Info("Emptying receipt queue", "remainingReceipts", outstandReceiptCount.String()) - // Send message from Subnet B to Subnet A to trigger the "regular" method of delivering receipts. - // The next message from B->A will contain the same receipts that were manually sent in the above steps, - // but they should not be processed again on Subnet A. - sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{ - DestinationBlockchainID: destination.BlockchainID, - DestinationAddress: common.HexToAddress("0x1111111111111111111111111111111111111111"), - RequiredGasLimit: big.NewInt(1), - FeeInfo: teleportermessenger.TeleporterFeeInfo{ - FeeTokenAddress: common.Address{}, - Amount: big.NewInt(0), - }, - AllowedRelayerAddresses: []common.Address{}, - Message: []byte{1, 2, 3, 4}, - } - - // This message will also have the same receipts as the previous message - receipt, _ := utils.SendCrossChainMessageAndWaitForAcceptance( - ctx, sourceTeleporterMessenger, source, destination, sendCrossChainMessageInput, fundedKey) - - // Relay message - teleporter.RelayTeleporterMessage(ctx, receipt, source, destination, true, fundedKey) - - outstandReceiptCount = utils.GetOutstandingReceiptCount(sourceTeleporterMessenger, destination.BlockchainID) - } - log.Info("Receipt queue emptied") -} - -// Returns Receipt for the transaction unlike TeleporterRegistry version since this is a non-teleporter case -// and we don't want to add the ValidatorSetSig ABI to the subnetInfo -func (n *LocalNetwork) ExecuteValidatorSetSigCallAndVerify( - ctx context.Context, - source interfaces.SubnetTestInfo, - destination interfaces.SubnetTestInfo, - validatorSetSigAddress common.Address, - senderKey *ecdsa.PrivateKey, - unsignedMessage *avalancheWarp.UnsignedMessage, - expectSuccess bool, -) *types.Receipt { - signedWarpMsg := utils.GetSignedMessage(ctx, source, destination, unsignedMessage.ID()) - log.Info("Got signed warp message", "messageID", signedWarpMsg.ID()) - - signedPredicateTx := utils.CreateExecuteCallPredicateTransaction( - ctx, - signedWarpMsg, - validatorSetSigAddress, - senderKey, - destination, - ) - - // Wait for tx to be accepted and verify events emitted - if expectSuccess { - return utils.SendTransactionAndWaitForSuccess(ctx, destination, signedPredicateTx) - } - return utils.SendTransactionAndWaitForFailure(ctx, destination, signedPredicateTx) -} - -func (n *LocalNetwork) AddProtocolVersionAndWaitForAcceptance( - ctx context.Context, - teleporter utils.TeleporterTestInfo, - subnet interfaces.SubnetTestInfo, - newTeleporterAddress common.Address, - senderKey *ecdsa.PrivateKey, - unsignedMessage *avalancheWarp.UnsignedMessage, -) { - signedWarpMsg := utils.GetSignedMessage(ctx, subnet, subnet, unsignedMessage.ID()) - log.Info("Got signed warp message", "messageID", signedWarpMsg.ID()) - - // Construct tx to add protocol version and send to destination chain - signedTx := utils.CreateAddProtocolVersionTransaction( - ctx, - signedWarpMsg, - teleporter.TeleporterRegistryAddress(subnet), - senderKey, - subnet, - ) - - curLatestVersion := teleporter.GetLatestTeleporterVersion(subnet) - expectedLatestVersion := big.NewInt(curLatestVersion.Int64() + 1) - - // Wait for tx to be accepted, and verify events emitted - receipt := utils.SendTransactionAndWaitForSuccess(ctx, subnet, signedTx) - teleporterRegistry := teleporter.TeleporterRegistry(subnet) - addProtocolVersionEvent, err := utils.GetEventFromLogs(receipt.Logs, teleporterRegistry.ParseAddProtocolVersion) - Expect(err).Should(BeNil()) - Expect(addProtocolVersionEvent.Version.Cmp(expectedLatestVersion)).Should(Equal(0)) - Expect(addProtocolVersionEvent.ProtocolAddress).Should(Equal(newTeleporterAddress)) - - versionUpdatedEvent, err := utils.GetEventFromLogs(receipt.Logs, teleporterRegistry.ParseLatestVersionUpdated) - Expect(err).Should(BeNil()) - Expect(versionUpdatedEvent.OldVersion.Cmp(curLatestVersion)).Should(Equal(0)) - Expect(versionUpdatedEvent.NewVersion.Cmp(expectedLatestVersion)).Should(Equal(0)) -} - func (n *LocalNetwork) GetTwoSubnets() ( interfaces.SubnetTestInfo, interfaces.SubnetTestInfo, @@ -562,85 +390,3 @@ func (n *LocalNetwork) GetTwoSubnets() ( Expect(len(subnets)).Should(BeNumerically(">=", 2)) return subnets[0], subnets[1] } - -func (n *LocalNetwork) SendExampleCrossChainMessageAndVerify( - ctx context.Context, - teleporter utils.TeleporterTestInfo, - source interfaces.SubnetTestInfo, - sourceExampleMessenger *testmessenger.TestMessenger, - destination interfaces.SubnetTestInfo, - destExampleMessengerAddress common.Address, - destExampleMessenger *testmessenger.TestMessenger, - senderKey *ecdsa.PrivateKey, - message string, - expectSuccess bool, -) { - // Call the example messenger contract on Subnet A - optsA, err := bind.NewKeyedTransactorWithChainID(senderKey, source.EVMChainID) - Expect(err).Should(BeNil()) - tx, err := sourceExampleMessenger.SendMessage( - optsA, - destination.BlockchainID, - destExampleMessengerAddress, - common.BigToAddress(common.Big0), - big.NewInt(0), - testmessenger.SendMessageRequiredGas, - message, - ) - Expect(err).Should(BeNil()) - - // Wait for the transaction to be mined - receipt := utils.WaitForTransactionSuccess(ctx, source, tx.Hash()) - - sourceTeleporterMessenger := teleporter.TeleporterMessenger(source) - destTeleporterMessenger := teleporter.TeleporterMessenger(destination) - - event, err := utils.GetEventFromLogs(receipt.Logs, sourceTeleporterMessenger.ParseSendCrossChainMessage) - Expect(err).Should(BeNil()) - Expect(event.DestinationBlockchainID[:]).Should(Equal(destination.BlockchainID[:])) - - teleporterMessageID := event.MessageID - - // - // Relay the message to the destination - // - receipt = teleporter.RelayTeleporterMessage(ctx, receipt, source, destination, true, senderKey) - - // - // Check Teleporter message received on the destination - // - delivered, err := destTeleporterMessenger.MessageReceived( - &bind.CallOpts{}, teleporterMessageID, - ) - Expect(err).Should(BeNil()) - Expect(delivered).Should(BeTrue()) - - if expectSuccess { - // Check that message execution was successful - messageExecutedEvent, err := utils.GetEventFromLogs( - receipt.Logs, - destTeleporterMessenger.ParseMessageExecuted, - ) - Expect(err).Should(BeNil()) - Expect(messageExecutedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) - } else { - // Check that message execution failed - messageExecutionFailedEvent, err := utils.GetEventFromLogs( - receipt.Logs, - destTeleporterMessenger.ParseMessageExecutionFailed, - ) - Expect(err).Should(BeNil()) - Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) - } - - // - // Verify we received the expected string - // - _, currMessage, err := destExampleMessenger.GetCurrentMessage(&bind.CallOpts{}, source.BlockchainID) - Expect(err).Should(BeNil()) - if expectSuccess { - Expect(currMessage).Should(Equal(message)) - } else { - Expect(currMessage).ShouldNot(Equal(message)) - } -} diff --git a/tests/utils/teleporter.go b/tests/utils/teleporter.go index 961184f89..a140d51eb 100644 --- a/tests/utils/teleporter.go +++ b/tests/utils/teleporter.go @@ -188,15 +188,173 @@ func (t TeleporterTestInfo) RelayTeleporterMessage( return receipt } -// -// Deployment utils -// +func (t TeleporterTestInfo) SendExampleCrossChainMessageAndVerify( + ctx context.Context, + source interfaces.SubnetTestInfo, + sourceExampleMessenger *testmessenger.TestMessenger, + destination interfaces.SubnetTestInfo, + destExampleMessengerAddress common.Address, + destExampleMessenger *testmessenger.TestMessenger, + senderKey *ecdsa.PrivateKey, + message string, + expectSuccess bool, +) { + // Call the example messenger contract on Subnet A + optsA, err := bind.NewKeyedTransactorWithChainID(senderKey, source.EVMChainID) + Expect(err).Should(BeNil()) + tx, err := sourceExampleMessenger.SendMessage( + optsA, + destination.BlockchainID, + destExampleMessengerAddress, + common.BigToAddress(common.Big0), + big.NewInt(0), + testmessenger.SendMessageRequiredGas, + message, + ) + Expect(err).Should(BeNil()) + + // Wait for the transaction to be mined + receipt := WaitForTransactionSuccess(ctx, source, tx.Hash()) + + sourceTeleporterMessenger := t.TeleporterMessenger(source) + destTeleporterMessenger := t.TeleporterMessenger(destination) + + event, err := GetEventFromLogs(receipt.Logs, sourceTeleporterMessenger.ParseSendCrossChainMessage) + Expect(err).Should(BeNil()) + Expect(event.DestinationBlockchainID[:]).Should(Equal(destination.BlockchainID[:])) + + teleporterMessageID := event.MessageID + + // + // Relay the message to the destination + // + receipt = t.RelayTeleporterMessage(ctx, receipt, source, destination, true, senderKey) + + // + // Check Teleporter message received on the destination + // + delivered, err := destTeleporterMessenger.MessageReceived( + &bind.CallOpts{}, teleporterMessageID, + ) + Expect(err).Should(BeNil()) + Expect(delivered).Should(BeTrue()) + + if expectSuccess { + // Check that message execution was successful + messageExecutedEvent, err := GetEventFromLogs( + receipt.Logs, + destTeleporterMessenger.ParseMessageExecuted, + ) + Expect(err).Should(BeNil()) + Expect(messageExecutedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) + } else { + // Check that message execution failed + messageExecutionFailedEvent, err := GetEventFromLogs( + receipt.Logs, + destTeleporterMessenger.ParseMessageExecutionFailed, + ) + Expect(err).Should(BeNil()) + Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) + } + + // + // Verify we received the expected string + // + _, currMessage, err := destExampleMessenger.GetCurrentMessage(&bind.CallOpts{}, source.BlockchainID) + Expect(err).Should(BeNil()) + if expectSuccess { + Expect(currMessage).Should(Equal(message)) + } else { + Expect(currMessage).ShouldNot(Equal(message)) + } +} + +func (t TeleporterTestInfo) AddProtocolVersionAndWaitForAcceptance( + ctx context.Context, + subnet interfaces.SubnetTestInfo, + newTeleporterAddress common.Address, + senderKey *ecdsa.PrivateKey, + unsignedMessage *avalancheWarp.UnsignedMessage, +) { + signedWarpMsg := GetSignedMessage(ctx, subnet, subnet, unsignedMessage.ID()) + log.Info("Got signed warp message", "messageID", signedWarpMsg.ID()) + + // Construct tx to add protocol version and send to destination chain + signedTx := CreateAddProtocolVersionTransaction( + ctx, + signedWarpMsg, + t.TeleporterRegistryAddress(subnet), + senderKey, + subnet, + ) + + curLatestVersion := t.GetLatestTeleporterVersion(subnet) + expectedLatestVersion := big.NewInt(curLatestVersion.Int64() + 1) + + // Wait for tx to be accepted, and verify events emitted + receipt := SendTransactionAndWaitForSuccess(ctx, subnet, signedTx) + teleporterRegistry := t.TeleporterRegistry(subnet) + addProtocolVersionEvent, err := GetEventFromLogs(receipt.Logs, teleporterRegistry.ParseAddProtocolVersion) + Expect(err).Should(BeNil()) + Expect(addProtocolVersionEvent.Version.Cmp(expectedLatestVersion)).Should(Equal(0)) + Expect(addProtocolVersionEvent.ProtocolAddress).Should(Equal(newTeleporterAddress)) + + versionUpdatedEvent, err := GetEventFromLogs(receipt.Logs, teleporterRegistry.ParseLatestVersionUpdated) + Expect(err).Should(BeNil()) + Expect(versionUpdatedEvent.OldVersion.Cmp(curLatestVersion)).Should(Equal(0)) + Expect(versionUpdatedEvent.NewVersion.Cmp(expectedLatestVersion)).Should(Equal(0)) +} + +func (t TeleporterTestInfo) GetLatestTeleporterVersion(subnet interfaces.SubnetTestInfo) *big.Int { + version, err := t.TeleporterRegistry(subnet).LatestVersion(&bind.CallOpts{}) + Expect(err).Should(BeNil()) + return version +} + +func (t TeleporterTestInfo) ClearReceiptQueue( + ctx context.Context, + fundedKey *ecdsa.PrivateKey, + source interfaces.SubnetTestInfo, + destination interfaces.SubnetTestInfo, +) { + sourceTeleporterMessenger := t.TeleporterMessenger(source) + outstandReceiptCount := GetOutstandingReceiptCount( + t.TeleporterMessenger(source), + destination.BlockchainID, + ) + for outstandReceiptCount.Cmp(big.NewInt(0)) != 0 { + log.Info("Emptying receipt queue", "remainingReceipts", outstandReceiptCount.String()) + // Send message from Subnet B to Subnet A to trigger the "regular" method of delivering receipts. + // The next message from B->A will contain the same receipts that were manually sent in the above steps, + // but they should not be processed again on Subnet A. + sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{ + DestinationBlockchainID: destination.BlockchainID, + DestinationAddress: common.HexToAddress("0x1111111111111111111111111111111111111111"), + RequiredGasLimit: big.NewInt(1), + FeeInfo: teleportermessenger.TeleporterFeeInfo{ + FeeTokenAddress: common.Address{}, + Amount: big.NewInt(0), + }, + AllowedRelayerAddresses: []common.Address{}, + Message: []byte{1, 2, 3, 4}, + } + + // This message will also have the same receipts as the previous message + receipt, _ := SendCrossChainMessageAndWaitForAcceptance( + ctx, sourceTeleporterMessenger, source, destination, sendCrossChainMessageInput, fundedKey) + + // Relay message + t.RelayTeleporterMessage(ctx, receipt, source, destination, true, fundedKey) + + outstandReceiptCount = GetOutstandingReceiptCount(sourceTeleporterMessenger, destination.BlockchainID) + } + log.Info("Receipt queue emptied") +} // Deploys a new version of Teleporter and returns its address // Does NOT modify the global Teleporter contract address to provide greater testing flexibility. -func DeployNewTeleporterVersion( +func (t TeleporterTestInfo) DeployNewTeleporterVersion( ctx context.Context, - teleporterInfo TeleporterTestInfo, subnet interfaces.SubnetTestInfo, fundedKey *ecdsa.PrivateKey, teleporterByteCodeFile string, @@ -213,7 +371,7 @@ func DeployNewTeleporterVersion( ) Expect(err).Should(BeNil()) - teleporterInfo.DeployTeleporterMessenger( + t.DeployTeleporterMessenger( ctx, subnet, teleporterDeployerTransaction, @@ -225,6 +383,10 @@ func DeployNewTeleporterVersion( return teleporterContractAddress } +// +// Deployment utils +// + func DeployTestMessenger( ctx context.Context, senderKey *ecdsa.PrivateKey, @@ -406,55 +568,6 @@ func SendSpecifiedReceiptsAndWaitForAcceptance( return receipt, event.MessageID } -func AddProtocolVersionAndWaitForAcceptance( - ctx context.Context, - sourceTeleporterInfo ChainTeleporterInfo, - subnet interfaces.SubnetTestInfo, - newTeleporterAddress common.Address, - senderKey *ecdsa.PrivateKey, - unsignedMessage *avalancheWarp.UnsignedMessage, -) { - signedWarpMsg := GetSignedMessage(ctx, subnet, subnet, unsignedMessage.ID()) - log.Info("Got signed warp message", "messageID", signedWarpMsg.ID()) - - // Construct tx to add protocol version and send to destination chain - signedTx := CreateAddProtocolVersionTransaction( - ctx, - signedWarpMsg, - sourceTeleporterInfo.TeleporterRegistryAddress, - senderKey, - subnet, - ) - - curLatestVersion, err := sourceTeleporterInfo.TeleporterRegistry.LatestVersion(&bind.CallOpts{}) - Expect(err).Should(BeNil()) - expectedLatestVersion := big.NewInt(curLatestVersion.Int64() + 1) - - // Wait for tx to be accepted, and verify events emitted - receipt := SendTransactionAndWaitForSuccess(ctx, subnet, signedTx) - addProtocolVersionEvent, err := GetEventFromLogs( - receipt.Logs, - sourceTeleporterInfo.TeleporterRegistry.ParseAddProtocolVersion, - ) - Expect(err).Should(BeNil()) - Expect(addProtocolVersionEvent.Version.Cmp(expectedLatestVersion)).Should(Equal(0)) - Expect(addProtocolVersionEvent.ProtocolAddress).Should(Equal(newTeleporterAddress)) - - versionUpdatedEvent, err := GetEventFromLogs( - receipt.Logs, - sourceTeleporterInfo.TeleporterRegistry.ParseLatestVersionUpdated, - ) - Expect(err).Should(BeNil()) - Expect(versionUpdatedEvent.OldVersion.Cmp(curLatestVersion)).Should(Equal(0)) - Expect(versionUpdatedEvent.NewVersion.Cmp(expectedLatestVersion)).Should(Equal(0)) -} - -func (t TeleporterTestInfo) GetLatestTeleporterVersion(subnet interfaces.SubnetTestInfo) *big.Int { - version, err := t.TeleporterRegistry(subnet).LatestVersion(&bind.CallOpts{}) - Expect(err).Should(BeNil()) - return version -} - func SendCrossChainMessageAndWaitForAcceptance( ctx context.Context, sourceTeleporterMessenger *teleportermessenger.TeleporterMessenger, @@ -500,49 +613,6 @@ func CheckReceiptReceived( return false } -func ClearReceiptQueue( - ctx context.Context, - teleporterInfo TeleporterTestInfo, - source interfaces.SubnetTestInfo, - destination interfaces.SubnetTestInfo, - fundedKey *ecdsa.PrivateKey, -) { - outstandReceiptCount := GetOutstandingReceiptCount( - teleporterInfo.TeleporterMessenger(source), - destination.BlockchainID, - ) - for outstandReceiptCount.Cmp(big.NewInt(0)) != 0 { - log.Info("Emptying receipt queue", "remainingReceipts", outstandReceiptCount.String()) - // Send message from Subnet B to Subnet A to trigger the "regular" method of delivering receipts. - // The next message from B->A will contain the same receipts that were manually sent in the above steps, - // but they should not be processed again on Subnet A. - sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{ - DestinationBlockchainID: destination.BlockchainID, - DestinationAddress: common.HexToAddress("0x1111111111111111111111111111111111111111"), - RequiredGasLimit: big.NewInt(1), - FeeInfo: teleportermessenger.TeleporterFeeInfo{ - FeeTokenAddress: common.Address{}, - Amount: big.NewInt(0), - }, - AllowedRelayerAddresses: []common.Address{}, - Message: []byte{1, 2, 3, 4}, - } - - // This message will also have the same receipts as the previous message - receipt, _ := SendCrossChainMessageAndWaitForAcceptance( - ctx, teleporterInfo.TeleporterMessenger(source), source, destination, sendCrossChainMessageInput, fundedKey) - - // Relay message - teleporterInfo.RelayTeleporterMessage(ctx, receipt, source, destination, true, fundedKey) - - outstandReceiptCount = GetOutstandingReceiptCount( - teleporterInfo.TeleporterMessenger(source), - destination.BlockchainID, - ) - } - log.Info("Receipt queue emptied") -} - func GetOutstandingReceiptCount( teleporterMessenger *teleportermessenger.TeleporterMessenger, destinationBlockchainID ids.ID, @@ -552,85 +622,6 @@ func GetOutstandingReceiptCount( return size } -func SendExampleCrossChainMessageAndVerify( - ctx context.Context, - teleporterInfo TeleporterTestInfo, - source interfaces.SubnetTestInfo, - sourceExampleMessenger *testmessenger.TestMessenger, - destination interfaces.SubnetTestInfo, - destExampleMessengerAddress common.Address, - destExampleMessenger *testmessenger.TestMessenger, - senderKey *ecdsa.PrivateKey, - message string, - expectSuccess bool, -) { - // Call the example messenger contract on Subnet A - optsA, err := bind.NewKeyedTransactorWithChainID(senderKey, source.EVMChainID) - Expect(err).Should(BeNil()) - tx, err := sourceExampleMessenger.SendMessage( - optsA, - destination.BlockchainID, - destExampleMessengerAddress, - common.BigToAddress(common.Big0), - big.NewInt(0), - testmessenger.SendMessageRequiredGas, - message, - ) - Expect(err).Should(BeNil()) - - // Wait for the transaction to be mined - receipt := WaitForTransactionSuccess(ctx, source, tx.Hash()) - - event, err := GetEventFromLogs(receipt.Logs, teleporterInfo.TeleporterMessenger(source).ParseSendCrossChainMessage) - Expect(err).Should(BeNil()) - Expect(event.DestinationBlockchainID[:]).Should(Equal(destination.BlockchainID[:])) - - teleporterMessageID := event.MessageID - - // - // Relay the message to the destination - // - receipt = teleporterInfo.RelayTeleporterMessage(ctx, receipt, source, destination, true, senderKey) - - // - // Check Teleporter message received on the destination - // - delivered, err := teleporterInfo.TeleporterMessenger(destination).MessageReceived( - &bind.CallOpts{}, teleporterMessageID, - ) - Expect(err).Should(BeNil()) - Expect(delivered).Should(BeTrue()) - - if expectSuccess { - // Check that message execution was successful - messageExecutedEvent, err := GetEventFromLogs( - receipt.Logs, - teleporterInfo.TeleporterMessenger(destination).ParseMessageExecuted, - ) - Expect(err).Should(BeNil()) - Expect(messageExecutedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) - } else { - // Check that message execution failed - messageExecutionFailedEvent, err := GetEventFromLogs( - receipt.Logs, - teleporterInfo.TeleporterMessenger(destination).ParseMessageExecutionFailed, - ) - Expect(err).Should(BeNil()) - Expect(messageExecutionFailedEvent.MessageID[:]).Should(Equal(teleporterMessageID[:])) - } - - // - // Verify we received the expected string - // - _, currMessage, err := destExampleMessenger.GetCurrentMessage(&bind.CallOpts{}, source.BlockchainID) - Expect(err).Should(BeNil()) - if expectSuccess { - Expect(currMessage).Should(Equal(message)) - } else { - Expect(currMessage).ShouldNot(Equal(message)) - } -} - // // Transaction utils //