Skip to content

Commit

Permalink
Merge pull request #196 from ava-labs/gstuart/wait-bind-timeout
Browse files Browse the repository at this point in the history
Refactor transaction checking helpers and add timeout
  • Loading branch information
geoff-vball authored Dec 15, 2023
2 parents df7e327 + c3b30a5 commit 552ea59
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 174 deletions.
3 changes: 1 addition & 2 deletions tests/flows/block_hash_publish_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func BlockHashPublishReceive(network interfaces.Network) {
tx_opts, subnetBInfo.BlockchainID, receiverAddress)
Expect(err).Should(BeNil())

receipt, err := bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

// relay publication

Expand Down
7 changes: 2 additions & 5 deletions tests/flows/deliver_to_nonexistent_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
examplecrosschainmessenger "github.com/ava-labs/teleporter/abi-bindings/go/CrossChainApplications/ExampleMessenger/ExampleCrossChainMessenger"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
Expand Down Expand Up @@ -34,7 +33,7 @@ func DeliverToNonExistentContract(network interfaces.Network) {
fundDeployerTx := utils.CreateNativeTransferTransaction(
ctx, subnetBInfo, fundedKey, deployerAddress, fundAmount,
)
utils.SendTransactionAndWaitForAcceptance(ctx, subnetBInfo, fundDeployerTx, true)
utils.SendTransactionAndWaitForSuccess(ctx, subnetBInfo, fundDeployerTx)

//
// Deploy ExampleMessenger to Subnet A, but not to Subnet B
Expand Down Expand Up @@ -69,9 +68,7 @@ func DeliverToNonExistentContract(network interfaces.Network) {
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

sendEvent, err := utils.GetEventFromLogs(receipt.Logs, subnetAInfo.TeleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand Down
2 changes: 1 addition & 1 deletion tests/flows/deliver_to_wrong_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func DeliverToWrongChain(network interfaces.Network) {
// the same message to subnet C.
//
wrongChainDeliveryTx := createWrongChainDeliveryTransaction(ctx, deliveryTx, fundedKey, fundedAddress, subnetCInfo)
utils.SendTransactionAndWaitForAcceptance(ctx, subnetCInfo, wrongChainDeliveryTx, false)
utils.SendTransactionAndWaitForFailure(ctx, subnetCInfo, wrongChainDeliveryTx)
}

//
Expand Down
14 changes: 4 additions & 10 deletions tests/flows/erc20_bridge_multihop.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ func submitCreateBridgeToken(
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, source.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, source, tx)

event, err := utils.GetEventFromLogs(receipt.Logs, teleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand Down Expand Up @@ -429,9 +427,7 @@ func bridgeToken(
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, source.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, source, tx)

event, err := utils.GetEventFromLogs(receipt.Logs, teleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand All @@ -457,10 +453,8 @@ func approveBridgeToken(
opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, source.EVMChainID)
Expect(err).Should(BeNil())

txn, err := transactor.Approve(opts, spender, amount)
tx, err := transactor.Approve(opts, spender, amount)
Expect(err).Should(BeNil())

receipt, err := bind.WaitMined(ctx, source.RPCClient, txn)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
utils.WaitForTransactionSuccess(ctx, source, tx)
}
6 changes: 3 additions & 3 deletions tests/flows/erc20_to_native_token_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func ERC20ToNativeTokenBridge(network interfaces.LocalNetwork) {
tx, err := exampleERC20.Approve(transactor, bridgeContractAddress, bal)
Expect(err).Should(BeNil())

utils.WaitForTransactionSuccess(ctx, tx.Hash(), sourceSubnet)
utils.WaitForTransactionSuccess(ctx, sourceSubnet, tx)
}

{
Expand Down Expand Up @@ -276,7 +276,7 @@ func ERC20ToNativeTokenBridge(network interfaces.LocalNetwork) {
)
Expect(err).Should(BeNil())

destChainReceipt := utils.WaitForTransactionSuccess(ctx, tx.Hash(), destSubnet)
destChainReceipt := utils.WaitForTransactionSuccess(ctx, destSubnet, tx)

reportEvent, err := utils.GetEventFromLogs(
destChainReceipt.Logs,
Expand Down Expand Up @@ -339,7 +339,7 @@ func sendERC20TokensToDestination(
)
Expect(err).Should(BeNil())

sourceChainReceipt := utils.WaitForTransactionSuccess(ctx, tx.Hash(), sourceSubnet)
sourceChainReceipt := utils.WaitForTransactionSuccess(ctx, sourceSubnet, tx)

transferEvent, err := utils.GetEventFromLogs(
sourceChainReceipt.Logs,
Expand Down
5 changes: 1 addition & 4 deletions tests/flows/example_messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
examplecrosschainmessenger "github.com/ava-labs/teleporter/abi-bindings/go/CrossChainApplications/ExampleMessenger/ExampleCrossChainMessenger"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
Expand Down Expand Up @@ -45,9 +44,7 @@ func ExampleMessenger(network interfaces.Network) {
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

event, err := utils.GetEventFromLogs(receipt.Logs, subnetAInfo.TeleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand Down
5 changes: 1 addition & 4 deletions tests/flows/insufficient_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -34,9 +33,7 @@ func InsufficientGas(network interfaces.Network) {
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

event, err := utils.GetEventFromLogs(receipt.Logs, subnetAInfo.TeleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand Down
6 changes: 3 additions & 3 deletions tests/flows/native_token_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func NativeTokenBridge(network interfaces.LocalNetwork) {
)
Expect(err).Should(BeNil())

destChainReceipt := utils.WaitForTransactionSuccess(ctx, tx.Hash(), destSubnet)
destChainReceipt := utils.WaitForTransactionSuccess(ctx, destSubnet, tx)

reportEvent, err := utils.GetEventFromLogs(
destChainReceipt.Logs,
Expand Down Expand Up @@ -363,7 +363,7 @@ func sendTokensToSource(
)
Expect(err).Should(BeNil())

destChainReceipt := utils.WaitForTransactionSuccess(ctx, tx.Hash(), destinationSubnet)
destChainReceipt := utils.WaitForTransactionSuccess(ctx, destinationSubnet, tx)

transferEvent, err := utils.GetEventFromLogs(
destChainReceipt.Logs,
Expand Down Expand Up @@ -400,7 +400,7 @@ func sendNativeTokensToDestination(
)
Expect(err).Should(BeNil())

sourceChainReceipt := utils.WaitForTransactionSuccess(ctx, tx.Hash(), sourceSubnet)
sourceChainReceipt := utils.WaitForTransactionSuccess(ctx, sourceSubnet, tx)

transferEvent, err := utils.GetEventFromLogs(
sourceChainReceipt.Logs,
Expand Down
2 changes: 1 addition & 1 deletion tests/flows/relayer_modifies_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func relayAlteredMessage(
)

log.Info("Sending transaction to destination chain")
utils.SendTransactionAndWaitForAcceptance(ctx, destination, signedTx, false)
utils.SendTransactionAndWaitForFailure(ctx, destination, signedTx)
}

func createAlteredReceiveCrossChainMessageTransaction(
Expand Down
5 changes: 1 addition & 4 deletions tests/flows/retry_successful_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
examplecrosschainmessenger "github.com/ava-labs/teleporter/abi-bindings/go/CrossChainApplications/ExampleMessenger/ExampleCrossChainMessenger"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
Expand Down Expand Up @@ -44,9 +43,7 @@ func RetrySuccessfulExecution(network interfaces.Network) {
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt := utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

event, err := utils.GetEventFromLogs(receipt.Logs, subnetAInfo.TeleporterMessenger.ParseSendCrossChainMessage)
Expect(err).Should(BeNil())
Expand Down
7 changes: 2 additions & 5 deletions tests/flows/validator_churn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/big"

"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
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"
Expand Down Expand Up @@ -93,7 +92,7 @@ func ValidatorChurn(network interfaces.LocalNetwork) {
)

log.Info("Sending transaction to destination chain")
receipt = utils.SendTransactionAndWaitForAcceptance(ctx, subnetBInfo, signedTx, false)
utils.SendTransactionAndWaitForFailure(ctx, subnetBInfo, signedTx)

// Verify the message was not delivered
delivered, err := subnetBInfo.TeleporterMessenger.MessageReceived(
Expand All @@ -114,9 +113,7 @@ func ValidatorChurn(network interfaces.LocalNetwork) {
Expect(err).Should(BeNil())

// Wait for the transaction to be mined
receipt, err = bind.WaitMined(ctx, subnetAInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
receipt = utils.WaitForTransactionSuccess(ctx, subnetAInfo, tx)

network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true)

Expand Down
16 changes: 8 additions & 8 deletions tests/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (n *localNetwork) deployTeleporterContracts(
fundDeployerTx := utils.CreateNativeTransferTransaction(
ctx, subnetInfo, fundedKey, deployerAddress, fundAmount,
)
utils.SendTransactionAndWaitForAcceptance(ctx, subnetInfo, fundDeployerTx, true)
utils.SendTransactionAndWaitForSuccess(ctx, subnetInfo, fundDeployerTx)
}
log.Info("Finished funding Teleporter deployer", "blockchainID", subnetInfo.BlockchainID.Hex())

Expand Down Expand Up @@ -310,9 +310,8 @@ func (n *localNetwork) deployTeleporterRegistryContracts(

n.subnetsInfo[subnetInfo.SubnetID].TeleporterRegistryAddress = teleporterRegistryAddress
// Wait for the transaction to be mined
receipt, err := bind.WaitMined(ctx, subnetInfo.RPCClient, tx)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))
utils.WaitForTransactionSuccess(ctx, subnetInfo, tx)

log.Info("Deployed TeleporterRegistry contract to subnet", subnetInfo.SubnetID.Hex(),
"Deploy address", teleporterRegistryAddress.Hex())
}
Expand Down Expand Up @@ -351,7 +350,8 @@ func (n *localNetwork) RelayMessage(ctx context.Context,
sourceReceipt *types.Receipt,
source interfaces.SubnetTestInfo,
destination interfaces.SubnetTestInfo,
expectSuccess bool) *types.Receipt {
expectSuccess bool,
) *types.Receipt {
// Fetch the Teleporter message from the logs
sendEvent, err :=
utils.GetEventFromLogs(sourceReceipt.Logs, source.TeleporterMessenger.ParseSendCrossChainMessage)
Expand All @@ -370,12 +370,12 @@ func (n *localNetwork) RelayMessage(ctx context.Context,
)

log.Info("Sending transaction to destination chain")
receipt := utils.SendTransactionAndWaitForAcceptance(ctx, destination, signedTx, expectSuccess)

if !expectSuccess {
return nil
return utils.SendTransactionAndWaitForFailure(ctx, destination, signedTx)
}

receipt := utils.SendTransactionAndWaitForSuccess(ctx, destination, signedTx)

// Check the transaction logs for the ReceiveCrossChainMessage event emitted by the Teleporter contract
receiveEvent, err :=
utils.GetEventFromLogs(receipt.Logs, destination.TeleporterMessenger.ParseReceiveCrossChainMessage)
Expand Down
Loading

0 comments on commit 552ea59

Please sign in to comment.