-
Notifications
You must be signed in to change notification settings - Fork 173
test: add E2E tests for Sui fungible token withdrawAndCall #3831
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
188a094
initiate sui fungible token withdrawAndCall e2e tests
ws4charlie d7f646b
create a unified function to create E2E tests WAC payload
ws4charlie f629d8a
add sui token withdraw and call E2E tests
ws4charlie 6fad36c
Merge branch 'develop' into e2e-sui-token-withdraw-and-call
ws4charlie 0d770b1
try consolidating #gosec G101 comments in e2e tests
ws4charlie 5f5b8bd
add #gosec G101 back because one single comment won't apply for all t…
ws4charlie 1c067b9
remove hardcoded invalid sui payload message as long as it replicate …
ws4charlie 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 hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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
Binary file not shown.
This file contains hidden or 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 hidden or 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,62 @@ | ||
| package e2etests | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "github.com/zeta-chain/protocol-contracts/pkg/gatewayzevm.sol" | ||
|
|
||
| "github.com/zeta-chain/node/e2e/runner" | ||
| "github.com/zeta-chain/node/e2e/utils" | ||
| crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
| ) | ||
|
|
||
| func TestSuiTokenWithdrawAndCall(r *runner.E2ERunner, args []string) { | ||
| require.Len(r, args, 1) | ||
|
|
||
| // ARRANGE | ||
| // Given target package ID (example package) and a token amount | ||
| targetPackageID := r.SuiExample.PackageID.String() | ||
| amount := utils.ParseBigInt(r, args[0]) | ||
|
|
||
| // use the deployer address as on_call payload message | ||
| signer, err := r.Account.SuiSigner() | ||
| require.NoError(r, err, "get deployer signer") | ||
| suiAddress := signer.Address() | ||
|
|
||
| // Given initial balance and called_count | ||
| balanceBefore := r.SuiGetFungibleTokenBalance(suiAddress) | ||
| calledCountBefore := r.SuiGetConnectedCalledCount() | ||
|
|
||
| // create the on_call payload | ||
| payloadOnCall, err := r.SuiCreateExampleWACPayload(suiAddress) | ||
| require.NoError(r, err) | ||
|
|
||
| // ACT | ||
| // approve both SUI gas budget token and fungible token ZRC20 | ||
| r.ApproveSUIZRC20(r.GatewayZEVMAddr) | ||
| r.ApproveFungibleTokenZRC20(r.GatewayZEVMAddr) | ||
|
|
||
| // perform the fungible token withdraw and call | ||
| tx := r.SuiWithdrawAndCallFungibleToken( | ||
| targetPackageID, | ||
| amount, | ||
| payloadOnCall, | ||
| gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)}, | ||
| ) | ||
| r.Logger.EVMTransaction(*tx, "withdraw_and_call") | ||
|
|
||
| // ASSERT | ||
| // wait for the cctx to be mined | ||
| cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
| r.Logger.CCTX(*cctx, "withdraw") | ||
| require.EqualValues(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status) | ||
|
|
||
| // check the balance after the withdraw | ||
| balanceAfter := r.SuiGetFungibleTokenBalance(signer.Address()) | ||
| require.EqualValues(r, balanceBefore+amount.Uint64(), balanceAfter) | ||
|
|
||
| // verify the called_count increased by 1 | ||
| calledCountAfter := r.SuiGetConnectedCalledCount() | ||
| require.Equal(r, calledCountBefore+1, calledCountAfter) | ||
| } |
82 changes: 82 additions & 0 deletions
82
e2e/e2etests/test_sui_token_withdraw_and_call_revert_with_call.go
This file contains hidden or 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,82 @@ | ||
| package e2etests | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/zeta-chain/protocol-contracts/pkg/gatewayzevm.sol" | ||
|
|
||
| "github.com/zeta-chain/node/e2e/runner" | ||
| "github.com/zeta-chain/node/e2e/utils" | ||
| "github.com/zeta-chain/node/testutil/sample" | ||
| crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
| ) | ||
|
|
||
| // TestSuiTokenWithdrawAndCallRevertWithCall executes withdrawAndCall on zevm gateway with fungible token. | ||
| // The outbound is rejected by the connected module due to invalid payload (invalid address), | ||
| // and 'onRevert' is called instead to handle the revert. | ||
| func TestSuiTokenWithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string) { | ||
| require.Len(r, args, 1) | ||
|
|
||
| // ARRANGE | ||
| // Given target package ID (example package) and a token amount | ||
| targetPackageID := r.SuiExample.PackageID.String() | ||
| amount := utils.ParseBigInt(r, args[0]) | ||
|
|
||
| // create the payload for 'on_call' with invalid address | ||
| // taking the first 10 letters to form an invalid address | ||
| invalidAddress := sample.SuiAddress(r)[:10] | ||
| payloadOnCall, err := r.SuiCreateExampleWACPayload(invalidAddress) | ||
| require.NoError(r, err) | ||
|
|
||
| // given ZEVM revert address (the dApp) | ||
| dAppAddress := r.TestDAppV2ZEVMAddr | ||
| dAppBalanceBefore, err := r.SuiTokenZRC20.BalanceOf(&bind.CallOpts{}, dAppAddress) | ||
| require.NoError(r, err) | ||
|
|
||
| // given random payload for 'onRevert' | ||
| payloadOnRevert := randomPayload(r) | ||
| r.AssertTestDAppEVMCalled(false, payloadOnRevert, amount) | ||
|
|
||
| // ACT | ||
| // approve both SUI gas budget token and fungible token ZRC20 | ||
| r.ApproveSUIZRC20(r.GatewayZEVMAddr) | ||
| r.ApproveFungibleTokenZRC20(r.GatewayZEVMAddr) | ||
|
|
||
| // perform the withdraw and call with revert options | ||
| tx := r.SuiWithdrawAndCallFungibleToken( | ||
| targetPackageID, | ||
| amount, | ||
| payloadOnCall, | ||
| gatewayzevm.RevertOptions{ | ||
| CallOnRevert: true, | ||
| RevertAddress: dAppAddress, | ||
| RevertMessage: []byte(payloadOnRevert), | ||
| OnRevertGasLimit: big.NewInt(0), | ||
| }, | ||
| ) | ||
| r.Logger.EVMTransaction(*tx, "withdraw_and_call") | ||
|
|
||
| // ASSERT | ||
| // wait for the cctx to be reverted | ||
| cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
| r.Logger.CCTX(*cctx, "withdraw") | ||
| utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_Reverted) | ||
|
|
||
| // should have called 'onRevert' | ||
| r.AssertTestDAppZEVMCalled(true, payloadOnRevert, big.NewInt(0)) | ||
|
|
||
| // sender and message should match | ||
| sender, err := r.TestDAppV2ZEVM.SenderWithMessage( | ||
| &bind.CallOpts{}, | ||
| []byte(payloadOnRevert), | ||
| ) | ||
| require.NoError(r, err) | ||
| require.Equal(r, r.ZEVMAuth.From, sender) | ||
|
|
||
| // the dApp address should get reverted amount | ||
| dAppBalanceAfter, err := r.SuiTokenZRC20.BalanceOf(&bind.CallOpts{}, dAppAddress) | ||
| require.NoError(r, err) | ||
| require.Equal(r, amount.Int64(), dAppBalanceAfter.Int64()-dAppBalanceBefore.Int64()) | ||
| } |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.