diff --git a/.env.example b/.env.example deleted file mode 100644 index 5135833ea..000000000 --- a/.env.example +++ /dev/null @@ -1,2 +0,0 @@ -user_private_key= -user_address= \ No newline at end of file diff --git a/.env.testnet b/.env.testnet deleted file mode 100644 index dfcdcc6cb..000000000 --- a/.env.testnet +++ /dev/null @@ -1,22 +0,0 @@ -# Subnet A (Dispatch) -subnet_a_rpc_url=https://subnets.avax.network/dispatch/testnet/rpc -subnet_a_subnet_id=7WtoAMPhrmh5KosDUsFL9yTcvw7YSxiKHPpdfs4JsgW47oZT5 -subnet_a_blockchain_id=2D8RG4UpSXbPbvPCAWppNJyqTG2i2CAXSkTgmTBBvs7GKNZjsY -subnet_a_teleporter_registry_address=0xf86cb19ad8405aefa7d09c778215d2cb6ebfb228 - -# Subnet B (Echo) -subnet_b_rpc_url=https://subnets.avax.network/echo/testnet/rpc -subnet_b_subnet_id=i9gFpZQHPLcGfZaQLiwFAStddQD7iTKBpFfurPFJsXm1CkTZK -subnet_b_blockchain_id=98qnjenm7MBd8G2cPZoRvZrgJC33JGSAAKghsQ6eojbLCeRNp -subnet_b_teleporter_registry_address=0xf86cb19ad8405aefa7d09c778215d2cb6ebfb228 - -# C-Chain -c_chain_rpc_url=https://api.avax-test.network/ext/bc/C/rpc -c_chain_subnet_id=11111111111111111111111111111111LpoYY -c_chain_blockchain_id=yH8D7ThNJkxmtkuv2jgBa4P1Rn3Qpr4pPr7QYNfcdoS6k6HWp -c_chain_teleporter_registry_address=0xf86cb19ad8405aefa7d09c778215d2cb6ebfb228 - -# Teleporter Contract -teleporter_contract_address=0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf -warp_messenger_precompile_addr=0x0200000000000000000000000000000000000005 - diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ebb39aca..a46408e01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" - name: Run Go unit tests run: | @@ -61,7 +61,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version-file: 'go.mod' + go-version-file: "go.mod" - name: Install Foundry run: ./scripts/install_foundry.sh @@ -71,7 +71,7 @@ jobs: run: | export PATH=$PATH:$HOME/.foundry/bin export PATH="$PATH:$GOPATH/bin" - ./scripts/local/e2e_test.sh --components teleporter + ./scripts/e2e_test.sh --components teleporter governance_e2e: name: governance-e2e-tests @@ -95,7 +95,7 @@ jobs: run: | export PATH=$PATH:$HOME/.foundry/bin export PATH="$PATH:$GOPATH/bin" - ./scripts/local/e2e_test.sh --components governance + ./scripts/e2e_test.sh --components governance validator_manager_e2e: name: validator-manager-e2e-tests @@ -119,7 +119,7 @@ jobs: run: | export PATH=$PATH:$HOME/.foundry/bin export PATH="$PATH:$GOPATH/bin" - ./scripts/local/e2e_test.sh --components validator-manager + ./scripts/e2e_test.sh --components validator-manager ictt_e2e: name: ictt-e2e-tests @@ -143,4 +143,4 @@ jobs: run: | export PATH=$PATH:$HOME/.foundry/bin export PATH="$PATH:$GOPATH/bin" - ./scripts/local/e2e_test.sh --components ictt + ./scripts/e2e_test.sh --components ictt diff --git a/.gitignore b/.gitignore index babc5dac1..189e54cea 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,6 @@ contracts/pkg docker-compose-test-local.yml docker-compose-run-local.yml -# Environment and configuration values -.env - # Ginkgo main.log server.log diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 194294ad1..d9f4c8306 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,7 @@ To start developing on Teleporter, you'll need Solidity >= v0.8.25. [Foundry](ht - Run the end-to-end tests ```sh -./scripts/local/e2e_test.sh +./scripts/e2e_test.sh ``` - Run the Solidity and Golang linters diff --git a/README.md b/README.md index 6ce84efb9..6ee349a1b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ To get started with using Teleporter, see [How to Deploy Teleporter Enabled Subn - [Structure](#structure) - [E2E tests](#e2e-tests) - [Run specific E2E tests](#run-specific-e2e-tests) - - [Run the E2E tests on another network](#run-the-e2e-tests-on-another-network) - [Upgradability](#upgradability) - [Deploy Teleporter to a Subnet](#deploy-teleporter-to-a-subnet) - [Deploy TeleporterRegistry to a Subnet](#deploy-teleporterregistry-to-a-subnet) @@ -67,7 +66,7 @@ Release versions follow the [semver](https://semver.org/) convention of incompat - `scripts/` includes bash scripts for interacting with Teleporter in various environments, as well as utility scripts. - `abi_bindings.sh` generates ABI bindings for the contracts in `contracts/` and outputs them to `abi-bindings/`. - `lint.sh` performs Solidity and Golang linting. - - `scripts/local/` includes scripts for running Teleporter in Docker. + - `scripts/` includes scripts for running Teleporter in Docker. - `docker/` includes configurations for a local, containerized setup of Teleporter. ## E2E tests @@ -79,7 +78,7 @@ To run the E2E tests locally, you'll need to install Gingko following the instru Then run the following command from the root of the repository: ```bash -./scripts/local/e2e_test.sh +./scripts/e2e_test.sh ``` ### Run specific E2E tests @@ -87,13 +86,13 @@ Then run the following command from the root of the repository: To run a specific E2E test, specify the environment variable `GINKGO_FOCUS`, which will then look for test descriptions that match the provided input. For example, to run the `Calculate Teleporter message IDs` test: ```bash -GINKGO_FOCUS="Calculate Teleporter message IDs" ./scripts/local/e2e_test.sh +GINKGO_FOCUS="Calculate Teleporter message IDs" ./scripts/e2e_test.sh ``` A substring of the full test description can be used as well: ```bash -GINKGO_FOCUS="Calculate Teleporter" ./scripts/local/e2e_test.sh +GINKGO_FOCUS="Calculate Teleporter" ./scripts/e2e_test.sh ``` The E2E tests also supports `GINKGO_LABEL_FILTER`, making it easy to group test cases and run them together. For example, to run all E2E tests for the example cross chain applications: @@ -107,20 +106,9 @@ The E2E tests also supports `GINKGO_LABEL_FILTER`, making it easy to group test ``` ```bash -GINKGO_LABEL_FILTER="cross chain apps" ./scripts/local/e2e_test.sh +GINKGO_LABEL_FILTER="cross chain apps" ./scripts/e2e_test.sh ``` -### Run the E2E tests on another network - -The same E2E test flows can be executed against external network by setting the proper environment variables in `.env.testnet` and `.env`, and running the following commands: - -```bash -cp .env.example .env # Set proper values after copying. -./scripts/testnet/run_testnet_e2e_flows.sh -``` - -The user wallet set in `.env` must have native tokens for each of the Subnets used in order for the test flows to be able to send transactions on those networks. The [Avalanche Testnet Faucet](https://core.app/tools/testnet-faucet) can be used to obtain native tokens for certain public testnet Subnets. - ## Upgradability The Teleporter contract is non-upgradeable and can not be changed once it is deployed. This provides immutability to the contracts, and ensures that the contract's behavior at each address is unchanging. However, to allow for new features and potential bug fixes, new versions of the Teleporter contract can be deployed to different addresses. The [TeleporterRegistry](./contracts/teleporter/TeleporterRegistry.sol) is used to keep track of the deployed versions of Teleporter, and to provide a standard interface for dApps to interact with the different Teleporter versions. diff --git a/scripts/local/e2e_test.sh b/scripts/e2e_test.sh similarity index 91% rename from scripts/local/e2e_test.sh rename to scripts/e2e_test.sh index e716ed907..475367684 100755 --- a/scripts/local/e2e_test.sh +++ b/scripts/e2e_test.sh @@ -6,11 +6,11 @@ set -e TELEPORTER_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" - cd ../.. && pwd + cd ../ && pwd ) function printHelp() { - echo "Usage: ./scripts/local/e2e_test.sh [--component component]" + echo "Usage: ./scripts/e2e_test.sh [--component component]" echo "" printUsage } @@ -26,7 +26,7 @@ Options: EOF } -valid_components=$(ls -d $TELEPORTER_PATH/tests/local/*/ | xargs -n 1 basename) +valid_components=$(ls -d $TELEPORTER_PATH/tests/suites/*/ | xargs -n 1 basename) components= while [ $# -gt 0 ]; do @@ -89,11 +89,11 @@ go install -v github.com/onsi/ginkgo/v2/ginkgo@${GINKGO_VERSION} for component in $(echo $components | tr ',' ' '); do echo "Building e2e tests for $component" - ginkgo build ./tests/local/$component + ginkgo build ./tests/suites/$component echo "Running e2e tests for $component" - RUN_E2E=true ./tests/local/$component/$component.test \ + RUN_E2E=true ./tests/suites/$component/$component.test \ --ginkgo.vv \ --ginkgo.label-filter=${GINKGO_LABEL_FILTER:-""} \ --ginkgo.focus=${GINKGO_FOCUS:-""} \ diff --git a/scripts/testnet/run_testnet_e2e_flows.sh b/scripts/testnet/run_testnet_e2e_flows.sh deleted file mode 100755 index 05a04de69..000000000 --- a/scripts/testnet/run_testnet_e2e_flows.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. -# See the file LICENSE for licensing terms. - -set -e - -TELEPORTER_PATH=$( - cd "$(dirname "${BASH_SOURCE[0]}")" - cd ../.. && pwd -) - -set -a - -source "$TELEPORTER_PATH"/scripts/versions.sh -source $TELEPORTER_PATH/.env -source $TELEPORTER_PATH/.env.testnet - -go run tests/testnet/main/run_testnet_flows.go diff --git a/tests/flows/governance/validator_set_sig.go b/tests/flows/governance/validator_set_sig.go index cb32a09e8..33bec5062 100644 --- a/tests/flows/governance/validator_set_sig.go +++ b/tests/flows/governance/validator_set_sig.go @@ -8,12 +8,12 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" validatorsetsig "github.com/ava-labs/teleporter/abi-bindings/go/governance/ValidatorSetSig" exampleerc20 "github.com/ava-labs/teleporter/abi-bindings/go/mocks/ExampleERC20" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) -func ValidatorSetSig(network interfaces.LocalNetwork) { +func ValidatorSetSig(network *localnetwork.LocalNetwork) { // ************************************************************************************************ // Setup // ************************************************************************************************ @@ -36,7 +36,7 @@ func ValidatorSetSig(network interfaces.LocalNetwork) { // ************************************************************************************************ // Setup // ************************************************************************************************ - subnetA, subnetB := utils.GetTwoSubnets(network) + subnetA, subnetB := network.GetTwoSubnets() _, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -150,9 +150,8 @@ func ValidatorSetSig(network interfaces.LocalNetwork) { // ************************************************************************************************ // Execute the ValidatorSetSig executeCall and wait for acceptance - receipt := utils.ExecuteValidatorSetSigCallAndVerify( + receipt := network.ExecuteValidatorSetSigCallAndVerify( ctx, - network, subnetB, subnetA, validatorSetSigContractAddress, @@ -173,9 +172,8 @@ func ValidatorSetSig(network interfaces.LocalNetwork) { // Resend the same message again and it should fail due to nonce being consumed - _ = utils.ExecuteValidatorSetSigCallAndVerify( + _ = network.ExecuteValidatorSetSigCallAndVerify( ctx, - network, subnetB, subnetA, validatorSetSigContractAddress, @@ -190,9 +188,8 @@ func ValidatorSetSig(network interfaces.LocalNetwork) { Expect(endingBalance).Should(Equal(big.NewInt(100))) // Send another valid transaction with the incremented nonce - receipt2 := utils.ExecuteValidatorSetSigCallAndVerify( + receipt2 := network.ExecuteValidatorSetSigCallAndVerify( ctx, - network, subnetB, subnetA, validatorSetSigContractAddress, @@ -222,9 +219,8 @@ func ValidatorSetSig(network interfaces.LocalNetwork) { // Send the third transaction where the validatorSetSig contract expects validator signatures // from the same chain that it is deployed on. - receipt3 := utils.ExecuteValidatorSetSigCallAndVerify( + receipt3 := network.ExecuteValidatorSetSigCallAndVerify( ctx, - network, subnetB, subnetB, validatorSetSigContractAddress2, diff --git a/tests/flows/ictt/erc20_home_erc20_remote.go b/tests/flows/ictt/erc20_home_erc20_remote.go index 272501ea0..7a60776dd 100644 --- a/tests/flows/ictt/erc20_home_erc20_remote.go +++ b/tests/flows/ictt/erc20_home_erc20_remote.go @@ -7,7 +7,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + 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" @@ -20,9 +20,9 @@ import ( * Transfers C-Chain example ERC20 tokens to Subnet A * Transfer tokens from Subnet A to C-Chain */ -func ERC20TokenHomeERC20TokenRemote(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ERC20TokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := teleporterUtils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -74,12 +74,12 @@ func ERC20TokenHomeERC20TokenRemote(network interfaces.Network, teleporter utils utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, erc20TokenHomeAddress, subnetAInfo, erc20TokenRemoteAddress, + fundedKey, ) // Generate new recipient to receive transferred tokens diff --git a/tests/flows/ictt/erc20_home_erc20_remote_multihop.go b/tests/flows/ictt/erc20_home_erc20_remote_multihop.go index 0f1fd7ba1..5f3addf52 100644 --- a/tests/flows/ictt/erc20_home_erc20_remote_multihop.go +++ b/tests/flows/ictt/erc20_home_erc20_remote_multihop.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -19,9 +19,9 @@ import ( * Transfer tokens from Subnet A to Subnet B through multi-hop * Transfer back tokens from Subnet B to Subnet A through multi-hop */ -func ERC20TokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ERC20TokenHomeERC20TokenRemoteMultiHop(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, subnetBInfo := utils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -89,21 +89,21 @@ func ERC20TokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, teleport // Register both ERC20TokenRemote instances on the ERC20TokenHome utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, erc20TokenHomeAddress, subnetAInfo, erc20TokenRemoteAddressA, + fundedKey, ) utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, erc20TokenHomeAddress, subnetBInfo, erc20TokenRemoteAddressB, + fundedKey, ) // Generate new recipient to receive transferred tokens @@ -162,7 +162,6 @@ func ERC20TokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, teleport secondaryFeeAmount := big.NewInt(0).Div(transferredAmount, big.NewInt(4)) utils.SendERC20TokenMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientKey, @@ -183,7 +182,6 @@ func ERC20TokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, teleport secondaryFeeAmount = big.NewInt(0).Div(transferredAmount, big.NewInt(4)) utils.SendERC20TokenMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientKey, diff --git a/tests/flows/ictt/erc20_home_erc20_remote_send_and_call.go b/tests/flows/ictt/erc20_home_erc20_remote_send_and_call.go index 5735ec5f4..87971b9c6 100644 --- a/tests/flows/ictt/erc20_home_erc20_remote_send_and_call.go +++ b/tests/flows/ictt/erc20_home_erc20_remote_send_and_call.go @@ -7,7 +7,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -20,9 +20,12 @@ import ( * Transfers C-Chain example ERC20 to EOA on Subnet A, and then transfer tokens from Subnet A back * C-Chain and calls contract on the C-Chain using sendAndCall */ -func ERC20TokenHomeERC20TokenRemoteSendAndCall(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ERC20TokenHomeERC20TokenRemoteSendAndCall( + network *localnetwork.LocalNetwork, + teleporter utils.TeleporterTestInfo, +) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -86,12 +89,12 @@ func ERC20TokenHomeERC20TokenRemoteSendAndCall(network interfaces.Network, telep utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, erc20TokenHomeAddress, subnetAInfo, erc20TokenRemoteAddress, + fundedKey, ) // Generate new recipient to receive transferred tokens diff --git a/tests/flows/ictt/erc20_home_native_remote.go b/tests/flows/ictt/erc20_home_native_remote.go index ff7c9910c..06ad686ae 100644 --- a/tests/flows/ictt/erc20_home_native_remote.go +++ b/tests/flows/ictt/erc20_home_native_remote.go @@ -7,7 +7,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" nativetokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/NativeTokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -31,9 +31,9 @@ var ( * Transfers C-Chain example ERC20 tokens to Subnet A as Subnet A's native token * Transfer back tokens from Subnet A to C-Chain */ -func ERC20TokenHomeNativeTokenRemote(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ERC20TokenHomeNativeTokenRemote(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -77,7 +77,6 @@ func ERC20TokenHomeNativeTokenRemote(network interfaces.Network, teleporter util collateralAmount := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, erc20TokenHomeAddress, subnetAInfo, @@ -85,6 +84,7 @@ func ERC20TokenHomeNativeTokenRemote(network interfaces.Network, teleporter util initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) utils.AddCollateralToERC20TokenHome( diff --git a/tests/flows/ictt/erc20_home_native_remote_multihop.go b/tests/flows/ictt/erc20_home_native_remote_multihop.go index bb8a51fcc..33d38d6b5 100644 --- a/tests/flows/ictt/erc20_home_native_remote_multihop.go +++ b/tests/flows/ictt/erc20_home_native_remote_multihop.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -22,9 +22,9 @@ import ( - Transfer tokens from Subnet A to Subnet B through multi-hop - Transfer back tokens from Subnet B to Subnet A through multi-hop */ -func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ERC20TokenHomeNativeTokenRemoteMultiHop(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, subnetBInfo := utils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -82,7 +82,6 @@ func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepor collateralAmountA := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, erc20TokenHomeAddress, subnetAInfo, @@ -90,12 +89,12 @@ func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepor initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) collateralAmountB := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, erc20TokenHomeAddress, subnetBInfo, @@ -103,6 +102,7 @@ func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepor initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) // Add collateral for both NativeTokenDestinations @@ -214,7 +214,6 @@ func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepor utils.SendNativeMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientAddress, @@ -233,7 +232,6 @@ func ERC20TokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepor secondaryFeeAmount := new(big.Int).Div(amountToSend, big.NewInt(4)) utils.SendNativeMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientAddress, diff --git a/tests/flows/ictt/native_home_erc20_remote.go b/tests/flows/ictt/native_home_erc20_remote.go index 0518370f9..2ca80710c 100644 --- a/tests/flows/ictt/native_home_erc20_remote.go +++ b/tests/flows/ictt/native_home_erc20_remote.go @@ -7,7 +7,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" nativetokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/NativeTokenHome" erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + 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" @@ -20,9 +20,9 @@ import ( * Transfers C-Chain native tokens to Subnet A * Transfer back tokens from Subnet A to C-Chain */ -func NativeTokenHomeERC20TokenRemote(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func NativeTokenHomeERC20TokenRemote(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := teleporterUtils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -70,12 +70,12 @@ func NativeTokenHomeERC20TokenRemote(network interfaces.Network, teleporter util utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, nativeTokenHomeAddress, subnetAInfo, erc20TokenRemoteAddress, + fundedKey, ) // Generate new recipient to receive transferred tokens diff --git a/tests/flows/ictt/native_home_erc20_remote_multihop.go b/tests/flows/ictt/native_home_erc20_remote_multihop.go index 274b43be3..d70dfb3d9 100644 --- a/tests/flows/ictt/native_home_erc20_remote_multihop.go +++ b/tests/flows/ictt/native_home_erc20_remote_multihop.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" nativetokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/NativeTokenHome" - "github.com/ava-labs/teleporter/tests/interfaces" + 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" @@ -21,9 +21,9 @@ import ( * Transfer tokens from Subnet A to Subnet B through multi-hop * Brige back tokens from Subnet B to Subnet A through multi-hop */ -func NativeTokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func NativeTokenHomeERC20TokenRemoteMultiHop(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, subnetBInfo := teleporterUtils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -85,22 +85,22 @@ func NativeTokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, telepor // Register both ERC20Destinations on the NativeTokenHome utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, nativeTokenHomeAddress, subnetAInfo, erc20TokenRemoteAddressA, + fundedKey, ) utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, nativeTokenHomeAddress, subnetBInfo, erc20TokenRemoteAddressB, + fundedKey, ) // Generate new recipient to receive transferred tokens @@ -159,7 +159,6 @@ func NativeTokenHomeERC20TokenRemoteMultiHop(network interfaces.Network, telepor secondaryFeeAmount := new(big.Int).Div(transferredAmount, big.NewInt(4)) utils.SendERC20TokenMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientKey, diff --git a/tests/flows/ictt/native_home_native_remote.go b/tests/flows/ictt/native_home_native_remote.go index 6508fdc50..fff3a86ec 100644 --- a/tests/flows/ictt/native_home_native_remote.go +++ b/tests/flows/ictt/native_home_native_remote.go @@ -6,7 +6,7 @@ import ( nativetokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/NativeTokenHome" nativetokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/NativeTokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -18,9 +18,9 @@ import ( * Transfers C-Chain native tokens to Subnet A * Transfer back tokens from Subnet A to C-Chain */ -func NativeTokenHomeNativeDestination(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func NativeTokenHomeNativeDestination(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -61,7 +61,6 @@ func NativeTokenHomeNativeDestination(network interfaces.Network, teleporter uti collateralAmount := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, nativeTokenHomeAddress, subnetAInfo, @@ -69,6 +68,7 @@ func NativeTokenHomeNativeDestination(network interfaces.Network, teleporter uti initialReserveImbalance, big.NewInt(1), multiplyOnRemote, + fundedKey, ) utils.AddCollateralToNativeTokenHome( diff --git a/tests/flows/ictt/native_home_native_remote_multihop.go b/tests/flows/ictt/native_home_native_remote_multihop.go index f29372e8c..4866a2af4 100644 --- a/tests/flows/ictt/native_home_native_remote_multihop.go +++ b/tests/flows/ictt/native_home_native_remote_multihop.go @@ -5,7 +5,7 @@ import ( "math/big" nativetokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/NativeTokenHome" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -21,9 +21,9 @@ import ( - Transfer tokens from Subnet A to Subnet B through multi-hop - Transfer back tokens from Subnet B to Subnet A through multi-hop */ -func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func NativeTokenHomeNativeTokenRemoteMultiHop(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, subnetBInfo := utils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -81,7 +81,6 @@ func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepo collateralAmountA := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, nativeTokenHomeAddress, subnetAInfo, @@ -89,12 +88,12 @@ func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepo initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) collateralAmountB := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, nativeTokenHomeAddress, subnetBInfo, @@ -102,6 +101,7 @@ func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepo initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) // Add collateral for both NativeTokenDestinations @@ -209,7 +209,6 @@ func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepo utils.SendNativeMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientAddress, @@ -231,7 +230,6 @@ func NativeTokenHomeNativeTokenRemoteMultiHop(network interfaces.Network, telepo // Multi-hop transfer back to Subnet A utils.SendNativeMultiHopAndVerify( ctx, - network, teleporter, fundedKey, recipientAddress, diff --git a/tests/flows/ictt/registration_and_collateral_check.go b/tests/flows/ictt/registration_and_collateral_check.go index dac3a289b..39f612a0e 100644 --- a/tests/flows/ictt/registration_and_collateral_check.go +++ b/tests/flows/ictt/registration_and_collateral_check.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" @@ -21,9 +21,9 @@ import ( * Collateralize the remote * Check sending to collateralized remote succeeds and withdraws with correct scale. */ -func RegistrationAndCollateralCheck(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func RegistrationAndCollateralCheck(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -102,7 +102,6 @@ func RegistrationAndCollateralCheck(network interfaces.Network, teleporter utils collateralNeeded := utils.RegisterTokenRemoteOnHome( ctx, teleporter, - network, cChainInfo, erc20TokenHomeAddress, subnetAInfo, @@ -110,6 +109,7 @@ func RegistrationAndCollateralCheck(network interfaces.Network, teleporter utils initialReserveImbalance, utils.GetTokenMultiplier(decimalsShift), multiplyOnRemote, + fundedKey, ) // Try sending again and expect failure since remote is not collateralized diff --git a/tests/flows/ictt/transparent_proxy_upgradeability.go b/tests/flows/ictt/transparent_proxy_upgradeability.go index 96184894d..e25cc4933 100644 --- a/tests/flows/ictt/transparent_proxy_upgradeability.go +++ b/tests/flows/ictt/transparent_proxy_upgradeability.go @@ -8,7 +8,7 @@ import ( erc20tokenhome "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHome" erc20tokenhomeupgradeable "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenHome/ERC20TokenHomeUpgradeable" erc20tokenremote "github.com/ava-labs/teleporter/abi-bindings/go/ictt/TokenRemote/ERC20TokenRemote" - "github.com/ava-labs/teleporter/tests/interfaces" + 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" @@ -27,9 +27,9 @@ import ( * Check that the transfer was successful, and expected balances are correct */ -func TransparentUpgradeableProxy(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func TransparentUpgradeableProxy(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := teleporterUtils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -99,12 +99,12 @@ func TransparentUpgradeableProxy(network interfaces.Network, teleporter utils.Te utils.RegisterERC20TokenRemoteOnHome( ctx, - network, teleporter, cChainInfo, erc20TokenHomeAddress, subnetAInfo, erc20TokenRemoteAddress, + fundedKey, ) // Send a transfer from primary network to Subnet A diff --git a/tests/flows/teleporter/add_fee_amount.go b/tests/flows/teleporter/add_fee_amount.go index abf6c7932..843b38a83 100644 --- a/tests/flows/teleporter/add_fee_amount.go +++ b/tests/flows/teleporter/add_fee_amount.go @@ -6,15 +6,15 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" . "github.com/onsi/gomega" ) -func AddFeeAmount(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func AddFeeAmount(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() teleporterContractAddress := teleporter.TeleporterMessengerAddress(subnetAInfo) fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() diff --git a/tests/flows/teleporter/basic_send_receive.go b/tests/flows/teleporter/basic_send_receive.go index c75f24a5a..7a9764cea 100644 --- a/tests/flows/teleporter/basic_send_receive.go +++ b/tests/flows/teleporter/basic_send_receive.go @@ -6,16 +6,16 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" . "github.com/onsi/gomega" ) // Tests basic one-way send from Subnet A to Subnet B and vice versa -func BasicSendReceive(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func BasicSendReceive(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() teleporterContractAddress := teleporter.TeleporterMessengerAddress(subnetAInfo) fundedAddress, fundedKey := network.GetFundedAccountInfo() @@ -25,9 +25,7 @@ func BasicSendReceive(network interfaces.Network, teleporter utils.TeleporterTes // 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. - if !network.IsExternalNetwork() { - utils.ClearReceiptQueue(ctx, teleporter, subnetBInfo, subnetAInfo, fundedKey) - } + network.ClearReceiptQueue(ctx, teleporter, fundedKey, subnetBInfo, subnetAInfo) feeAmount := big.NewInt(1) feeTokenAddress, feeToken := utils.DeployExampleERC20( @@ -96,15 +94,10 @@ func BasicSendReceive(network interfaces.Network, teleporter utils.TeleporterTes // Relay the message to the destination deliveryReceipt = teleporter.RelayTeleporterMessage(ctx, receipt, subnetBInfo, subnetAInfo, true, fundedKey) - // Check that the receipt was received for expected Teleporter message ID - // This check is not performed for external networks because the specific receipt for this message - // may not have been included if the receipt queue had an existing build up of more than 5 messages. - if !network.IsExternalNetwork() { - Expect(utils.CheckReceiptReceived( - deliveryReceipt, - expectedReceiptID, - teleporter.TeleporterMessenger(subnetAInfo))).Should(BeTrue()) - } + Expect(utils.CheckReceiptReceived( + deliveryReceipt, + expectedReceiptID, + teleporter.TeleporterMessenger(subnetAInfo))).Should(BeTrue()) // Check Teleporter message received on the destination delivered, err = teleporter.TeleporterMessenger(subnetAInfo).MessageReceived( @@ -114,9 +107,8 @@ func BasicSendReceive(network interfaces.Network, teleporter utils.TeleporterTes Expect(delivered).Should(BeTrue()) // If the reward address of the message from A->B is the funded address, which is able to send - // transactions on subnet A, then redeem the rewards. This check is not performed for external - // networks since the specific receipt may not have been included in the message, as noted above. - if !network.IsExternalNetwork() && receiveEvent.RewardRedeemer == fundedAddress { + // transactions on subnet A, then redeem the rewards. + if receiveEvent.RewardRedeemer == fundedAddress { utils.RedeemRelayerRewardsAndConfirm( ctx, teleporter.TeleporterMessenger(subnetAInfo), subnetAInfo, feeToken, feeTokenAddress, fundedKey, feeAmount, ) diff --git a/tests/flows/teleporter/deliver_to_nonexistent_contract.go b/tests/flows/teleporter/deliver_to_nonexistent_contract.go index e5787f999..9a4f976fc 100644 --- a/tests/flows/teleporter/deliver_to_nonexistent_contract.go +++ b/tests/flows/teleporter/deliver_to_nonexistent_contract.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" testmessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/tests/TestMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -14,9 +14,9 @@ import ( . "github.com/onsi/gomega" ) -func DeliverToNonExistentContract(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func DeliverToNonExistentContract(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() deployerKey, err := crypto.GenerateKey() diff --git a/tests/flows/teleporter/deliver_to_wrong_chain.go b/tests/flows/teleporter/deliver_to_wrong_chain.go index 1c87ccdd2..3ce462d69 100644 --- a/tests/flows/teleporter/deliver_to_wrong_chain.go +++ b/tests/flows/teleporter/deliver_to_wrong_chain.go @@ -2,22 +2,20 @@ package teleporter import ( "context" - "crypto/ecdsa" "math/big" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/subnet-evm/core/types" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" . "github.com/onsi/gomega" ) -func DeliverToWrongChain(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func DeliverToWrongChain(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, subnetCInfo := utils.GetTwoSubnets(network) + subnetBInfo, subnetCInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // @@ -59,27 +57,7 @@ func DeliverToWrongChain(network interfaces.Network, teleporter utils.Teleporter fundedKey, ) - if network.SupportsIndependentRelaying() { - // - // Try to relay the message to subnet C, should fail - // - teleporter.RelayTeleporterMessage(ctx, receipt, subnetAInfo, subnetCInfo, false, fundedKey) - } else { - // - // Wait for external relayer to properly deliver the message to subnet B - // - deliveryReceipt := teleporter.RelayTeleporterMessage(ctx, receipt, subnetAInfo, subnetBInfo, true, fundedKey) - deliveryTx, isPending, err := subnetBInfo.RPCClient.TransactionByHash(ctx, deliveryReceipt.TxHash) - Expect(err).Should(BeNil()) - Expect(isPending).Should(BeFalse()) - - // - // Take the successful delivery transaction, and use it to create a transaction that attempts to deliver - // the same message to subnet C. - // - wrongChainDeliveryTx := createWrongChainDeliveryTransaction(ctx, deliveryTx, fundedKey, fundedAddress, subnetCInfo) - utils.SendTransactionAndWaitForFailure(ctx, subnetCInfo, wrongChainDeliveryTx) - } + teleporter.RelayTeleporterMessage(ctx, receipt, subnetAInfo, subnetCInfo, false, fundedKey) // // Check that the message was not received on the Subnet C @@ -90,25 +68,3 @@ func DeliverToWrongChain(network interfaces.Network, teleporter utils.Teleporter Expect(err).Should(BeNil()) Expect(delivered).Should(BeFalse()) } - -func createWrongChainDeliveryTransaction( - ctx context.Context, - deliveryTx *types.Transaction, - fundedKey *ecdsa.PrivateKey, - fundedAddress common.Address, - destination interfaces.SubnetTestInfo, -) *types.Transaction { - gasFeeCap, gasTipCap, nonce := utils.CalculateTxParams(ctx, destination, fundedAddress) - unsignedTx := types.NewTx(&types.DynamicFeeTx{ - ChainID: destination.EVMChainID, - Nonce: nonce, - To: deliveryTx.To(), - Gas: deliveryTx.Gas(), - GasFeeCap: gasFeeCap, - GasTipCap: gasTipCap, - Value: big.NewInt(0), - Data: deliveryTx.Data(), - AccessList: deliveryTx.AccessList(), - }) - return utils.SignTransaction(unsignedTx, fundedKey, destination.EVMChainID) -} diff --git a/tests/flows/teleporter/insufficient_gas.go b/tests/flows/teleporter/insufficient_gas.go index 5af9f4ddb..66bcef13c 100644 --- a/tests/flows/teleporter/insufficient_gas.go +++ b/tests/flows/teleporter/insufficient_gas.go @@ -5,14 +5,14 @@ import ( "math/big" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) -func InsufficientGas(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func InsufficientGas(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() diff --git a/tests/flows/teleporter/registry/check_upgrade_access.go b/tests/flows/teleporter/registry/check_upgrade_access.go index 027db6017..07d66c2e7 100644 --- a/tests/flows/teleporter/registry/check_upgrade_access.go +++ b/tests/flows/teleporter/registry/check_upgrade_access.go @@ -6,14 +6,14 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" "github.com/ava-labs/teleporter/tests/flows" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" . "github.com/onsi/gomega" ) -func CheckUpgradeAccess(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func CheckUpgradeAccess(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetInfo := network.GetPrimaryNetworkInfo() fundedAddress, fundedKey := network.GetFundedAccountInfo() diff --git a/tests/flows/teleporter/registry/pause_teleporter.go b/tests/flows/teleporter/registry/pause_teleporter.go index 58fd4ded2..1f423660b 100644 --- a/tests/flows/teleporter/registry/pause_teleporter.go +++ b/tests/flows/teleporter/registry/pause_teleporter.go @@ -4,14 +4,14 @@ import ( "context" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) -func PauseTeleporter(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func PauseTeleporter(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // @@ -51,7 +51,7 @@ func PauseTeleporter(network interfaces.Network, teleporter utils.TeleporterTest Expect(isPaused).Should(BeTrue()) // Send a message from subnet A to subnet B, which should fail - utils.SendExampleCrossChainMessageAndVerify( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, subnetAInfo, @@ -61,7 +61,8 @@ func PauseTeleporter(network interfaces.Network, teleporter utils.TeleporterTest testMessengerB, fundedKey, "message_1", - false) + false, + ) // Unpause Teleporter on subnet B tx, err = testMessengerB.UnpauseTeleporterAddress(opts, teleporterAddress) @@ -77,7 +78,7 @@ func PauseTeleporter(network interfaces.Network, teleporter utils.TeleporterTest Expect(isPaused).Should(BeFalse()) // Send a message from subnet A to subnet B again, which should now succeed - utils.SendExampleCrossChainMessageAndVerify( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, subnetAInfo, @@ -87,5 +88,6 @@ func PauseTeleporter(network interfaces.Network, teleporter utils.TeleporterTest testMessengerB, fundedKey, "message_2", - true) + true, + ) } diff --git a/tests/flows/teleporter/registry/teleporter_registry.go b/tests/flows/teleporter/registry/teleporter_registry.go index a43ae276b..43f328aa3 100644 --- a/tests/flows/teleporter/registry/teleporter_registry.go +++ b/tests/flows/teleporter/registry/teleporter_registry.go @@ -5,7 +5,7 @@ import ( "time" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" . "github.com/onsi/gomega" @@ -15,7 +15,7 @@ const ( teleporterByteCodeFile = "./out/TeleporterMessenger.sol/TeleporterMessenger.json" ) -func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.TeleporterTestInfo) { +func TeleporterRegistry(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { // Deploy dApp on both chains that use Teleporter Registry // Deploy version 2 of Teleporter to both chains // Construct AddProtocolVersion txs for both chains @@ -28,7 +28,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo // Retry the previously failed message execution, verify message is now able to be delivered to dApp cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, subnetBInfo := utils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() @@ -54,6 +54,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo for _, subnet := range network.GetAllSubnetsInfo() { newTeleporterAddress = utils.DeployNewTeleporterVersion(ctx, teleporter, subnet, fundedKey, teleporterByteCodeFile) } + networkID := network.GetNetworkID() // Create chain config file with off chain message for each chain offchainMessageC, warpEnabledChainConfigC := utils.InitOffChainMessageChainConfig( @@ -91,9 +92,9 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo network.RestartNodes(restartCtx, nil) // Call addProtocolVersion on subnetB to register the new Teleporter version - utils.AddProtocolVersionAndWaitForAcceptance( + network.AddProtocolVersionAndWaitForAcceptance( ctx, - *teleporter[subnetBInfo.BlockchainID], + teleporter, subnetBInfo, newTeleporterAddress, fundedKey, @@ -102,7 +103,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo // 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. - utils.SendExampleCrossChainMessageAndVerify( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, cChainInfo, @@ -139,7 +140,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo // Send a message using old Teleporter version to test messenger with updated minimum Teleporter version. // Message should fail since we updated minimum Teleporter version. - utils.SendExampleCrossChainMessageAndVerify( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, cChainInfo, @@ -158,7 +159,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo teleporter.InitializeBlockchainID(subnet, fundedKey) } - utils.SendExampleCrossChainMessageAndVerify( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, subnetBInfo, @@ -172,9 +173,9 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo ) // Call addProtocolVersion on subnetA to register the new Teleporter version - utils.AddProtocolVersionAndWaitForAcceptance( + network.AddProtocolVersionAndWaitForAcceptance( ctx, - *teleporter[cChainInfo.BlockchainID], + teleporter, cChainInfo, newTeleporterAddress, fundedKey, @@ -183,7 +184,7 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo // 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( + network.SendExampleCrossChainMessageAndVerify( ctx, teleporter, subnetBInfo, @@ -198,9 +199,9 @@ func TeleporterRegistry(network interfaces.LocalNetwork, teleporter utils.Telepo // To make sure all subnets are using the same Teleporter version, call addProtocolVersion on subnetA // to register the new Teleporter version - utils.AddProtocolVersionAndWaitForAcceptance( + network.AddProtocolVersionAndWaitForAcceptance( ctx, - *teleporter[subnetAInfo.BlockchainID], + teleporter, subnetAInfo, newTeleporterAddress, fundedKey, diff --git a/tests/flows/teleporter/relay_message_twice.go b/tests/flows/teleporter/relay_message_twice.go index dc28cc763..791e177b8 100644 --- a/tests/flows/teleporter/relay_message_twice.go +++ b/tests/flows/teleporter/relay_message_twice.go @@ -6,7 +6,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" @@ -14,9 +14,9 @@ import ( . "github.com/onsi/gomega" ) -func RelayMessageTwice(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func RelayMessageTwice(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // diff --git a/tests/flows/teleporter/relayer_modifies_message.go b/tests/flows/teleporter/relayer_modifies_message.go index 32c1385d4..a328593c7 100644 --- a/tests/flows/teleporter/relayer_modifies_message.go +++ b/tests/flows/teleporter/relayer_modifies_message.go @@ -13,6 +13,7 @@ import ( predicateutils "github.com/ava-labs/subnet-evm/predicate" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" gasUtils "github.com/ava-labs/teleporter/utils/gas-utils" "github.com/ethereum/go-ethereum/common" @@ -22,9 +23,9 @@ import ( ) // Disallow this test from being run on anything but a local network, since it requires special behavior by the relayer -func RelayerModifiesMessage(network interfaces.LocalNetwork, teleporter utils.TeleporterTestInfo) { +func RelayerModifiesMessage(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // Send a transaction to Subnet A to issue a Warp Message from the Teleporter contract to Subnet B @@ -53,7 +54,8 @@ func RelayerModifiesMessage(network interfaces.LocalNetwork, teleporter utils.Te receipt, subnetAInfo, subnetBInfo, - network) + network, + ) // Check Teleporter message was not received on the destination delivered, err := teleporter.TeleporterMessenger(subnetBInfo).MessageReceived(&bind.CallOpts{}, messageID) @@ -67,7 +69,7 @@ func relayAlteredMessage( sourceReceipt *types.Receipt, source interfaces.SubnetTestInfo, destination interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, + network *localnetwork.LocalNetwork, ) { // Fetch the Teleporter message from the logs sendEvent, err := utils.GetEventFromLogs( diff --git a/tests/flows/teleporter/resubmit_altered_message.go b/tests/flows/teleporter/resubmit_altered_message.go index dcc47c75f..3df24f170 100644 --- a/tests/flows/teleporter/resubmit_altered_message.go +++ b/tests/flows/teleporter/resubmit_altered_message.go @@ -6,16 +6,16 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" . "github.com/onsi/gomega" ) -func ResubmitAlteredMessage(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func ResubmitAlteredMessage(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // Send a transaction to Subnet A to issue a Warp Message from the Teleporter contract to Subnet B diff --git a/tests/flows/teleporter/retry_successful_execution.go b/tests/flows/teleporter/retry_successful_execution.go index a90cb5305..23b9a64fe 100644 --- a/tests/flows/teleporter/retry_successful_execution.go +++ b/tests/flows/teleporter/retry_successful_execution.go @@ -6,14 +6,14 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" testmessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/tests/TestMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) -func RetrySuccessfulExecution(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func RetrySuccessfulExecution(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // @@ -95,6 +95,7 @@ func RetrySuccessfulExecution(network interfaces.Network, teleporter utils.Telep // optsB, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetBInfo.EVMChainID) Expect(err).Should(BeNil()) + tx, err = teleporter.TeleporterMessenger(subnetBInfo).RetryMessageExecution( optsB, subnetAInfo.BlockchainID, diff --git a/tests/flows/teleporter/send_specific_receipts.go b/tests/flows/teleporter/send_specific_receipts.go index baf958f9c..fff563247 100644 --- a/tests/flows/teleporter/send_specific_receipts.go +++ b/tests/flows/teleporter/send_specific_receipts.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" teleporterutils "github.com/ava-labs/teleporter/utils/teleporter-utils" "github.com/ethereum/go-ethereum/common" @@ -16,19 +17,17 @@ import ( . "github.com/onsi/gomega" ) -func SendSpecificReceipts(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func SendSpecificReceipts(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() + subnetATeleporterMessenger := teleporter.TeleporterMessenger(subnetAInfo) + subnetBTeleporterMessenger := teleporter.TeleporterMessenger(subnetBInfo) teleporterContractAddress := teleporter.TeleporterMessengerAddress(subnetAInfo) _, fundedKey := network.GetFundedAccountInfo() ctx := context.Background() // 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. - if !network.IsExternalNetwork() { - utils.ClearReceiptQueue(ctx, teleporter, subnetBInfo, subnetAInfo, fundedKey) - } + network.ClearReceiptQueue(ctx, teleporter, fundedKey, subnetBInfo, subnetAInfo) // Use mock token as the fee token mockTokenAddress, mockToken := utils.DeployExampleERC20( @@ -61,7 +60,7 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte // Send first message from Subnet A to Subnet B with fee amount 5 sendCrossChainMsgReceipt, messageID1 := utils.SendCrossChainMessageAndWaitForAcceptance( - ctx, teleporter.TeleporterMessenger(subnetAInfo), subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey) + ctx, subnetATeleporterMessenger, subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey) // Relay the message from SubnetA to SubnetB deliveryReceipt1 := teleporter.RelayTeleporterMessage( @@ -74,18 +73,18 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte ) receiveEvent1, err := utils.GetEventFromLogs( deliveryReceipt1.Logs, - teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage) + subnetBTeleporterMessenger.ParseReceiveCrossChainMessage) Expect(err).Should(BeNil()) Expect(receiveEvent1.MessageID[:]).Should(Equal(messageID1[:])) // Check that the first message was delivered - delivered, err := teleporter.TeleporterMessenger(subnetBInfo).MessageReceived(&bind.CallOpts{}, messageID1) + delivered, err := subnetBTeleporterMessenger.MessageReceived(&bind.CallOpts{}, messageID1) Expect(err).Should(BeNil()) Expect(delivered).Should(BeTrue()) // Send second message from Subnet A to Subnet B with fee amount 5 sendCrossChainMsgReceipt, messageID2 := utils.SendCrossChainMessageAndWaitForAcceptance( - ctx, teleporter.TeleporterMessenger(subnetAInfo), subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey) + ctx, subnetATeleporterMessenger, subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedKey) // Relay the message from SubnetA to SubnetB deliveryReceipt2 := teleporter.RelayTeleporterMessage( @@ -98,19 +97,19 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte ) receiveEvent2, err := utils.GetEventFromLogs( deliveryReceipt2.Logs, - teleporter.TeleporterMessenger(subnetBInfo).ParseReceiveCrossChainMessage) + subnetBTeleporterMessenger.ParseReceiveCrossChainMessage) Expect(err).Should(BeNil()) Expect(receiveEvent2.MessageID[:]).Should(Equal(messageID2[:])) // Check that the second message was delivered - delivered, err = teleporter.TeleporterMessenger(subnetBInfo).MessageReceived(&bind.CallOpts{}, messageID2) + delivered, err = subnetBTeleporterMessenger.MessageReceived(&bind.CallOpts{}, messageID2) Expect(err).Should(BeNil()) Expect(delivered).Should(BeTrue()) // Call send specific receipts to get reward of relaying two messages receipt, messageID := utils.SendSpecifiedReceiptsAndWaitForAcceptance( ctx, - teleporter.TeleporterMessenger(subnetBInfo), + subnetBTeleporterMessenger, subnetBInfo, subnetAInfo.BlockchainID, [][32]byte{messageID1, messageID2}, @@ -126,13 +125,13 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte receipt = teleporter.RelayTeleporterMessage(ctx, receipt, subnetBInfo, subnetAInfo, true, fundedKey) // Check that the message back to Subnet A was delivered - delivered, err = teleporter.TeleporterMessenger(subnetAInfo).MessageReceived(&bind.CallOpts{}, messageID) + delivered, err = subnetATeleporterMessenger.MessageReceived(&bind.CallOpts{}, messageID) Expect(err).Should(BeNil()) Expect(delivered).Should(BeTrue()) // Check that the expected receipts were received and emitted ReceiptReceived - Expect(utils.CheckReceiptReceived(receipt, messageID1, teleporter.TeleporterMessenger(subnetAInfo))).Should(BeTrue()) - Expect(utils.CheckReceiptReceived(receipt, messageID2, teleporter.TeleporterMessenger(subnetAInfo))).Should(BeTrue()) + Expect(utils.CheckReceiptReceived(receipt, messageID1, subnetATeleporterMessenger)).Should(BeTrue()) + Expect(utils.CheckReceiptReceived(receipt, messageID2, subnetATeleporterMessenger)).Should(BeTrue()) // Check the reward amounts. // Even on external networks, the relayer should only have the expected fee amount @@ -146,71 +145,68 @@ func SendSpecificReceipts(network interfaces.Network, teleporter utils.Teleporte relayerFeePerMessage, ) - // If the network is internal to the test application, send a message from Subnet B to Subnet A to trigger + // Send a 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. - // These checks are not performed for external networks because unrelated messages may have already changed - // the state of the receipt queues. - if !network.IsExternalNetwork() { - sendCrossChainMessageInput = teleportermessenger.TeleporterMessageInput{ - DestinationBlockchainID: subnetAInfo.BlockchainID, - DestinationAddress: destinationAddress, - FeeInfo: teleportermessenger.TeleporterFeeInfo{ - FeeTokenAddress: mockTokenAddress, - Amount: big.NewInt(0), - }, - RequiredGasLimit: big.NewInt(1), - AllowedRelayerAddresses: []common.Address{}, - Message: []byte{1, 2, 3, 4}, - } + sendCrossChainMessageInput = teleportermessenger.TeleporterMessageInput{ + DestinationBlockchainID: subnetAInfo.BlockchainID, + DestinationAddress: destinationAddress, + FeeInfo: teleportermessenger.TeleporterFeeInfo{ + FeeTokenAddress: mockTokenAddress, + Amount: big.NewInt(0), + }, + RequiredGasLimit: big.NewInt(1), + AllowedRelayerAddresses: []common.Address{}, + Message: []byte{1, 2, 3, 4}, + } - // This message will also have the same receipts as the previous message - receipt, messageID = utils.SendCrossChainMessageAndWaitForAcceptance( - ctx, teleporter.TeleporterMessenger(subnetBInfo), subnetBInfo, subnetAInfo, sendCrossChainMessageInput, fundedKey) + // This message will also have the same receipts as the previous message + receipt, messageID = utils.SendCrossChainMessageAndWaitForAcceptance( + ctx, subnetBTeleporterMessenger, subnetBInfo, subnetAInfo, sendCrossChainMessageInput, fundedKey) - // Relay message from Subnet B to Subnet A - receipt = teleporter.RelayTeleporterMessage(ctx, receipt, subnetBInfo, subnetAInfo, true, fundedKey) - // Check delivered - delivered, err = teleporter.TeleporterMessenger(subnetAInfo).MessageReceived( - &bind.CallOpts{}, - messageID) - Expect(err).Should(BeNil()) - Expect(delivered).Should(BeTrue()) + // Relay message from Subnet B to Subnet A + receipt = teleporter.RelayTeleporterMessage(ctx, receipt, subnetBInfo, subnetAInfo, true, fundedKey) + // Check delivered + delivered, err = subnetATeleporterMessenger.MessageReceived( + &bind.CallOpts{}, + messageID, + ) + Expect(err).Should(BeNil()) + Expect(delivered).Should(BeTrue()) - // Check that the expected receipts were included in the message but did not emit ReceiptReceived - // because they were previously received - Expect(utils.CheckReceiptReceived(receipt, messageID1, teleporter.TeleporterMessenger(subnetAInfo))).Should(BeFalse()) - Expect(utils.CheckReceiptReceived(receipt, messageID2, teleporter.TeleporterMessenger(subnetAInfo))).Should(BeFalse()) + // Check that the expected receipts were included in the message but did not emit ReceiptReceived + // because they were previously received + Expect(utils.CheckReceiptReceived(receipt, messageID1, subnetATeleporterMessenger)).Should(BeFalse()) + Expect(utils.CheckReceiptReceived(receipt, messageID2, subnetATeleporterMessenger)).Should(BeFalse()) - receiveEvent, err := utils.GetEventFromLogs( - receipt.Logs, - teleporter.TeleporterMessenger(subnetAInfo).ParseReceiveCrossChainMessage, - ) - Expect(err).Should(BeNil()) - log.Info("Receipt included", "count", len(receiveEvent.Message.Receipts), "receipts", receiveEvent.Message.Receipts) - Expect(receiptIncluded( - teleporterContractAddress, - messageID1, - subnetAInfo, - subnetBInfo, - receiveEvent.Message.Receipts)).Should(BeTrue()) - Expect(receiptIncluded( - teleporterContractAddress, - messageID2, - subnetAInfo, - subnetBInfo, - receiveEvent.Message.Receipts)).Should(BeTrue()) + receiveEvent, err := utils.GetEventFromLogs( + receipt.Logs, + subnetATeleporterMessenger.ParseReceiveCrossChainMessage, + ) + Expect(err).Should(BeNil()) + log.Info("Receipt included", "count", len(receiveEvent.Message.Receipts), "receipts", receiveEvent.Message.Receipts) + Expect(receiptIncluded( + teleporterContractAddress, + messageID1, + subnetAInfo, + subnetBInfo, + receiveEvent.Message.Receipts)).Should(BeTrue()) + Expect(receiptIncluded( + teleporterContractAddress, + messageID2, + subnetAInfo, + subnetBInfo, + receiveEvent.Message.Receipts)).Should(BeTrue()) - // Check the reward amount remains the same - checkExpectedRewardAmounts( - teleporter, - subnetAInfo, - receiveEvent1, - receiveEvent2, - mockTokenAddress, - relayerFeePerMessage, - ) - } + // Check the reward amount remains the same + checkExpectedRewardAmounts( + teleporter, + subnetAInfo, + receiveEvent1, + receiveEvent2, + mockTokenAddress, + relayerFeePerMessage, + ) } // Checks the given message ID is included in the list of receipts. diff --git a/tests/flows/teleporter/teleporter_message_ids.go b/tests/flows/teleporter/teleporter_message_ids.go index a00d0cf17..a3be9ee3e 100644 --- a/tests/flows/teleporter/teleporter_message_ids.go +++ b/tests/flows/teleporter/teleporter_message_ids.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" teleporterutils "github.com/ava-labs/teleporter/utils/teleporter-utils" "github.com/ethereum/go-ethereum/common" @@ -16,7 +16,7 @@ import ( ) // Tests Teleporter message ID calculation -func CalculateMessageID(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func CalculateMessageID(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetInfo := network.GetPrimaryNetworkInfo() teleporterContractAddress := teleporter.TeleporterMessengerAddress(subnetInfo) diff --git a/tests/flows/teleporter/unallowed_relayer.go b/tests/flows/teleporter/unallowed_relayer.go index 0da726cee..252523733 100644 --- a/tests/flows/teleporter/unallowed_relayer.go +++ b/tests/flows/teleporter/unallowed_relayer.go @@ -6,16 +6,16 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" . "github.com/onsi/gomega" ) -func UnallowedRelayer(network interfaces.Network, teleporter utils.TeleporterTestInfo) { +func UnallowedRelayer(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { subnetAInfo := network.GetPrimaryNetworkInfo() - subnetBInfo, _ := utils.GetTwoSubnets(network) + subnetBInfo, _ := network.GetTwoSubnets() fundedAddress, fundedKey := network.GetFundedAccountInfo() // diff --git a/tests/flows/teleporter/validator_churn.go b/tests/flows/teleporter/validator_churn.go index da7ec7016..ef4fc1f01 100644 --- a/tests/flows/teleporter/validator_churn.go +++ b/tests/flows/teleporter/validator_churn.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" subnetEvmUtils "github.com/ava-labs/subnet-evm/tests/utils" teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" @@ -17,8 +17,8 @@ import ( const newNodeCount = 2 -func ValidatorChurn(network interfaces.LocalNetwork, teleporter utils.TeleporterTestInfo) { - subnetAInfo, subnetBInfo := utils.GetTwoSubnets(network) +func ValidatorChurn(network *localnetwork.LocalNetwork, teleporter utils.TeleporterTestInfo) { + subnetAInfo, subnetBInfo := network.GetTwoSubnets() teleporterContractAddress := teleporter.TeleporterMessengerAddress(subnetAInfo) fundedAddress, fundedKey := network.GetFundedAccountInfo() @@ -69,7 +69,7 @@ func ValidatorChurn(network interfaces.LocalNetwork, teleporter utils.Teleporter network.AddSubnetValidators(addValidatorsCtx, subnetAInfo.SubnetID, newNodeCount) // Refresh the subnet info - subnetAInfo, subnetBInfo = utils.GetTwoSubnets(network) + subnetAInfo, subnetBInfo = network.GetTwoSubnets() // 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 diff --git a/tests/flows/validator-manager/erc20_token_staking.go b/tests/flows/validator-manager/erc20_token_staking.go index b720b475b..4ccf1243b 100644 --- a/tests/flows/validator-manager/erc20_token_staking.go +++ b/tests/flows/validator-manager/erc20_token_staking.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) @@ -29,10 +29,10 @@ import ( * - Deliver the Warp message to the subnet * - Verify that the validator is delisted from the staking contract */ -func ERC20TokenStakingManager(network interfaces.LocalNetwork) { +func ERC20TokenStakingManager(network *localnetwork.LocalNetwork) { // Get the subnets info cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() _, fundedKey := network.GetFundedAccountInfo() pChainInfo := utils.GetPChainInfo(cChainInfo) @@ -55,7 +55,7 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { nodes := utils.ConvertSubnet( ctx, subnetAInfo, - network, + network.GetPChainWallet(), stakingManagerAddress, fundedKey, ) @@ -69,7 +69,7 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { pChainInfo, stakingManager, stakingManagerAddress, - network, + network.GetNetworkID(), signatureAggregator, nodes, ) @@ -79,7 +79,6 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { // utils.InitializeAndCompleteEndInitialERC20Validation( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -89,6 +88,8 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { initialValidationIDs[0], 0, nodes[0].Weight, + network.GetPChainWallet(), + network.GetNetworkID(), ) // @@ -97,7 +98,6 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { expiry := uint64(time.Now().Add(24 * time.Hour).Unix()) validationID := utils.InitializeAndCompleteERC20ValidatorRegistration( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -107,6 +107,8 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { erc20, expiry, nodes[0], + network.GetPChainWallet(), + network.GetNetworkID(), ) // @@ -152,7 +154,7 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { // Issue a tx to update the validator's weight on the P-Chain network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - utils.PChainProposerVMWorkaround(network) + utils.PChainProposerVMWorkaround(network.GetPChainWallet()) utils.AdvanceProposerVM(ctx, subnetAInfo, fundedKey, 5) // Construct a SubnetValidatorWeightUpdateMessage Warp message from the P-Chain @@ -162,8 +164,8 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { newValidatorWeight, subnetAInfo, pChainInfo, - network, signatureAggregator, + network.GetNetworkID(), ) // Deliver the Warp message to the subnet @@ -213,7 +215,7 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { // Issue a tx to update the validator's weight on the P-Chain network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - utils.PChainProposerVMWorkaround(network) + utils.PChainProposerVMWorkaround(network.GetPChainWallet()) utils.AdvanceProposerVM(ctx, subnetAInfo, fundedKey, 5) // Construct a SubnetValidatorWeightUpdateMessage Warp message from the P-Chain @@ -223,8 +225,8 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { nodes[0].Weight, subnetAInfo, pChainInfo, - network, signatureAggregator, + network.GetNetworkID(), ) // Deliver the Warp message to the subnet @@ -252,7 +254,6 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { // utils.InitializeAndCompleteEndERC20Validation( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -263,5 +264,7 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { expiry, nodes[0], 1, + network.GetPChainWallet(), + network.GetNetworkID(), ) } diff --git a/tests/flows/validator-manager/native_token_staking.go b/tests/flows/validator-manager/native_token_staking.go index 80a7961b0..b3ef833a4 100644 --- a/tests/flows/validator-manager/native_token_staking.go +++ b/tests/flows/validator-manager/native_token_staking.go @@ -8,7 +8,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/subnet-evm/accounts/abi/bind" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" . "github.com/onsi/gomega" ) @@ -29,10 +29,10 @@ import ( * - Deliver the Warp message to the subnet * - Verify that the validator is delisted from the staking contract */ -func NativeTokenStakingManager(network interfaces.LocalNetwork) { +func NativeTokenStakingManager(network *localnetwork.LocalNetwork) { // Get the subnets info cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() _, fundedKey := network.GetFundedAccountInfo() pChainInfo := utils.GetPChainInfo(cChainInfo) @@ -57,7 +57,7 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { nodes := utils.ConvertSubnet( ctx, subnetAInfo, - network, + network.GetPChainWallet(), stakingManagerAddress, fundedKey, ) @@ -71,7 +71,7 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { pChainInfo, stakingManager, stakingManagerAddress, - network, + network.GetNetworkID(), signatureAggregator, nodes, ) @@ -81,7 +81,6 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { // utils.InitializeAndCompleteEndInitialNativeValidation( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -91,6 +90,8 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { initialValidationIDs[0], 0, nodes[0].Weight, + network.GetPChainWallet(), + network.GetNetworkID(), ) // @@ -99,7 +100,6 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { expiry := uint64(time.Now().Add(24 * time.Hour).Unix()) validationID := utils.InitializeAndCompleteNativeValidatorRegistration( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -108,6 +108,8 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { stakingManagerAddress, expiry, nodes[0], + network.GetPChainWallet(), + network.GetNetworkID(), ) // @@ -152,7 +154,7 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { // Issue a tx to update the validator's weight on the P-Chain network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - utils.PChainProposerVMWorkaround(network) + utils.PChainProposerVMWorkaround(network.GetPChainWallet()) utils.AdvanceProposerVM(ctx, subnetAInfo, fundedKey, 5) // Construct a SubnetValidatorWeightUpdateMessage Warp message from the P-Chain @@ -162,8 +164,8 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { newValidatorWeight, subnetAInfo, pChainInfo, - network, signatureAggregator, + network.GetNetworkID(), ) // Deliver the Warp message to the subnet @@ -212,7 +214,7 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { // Issue a tx to update the validator's weight on the P-Chain network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - utils.PChainProposerVMWorkaround(network) + utils.PChainProposerVMWorkaround(network.GetPChainWallet()) utils.AdvanceProposerVM(ctx, subnetAInfo, fundedKey, 5) // Construct a SubnetValidatorWeightUpdateMessage Warp message from the P-Chain @@ -222,8 +224,8 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { nodes[0].Weight, subnetAInfo, pChainInfo, - network, signatureAggregator, + network.GetNetworkID(), ) // Deliver the Warp message to the subnet @@ -251,7 +253,6 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { // utils.InitializeAndCompleteEndNativeValidation( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -262,5 +263,7 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { expiry, nodes[0], 1, + network.GetPChainWallet(), + network.GetNetworkID(), ) } diff --git a/tests/flows/validator-manager/poa_to_pos.go b/tests/flows/validator-manager/poa_to_pos.go index 1d7a04d72..7114f4af2 100644 --- a/tests/flows/validator-manager/poa_to_pos.go +++ b/tests/flows/validator-manager/poa_to_pos.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi/bind" nativetokenstakingmanager "github.com/ava-labs/teleporter/abi-bindings/go/validator-manager/NativeTokenStakingManager" poavalidatormanager "github.com/ava-labs/teleporter/abi-bindings/go/validator-manager/PoAValidatorManager" - "github.com/ava-labs/teleporter/tests/interfaces" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" "github.com/ethereum/go-ethereum/crypto" @@ -36,9 +36,9 @@ import ( * - Delist the previous PoA validator properly * - Delist the PoS validator */ -func PoAMigrationToPoS(network interfaces.LocalNetwork) { +func PoAMigrationToPoS(network *localnetwork.LocalNetwork) { cChainInfo := network.GetPrimaryNetworkInfo() - subnetAInfo, _ := utils.GetTwoSubnets(network) + subnetAInfo, _ := network.GetTwoSubnets() _, fundedKey := network.GetFundedAccountInfo() pChainInfo := utils.GetPChainInfo(cChainInfo) @@ -102,7 +102,7 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { nodes := utils.ConvertSubnet( ctx, subnetAInfo, - network, + network.GetPChainWallet(), proxyAddress, fundedKey, ) @@ -116,7 +116,7 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { pChainInfo, poaValidatorManager, proxyAddress, - network, + network.GetNetworkID(), signatureAggregator, nodes, ) @@ -126,7 +126,6 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { // utils.InitializeAndCompleteEndInitialPoAValidation( ctx, - network, signatureAggregator, ownerKey, fundedKey, @@ -137,6 +136,8 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { initialValidationIDs[0], 0, nodes[0].Weight, + network.GetPChainWallet(), + network.GetNetworkID(), ) // Try to call with invalid owner @@ -160,7 +161,6 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { expiry := uint64(time.Now().Add(24 * time.Hour).Unix()) poaValidationID := utils.InitializeAndCompletePoAValidatorRegistration( ctx, - network, signatureAggregator, ownerKey, fundedKey, @@ -170,6 +170,8 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { proxyAddress, expiry, nodes[0], + network.GetPChainWallet(), + network.GetNetworkID(), ) poaValidator, err := poaValidatorManager.GetValidator(&bind.CallOpts{}, poaValidationID) Expect(err).Should(BeNil()) @@ -240,7 +242,6 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { utils.InitializeAndCompleteEndNativeValidation( ctx, - network, signatureAggregator, ownerKey, subnetAInfo, @@ -251,12 +252,13 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { expiry, nodes[0], 1, + network.GetPChainWallet(), + network.GetNetworkID(), ) expiry2 := uint64(time.Now().Add(24 * time.Hour).Unix()) posValidationID := utils.InitializeAndCompleteNativeValidatorRegistration( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -265,12 +267,13 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { proxyAddress, expiry2, nodes[0], + network.GetPChainWallet(), + network.GetNetworkID(), ) // Delist the PoS validator utils.InitializeAndCompleteEndNativeValidation( ctx, - network, signatureAggregator, fundedKey, subnetAInfo, @@ -281,5 +284,7 @@ func PoAMigrationToPoS(network interfaces.LocalNetwork) { expiry2, nodes[0], 1, + network.GetPChainWallet(), + network.GetNetworkID(), ) } diff --git a/tests/interfaces/local_network.go b/tests/interfaces/local_network.go deleted file mode 100644 index 2639cc662..000000000 --- a/tests/interfaces/local_network.go +++ /dev/null @@ -1,17 +0,0 @@ -package interfaces - -import ( - "context" - - "github.com/ava-labs/avalanchego/ids" - pwallet "github.com/ava-labs/avalanchego/wallet/chain/p/wallet" -) - -type LocalNetwork interface { - Network - AddSubnetValidators(ctx context.Context, subnetID ids.ID, count uint) - SetChainConfigs(chainConfigs map[string]string) - RestartNodes(ctx context.Context, nodeIDs []ids.NodeID) - GetNetworkID() uint32 - GetPChainWallet() pwallet.Wallet -} diff --git a/tests/interfaces/network.go b/tests/interfaces/network.go deleted file mode 100644 index 204813dfb..000000000 --- a/tests/interfaces/network.go +++ /dev/null @@ -1,33 +0,0 @@ -package interfaces - -import ( - "crypto/ecdsa" - - "github.com/ethereum/go-ethereum/common" -) - -// Defines the interface for the network setup functions used in the E2E tests -type Network interface { - // Returns information about the primary network - GetPrimaryNetworkInfo() SubnetTestInfo - - // Returns all of the subnets support by this network, excluding the primary network - GetSubnetsInfo() []SubnetTestInfo - - // Returns all of the subnets support by this network in no particular order, including the primary network. - // If the distinction between primary network and other subnets needs to be made, - // use GetPrimaryNetworkInfo() and GetSubnetsInfo() instead. - GetAllSubnetsInfo() []SubnetTestInfo - - // An address and corresponding key that has native tokens on each of the subnets in this network. - GetFundedAccountInfo() (common.Address, *ecdsa.PrivateKey) - - // Whether or not the Avalanche network being used is available outside the scope of the test application. - IsExternalNetwork() bool - - // Whether or not the funded wallet is capable of relaying messages between subnets in this network. - // Intended to be true for local networks where all nodes are querable by the test application for their - // BLS signatures, and false for testnet networks where test application does not necessarily have - // connections with each validator. - SupportsIndependentRelaying() bool -} diff --git a/tests/local/network.go b/tests/network/network.go similarity index 63% rename from tests/local/network.go rename to tests/network/network.go index 2839b082c..7f51add76 100644 --- a/tests/local/network.go +++ b/tests/network/network.go @@ -1,4 +1,4 @@ -package local +package network import ( "context" @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/hex" "encoding/json" + "math/big" "os" "slices" "sort" @@ -19,21 +20,25 @@ import ( "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" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" . "github.com/onsi/gomega" ) -var _ interfaces.LocalNetwork = &LocalNetwork{} - // Implements Network, pointing to the network setup in local_network_setup.go type LocalNetwork struct { primaryNetworkInfo *interfaces.SubnetTestInfo @@ -288,16 +293,6 @@ func (n *LocalNetwork) GetFundedAccountInfo() (common.Address, *ecdsa.PrivateKey return fundedAddress, n.globalFundedKey } -func (n *LocalNetwork) IsExternalNetwork() bool { - return false -} - -func (n *LocalNetwork) SupportsIndependentRelaying() bool { - // Messages can be relayed by the test application for local - // networks with connections to each node. - return true -} - func (n *LocalNetwork) setAllSubnetValues() { subnetIDs := n.GetSubnetsInfo() Expect(len(subnetIDs)).Should(Equal(2)) @@ -451,3 +446,201 @@ func (n *LocalNetwork) Dir() string { 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, +) { + subnets := n.GetSubnetsInfo() + 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/local/governance/governance_suite_test.go b/tests/suites/governance/governance_suite_test.go similarity index 88% rename from tests/local/governance/governance_suite_test.go rename to tests/suites/governance/governance_suite_test.go index b7fd6beea..dc94a2cde 100644 --- a/tests/local/governance/governance_suite_test.go +++ b/tests/suites/governance/governance_suite_test.go @@ -7,7 +7,7 @@ import ( "time" governanceFlows "github.com/ava-labs/teleporter/tests/flows/governance" - "github.com/ava-labs/teleporter/tests/local" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ethereum/go-ethereum/log" "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -19,7 +19,7 @@ const ( ) var ( - LocalNetworkInstance *local.LocalNetwork + LocalNetworkInstance *localnetwork.LocalNetwork ) func TestGovernance(t *testing.T) { @@ -36,11 +36,11 @@ var _ = ginkgo.BeforeSuite(func() { // Create the local network instance ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) defer cancel() - LocalNetworkInstance = local.NewLocalNetwork( + LocalNetworkInstance = localnetwork.NewLocalNetwork( ctx, "governance-test-local-network", warpGenesisTemplateFile, - []local.SubnetSpec{ + []localnetwork.SubnetSpec{ { Name: "A", EVMChainID: 12345, diff --git a/tests/local/ictt/ictt_suite_test.go b/tests/suites/ictt/ictt_suite_test.go similarity index 96% rename from tests/local/ictt/ictt_suite_test.go rename to tests/suites/ictt/ictt_suite_test.go index fbdae4187..d984c9877 100644 --- a/tests/local/ictt/ictt_suite_test.go +++ b/tests/suites/ictt/ictt_suite_test.go @@ -7,7 +7,7 @@ import ( "time" icttFlows "github.com/ava-labs/teleporter/tests/flows/ictt" - "github.com/ava-labs/teleporter/tests/local" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" deploymentUtils "github.com/ava-labs/teleporter/utils/deployment-utils" "github.com/ethereum/go-ethereum/log" @@ -31,7 +31,7 @@ const ( ) var ( - LocalNetworkInstance *local.LocalNetwork + LocalNetworkInstance *localnetwork.LocalNetwork TeleporterInfo utils.TeleporterTestInfo ) @@ -61,11 +61,11 @@ var _ = ginkgo.BeforeSuite(func() { // Create the local network instance ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) defer cancel() - LocalNetworkInstance = local.NewLocalNetwork( + LocalNetworkInstance = localnetwork.NewLocalNetwork( ctx, "teleporter-test-local-network", warpGenesisTemplateFile, - []local.SubnetSpec{ + []localnetwork.SubnetSpec{ { Name: "A", EVMChainID: 12345, diff --git a/tests/local/teleporter/teleporter_suite_test.go b/tests/suites/teleporter/teleporter_suite_test.go similarity index 95% rename from tests/local/teleporter/teleporter_suite_test.go rename to tests/suites/teleporter/teleporter_suite_test.go index 7a3d47c36..9c97c806e 100644 --- a/tests/local/teleporter/teleporter_suite_test.go +++ b/tests/suites/teleporter/teleporter_suite_test.go @@ -1,3 +1,6 @@ +// Copyright (C) 2023, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package teleporter_test import ( @@ -8,7 +11,7 @@ import ( teleporterFlows "github.com/ava-labs/teleporter/tests/flows/teleporter" registryFlows "github.com/ava-labs/teleporter/tests/flows/teleporter/registry" - "github.com/ava-labs/teleporter/tests/local" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ava-labs/teleporter/tests/utils" deploymentUtils "github.com/ava-labs/teleporter/utils/deployment-utils" "github.com/ethereum/go-ethereum/log" @@ -26,7 +29,7 @@ const ( ) var ( - LocalNetworkInstance *local.LocalNetwork + LocalNetworkInstance *localnetwork.LocalNetwork TeleporterInfo utils.TeleporterTestInfo ) @@ -56,11 +59,12 @@ var _ = ginkgo.BeforeSuite(func() { // Create the local network instance ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) defer cancel() - LocalNetworkInstance = local.NewLocalNetwork( + + LocalNetworkInstance = localnetwork.NewLocalNetwork( ctx, "teleporter-test-local-network", warpGenesisTemplateFile, - []local.SubnetSpec{ + []localnetwork.SubnetSpec{ { Name: "A", EVMChainID: 12345, @@ -93,6 +97,7 @@ var _ = ginkgo.BeforeSuite(func() { teleporterContractAddress, fundedKey, ) + for _, subnet := range LocalNetworkInstance.GetAllSubnetsInfo() { TeleporterInfo.SetTeleporter(teleporterContractAddress, subnet) TeleporterInfo.InitializeBlockchainID(subnet, fundedKey) diff --git a/tests/local/validator-manager/validator_manager_suite_test.go b/tests/suites/validator-manager/validator_manager_suite_test.go similarity index 90% rename from tests/local/validator-manager/validator_manager_suite_test.go rename to tests/suites/validator-manager/validator_manager_suite_test.go index 92f7eaf41..ccbd2f103 100644 --- a/tests/local/validator-manager/validator_manager_suite_test.go +++ b/tests/suites/validator-manager/validator_manager_suite_test.go @@ -7,7 +7,7 @@ import ( "time" validatorManagerFlows "github.com/ava-labs/teleporter/tests/flows/validator-manager" - "github.com/ava-labs/teleporter/tests/local" + localnetwork "github.com/ava-labs/teleporter/tests/network" "github.com/ethereum/go-ethereum/log" "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -19,7 +19,7 @@ const ( ) var ( - LocalNetworkInstance *local.LocalNetwork + LocalNetworkInstance *localnetwork.LocalNetwork ) func TestValidatorManager(t *testing.T) { @@ -36,11 +36,11 @@ var _ = ginkgo.BeforeEach(func() { // Create the local network instance ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) defer cancel() - LocalNetworkInstance = local.NewLocalNetwork( + LocalNetworkInstance = localnetwork.NewLocalNetwork( ctx, "validator-manager-test-local-network", warpGenesisTemplateFile, - []local.SubnetSpec{ + []localnetwork.SubnetSpec{ { Name: "A", EVMChainID: 12345, diff --git a/tests/utils/chain.go b/tests/utils/chain.go index 2d872fdc2..6286e7e92 100644 --- a/tests/utils/chain.go +++ b/tests/utils/chain.go @@ -453,15 +453,6 @@ func GetPChainInfo(cChainInfo interfaces.SubnetTestInfo) interfaces.SubnetTestIn } } -func GetTwoSubnets(network interfaces.Network) ( - interfaces.SubnetTestInfo, - interfaces.SubnetTestInfo, -) { - subnets := network.GetSubnetsInfo() - Expect(len(subnets)).Should(BeNumerically(">=", 2)) - return subnets[0], subnets[1] -} - type ChainConfigMap map[string]string // Sets the chain config in customChainConfigs for the specified subnet diff --git a/tests/utils/governance.go b/tests/utils/governance.go index 96d03555d..3df3ae29b 100644 --- a/tests/utils/governance.go +++ b/tests/utils/governance.go @@ -40,7 +40,6 @@ func DeployValidatorSetSig( // and we don't want to add the ValidatorSetSig ABI to the subnetInfo func ExecuteValidatorSetSigCallAndVerify( ctx context.Context, - network interfaces.Network, source interfaces.SubnetTestInfo, destination interfaces.SubnetTestInfo, validatorSetSigAddress common.Address, diff --git a/tests/utils/ictt.go b/tests/utils/ictt.go index 0eecfc721..d41e801d4 100644 --- a/tests/utils/ictt.go +++ b/tests/utils/ictt.go @@ -301,17 +301,16 @@ func DeployExampleERC20Decimals( func RegisterERC20TokenRemoteOnHome( ctx context.Context, - network interfaces.Network, teleporter TeleporterTestInfo, homeSubnet interfaces.SubnetTestInfo, homeAddress common.Address, remoteSubnet interfaces.SubnetTestInfo, remoteAddress common.Address, + fundedKey *ecdsa.PrivateKey, ) { RegisterTokenRemoteOnHome( ctx, teleporter, - network, homeSubnet, homeAddress, remoteSubnet, @@ -319,13 +318,13 @@ func RegisterERC20TokenRemoteOnHome( big.NewInt(0), big.NewInt(1), false, + fundedKey, ) } func RegisterTokenRemoteOnHome( ctx context.Context, teleporter TeleporterTestInfo, - network interfaces.Network, homeSubnet interfaces.SubnetTestInfo, homeAddress common.Address, remoteSubnet interfaces.SubnetTestInfo, @@ -333,6 +332,7 @@ func RegisterTokenRemoteOnHome( expectedInitialReserveBalance *big.Int, expectedTokenMultiplier *big.Int, expectedmultiplyOnRemote bool, + fundedKey *ecdsa.PrivateKey, ) *big.Int { // Call the remote to send a register message to the home tokenRemote, err := tokenremote.NewTokenRemote( @@ -340,7 +340,6 @@ func RegisterTokenRemoteOnHome( remoteSubnet.RPCClient, ) Expect(err).Should(BeNil()) - _, fundedKey := network.GetFundedAccountInfo() // Deploy a new ERC20 token for testing registering with fees feeTokenAddress, feeToken := DeployExampleERC20Decimals( @@ -825,7 +824,6 @@ func SendAndCallERC20TokenRemote( // with respect to the original asset on the C-Chain func SendNativeMultiHopAndVerify( ctx context.Context, - network interfaces.Network, teleporter TeleporterTestInfo, sendingKey *ecdsa.PrivateKey, recipientAddress common.Address, @@ -861,8 +859,6 @@ func SendNativeMultiHopAndVerify( sendingKey, ) - _, fundedKey := network.GetFundedAccountInfo() - // Relay the first message back to the home chain, in this case C-Chain, // which then performs the multi-hop transfer to the destination TokenRemote instance. intermediateReceipt := teleporter.RelayTeleporterMessage( @@ -871,7 +867,7 @@ func SendNativeMultiHopAndVerify( fromSubnet, cChainInfo, true, - fundedKey, + sendingKey, ) initialBalance, err := toSubnet.RPCClient.BalanceAt(ctx, recipientAddress, nil) @@ -886,7 +882,7 @@ func SendNativeMultiHopAndVerify( cChainInfo, toSubnet, true, - fundedKey, + sendingKey, ) transferredAmount := big.NewInt(0).Sub(amount, input.SecondaryFee) @@ -900,7 +896,6 @@ func SendNativeMultiHopAndVerify( func SendERC20TokenMultiHopAndVerify( ctx context.Context, - network interfaces.Network, teleporter TeleporterTestInfo, fundedKey *ecdsa.PrivateKey, sendingKey *ecdsa.PrivateKey, diff --git a/tests/utils/validator_manager.go b/tests/utils/validator_manager.go index c90ff9bf0..648488f8e 100644 --- a/tests/utils/validator_manager.go +++ b/tests/utils/validator_manager.go @@ -25,6 +25,7 @@ import ( warpMessage "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload" "github.com/ava-labs/avalanchego/vms/secp256k1fx" + pwallet "github.com/ava-labs/avalanchego/wallet/chain/p/wallet" "github.com/ava-labs/awm-relayer/signature-aggregator/aggregator" "github.com/ava-labs/subnet-evm/accounts/abi/bind" "github.com/ava-labs/subnet-evm/core/types" @@ -283,7 +284,7 @@ func InitializeNativeTokenValidatorSet( pChainInfo interfaces.SubnetTestInfo, validatorManager *nativetokenstakingmanager.NativeTokenStakingManager, validatorManagerAddress common.Address, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, nodes []Node, ) []ids.ID { @@ -320,7 +321,7 @@ func InitializeNativeTokenValidatorSet( subnetConversionID, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) // Deliver the Warp message to the subnet @@ -357,7 +358,7 @@ func InitializeERC20TokenValidatorSet( pChainInfo interfaces.SubnetTestInfo, validatorManager *erc20tokenstakingmanager.ERC20TokenStakingManager, validatorManagerAddress common.Address, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, nodes []Node, ) []ids.ID { @@ -394,7 +395,7 @@ func InitializeERC20TokenValidatorSet( subnetConversionID, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -432,7 +433,7 @@ func InitializePoAValidatorSet( pChainInfo interfaces.SubnetTestInfo, validatorManager *poavalidatormanager.PoAValidatorManager, validatorManagerAddress common.Address, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, nodes []Node, ) []ids.ID { @@ -469,7 +470,7 @@ func InitializePoAValidatorSet( subnetConversionID, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) // Deliver the Warp message to the subnet @@ -768,7 +769,6 @@ func CallWarpReceiver( func InitializeAndCompleteNativeValidatorRegistration( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -777,6 +777,8 @@ func InitializeAndCompleteNativeValidatorRegistration( stakingManagerContractAddress common.Address, expiry uint64, node Node, + pchainWallet pwallet.Wallet, + networkID uint32, ) ids.ID { stakeAmount, err := stakingManager.WeightToValue( &bind.CallOpts{}, @@ -798,13 +800,13 @@ func InitializeAndCompleteNativeValidatorRegistration( // (Sending to the P-Chain will be skipped for now) signedWarpMessage := ConstructSignedWarpMessage(ctx, receipt, subnetInfo, pChainInfo) - _, err = network.GetPChainWallet().IssueRegisterSubnetValidatorTx( + _, err = pchainWallet.IssueRegisterSubnetValidatorTx( 100*units.Avax, node.NodePoP.ProofOfPossession, signedWarpMessage.Bytes(), ) Expect(err).Should(BeNil()) - PChainProposerVMWorkaround(network) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -816,7 +818,7 @@ func InitializeAndCompleteNativeValidatorRegistration( true, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -841,7 +843,6 @@ func InitializeAndCompleteNativeValidatorRegistration( func InitializeAndCompleteERC20ValidatorRegistration( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -851,6 +852,8 @@ func InitializeAndCompleteERC20ValidatorRegistration( erc20 *exampleerc20.ExampleERC20, expiry uint64, node Node, + pchainWallet pwallet.Wallet, + networkID uint32, ) ids.ID { stakeAmount, err := stakingManager.WeightToValue( &bind.CallOpts{}, @@ -875,13 +878,13 @@ func InitializeAndCompleteERC20ValidatorRegistration( // Gather subnet-evm Warp signatures for the RegisterSubnetValidatorMessage & relay to the P-Chain signedWarpMessage := ConstructSignedWarpMessage(ctx, receipt, subnetInfo, pChainInfo) - _, err = network.GetPChainWallet().IssueRegisterSubnetValidatorTx( + _, err = pchainWallet.IssueRegisterSubnetValidatorTx( 100*units.Avax, node.NodePoP.ProofOfPossession, signedWarpMessage.Bytes(), ) Expect(err).Should(BeNil()) - PChainProposerVMWorkaround(network) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -893,7 +896,7 @@ func InitializeAndCompleteERC20ValidatorRegistration( true, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -918,7 +921,6 @@ func InitializeAndCompleteERC20ValidatorRegistration( func InitializeAndCompletePoAValidatorRegistration( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, ownerKey *ecdsa.PrivateKey, fundedKey *ecdsa.PrivateKey, @@ -928,6 +930,8 @@ func InitializeAndCompletePoAValidatorRegistration( validatorManagerAddress common.Address, expiry uint64, node Node, + pchainWallet pwallet.Wallet, + networkID uint32, ) ids.ID { // Initiate validator registration receipt, validationID := InitializePoAValidatorRegistration( @@ -942,13 +946,13 @@ func InitializeAndCompletePoAValidatorRegistration( // Gather subnet-evm Warp signatures for the RegisterSubnetValidatorMessage & relay to the P-Chain signedWarpMessage := ConstructSignedWarpMessage(ctx, receipt, subnetInfo, pChainInfo) - _, err := network.GetPChainWallet().IssueRegisterSubnetValidatorTx( + _, err := pchainWallet.IssueRegisterSubnetValidatorTx( 100*units.Avax, node.NodePoP.ProofOfPossession, signedWarpMessage.Bytes(), ) Expect(err).Should(BeNil()) - PChainProposerVMWorkaround(network) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -960,7 +964,7 @@ func InitializeAndCompletePoAValidatorRegistration( true, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1334,7 +1338,6 @@ func CompleteEndNativeDelegation( func InitializeAndCompleteEndInitialNativeValidation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -1344,6 +1347,8 @@ func InitializeAndCompleteEndInitialNativeValidation( validationID ids.ID, index uint32, weight uint64, + pchainWallet pwallet.Wallet, + networkID uint32, ) { log.Println("Initializing initial validator removal") WaitMinStakeDuration(ctx, subnetInfo, fundedKey) @@ -1374,8 +1379,8 @@ func InitializeAndCompleteEndInitialNativeValidation( Expect(err).Should(BeNil()) // Deliver the Warp message to the P-Chain - network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - PChainProposerVMWorkaround(network) + pchainWallet.IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -1386,7 +1391,7 @@ func InitializeAndCompleteEndInitialNativeValidation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1410,7 +1415,6 @@ func InitializeAndCompleteEndInitialNativeValidation( func InitializeAndCompleteEndNativeValidation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -1421,6 +1425,8 @@ func InitializeAndCompleteEndNativeValidation( expiry uint64, node Node, nonce uint64, + pchainWallet pwallet.Wallet, + networkID uint32, ) { log.Println("Initializing validator removal") WaitMinStakeDuration(ctx, subnetInfo, fundedKey) @@ -1450,8 +1456,8 @@ func InitializeAndCompleteEndNativeValidation( Expect(err).Should(BeNil()) // Deliver the Warp message to the P-Chain - network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - PChainProposerVMWorkaround(network) + pchainWallet.IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -1463,7 +1469,7 @@ func InitializeAndCompleteEndNativeValidation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1487,7 +1493,6 @@ func InitializeAndCompleteEndNativeValidation( func InitializeAndCompleteEndInitialERC20Validation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -1497,6 +1502,8 @@ func InitializeAndCompleteEndInitialERC20Validation( validationID ids.ID, index uint32, weight uint64, + pchainWallet pwallet.Wallet, + networkID uint32, ) { log.Println("Initializing initial validator removal") WaitMinStakeDuration(ctx, subnetInfo, fundedKey) @@ -1527,8 +1534,8 @@ func InitializeAndCompleteEndInitialERC20Validation( Expect(err).Should(BeNil()) // Deliver the Warp message to the P-Chain - network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - PChainProposerVMWorkaround(network) + pchainWallet.IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -1539,7 +1546,7 @@ func InitializeAndCompleteEndInitialERC20Validation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1563,7 +1570,6 @@ func InitializeAndCompleteEndInitialERC20Validation( func InitializeAndCompleteEndERC20Validation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, fundedKey *ecdsa.PrivateKey, subnetInfo interfaces.SubnetTestInfo, @@ -1574,6 +1580,8 @@ func InitializeAndCompleteEndERC20Validation( expiry uint64, node Node, nonce uint64, + pchainWallet pwallet.Wallet, + networkID uint32, ) { log.Println("Initializing validator removal") WaitMinStakeDuration(ctx, subnetInfo, fundedKey) @@ -1603,8 +1611,8 @@ func InitializeAndCompleteEndERC20Validation( Expect(err).Should(BeNil()) // Deliver the Warp message to the P-Chain - network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - PChainProposerVMWorkaround(network) + pchainWallet.IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -1616,7 +1624,7 @@ func InitializeAndCompleteEndERC20Validation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1640,7 +1648,6 @@ func InitializeAndCompleteEndERC20Validation( func InitializeAndCompleteEndInitialPoAValidation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, ownerKey *ecdsa.PrivateKey, fundedKey *ecdsa.PrivateKey, @@ -1651,6 +1658,8 @@ func InitializeAndCompleteEndInitialPoAValidation( validationID ids.ID, index uint32, weight uint64, + pchainWallet pwallet.Wallet, + networkID uint32, ) { log.Println("Initializing initial validator removal") WaitMinStakeDuration(ctx, subnetInfo, fundedKey) @@ -1681,8 +1690,8 @@ func InitializeAndCompleteEndInitialPoAValidation( Expect(err).Should(BeNil()) // Deliver the Warp message to the P-Chain - network.GetPChainWallet().IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) - PChainProposerVMWorkaround(network) + pchainWallet.IssueSetSubnetValidatorWeightTx(signedWarpMessage.Bytes()) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) // Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain @@ -1693,7 +1702,7 @@ func InitializeAndCompleteEndInitialPoAValidation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1717,7 +1726,6 @@ func InitializeAndCompleteEndInitialPoAValidation( func InitializeAndCompleteEndPoAValidation( ctx context.Context, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, ownerKey *ecdsa.PrivateKey, fundedKey *ecdsa.PrivateKey, @@ -1728,6 +1736,7 @@ func InitializeAndCompleteEndPoAValidation( validationID ids.ID, weight uint64, nonce uint64, + networkID uint32, ) { receipt := InitializeEndPoAValidation( ctx, @@ -1760,7 +1769,7 @@ func InitializeAndCompleteEndPoAValidation( false, subnetInfo, pChainInfo, - network, + networkID, signatureAggregator, ) @@ -1792,7 +1801,7 @@ func ConstructSubnetValidatorRegistrationMessageForInitialValidator( valid bool, subnet interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, ) *avalancheWarp.Message { justification := platformvm.SubnetValidatorRegistrationJustification{ @@ -1811,7 +1820,7 @@ func ConstructSubnetValidatorRegistrationMessageForInitialValidator( registrationAddressedCall, err := warpPayload.NewAddressedCall(nil, registrationPayload.Bytes()) Expect(err).Should(BeNil()) registrationUnsignedMessage, err := avalancheWarp.NewUnsignedMessage( - network.GetNetworkID(), + networkID, pChainInfo.BlockchainID, registrationAddressedCall.Bytes(), ) @@ -1835,7 +1844,7 @@ func ConstructSubnetValidatorRegistrationMessage( valid bool, subnet interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, ) *avalancheWarp.Message { msg, err := warpMessage.NewRegisterSubnetValidator( @@ -1861,7 +1870,7 @@ func ConstructSubnetValidatorRegistrationMessage( registrationAddressedCall, err := warpPayload.NewAddressedCall(nil, registrationPayload.Bytes()) Expect(err).Should(BeNil()) registrationUnsignedMessage, err := avalancheWarp.NewUnsignedMessage( - network.GetNetworkID(), + networkID, pChainInfo.BlockchainID, registrationAddressedCall.Bytes(), ) @@ -1884,15 +1893,15 @@ func ConstructSubnetValidatorWeightUpdateMessage( weight uint64, subnet interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, signatureAggregator *aggregator.SignatureAggregator, + networkID uint32, ) *avalancheWarp.Message { payload, err := warpMessage.NewSubnetValidatorWeight(validationID, nonce, weight) Expect(err).Should(BeNil()) updateAddressedCall, err := warpPayload.NewAddressedCall(nil, payload.Bytes()) Expect(err).Should(BeNil()) updateUnsignedMessage, err := avalancheWarp.NewUnsignedMessage( - network.GetNetworkID(), + networkID, pChainInfo.BlockchainID, updateAddressedCall.Bytes(), ) @@ -1912,7 +1921,7 @@ func ConstructSubnetConversionMessage( subnetConversionID ids.ID, subnet interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, + networkID uint32, signatureAggregator *aggregator.SignatureAggregator, ) *avalancheWarp.Message { subnetConversionPayload, err := warpMessage.NewSubnetConversion(subnetConversionID) @@ -1923,7 +1932,7 @@ func ConstructSubnetConversionMessage( ) Expect(err).Should(BeNil()) subnetConversionUnsignedMessage, err := avalancheWarp.NewUnsignedMessage( - network.GetNetworkID(), + networkID, pChainInfo.BlockchainID, subnetConversionAddressedCall.Bytes(), ) @@ -2132,7 +2141,7 @@ func PackInitialValidator(iv interface{}) ([]byte, error) { } func PChainProposerVMWorkaround( - network interfaces.LocalNetwork, + pchainWallet pwallet.Wallet, ) { // Workaround current block map rules destAddr, err := address.ParseToID(DefaultPChainAddress) @@ -2140,12 +2149,12 @@ func PChainProposerVMWorkaround( log.Println("Waiting for P-Chain...") time.Sleep(30 * time.Second) - pBuilder := network.GetPChainWallet().Builder() + pBuilder := pchainWallet.Builder() pContext := pBuilder.Context() avaxAssetID := pContext.AVAXAssetID locktime := uint64(time.Date(2030, 1, 1, 0, 0, 0, 0, time.UTC).Unix()) amount := 500 * units.MilliAvax - _, err = network.GetPChainWallet().IssueBaseTx([]*avax.TransferableOutput{ + _, err = pchainWallet.IssueBaseTx([]*avax.TransferableOutput{ { Asset: avax.Asset{ ID: avaxAssetID, @@ -2165,7 +2174,7 @@ func PChainProposerVMWorkaround( }, }) Expect(err).Should(BeNil()) - _, err = network.GetPChainWallet().IssueBaseTx([]*avax.TransferableOutput{ + _, err = pchainWallet.IssueBaseTx([]*avax.TransferableOutput{ { Asset: avax.Asset{ ID: avaxAssetID, @@ -2205,7 +2214,7 @@ func AdvanceProposerVM( func ConvertSubnet( ctx context.Context, subnetInfo interfaces.SubnetTestInfo, - network interfaces.LocalNetwork, + pchainWallet pwallet.Wallet, stakingManagerAddress common.Address, fundedKey *ecdsa.PrivateKey, ) []Node { @@ -2220,7 +2229,7 @@ func ConvertSubnet( NodePoP: nodePoP, }) - _, err = network.GetPChainWallet().IssueRemoveSubnetValidatorTx( + _, err = pchainWallet.IssueRemoveSubnetValidatorTx( nodeID, subnetInfo.SubnetID, ) @@ -2262,7 +2271,7 @@ func ConvertSubnet( } log.Println("Issuing ConvertSubnetTx") - _, err = network.GetPChainWallet().IssueConvertSubnetTx( + _, err = pchainWallet.IssueConvertSubnetTx( subnetInfo.SubnetID, subnetInfo.BlockchainID, stakingManagerAddress[:], @@ -2270,7 +2279,7 @@ func ConvertSubnet( ) Expect(err).Should(BeNil()) - PChainProposerVMWorkaround(network) + PChainProposerVMWorkaround(pchainWallet) AdvanceProposerVM(ctx, subnetInfo, fundedKey, 5) return nodes