Skip to content

Commit

Permalink
Merge pull request #441 from ava-labs/wait-teleporter-delivered
Browse files Browse the repository at this point in the history
Use wait teleporter message utility
  • Loading branch information
cam-schultz authored Aug 20, 2024
2 parents 46daa55 + 4a61a21 commit df0fc8f
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 148 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ava-labs/avalanchego v1.11.10
github.com/ava-labs/coreth v0.13.7
github.com/ava-labs/subnet-evm v0.6.8
github.com/ava-labs/teleporter v1.0.4
github.com/ava-labs/teleporter v1.0.5
github.com/aws/aws-sdk-go-v2 v1.30.3
github.com/aws/aws-sdk-go-v2/config v1.27.9
github.com/aws/aws-sdk-go-v2/service/kms v1.35.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/ava-labs/coreth v0.13.7 h1:k8T9u/ROifl8f7oXjHRc1KvSISRl9txvy7gGVmHEz6
github.com/ava-labs/coreth v0.13.7/go.mod h1:tXDujonxXFOF6oK5HS2EmgtSXJK3Gy6RpZxb5WzR9rM=
github.com/ava-labs/subnet-evm v0.6.8 h1:IrHGajBYWs692YIYdd5J0oVWWt88Q/XAZQq/dOtkHFw=
github.com/ava-labs/subnet-evm v0.6.8/go.mod h1:qt8DXyGm40CY9yffNOe1+4yUyL9mD3v5RPWqAuGj5u4=
github.com/ava-labs/teleporter v1.0.4 h1:+OAS3YyPc/LijR29qu3EqU6xAnQnjOgf4EtDlCMcDsc=
github.com/ava-labs/teleporter v1.0.4/go.mod h1:bUiOSIGjFktkYg01XDjeaZdgLEx0ZpUDfJXI6Z0rHY8=
github.com/ava-labs/teleporter v1.0.5 h1:51fRzvo7eo9VotYq6cldx+yoAkEk5o9yCXOJ6q3tSEo=
github.com/ava-labs/teleporter v1.0.5/go.mod h1:C5/ETmPQh/MxZOCARrhPV+J40y4R3TOeT0lvQrjz/RE=
github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc=
github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg=
Expand Down
2 changes: 1 addition & 1 deletion tests/contracts/lib/teleporter
56 changes: 32 additions & 24 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,51 +45,59 @@ func TestE2E(t *testing.T) {

// Define the Relayer before and after suite functions.
var _ = ginkgo.BeforeSuite(func() {
localNetworkInstance = local.NewLocalNetwork(
"awm-relayer-e2e-test",
warpGenesisTemplateFile,
[]local.SubnetSpec{
{
Name: "A",
EVMChainID: 12345,
NodeCount: 2,
},
{
Name: "B",
EVMChainID: 54321,
NodeCount: 2,
},
},
0,
)
// Generate the Teleporter deployment values
teleporterContractAddress := common.HexToAddress(
testUtils.ReadHexTextFile("./tests/utils/UniversalTeleporterMessengerContractAddress.txt"),
)
teleporterDeployerAddress := common.HexToAddress(
testUtils.ReadHexTextFile("./tests/utils/UniversalTeleporterDeployerAddress.txt"),
)
teleporterDeployedByteCode := testUtils.ReadHexTextFile(
"./tests/utils/UniversalTeleporterDeployedBytecode.txt",
)
teleporterDeployerTransactionStr := testUtils.ReadHexTextFile(
"./tests/utils/UniversalTeleporterDeployerTransaction.txt",
)
teleporterDeployerTransaction, err := hex.DecodeString(
utils.SanitizeHexString(teleporterDeployerTransactionStr),
)
Expect(err).Should(BeNil())
localNetworkInstance = local.NewLocalNetwork(
"awm-relayer-e2e-test",
warpGenesisTemplateFile,
[]local.SubnetSpec{
{
Name: "A",
EVMChainID: 12345,
TeleporterContractAddress: teleporterContractAddress,
TeleporterDeployedBytecode: teleporterDeployedByteCode,
TeleporterDeployerAddress: teleporterDeployerAddress,
NodeCount: 2,
},
{
Name: "B",
EVMChainID: 54321,
TeleporterContractAddress: teleporterContractAddress,
TeleporterDeployedBytecode: teleporterDeployedByteCode,
TeleporterDeployerAddress: teleporterDeployerAddress,
NodeCount: 2,
},
},
0,
)

_, fundedKey := localNetworkInstance.GetFundedAccountInfo()
localNetworkInstance.DeployTeleporterContracts(
log.Info("Deployed Teleporter contracts")
localNetworkInstance.DeployTeleporterContractToCChain(
teleporterDeployerTransaction,
teleporterDeployerAddress,
teleporterContractAddress,
fundedKey,
true,
)
log.Info("Deployed Teleporter contracts")
localNetworkInstance.DeployTeleporterRegistryContracts(
teleporterContractAddress,
fundedKey,
)
localNetworkInstance.SetTeleporterContractAddress(teleporterContractAddress)

// Deploy the Teleporter registry contracts to all subnets and the C-Chain.
localNetworkInstance.DeployTeleporterRegistryContracts(teleporterContractAddress, fundedKey)

var ctx context.Context
ctx, cancelDecider = context.WithCancel(context.Background())
Expand Down
1 change: 1 addition & 0 deletions tests/utils/UniversalTeleporterDeployedBytecode.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/utils/UniversalTeleporterDeployerAddress.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x7307D51641453D3DbB28c0c3303D5661e3Bc9507
0xB845be8Fca46B198ad68b60112F0C9b7910B5086
2 changes: 1 addition & 1 deletion tests/utils/UniversalTeleporterDeployerTransaction.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xDc65BB82E60F5096BDD267b20d236DbA804C8b2E
0x68D42653C8455969EDae4F89281f4b9Ed3E9080d
91 changes: 8 additions & 83 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/logging"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
offchainregistry "github.com/ava-labs/awm-relayer/messages/off-chain-registry"
relayercfg "github.com/ava-labs/awm-relayer/relayer/config"
Expand All @@ -27,14 +25,10 @@ import (
relayerUtils "github.com/ava-labs/awm-relayer/utils"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
predicateutils "github.com/ava-labs/subnet-evm/predicate"
subnetevmutils "github.com/ava-labs/subnet-evm/utils"
teleportermessenger "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/TeleporterMessenger"
"github.com/ava-labs/teleporter/tests/interfaces"
"github.com/ava-labs/teleporter/tests/utils"
teleporterTestUtils "github.com/ava-labs/teleporter/tests/utils"
teleporterUtils "github.com/ava-labs/teleporter/utils/teleporter-utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -416,89 +410,17 @@ func RelayBasicMessage(
Expect(err).Should(BeNil())
defer sub.Unsubscribe()

_, teleporterMessage, teleporterMessageID := SendBasicTeleporterMessage(
_, _, teleporterMessageID := SendBasicTeleporterMessage(
ctx,
source,
destination,
fundedKey,
destinationAddress,
)

log.Info("Waiting for new block confirmation")
newHead := <-newHeadsDest
blockNumber := newHead.Number
log.Info(
"Received new head",
"height", blockNumber.Uint64(),
"hash", newHead.Hash(),
)
block, err := destination.RPCClient.BlockByNumber(ctx, blockNumber)
Expect(err).Should(BeNil())
log.Info(
"Got block",
"blockHash", block.Hash(),
"blockNumber", block.NumberU64(),
"transactions", block.Transactions(),
"numTransactions", len(block.Transactions()),
"block", block,
)
accessLists := block.Transactions()[0].AccessList()
Expect(len(accessLists)).Should(Equal(1))
Expect(accessLists[0].Address).Should(Equal(warp.Module.Address))

// Check the transaction storage key has warp message we're expecting
storageKeyHashes := accessLists[0].StorageKeys
packedPredicate := subnetevmutils.HashSliceToBytes(storageKeyHashes)
predicateBytes, err := predicateutils.UnpackPredicate(packedPredicate)
Expect(err).Should(BeNil())
receivedWarpMessage, err := avalancheWarp.ParseMessage(predicateBytes)
Expect(err).Should(BeNil())

// Check that the transaction has successful receipt status
txHash := block.Transactions()[0].Hash()
receipt, err := destination.RPCClient.TransactionReceipt(ctx, txHash)
Expect(err).Should(BeNil())
Expect(receipt.Status).Should(Equal(types.ReceiptStatusSuccessful))

// Check that the transaction emits ReceiveCrossChainMessage
receiveEvent, err := teleporterTestUtils.GetEventFromLogs(
receipt.Logs,
destination.TeleporterMessenger.ParseReceiveCrossChainMessage,
)
Expect(err).Should(BeNil())
Expect(receiveEvent.SourceBlockchainID[:]).Should(Equal(source.BlockchainID[:]))
Expect(receiveEvent.MessageID[:]).Should(Equal(teleporterMessageID[:]))

//
// Validate Received Warp Message Values
//
log.Info("Validating received warp message")
Expect(receivedWarpMessage.SourceChainID).Should(Equal(source.BlockchainID))
addressedPayload, err := warpPayload.ParseAddressedCall(receivedWarpMessage.Payload)
Expect(err).Should(BeNil())

// Check that the teleporter message is correct
// We don't validate the entire message, since the message receipts
// are populated by the Teleporter contract
var receivedTeleporterMessage teleportermessenger.TeleporterMessage
err = receivedTeleporterMessage.Unpack(addressedPayload.Payload)
log.Info("Waiting for Teleporter message delivery")
err = utils.WaitTeleporterMessageDelivered(ctx, destination.TeleporterMessenger, teleporterMessageID)
Expect(err).Should(BeNil())

receivedMessageID, err := teleporterUtils.CalculateMessageID(
teleporterContractAddress,
source.BlockchainID,
destination.BlockchainID,
teleporterMessage.MessageNonce,
)
Expect(err).Should(BeNil())
Expect(receivedMessageID).Should(Equal(teleporterMessageID))
Expect(receivedTeleporterMessage.OriginSenderAddress).Should(Equal(teleporterMessage.OriginSenderAddress))
receivedDestinationID, err := ids.ToID(receivedTeleporterMessage.DestinationBlockchainID[:])
Expect(err).Should(BeNil())
Expect(receivedDestinationID).Should(Equal(destination.BlockchainID))
Expect(receivedTeleporterMessage.DestinationAddress).Should(Equal(teleporterMessage.DestinationAddress))
Expect(receivedTeleporterMessage.RequiredGasLimit.Uint64()).Should(Equal(teleporterMessage.RequiredGasLimit.Uint64()))
Expect(receivedTeleporterMessage.Message).Should(Equal(teleporterMessage.Message))
}

func WriteRelayerConfig(relayerConfig relayercfg.Config, fname string) string {
Expand Down Expand Up @@ -572,8 +494,11 @@ func TriggerProcessMissedBlocks(
log.Info("Starting the relayer")
relayerCleanup := BuildAndRunRelayerExecutable(ctx, relayerConfigPath)
defer relayerCleanup()
log.Info("Waiting for a new block confirmation on the destination")
<-newHeads

log.Info("Waiting for Teleporter message delivery")
err = utils.WaitTeleporterMessageDelivered(ctx, destinationSubnetInfo.TeleporterMessenger, id3)
Expect(err).Should(BeNil())

delivered1, err := destinationSubnetInfo.TeleporterMessenger.MessageReceived(
&bind.CallOpts{}, id1,
)
Expand Down
82 changes: 48 additions & 34 deletions tests/utils/warp-genesis-template.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,57 @@
{
"config": {
"chainId": <EVM_CHAIN_ID>,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"feeConfig": {
"gasLimit": 20000000,
"minBaseFee": 1000000000,
"targetGas": 100000000,
"baseFeeChangeDenominator": 48,
"minBlockGasCost": 0,
"maxBlockGasCost": 10000000,
"targetBlockRate": 2,
"blockGasCostStep": 500000
},
"warpConfig": {
"blockTimestamp": 1719343601
}
"chainId": <EVM_CHAIN_ID>,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"feeConfig": {
"gasLimit": 20000000,
"minBaseFee": 1000000000,
"targetGas": 100000000,
"baseFeeChangeDenominator": 48,
"minBlockGasCost": 0,
"maxBlockGasCost": 10000000,
"targetBlockRate": 2,
"blockGasCostStep": 500000
},
"warpConfig": {
"blockTimestamp": 1719343601
},
"contractNativeMinterConfig": {
"blockTimestamp": 0,
"adminAddresses": [
"0xAcB633F5B00099c7ec187eB00156c5cd9D854b5B",
"0x3405506b3711859c5070949ed9b700c7ba7bf750"
]
}
},
"alloc": {
"0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
"balance": "0x52B7D2DCC80CD2E4000000"
},
"0x0Fa8EA536Be85F32724D57A37758761B86416123": {
"balance": "0x52B7D2DCC80CD2E4000000"
},
"0x1dD31B5351e76d51F4B152ce64fE5cf594694De5": {
"balance": "0x52B7D2DCC80CD2E4000000"
}
"0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": {
"balance": "0x52B7D2DCC80CD2E4000000"
},
"<TELEPORTER_MESSENGER_CONTRACT_ADDRESS>": {
"balance": "0x0",
"code": "<TELEPORTER_MESSENGER_DEPLOYED_BYTECODE>",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000001"
},
"nonce": 1
},
"<TELEPORTER_MESSENGER_DEPLOYER_ADDRESS>": {
"balance": "0x0",
"nonce": 1
}
},
"nonce": "0x0",
"timestamp": "0x0",
"timestamp": "0x667B19F0",
"extraData": "0x00",
"gasLimit": "0x1312D00",
"difficulty": "0x0",
Expand Down

0 comments on commit df0fc8f

Please sign in to comment.