Skip to content

Commit

Permalink
set cap in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Aug 30, 2024
1 parent d8b9bce commit b971bbd
Showing 1 changed file with 57 additions and 8 deletions.
65 changes: 57 additions & 8 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"
Expand Down Expand Up @@ -441,7 +442,7 @@ func (zts ZetaTxServer) DeployZRC20s(
}

// deploy eth zrc20
_, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
res, err := zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
"",
chains.GoerliLocalnet.ChainId,
Expand All @@ -454,9 +455,16 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", fmt.Errorf("failed to deploy eth zrc20: %s", err.Error())
}
zrc20, err := fetchZRC20FromDeployResponse(res)
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
return "", err
}

// deploy btc zrc20
_, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
"",
chains.BitcoinRegtest.ChainId,
Expand All @@ -469,9 +477,16 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", fmt.Errorf("failed to deploy btc zrc20: %s", err.Error())
}
zrc20, err = fetchZRC20FromDeployResponse(res)
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
return "", err
}

// deploy sol zrc20
_, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
"",
chains.SolanaLocalnet.ChainId,
Expand All @@ -484,9 +499,16 @@ func (zts ZetaTxServer) DeployZRC20s(
if err != nil {
return "", fmt.Errorf("failed to deploy sol zrc20: %s", err.Error())
}
zrc20, err = fetchZRC20FromDeployResponse(res)
if err != nil {
return "", err
}
if err := zts.initializeLiquidityCap(zrc20); err != nil {
return "", err
}

// deploy erc20 zrc20
res, err := zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
res, err = zts.BroadcastTx(deployerAccount, fungibletypes.NewMsgDeployFungibleCoinZRC20(
deployerAddr,
erc20Addr,
chains.GoerliLocalnet.ChainId,
Expand All @@ -501,12 +523,12 @@ func (zts ZetaTxServer) DeployZRC20s(
}

// fetch the erc20 zrc20 contract address and remove the quotes
erc20zrc20Addr, err := FetchAttributeFromTxResponse(res, "Contract")
erc20zrc20Addr, err := fetchZRC20FromDeployResponse(res)
if err != nil {
return "", fmt.Errorf("failed to fetch erc20 zrc20 contract address: %s, %s", err.Error(), res.String())
return "", err
}
if !ethcommon.IsHexAddress(erc20zrc20Addr) {
return "", fmt.Errorf("invalid address in event: %s", erc20zrc20Addr)
if err := zts.initializeLiquidityCap(erc20zrc20Addr); err != nil {
return "", err
}

return erc20zrc20Addr, nil
Expand Down Expand Up @@ -557,6 +579,33 @@ func (zts *ZetaTxServer) SetAuthorityClient(authorityClient authoritytypes.Query
zts.authorityClient = authorityClient
}

// initializeLiquidityCap initializes the liquidity cap for the given coin with a large value
func (zts ZetaTxServer) initializeLiquidityCap(zrc20 string) error {
liquidityCap := sdktypes.NewUint(1e18).MulUint64(1e12)

msg := fungibletypes.NewMsgUpdateZRC20LiquidityCap(
zts.MustGetAccountAddressFromName(utils.OperationalPolicyName),
zrc20,
liquidityCap,
)
_, err := zts.BroadcastTx(utils.OperationalPolicyName, msg)
return err
}

// fetchZRC20FromDeployResponse fetches the zrc20 address from the response
func fetchZRC20FromDeployResponse(res *sdktypes.TxResponse) (string, error) {
// fetch the erc20 zrc20 contract address and remove the quotes
zrc20Addr, err := FetchAttributeFromTxResponse(res, "Contract")
if err != nil {
return "", fmt.Errorf("failed to fetch zrc20 contract address: %s, %s", err.Error(), res.String())
}
if !ethcommon.IsHexAddress(zrc20Addr) {
return "", fmt.Errorf("invalid address in event: %s", zrc20Addr)
}

return zrc20Addr, nil
}

// fetchMessagePermissions fetches the message permissions for a given message
// return a bool preV19 to indicate the node is preV19 and the query doesn't exist
func (zts ZetaTxServer) fetchMessagePermissions(msg sdktypes.Msg) (authoritytypes.PolicyType, bool, error) {
Expand Down

0 comments on commit b971bbd

Please sign in to comment.