Skip to content

Commit

Permalink
Merge branch 'develop' into feat/zetaclient/tss-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
swift1337 authored Nov 22, 2024
2 parents 7d9c96b + cda3398 commit 95c87d8
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 60 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ ifdef UPGRADE_TEST_FROM_SOURCE
zetanode-upgrade: e2e-images
@echo "Building zetanode-upgrade from source"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime-source \
--build-arg OLD_VERSION='release/v21' \
--build-arg OLD_VERSION='release/v22' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT)
.
Expand All @@ -336,7 +336,7 @@ else
zetanode-upgrade: e2e-images
@echo "Building zetanode-upgrade from binaries"
$(DOCKER) build -t zetanode:old -f Dockerfile-localnet --target old-runtime \
--build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v21.0.0' \
--build-arg OLD_VERSION='https://github.com/zeta-chain/node/releases/download/v22.1.1' \
--build-arg NODE_VERSION=$(NODE_VERSION) \
--build-arg NODE_COMMIT=$(NODE_COMMIT) \
.
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func erc20TestRoutine(
startTime := time.Now()

// funding the account
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10)
txERC20Send := deployerRunner.SendERC20OnEvm(account.EVMAddress(), 10000)
erc20Runner.WaitForTxReceiptOnEvm(txERC20Send)

// depositing the necessary tokens on ZetaChain
Expand Down
4 changes: 3 additions & 1 deletion contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ services:
ipv4_address: 172.20.0.102

bitcoin:
image: ghcr.io/zeta-chain/ruimarinho-bitcoin-core:22 # version 23 is not working with btcd 0.22.0 due to change in createwallet rpc
image: ghcr.io/zeta-chain/bitcoin-core-docker:28.0
container_name: bitcoin
hostname: bitcoin
networks:
Expand All @@ -213,6 +213,8 @@ services:
-rpcbind=0.0.0.0
-rpcauth=smoketest:63acf9b8dccecce914d85ff8c044b78b$$5892f9bbc84f4364e79f0970039f88bdd823f168d4acc76099ab97b14a766a99
-txindex=1
-deprecatedrpc=create_bdb
-deprecatedrpc=warnings

solana:
image: solana-local:latest
Expand Down
6 changes: 3 additions & 3 deletions docs/openapi/openapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<link
rel="stylesheet"
type="text/css"
href="https://unpkg.com/swagger-ui-dist@4.18.1/swagger-ui.css"
href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui.min.css"
/>
<link
rel="icon"
type="image/png"
href="https://unpkg.com/swagger-ui-dist@4.18.1/favicon-16x16.png"
href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/favicon-16x16.png"
/>
</head>
<body>
<div id="swagger-ui"></div>

<script src="https://unpkg.com/swagger-ui-dist@4.18.1/swagger-ui-bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui-bundle.min.js"></script>
<script>
window.onload = function() {
window.ui = SwaggerUIBundle({
Expand Down
45 changes: 4 additions & 41 deletions e2e/e2etests/test_erc20_deposit_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package e2etests

import (
"errors"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -64,7 +62,9 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) {
r.Logger.Info("Sending a deposit that should revert with a liquidity pool")

r.Logger.Info("Creating the liquidity pool USTD/ZETA")
err = createZetaERC20LiquidityPool(r)
fifty := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(50))
r.AddLiquidityETH(fifty, fifty)
r.AddLiquidityERC20(fifty, fifty)
require.NoError(r, err)

r.Logger.Info("Liquidity pool created")
Expand All @@ -73,7 +73,7 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) {
require.NoError(r, err)

// send the deposit
amount = big.NewInt(1e7)
amount = big.NewInt(1e10)
inboundHash, err = sendInvalidERC20Deposit(r, amount)
require.NoError(r, err)

Expand Down Expand Up @@ -120,43 +120,6 @@ func TestERC20DepositAndCallRefund(r *runner.E2ERunner, _ []string) {
r.Logger.Info("\tbalance after refund: %s", erc20BalanceAfterRefund.String())
}

func createZetaERC20LiquidityPool(r *runner.E2ERunner) error {
amount := big.NewInt(1e10)
txHash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{})
utils.WaitCctxMinedByInboundHash(r.Ctx, txHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout)

tx, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e10))
if err != nil {
return err
}
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
if receipt.Status == 0 {
return errors.New("approve failed")
}

previousValue := r.ZEVMAuth.Value
r.ZEVMAuth.Value = big.NewInt(1e10)
tx, err = r.UniswapV2Router.AddLiquidityETH(
r.ZEVMAuth,
r.ERC20ZRC20Addr,
amount,
big.NewInt(0),
big.NewInt(0),
r.EVMAddress(),
big.NewInt(time.Now().Add(10*time.Minute).Unix()),
)
r.ZEVMAuth.Value = previousValue
if err != nil {
return err
}
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
if receipt.Status == 0 {
return fmt.Errorf("add liquidity failed")
}

return nil
}

func sendInvalidERC20Deposit(r *runner.E2ERunner, amount *big.Int) (string, error) {
tx, err := r.ERC20.Approve(r.EVMAuth, r.ERC20CustodyAddr, amount)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion e2e/runner/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func (r *E2ERunner) SendERC20OnEvm(address ethcommon.Address, amountERC20 int64)
func (r *E2ERunner) DepositERC20() ethcommon.Hash {
r.Logger.Print("⏳ depositing ERC20 into ZEVM")

return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), big.NewInt(1e18), []byte{})
oneHundred := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(100))
return r.DepositERC20WithAmountAndMessage(r.EVMAddress(), oneHundred, []byte{})
}

func (r *E2ERunner) DepositERC20WithAmountAndMessage(to ethcommon.Address, amount *big.Int, msg []byte) ethcommon.Hash {
Expand Down
8 changes: 6 additions & 2 deletions e2e/runner/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func (r *E2ERunner) AddLiquidityETH(amountZETA, amountETH *big.Int) {
require.NoError(r, err)

receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
require.EqualValues(r, types.ReceiptStatusSuccessful, receipt.Status, "add liquidity failed")
if receipt.Status == types.ReceiptStatusFailed {
r.Logger.Error("Add liquidity failed for ZETA/ETH")
}

// get the pair address
pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ETHZRC20Addr)
Expand Down Expand Up @@ -72,7 +74,9 @@ func (r *E2ERunner) AddLiquidityERC20(amountZETA, amountERC20 *big.Int) {
require.NoError(r, err)

receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
require.EqualValues(r, types.ReceiptStatusSuccessful, receipt.Status, "add liquidity failed")
if receipt.Status == types.ReceiptStatusFailed {
r.Logger.Error("Add liquidity failed for ZETA/ERC20")
}

// get the pair address
pairAddress, err := r.UniswapV2Factory.GetPair(&bind.CallOpts{}, r.WZetaAddr, r.ERC20ZRC20Addr)
Expand Down
33 changes: 26 additions & 7 deletions e2e/runner/setup_bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package runner

import (
"encoding/hex"
"encoding/json"
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/rpcclient"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ func (r *E2ERunner) SetupBitcoinAccounts(createWallet bool) {
}()

// setup deployer address
r.SetupBtcAddress(r.Name, createWallet)
r.SetupBtcAddress(createWallet)

// import the TSS address to index TSS utxos and transactions
err := r.BtcRPCClient.ImportAddress(r.BTCTSSAddress.EncodeAddress())
Expand Down Expand Up @@ -70,21 +70,40 @@ func (r *E2ERunner) GetBtcAddress() (*btcutil.AddressWitnessPubKeyHash, *btcutil
}

// SetupBtcAddress setups the deployer Bitcoin address
func (r *E2ERunner) SetupBtcAddress(name string, setupWallet bool) {
func (r *E2ERunner) SetupBtcAddress(createWallet bool) {
// set the deployer address
address, privkeyWIF := r.GetBtcAddress()
r.BTCDeployerAddress = address

r.Logger.Info("BTCDeployerAddress: %s, %v", r.BTCDeployerAddress.EncodeAddress(), setupWallet)
r.Logger.Info("BTCDeployerAddress: %s, %v", r.BTCDeployerAddress.EncodeAddress(), createWallet)

// import the deployer private key as a Bitcoin node wallet
if setupWallet {
_, err := r.BtcRPCClient.CreateWallet(r.Name, rpcclient.WithCreateWalletBlank())
if createWallet {
// we must use a raw request as the rpcclient does not expose the
// descriptors arg which must be set to false
// https://github.com/btcsuite/btcd/issues/2179
// https://developer.bitcoin.org/reference/rpc/createwallet.html
args := []interface{}{
r.Name, // wallet_name
false, // disable_private_keys
true, // blank
"", // passphrase
false, // avoid_reuse
false, // descriptors
true, // load_on_startup
}
argsRawMsg := []json.RawMessage{}
for _, arg := range args {
encodedArg, err := json.Marshal(arg)
require.NoError(r, err)
argsRawMsg = append(argsRawMsg, encodedArg)
}
_, err := r.BtcRPCClient.RawRequest("createwallet", argsRawMsg)
if err != nil {
require.ErrorContains(r, err, "Database already exists")
}

err = r.BtcRPCClient.ImportPrivKeyRescan(privkeyWIF, name, true)
err = r.BtcRPCClient.ImportPrivKeyRescan(privkeyWIF, r.Name, true)
require.NoError(r, err, "failed to execute ImportPrivKeyRescan")
}
}
8 changes: 7 additions & 1 deletion e2e/utils/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ func RequireCCTXStatus(
expected crosschaintypes.CctxStatus,
msgAndArgs ...any,
) {
msg := fmt.Sprintf("cctx status is not %q cctx index %s", expected.String(), cctx.Index)
msg := fmt.Sprintf(
"cctx status is not %q cctx index %s, status: %s, error: %s",
expected.String(),
cctx.Index,
cctx.CctxStatus.StatusMessage,
cctx.CctxStatus.ErrorMessage,
)

require.NotNil(t, cctx.CctxStatus)
require.Equal(t, expected, cctx.CctxStatus.Status, msg+errSuffix(msgAndArgs...))
Expand Down
2 changes: 2 additions & 0 deletions pkg/chains/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
BitcoinMainnet.ChainId: &chaincfg.MainNetParams,
BitcoinTestnet.ChainId: &chaincfg.TestNet3Params,
BitcoinSignetTestnet.ChainId: &chaincfg.SigNetParams,
BitcoinTestnet4.ChainId: &TestNet4Params,
}

// networkNameToChainID maps the Bitcoin network name to the chain ID
Expand All @@ -21,6 +22,7 @@ var (
chaincfg.MainNetParams.Name: BitcoinMainnet.ChainId,
chaincfg.TestNet3Params.Name: BitcoinTestnet.ChainId,
chaincfg.SigNetParams.Name: BitcoinSignetTestnet.ChainId,
TestNet4Params.Name: BitcoinTestnet4.ChainId,
}
)

Expand Down
6 changes: 6 additions & 0 deletions pkg/chains/bitcoin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestBitcoinNetParamsFromChainID(t *testing.T) {
{"Mainnet", BitcoinMainnet.ChainId, &chaincfg.MainNetParams, false},
{"Testnet", BitcoinTestnet.ChainId, &chaincfg.TestNet3Params, false},
{"Signet", BitcoinSignetTestnet.ChainId, &chaincfg.SigNetParams, false},
{"Testnet4", BitcoinTestnet4.ChainId, &TestNet4Params, false},
{"Unknown", -1, nil, true},
}

Expand Down Expand Up @@ -46,6 +47,7 @@ func TestBitcoinChainIDFromNetParams(t *testing.T) {
{"Mainnet", chaincfg.MainNetParams.Name, BitcoinMainnet.ChainId, false},
{"Testnet", chaincfg.TestNet3Params.Name, BitcoinTestnet.ChainId, false},
{"Signet", chaincfg.SigNetParams.Name, BitcoinSignetTestnet.ChainId, false},
{"Testnet4", TestNet4Params.Name, BitcoinTestnet4.ChainId, false},
{"Unknown", "Unknown", 0, true},
}

Expand All @@ -67,10 +69,14 @@ func TestIsBitcoinRegnet(t *testing.T) {
require.True(t, IsBitcoinRegnet(BitcoinRegtest.ChainId))
require.False(t, IsBitcoinRegnet(BitcoinMainnet.ChainId))
require.False(t, IsBitcoinRegnet(BitcoinTestnet.ChainId))
require.False(t, IsBitcoinRegnet(BitcoinSignetTestnet.ChainId))
require.False(t, IsBitcoinRegnet(BitcoinTestnet4.ChainId))
}

func TestIsBitcoinMainnet(t *testing.T) {
require.True(t, IsBitcoinMainnet(BitcoinMainnet.ChainId))
require.False(t, IsBitcoinMainnet(BitcoinRegtest.ChainId))
require.False(t, IsBitcoinMainnet(BitcoinTestnet.ChainId))
require.False(t, IsBitcoinMainnet(BitcoinSignetTestnet.ChainId))
require.False(t, IsBitcoinMainnet(BitcoinTestnet4.ChainId))
}
Loading

0 comments on commit 95c87d8

Please sign in to comment.