-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for crosschain evm hooks (#1787)
* make staking keeper private * process logs test case * add more test cases * add tests for parsing ZETA sent event * add unit tests for process ZRC20 withdraw * add more unit tests * add changelog.md * Update e2e/e2etests/test_bitcoin_withdraw.go Co-authored-by: Lucas Bertrand <[email protected]> * Update x/crosschain/keeper/evm_hooks.go Co-authored-by: Lucas Bertrand <[email protected]> * Update x/crosschain/keeper/evm_hooks_test.go Co-authored-by: Lucas Bertrand <[email protected]> * move block data to sample package * move helpers to the top * move withdraw for btc legacy address to a separate test * remove invalid withdraw of 0.1 BTC * increase approval amount --------- Co-authored-by: Lucas Bertrand <[email protected]>
- Loading branch information
Showing
9 changed files
with
825 additions
and
68 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 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
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,45 @@ | ||
package e2etests | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/btcsuite/btcutil" | ||
"github.com/zeta-chain/zetacore/e2e/runner" | ||
"github.com/zeta-chain/zetacore/e2e/utils" | ||
) | ||
|
||
func TestBitcoinWithdrawToInvalidAddress(r *runner.E2ERunner) { | ||
WithdrawToInvalidAddress(r) | ||
} | ||
|
||
func WithdrawToInvalidAddress(r *runner.E2ERunner) { | ||
|
||
amount := big.NewInt(0.00001 * btcutil.SatoshiPerBitcoin) | ||
approvalAmount := 1000000000000000000 | ||
// approve the ZRC20 contract to spend approvalAmount BTC from the deployer address. | ||
// the actual amount transferred is 0.00001 BTC, but we approve more to cover withdraw fee | ||
tx, err := r.BTCZRC20.Approve(r.ZevmAuth, r.BTCZRC20Addr, big.NewInt(int64(approvalAmount))) | ||
if err != nil { | ||
panic(err) | ||
} | ||
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZevmClient, tx, r.Logger, r.ReceiptTimeout) | ||
if receipt.Status != 1 { | ||
panic(fmt.Errorf("approve receipt status is not 1")) | ||
} | ||
|
||
// mine blocks | ||
stop := r.MineBlocks() | ||
|
||
// withdraw 0.00001 BTC from ZRC20 to BTC legacy address | ||
tx, err = r.BTCZRC20.Withdraw(r.ZevmAuth, []byte("1EYVvXLusCxtVuEwoYvWRyN5EZTXwPVvo3"), amount) | ||
if err != nil { | ||
panic(err) | ||
} | ||
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZevmClient, tx, r.Logger, r.ReceiptTimeout) | ||
if receipt.Status == 1 { | ||
panic(fmt.Errorf("withdraw receipt status is successful for an invalid BTC address")) | ||
} | ||
// stop mining | ||
stop <- struct{}{} | ||
} |
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
Large diffs are not rendered by default.
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
Oops, something went wrong.