Skip to content

Commit

Permalink
Merge pull request #170 from ava-labs/testnet-standalone-flows
Browse files Browse the repository at this point in the history
Standalone application for running E2E test flows against live networks
  • Loading branch information
michaelkaplan13 authored Dec 6, 2023
2 parents 28a3475 + 08dadba commit 649d274
Show file tree
Hide file tree
Showing 37 changed files with 1,880 additions and 1,643 deletions.
6 changes: 3 additions & 3 deletions .env.testnet
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# subnet A (Amplify)
subnet_a_url=https://subnets.avax.network/amplify/testnet/rpc
subnet_a_rpc_url=https://subnets.avax.network/amplify/testnet/rpc
subnet_a_subnet_id=2PsShLjrFFwR51DMcAh8pyuwzLn1Ym3zRhuXLTmLCR1STk2mL6
subnet_a_chain_id=2nFUad4Nw4pCgEF6MwYgGuKrzKbHJzM8wF29jeVUL41RWHgNRa
subnet_a_chain_id_hex=ea70d815f0232f5419dabafe36c964ffe5c22d17ac367b60b556ab3e17a36458
subnet_a_erc20_bridge_contract=0x297C4dCBB51839caEBB550C8387a52b4F3676d35
subnet_a_native_erc20_contract=0x2010D09052e5D3d0F2E80f62b7FB2E564e83B865

# subnet B (Bulletin)
subnet_b_url=https://subnets.avax.network/bulletin/testnet/rpc
subnet_b_rpc_url=https://subnets.avax.network/bulletin/testnet/rpc
subnet_b_subnet_id=cbXsFGWSDWUYTmRXUoCirVDdQkZmUWrkQQYoVc2wUoDm8eFup
subnet_b_chain_id=2e3RJ3ub9Pceh8fJ3HX3gZ6nSXJLvBJ9WoXLcU4nwdpZ8X2RLq
subnet_b_chain_id_hex=d7cdc6f08b167595d1577e24838113a88b1005b471a6c430d79c48b4c89cfc53
subnet_b_erc20_bridge_contract=0x48Db0f37e1Bfb569b420aEf96bcaaE9b889Bd2E9
subnet_b_bridge_token_contract=0x3C77573dF123f287470BC463835CE6dDc60d5eeD

# subnet C (Conduit)
subnet_c_url=https://subnets.avax.network/conduit/testnet/rpc
subnet_c_rpc_url=https://subnets.avax.network/conduit/testnet/rpc
subnet_c_subnet_id=wW7JVmjXp8SKrpacGzM81RBXdfcLDVY6M2DkFyArEXgtkyozK
subnet_c_chain_id=9asUA3QckLh7vGnFQiiUJGPTx8KE4nFtP8c1wTWJuP8XiWW75
subnet_c_chain_id_hex=137daedb40251e7c196fd9711f6cd4a787d154cdc59fb7777d4d079cc116e5f1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ docker-compose-run-local.yml
# Ginkgo
main.log
server.log
tests.test
*.test

# Forge documentation
contracts/docs/
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,14 @@ Then run the following command from the root of the repository:

### Run the E2E tests on another network

The E2E tests can be run on another network by implementing the `Network` interface in [`package network`](./tests/network/network.go). For example, the type `FujiNetwork` in [`example_fuji_network.go`](./tests/network/example_fuji_network.go) implements this interface, pointing to the [Amplify](https://subnets-test.avax.network/amplify), [Bulletin](https://subnets-test.avax.network/bulletin), and [Conduit](https://subnets-test.avax.network/conduit) Fuji subnets. After implementing this interface, you can run the E2E tests on this network by running a program such as:
```go
func main() {
// Register a failure handler that panics
gomega.RegisterFailHandler(func(message string, callerSkip ...int) {
panic(message)
})

// Run the test, composing it with the Network implementation
network := network.NewFujiNetwork()
defer network.CloseNetworkConnections()
tests.BasicOneWaySend(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.

## ABI Bindings

To generate Golang ABI bindings for the Solidity smart contracts, run:
Expand Down
54 changes: 29 additions & 25 deletions docker/run_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ if [ ! -e $dir_prefix/NETWORK_RUNNING ]; then

export PATH="$PATH:$HOME/.foundry/bin"

subnet_a_url="http://127.0.0.1:9650/ext/bc/$subnet_a_chain_id/rpc"
subnet_b_url="http://127.0.0.1:9650/ext/bc/$subnet_b_chain_id/rpc"
subnet_c_url="http://127.0.0.1:9650/ext/bc/$subnet_c_chain_id/rpc"
c_chain_url="http://127.0.0.1:9650/ext/bc/C/rpc"
subnet_a_rpc_url="http://127.0.0.1:9650/ext/bc/$subnet_a_chain_id/rpc"
subnet_a_ws_url="ws://127.0.0.1:9650/ext/bc/$subnet_a_chain_id/ws"
subnet_b_rpc_url="http://127.0.0.1:9650/ext/bc/$subnet_b_chain_id/rpc"
subnet_b_ws_url="ws://127.0.0.1:9650/ext/bc/$subnet_b_chain_id/ws"
subnet_c_rpc_url="http://127.0.0.1:9650/ext/bc/$subnet_c_chain_id/rpc"
subnet_c_ws_url="ws://127.0.0.1:9650/ext/bc/$subnet_c_chain_id/ws"
c_chain_rpc_url="http://127.0.0.1:9650/ext/bc/C/rpc"
c_chain_ws_url="ws://127.0.0.1:9650/ext/bc/C/ws"

# Deploy TeleporterMessenger contract to each chain.
cd contracts
Expand All @@ -97,32 +101,32 @@ if [ ! -e $dir_prefix/NETWORK_RUNNING ]; then
echo $teleporter_deploy_address $teleporter_contract_address
echo "Finished reading universal deploy address and transaction"

cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_a_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_b_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_c_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $c_chain_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_a_rpc_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_b_rpc_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $subnet_c_rpc_url
cast send --private-key $user_private_key --value 50ether $teleporter_deploy_address --rpc-url $c_chain_rpc_url
echo "Sent ether to teleporter deployer on each subnet."

# Verify that the transaction status was successful for the deployments
status=$(cast publish --rpc-url $subnet_a_url $teleporter_deploy_tx | getJsonVal "['status']")
status=$(cast publish --rpc-url $subnet_a_rpc_url $teleporter_deploy_tx | getJsonVal "['status']")
if [[ $status != "0x1" ]]; then
echo "Error deploying Teleporter Messenger on subnet A."
exit 1
fi
echo "Deployed TeleporterMessenger to Subnet A."
status=$(cast publish --rpc-url $subnet_b_url $teleporter_deploy_tx | getJsonVal "['status']")
status=$(cast publish --rpc-url $subnet_b_rpc_url $teleporter_deploy_tx | getJsonVal "['status']")
if [[ $status != "0x1" ]]; then
echo "Error deploying Teleporter Messenger on subnet B."
exit 1
fi
echo "Deployed TeleporterMessenger to Subnet B."
status=$(cast publish --rpc-url $subnet_c_url $teleporter_deploy_tx | getJsonVal "['status']")
status=$(cast publish --rpc-url $subnet_c_rpc_url $teleporter_deploy_tx | getJsonVal "['status']")
if [[ $status != "0x1" ]]; then
echo "Error deploying Teleporter Messenger on subnet C."
exit 1
fi
echo "Deployed TeleporterMessenger to Subnet C."
status=$(cast publish --rpc-url $c_chain_url $teleporter_deploy_tx | getJsonVal "['status']")
status=$(cast publish --rpc-url $c_chain_rpc_url $teleporter_deploy_tx | getJsonVal "['status']")
if [[ $status != "0x1" ]]; then
echo "Error deploying Teleporter Messenger on C-chain."
exit 1
Expand All @@ -132,29 +136,29 @@ if [ ! -e $dir_prefix/NETWORK_RUNNING ]; then
# Deploy TeleporterRegistry to each chain.
cd contracts
registry_deploy_result_a=$(forge create --private-key $user_private_key \
--rpc-url $subnet_a_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
registry_address_a=$(parseContractAddress "$registry_deploy_result_a")
echo "TeleporterRegistry contract deployed to subnet A at $registry_address_a."
--rpc-url $subnet_a_rpc_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
subnet_a_teleporter_registry_address=$(parseContractAddress "$registry_deploy_result_a")
echo "TeleporterRegistry contract deployed to subnet A at $subnet_a_teleporter_registry_address."

registry_deploy_result_b=$(forge create --private-key $user_private_key \
--rpc-url $subnet_b_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
registry_address_b=$(parseContractAddress "$registry_deploy_result_b")
echo "TeleporterRegistry contract deployed to subnet B at $registry_address_b."
--rpc-url $subnet_b_rpc_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
subnet_b_teleporter_registry_address=$(parseContractAddress "$registry_deploy_result_b")
echo "TeleporterRegistry contract deployed to subnet B at $subnet_b_teleporter_registry_address."

registry_deploy_result_c=$(forge create --private-key $user_private_key \
--rpc-url $subnet_c_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
registry_address_c=$(parseContractAddress "$registry_deploy_result_c")
echo "TeleporterRegistry contract deployed to subnet C at $registry_address_c."
--rpc-url $subnet_c_rpc_url src/Teleporter/upgrades/TeleporterRegistry.sol:TeleporterRegistry --constructor-args "[(1,$teleporter_contract_address)]")
subnet_c_teleporter_registry_address=$(parseContractAddress "$registry_deploy_result_c")
echo "TeleporterRegistry contract deployed to subnet C at $subnet_c_teleporter_registry_address."
cd ..

# Send tokens to cover gas costs for the relayers.
relayer_private_key=C2CE4E001B7585F543982A01FBC537CFF261A672FA8BD1FAFC08A207098FE2DE
relayer_address=0xA100fF48a37cab9f87c8b5Da933DA46ea1a5fb80

cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_a_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_b_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_c_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $c_chain_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_a_rpc_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_b_rpc_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $subnet_c_rpc_url
cast send --private-key $user_private_key --value 500ether $relayer_address --rpc-url $c_chain_rpc_url
echo "Sent ether to relayer account on each subnet."

subnet_a_chain_id_hex=$(getBlockchainIDHex $subnet_a_chain_id)
Expand Down
4 changes: 2 additions & 2 deletions scripts/local/e2e_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ cd $cwd
# to install the ginkgo binary (required for test build and run)
go install -v github.com/onsi/ginkgo/v2/ginkgo@${GINKGO_VERSION}

ginkgo build ./tests/
ginkgo build ./tests/local/

# Run the tests
echo "Running e2e tests $RUN_E2E"
RUN_E2E=true ./tests/tests.test \
RUN_E2E=true ./tests/local/local.test \
--ginkgo.vv \
--ginkgo.label-filter=${GINKGO_LABEL_FILTER:-""} \
--ginkgo.trace
Expand Down
15 changes: 15 additions & 0 deletions scripts/testnet/run_testnet_e2e_flows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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/.env
source $TELEPORTER_PATH/.env.testnet
go run tests/testnet/main/run_testnet_flows.go
79 changes: 0 additions & 79 deletions tests/deliver_to_wrong_chain.go

This file was deleted.

53 changes: 33 additions & 20 deletions tests/add_fee_amount.go → tests/flows/add_fee_amount.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
package tests
package flows

import (
"context"
"math/big"

"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/network"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
localUtils "github.com/ava-labs/teleporter/tests/utils/local-network-utils"
"github.com/ethereum/go-ethereum/common"
. "github.com/onsi/gomega"
)

func AddFeeAmount(network network.Network) {
subnets := network.GetSubnetsInfo()
Expect(len(subnets)).Should(BeNumerically(">=", 2))
subnetAInfo := subnets[0]
subnetBInfo := subnets[1]
func AddFeeAmount(network interfaces.Network) {
subnetAInfo, subnetBInfo, _ := utils.GetThreeSubnets(network)
teleporterContractAddress := network.GetTeleporterContractAddress()
fundedAddress, fundedKey := network.GetFundedAccountInfo()
ctx := context.Background()

// Use mock token as the fee token
mockTokenAddress, mockToken := localUtils.DeployExampleERC20(
mockTokenAddress, mockToken := utils.DeployExampleERC20(
context.Background(),
fundedKey,
subnetAInfo,
)
localUtils.ExampleERC20Approve(
utils.ERC20Approve(
ctx,
mockToken,
teleporterContractAddress,
Expand All @@ -38,7 +34,7 @@ func AddFeeAmount(network network.Network) {
)

initFeeAmount := big.NewInt(1)
// Send a transaction to Subnet A to issue a Warp Message from the Teleporter contract to Subnet B
// Send a transaction to SubnetA to issue a Warp Message from the Teleporter contract to SubnetB
sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{
DestinationBlockchainID: subnetBInfo.BlockchainID,
DestinationAddress: fundedAddress,
Expand Down Expand Up @@ -68,14 +64,25 @@ func AddFeeAmount(network network.Network) {
)

// Relay message from SubnetA to SubnetB
network.RelayMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true)
deliveryReceipt := network.RelayMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true)
receiveEvent, err := utils.GetEventFromLogs(
deliveryReceipt.Logs,
subnetBInfo.TeleporterMessenger.ParseReceiveCrossChainMessage)
Expect(err).Should(BeNil())

// Check Teleporter message received on the destination
// Check Teleporter message received on the destination (SubnetB)
delivered, err :=
subnetBInfo.TeleporterMessenger.MessageReceived(&bind.CallOpts{}, subnetAInfo.BlockchainID, messageID)
Expect(err).Should(BeNil())
Expect(delivered).Should(BeTrue())

// Check the initial relayer reward amount on SubnetA.
initialRewardAmount, err := subnetAInfo.TeleporterMessenger.CheckRelayerRewardAmount(
&bind.CallOpts{},
receiveEvent.RewardRedeemer,
mockTokenAddress)
Expect(err).Should(BeNil())

// Send message from SubnetB to SubnetA. This will include the receipt for the previous message from A->B
sendCrossChainMessageInput.DestinationBlockchainID = subnetAInfo.BlockchainID
sendCrossChainMessageInput.FeeInfo.Amount = big.NewInt(0)
Expand All @@ -91,13 +98,19 @@ func AddFeeAmount(network network.Network) {
Expect(err).Should(BeNil())
Expect(delivered).Should(BeTrue())

// Check the relayer reward amount
amount, err :=
subnetAInfo.TeleporterMessenger.CheckRelayerRewardAmount(&bind.CallOpts{}, fundedAddress, mockTokenAddress)
// Check the updated relayer reward amount
expectedIncrease := new(big.Int).Add(initFeeAmount, additionalFeeAmount)
newRewardAmount, err := subnetAInfo.TeleporterMessenger.CheckRelayerRewardAmount(
&bind.CallOpts{},
receiveEvent.RewardRedeemer,
mockTokenAddress)
Expect(err).Should(BeNil())
Expect(amount).Should(Equal(additionalFeeAmount.Add(additionalFeeAmount, initFeeAmount)))
Expect(newRewardAmount).Should(Equal(new(big.Int).Add(initialRewardAmount, expectedIncrease)))

utils.RedeemRelayerRewardsAndConfirm(
ctx, subnetAInfo, mockToken, mockTokenAddress, fundedKey, amount,
)
// If the funded address is the one able to redeem the rewards, do so and check the reward amount is reset.
if fundedAddress == receiveEvent.RewardRedeemer {
utils.RedeemRelayerRewardsAndConfirm(
ctx, subnetAInfo, mockToken, mockTokenAddress, fundedKey, newRewardAmount,
)
}
}
Loading

0 comments on commit 649d274

Please sign in to comment.