-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test send specific receipts (Part 2) #113
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5a31e6e
test insufficient gas
gwen917 b92a21b
fix
gwen917 142e065
send specific receipts
gwen917 cb96f56
Merge remote-tracking branch 'origin/main' into test-case-send-specif…
gwen917 2f75462
Merge remote-tracking branch 'origin/main' into test-case-insufficien…
gwen917 6c298ad
Merge remote-tracking branch 'origin/test-case-add-fee-amount' into t…
gwen917 bcb76c3
Merge remote-tracking branch 'origin/test-case-add-fee-amount' into t…
gwen917 eb3bce9
Merge remote-tracking branch 'origin/test-case-insufficient-gas' into…
gwen917 1b2ffca
Merge remote-tracking branch 'origin/test-case-add-fee-amount' into t…
gwen917 3f373db
Merge remote-tracking branch 'origin/test-case-insufficient-gas' into…
gwen917 7441638
send receipt multiple times
gwen917 3e57df9
Merge remote-tracking branch 'origin/general-e2e' into test-case-send…
gwen917 76a47a2
fix
gwen917 e0a076f
fix comments
gwen917 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,131 @@ | ||
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" | ||
"github.com/ethereum/go-ethereum/common" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func SendSpecificReceiptsGinkgo() { | ||
SendSpecificReceipts(&network.LocalNetwork{}) | ||
} | ||
|
||
func SendSpecificReceipts(network network.Network) { | ||
subnets := network.GetSubnetsInfo() | ||
subnetAInfo := subnets[0] | ||
subnetBInfo := subnets[1] | ||
teleporterContractAddress := network.GetTeleporterContractAddress() | ||
fundedAddress, fundedKey := network.GetFundedAccountInfo() | ||
ctx := context.Background() | ||
|
||
subnetATeleporterMessenger, err := teleportermessenger.NewTeleporterMessenger(teleporterContractAddress, subnetAInfo.ChainRPCClient) | ||
Expect(err).Should(BeNil()) | ||
subnetBTeleporterMessenger, err := teleportermessenger.NewTeleporterMessenger(teleporterContractAddress, subnetBInfo.ChainRPCClient) | ||
Expect(err).Should(BeNil()) | ||
|
||
// Use mock token as the fee token | ||
mockTokenAddress, mockToken := utils.DeployMockToken(context.Background(), fundedAddress, fundedKey, subnetAInfo) | ||
utils.ExampleERC20Approve(ctx, mockToken, teleporterContractAddress, big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(10)), subnetAInfo) | ||
|
||
relayerFeePerMessage := big.NewInt(5) | ||
totalAccumulatedRelayerFee := big.NewInt(10) | ||
// Send two messages from Subnet A to Subnet B | ||
sendCrossChainMessageInput := teleportermessenger.TeleporterMessageInput{ | ||
DestinationChainID: subnetBInfo.BlockchainID, | ||
DestinationAddress: fundedAddress, | ||
FeeInfo: teleportermessenger.TeleporterFeeInfo{ | ||
ContractAddress: mockTokenAddress, | ||
Amount: relayerFeePerMessage, | ||
}, | ||
RequiredGasLimit: big.NewInt(1), | ||
AllowedRelayerAddresses: []common.Address{}, | ||
Message: []byte{1, 2, 3, 4}, | ||
} | ||
|
||
// Send first message from Subnet A to Subnet B with fee amount 5 | ||
sendCrossChainMsgReceipt, messageID1 := utils.SendCrossChainMessageAndWaitForAcceptance( | ||
ctx, subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedAddress, fundedKey, subnetATeleporterMessenger) | ||
|
||
// Relay message from SubnetA to SubnetB | ||
network.RelayMessage(ctx, sendCrossChainMsgReceipt.BlockHash, sendCrossChainMsgReceipt.BlockNumber, subnetAInfo, subnetBInfo) | ||
// Check messge delivered | ||
delivered, err := subnetBTeleporterMessenger.MessageReceived(&bind.CallOpts{}, subnetAInfo.BlockchainID, messageID1) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
// Send second message from Subnet A to Subnet B with fee amount 5 | ||
sendCrossChainMsgReceipt, messageID2 := utils.SendCrossChainMessageAndWaitForAcceptance( | ||
ctx, subnetAInfo, subnetBInfo, sendCrossChainMessageInput, fundedAddress, fundedKey, subnetATeleporterMessenger) | ||
|
||
// Relay message from SubnetA to SubnetB | ||
network.RelayMessage(ctx, sendCrossChainMsgReceipt.BlockHash, sendCrossChainMsgReceipt.BlockNumber, subnetAInfo, subnetBInfo) | ||
// Check delivered | ||
delivered, err = subnetBTeleporterMessenger.MessageReceived(&bind.CallOpts{}, subnetAInfo.BlockchainID, messageID2) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
// Relayer send specific receipts to get reward of relaying two messages | ||
receipt, messageID := utils.SendSpecifiedReceiptsAndWaitForAcceptance( | ||
ctx, | ||
subnetAInfo.BlockchainID, | ||
subnetBInfo, | ||
[]*big.Int{messageID1, messageID2}, | ||
teleportermessenger.TeleporterFeeInfo{ | ||
ContractAddress: mockTokenAddress, | ||
Amount: big.NewInt(0), | ||
}, | ||
[]common.Address{}, | ||
fundedAddress, | ||
fundedKey, | ||
subnetBTeleporterMessenger, | ||
) | ||
|
||
// Relay message from Subnet B to Subnet A | ||
network.RelayMessage(ctx, receipt.BlockHash, receipt.BlockNumber, subnetBInfo, subnetAInfo) | ||
// Check delivered | ||
delivered, err = subnetATeleporterMessenger.MessageReceived(&bind.CallOpts{}, subnetBInfo.BlockchainID, messageID) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
// Check the reward amount. The reward amount should be 10 | ||
amount, err := subnetATeleporterMessenger.CheckRelayerRewardAmount(&bind.CallOpts{}, fundedAddress, mockTokenAddress) | ||
Expect(err).Should(BeNil()) | ||
Expect(amount).Should(Equal(totalAccumulatedRelayerFee)) | ||
|
||
// Send message from Subnet B to Subnet A to trigger the "regular" method of delivering receipts. | ||
// The next message from B->A will contain the same receipts that were manually sent in the above steps, | ||
// but they should not be processed again on Subnet A. | ||
sendCrossChainMessageInput = teleportermessenger.TeleporterMessageInput{ | ||
DestinationChainID: subnetAInfo.BlockchainID, | ||
DestinationAddress: fundedAddress, | ||
FeeInfo: teleportermessenger.TeleporterFeeInfo{ | ||
ContractAddress: mockTokenAddress, | ||
Amount: big.NewInt(0), | ||
}, | ||
RequiredGasLimit: big.NewInt(1), | ||
AllowedRelayerAddresses: []common.Address{}, | ||
Message: []byte{1, 2, 3, 4}, | ||
} | ||
|
||
// This message will also have the same receipt as the previous message | ||
receipt, messageID = utils.SendCrossChainMessageAndWaitForAcceptance( | ||
ctx, subnetBInfo, subnetAInfo, sendCrossChainMessageInput, fundedAddress, fundedKey, subnetBTeleporterMessenger) | ||
|
||
// Relay message from Subnet B to Subnet A | ||
network.RelayMessage(ctx, receipt.BlockHash, receipt.BlockNumber, subnetBInfo, subnetAInfo) | ||
// Check delivered | ||
delivered, err = subnetATeleporterMessenger.MessageReceived(&bind.CallOpts{}, subnetBInfo.BlockchainID, messageID) | ||
Expect(err).Should(BeNil()) | ||
Expect(delivered).Should(BeTrue()) | ||
|
||
// Check the reward amount remains the same | ||
amount, err = subnetATeleporterMessenger.CheckRelayerRewardAmount(&bind.CallOpts{}, fundedAddress, mockTokenAddress) | ||
Expect(err).Should(BeNil()) | ||
Expect(amount).Should(Equal(totalAccumulatedRelayerFee)) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an additional step of sending an arbitrary message from Subnet B -> Subnet A? This message will also include the receipts that were explicitly sent in the above steps. We should check that the relayer reward amount is unchanged, even after the receipt is delivered again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure. Then, will it cover
Test receiving a receipt multiple times has no effect
case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup it will! I pointed it out for completeness here, but that will also cover that test case.