Skip to content

Commit

Permalink
Rename network
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Oct 10, 2024
1 parent 972f91a commit 95fc40c
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 179 deletions.
25 changes: 13 additions & 12 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/ava-labs/teleporter/tests/flows"
"github.com/ava-labs/teleporter/tests/network"
localnetwork "github.com/ava-labs/teleporter/tests/network"
deploymentUtils "github.com/ava-labs/teleporter/utils/deployment-utils"
"github.com/ethereum/go-ethereum/log"
"github.com/onsi/ginkgo/v2"
Expand All @@ -27,9 +27,7 @@ const (
validatorSetSigLabel = "ValidatorSetSig"
)

var (
LocalNetworkInstance *network.LocalNetwork
)
var LocalNetworkInstance *localnetwork.LocalNetwork

func TestE2E(t *testing.T) {
if os.Getenv("RUN_E2E") == "" {
Expand All @@ -43,22 +41,25 @@ func TestE2E(t *testing.T) {
// Define the Teleporter before and after suite functions.
var _ = ginkgo.BeforeSuite(func() {
// Generate the Teleporter deployment values
teleporterDeployerTransaction, teleporterDeployedBytecode, teleporterDeployerAddress, teleporterContractAddress, err :=
deploymentUtils.ConstructKeylessTransaction(
teleporterByteCodeFile,
false,
deploymentUtils.GetDefaultContractCreationGasPrice(),
)
teleporterDeployerTransaction,
teleporterDeployedBytecode,
teleporterDeployerAddress,
teleporterContractAddress,
err := deploymentUtils.ConstructKeylessTransaction(
teleporterByteCodeFile,
false,
deploymentUtils.GetDefaultContractCreationGasPrice(),
)
Expect(err).Should(BeNil())

// Create the local network instance
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
LocalNetworkInstance = network.NewLocalNetwork(
LocalNetworkInstance = localnetwork.NewLocalNetwork(
ctx,
"teleporter-test-local-network",
warpGenesisTemplateFile,
[]network.SubnetSpec{
[]localnetwork.SubnetSpec{
{
Name: "A",
EVMChainID: 12345,
Expand Down
16 changes: 8 additions & 8 deletions tests/flows/add_fee_amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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/network"
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(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
teleporterContractAddress := n.GetTeleporterContractAddress()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func AddFeeAmount(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, _ := network.GetTwoSubnets()
teleporterContractAddress := network.GetTeleporterContractAddress()
fundedAddress, fundedKey := network.GetFundedAccountInfo()
ctx := context.Background()

// Use mock token as the fee token
Expand Down Expand Up @@ -66,7 +66,7 @@ func AddFeeAmount(n *network.LocalNetwork) {
)

// Relay message from Subnet A to Subnet B
deliveryReceipt := n.RelayMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true)
deliveryReceipt := network.RelayMessage(ctx, sendCrossChainMsgReceipt, subnetAInfo, subnetBInfo, true)
receiveEvent, err := utils.GetEventFromLogs(
deliveryReceipt.Logs,
subnetBInfo.TeleporterMessenger.ParseReceiveCrossChainMessage)
Expand Down Expand Up @@ -98,7 +98,7 @@ func AddFeeAmount(n *network.LocalNetwork) {
fundedKey)

// Relay message containing the specific receipt from Subnet B to Subnet A
n.RelayMessage(ctx, sendSpecificReceiptsReceipt, subnetBInfo, subnetAInfo, true)
network.RelayMessage(ctx, sendSpecificReceiptsReceipt, subnetBInfo, subnetAInfo, true)

// Check message delivered
delivered, err = subnetAInfo.TeleporterMessenger.MessageReceived(&bind.CallOpts{}, sendSpecificReceiptsMessageID)
Expand Down
38 changes: 15 additions & 23 deletions tests/flows/basic_send_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@ 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/network"
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(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
teleporterContractAddress := n.GetTeleporterContractAddress()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func BasicSendReceive(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, _ := network.GetTwoSubnets()
teleporterContractAddress := network.GetTeleporterContractAddress()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

// Send a transaction to Subnet A to issue a Warp Message from the Teleporter contract to Subnet B
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 !n.IsExternalNetwork() {
network.ClearReceiptQueue(ctx, n, fundedKey, subnetBInfo, subnetAInfo)
}
network.ClearReceiptQueue(ctx, fundedKey, subnetBInfo, subnetAInfo)

feeAmount := big.NewInt(1)
feeTokenAddress, feeToken := utils.DeployExampleERC20(
Expand Down Expand Up @@ -67,7 +65,7 @@ func BasicSendReceive(n *network.LocalNetwork) {
expectedReceiptID := teleporterMessageID

// Relay the message to the destination
deliveryReceipt := n.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
deliveryReceipt := network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
receiveEvent, err := utils.GetEventFromLogs(
deliveryReceipt.Logs,
subnetBInfo.TeleporterMessenger.ParseReceiveCrossChainMessage)
Expand All @@ -92,17 +90,12 @@ func BasicSendReceive(n *network.LocalNetwork) {
)

// Relay the message to the destination
deliveryReceipt = n.RelayMessage(ctx, receipt, subnetBInfo, subnetAInfo, true)
deliveryReceipt = network.RelayMessage(ctx, receipt, subnetBInfo, subnetAInfo, true)

// 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 !n.IsExternalNetwork() {
Expect(utils.CheckReceiptReceived(
deliveryReceipt,
expectedReceiptID,
subnetAInfo.TeleporterMessenger)).Should(BeTrue())
}
Expect(utils.CheckReceiptReceived(
deliveryReceipt,
expectedReceiptID,
subnetAInfo.TeleporterMessenger)).Should(BeTrue())

// Check Teleporter message received on the destination
delivered, err = subnetAInfo.TeleporterMessenger.MessageReceived(
Expand All @@ -112,9 +105,8 @@ func BasicSendReceive(n *network.LocalNetwork) {
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 !n.IsExternalNetwork() && receiveEvent.RewardRedeemer == fundedAddress {
// transactions on subnet A, then redeem the rewards.
if receiveEvent.RewardRedeemer == fundedAddress {
utils.RedeemRelayerRewardsAndConfirm(
ctx, subnetAInfo, feeToken, feeTokenAddress, fundedKey, feeAmount,
)
Expand Down
10 changes: 5 additions & 5 deletions tests/flows/check_upgrade_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/teleporter/tests/network"
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(n *network.LocalNetwork) {
subnetInfo := n.GetPrimaryNetworkInfo()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func CheckUpgradeAccess(network *localnetwork.LocalNetwork) {
subnetInfo := network.GetPrimaryNetworkInfo()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

//
// Deploy TestMessenger to the subnet
//
ctx := context.Background()
teleporterAddress := n.GetTeleporterContractAddress()
teleporterAddress := network.GetTeleporterContractAddress()
_, testMessenger := utils.DeployTestMessenger(
ctx,
fundedKey,
Expand Down
12 changes: 6 additions & 6 deletions tests/flows/deliver_to_nonexistent_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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/network"
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"
"github.com/ethereum/go-ethereum/log"
. "github.com/onsi/gomega"
)

func DeliverToNonExistentContract(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func DeliverToNonExistentContract(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, _ := network.GetTwoSubnets()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

deployerKey, err := crypto.GenerateKey()
Expect(err).Should(BeNil())
Expand Down Expand Up @@ -84,7 +84,7 @@ func DeliverToNonExistentContract(n *network.LocalNetwork) {
// Relay the message to the destination
//
log.Info("Relaying the message to the destination")
receipt = n.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
receipt = network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
receiveEvent, err := utils.GetEventFromLogs(
receipt.Logs,
subnetAInfo.TeleporterMessenger.ParseReceiveCrossChainMessage,
Expand Down
12 changes: 6 additions & 6 deletions tests/flows/deliver_to_wrong_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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/network"
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(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, subnetCInfo := n.GetTwoSubnets()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func DeliverToWrongChain(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, subnetCInfo := network.GetTwoSubnets()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

//
// Get the expected teleporter message ID for Subnet C
Expand Down Expand Up @@ -56,7 +56,7 @@ func DeliverToWrongChain(n *network.LocalNetwork) {
fundedKey,
)

n.RelayMessage(ctx, receipt, subnetAInfo, subnetCInfo, false)
network.RelayMessage(ctx, receipt, subnetAInfo, subnetCInfo, false)

//
// Check that the message was not received on the Subnet C
Expand Down
12 changes: 6 additions & 6 deletions tests/flows/insufficient_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/teleporter/tests/network"
localnetwork "github.com/ava-labs/teleporter/tests/network"
"github.com/ava-labs/teleporter/tests/utils"
. "github.com/onsi/gomega"
)

func InsufficientGas(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func InsufficientGas(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, _ := network.GetTwoSubnets()
fundedAddress, fundedKey := network.GetFundedAccountInfo()
ctx := context.Background()

// Deploy TestMessenger to Subnets A
Expand Down Expand Up @@ -51,7 +51,7 @@ func InsufficientGas(n *network.LocalNetwork) {
messageID := event.MessageID

// Relay message from SubnetA to SubnetB
receipt = n.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
receipt = network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)

// Check Teleporter message received on the destination
delivered, err := subnetBInfo.TeleporterMessenger.MessageReceived(&bind.CallOpts{}, messageID)
Expand Down
14 changes: 6 additions & 8 deletions tests/flows/pause_teleporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
"context"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/teleporter/tests/network"
localnetwork "github.com/ava-labs/teleporter/tests/network"
"github.com/ava-labs/teleporter/tests/utils"
. "github.com/onsi/gomega"
)

func PauseTeleporter(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func PauseTeleporter(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
subnetBInfo, _ := network.GetTwoSubnets()
fundedAddress, fundedKey := network.GetFundedAccountInfo()

//
// Deploy TestMessenger to Subnets A and B
//
ctx := context.Background()
teleporterAddress := n.GetTeleporterContractAddress()
teleporterAddress := network.GetTeleporterContractAddress()
_, testMessengerA := utils.DeployTestMessenger(
ctx,
fundedKey,
Expand Down Expand Up @@ -51,7 +51,6 @@ func PauseTeleporter(n *network.LocalNetwork) {
// Send a message from subnet A to subnet B, which should fail
network.SendExampleCrossChainMessageAndVerify(
ctx,
n,
subnetAInfo,
testMessengerA,
subnetBInfo,
Expand All @@ -78,7 +77,6 @@ func PauseTeleporter(n *network.LocalNetwork) {
// Send a message from subnet A to subnet B again, which should now succeed
network.SendExampleCrossChainMessageAndVerify(
ctx,
n,
subnetAInfo,
testMessengerA,
subnetBInfo,
Expand Down
14 changes: 7 additions & 7 deletions tests/flows/relay_message_twice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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/network"
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 RelayMessageTwice(n *network.LocalNetwork) {
subnetAInfo := n.GetPrimaryNetworkInfo()
subnetBInfo, _ := n.GetTwoSubnets()
fundedAddress, fundedKey := n.GetFundedAccountInfo()
func RelayMessageTwice(network *localnetwork.LocalNetwork) {
subnetAInfo := network.GetPrimaryNetworkInfo()
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
Expand Down Expand Up @@ -47,7 +47,7 @@ func RelayMessageTwice(n *network.LocalNetwork) {
//
// Relay the message to the destination
//
n.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)
network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)

//
// Check Teleporter message received on the destination
Expand All @@ -63,5 +63,5 @@ func RelayMessageTwice(n *network.LocalNetwork) {
// Attempt to send the same message again, should fail
//
log.Info("Relaying the same Teleporter message again on the destination")
n.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, false)
network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, false)
}
Loading

0 comments on commit 95fc40c

Please sign in to comment.