-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from ava-labs/e2e-basic-send-receive-ginkgo
e2e test case: basic send *and receive*
- Loading branch information
Showing
5 changed files
with
168 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package tests | ||
|
||
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/utils" | ||
localUtils "github.com/ava-labs/teleporter/tests/utils/local-network-utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func BasicSendReceiveGinkgo() { | ||
BasicSendReceive(&network.LocalNetwork{}) | ||
} | ||
|
||
// Tests basic one-way send from Subnet A to Subnet B and vice versa | ||
func BasicSendReceive(network network.Network) { | ||
var ( | ||
teleporterMessageID *big.Int | ||
) | ||
|
||
subnets := network.GetSubnetsInfo() | ||
subnetAInfo := subnets[0] | ||
subnetBInfo := subnets[1] | ||
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() | ||
|
||
feeAmount := big.NewInt(1) | ||
feeTokenAddress, feeToken := localUtils.DeployExampleERC20( | ||
ctx, | ||
fundedKey, | ||
subnetAInfo, | ||
) | ||
localUtils.ExampleERC20Approve( | ||
ctx, | ||
feeToken, | ||
teleporterContractAddress, | ||
big.NewInt(0).Mul(big.NewInt(1e18), | ||
big.NewInt(10)), | ||
subnetAInfo, | ||
fundedKey, | ||
) | ||
|
||
sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{ | ||
DestinationChainID: subnetBInfo.BlockchainID, | ||
DestinationAddress: fundedAddress, | ||
FeeInfo: teleportermessenger.TeleporterFeeInfo{ | ||
FeeTokenAddress: feeTokenAddress, | ||
Amount: feeAmount, | ||
}, | ||
RequiredGasLimit: big.NewInt(1), | ||
AllowedRelayerAddresses: []common.Address{}, | ||
Message: []byte{1, 2, 3, 4}, | ||
} | ||
|
||
receipt, teleporterMessageID := utils.SendCrossChainMessageAndWaitForAcceptance( | ||
ctx, | ||
subnetAInfo, | ||
subnetBInfo, | ||
sendCrossChainMessageInput, | ||
fundedKey, | ||
) | ||
|
||
// | ||
// Relay the message to the destination | ||
// | ||
|
||
network.RelayMessage(ctx, receipt, subnetAInfo, subnetBInfo, true) | ||
|
||
// | ||
// Check Teleporter message received on the destination | ||
// | ||
delivered, err := subnetBInfo.TeleporterMessenger.MessageReceived( | ||
&bind.CallOpts{}, subnetAInfo.BlockchainID, teleporterMessageID, | ||
) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
// | ||
// Send a transaction to Subnet B to issue a Warp Message from the Teleporter contract to Subnet A | ||
// | ||
|
||
sendCrossChainMessageInput.DestinationChainID = subnetAInfo.BlockchainID | ||
sendCrossChainMessageInput.FeeInfo.Amount = big.NewInt(0) | ||
receipt, teleporterMessageID = utils.SendCrossChainMessageAndWaitForAcceptance( | ||
ctx, | ||
subnetBInfo, | ||
subnetAInfo, | ||
sendCrossChainMessageInput, | ||
fundedKey, | ||
) | ||
|
||
// | ||
// Relay the message to the destination | ||
// | ||
network.RelayMessage(ctx, receipt, subnetBInfo, subnetAInfo, true) | ||
|
||
// | ||
// Check Teleporter message received on the destination | ||
// | ||
delivered, err = subnetAInfo.TeleporterMessenger.MessageReceived( | ||
&bind.CallOpts{}, subnetBInfo.BlockchainID, teleporterMessageID, | ||
) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
utils.RedeemRelayerRewardsAndConfirm( | ||
ctx, subnetAInfo, feeToken, feeTokenAddress, fundedKey, feeAmount, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters