-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add bitcoin e2e test deposit_call (#2895)
* added bitcoin deposit and call e2e test * add e2e test for bitcoin deposit and call * fix precision issue when depositing BTC to tss address * add changelog entry * resolved changelog conflict --------- Co-authored-by: Lucas Bertrand <[email protected]>
- Loading branch information
1 parent
ecb328e
commit 17f26e6
Showing
5 changed files
with
70 additions
and
1 deletion.
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,55 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
testcontract "github.com/zeta-chain/node/testutil/contracts" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
zetabitcoin "github.com/zeta-chain/node/zetaclient/chains/bitcoin" | ||
) | ||
|
||
func TestBitcoinDepositAndCall(r *runner.E2ERunner, args []string) { | ||
// ARRANGE | ||
// Given BTC address | ||
r.SetBtcAddress(r.Name, false) | ||
|
||
// Given "Live" BTC network | ||
stop := r.MineBlocksIfLocalBitcoin() | ||
defer stop() | ||
|
||
// Given amount to send | ||
require.Len(r, args, 1) | ||
amount := parseFloat(r, args[0]) | ||
amountTotal := amount + zetabitcoin.DefaultDepositorFee | ||
|
||
// Given a list of UTXOs | ||
utxos, err := r.ListDeployerUTXOs() | ||
require.NoError(r, err) | ||
require.NotEmpty(r, utxos) | ||
|
||
// deploy an example contract in ZEVM | ||
contractAddr, _, contract, err := testcontract.DeployExample(r.ZEVMAuth, r.ZEVMClient) | ||
require.NoError(r, err) | ||
r.Logger.Print("Bitcoin: Example contract deployed at: %s", contractAddr.String()) | ||
|
||
// ACT | ||
// Send BTC to TSS address with a dummy memo | ||
data := []byte("hello satoshi") | ||
memo := append(contractAddr.Bytes(), data...) | ||
txHash, err := r.SendToTSSFromDeployerWithMemo(amountTotal, utxos, memo) | ||
require.NoError(r, err) | ||
|
||
// wait for the cctx to be mined | ||
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
r.Logger.CCTX(*cctx, "bitcoin_deposit_and_call") | ||
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) | ||
|
||
// check if example contract has been called, 'bar' value should be set to amount | ||
amoutSats, err := zetabitcoin.GetSatoshis(amount) | ||
require.NoError(r, err) | ||
utils.MustHaveCalledExampleContract(r, contract, big.NewInt(amoutSats)) | ||
} |
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