Skip to content

Commit

Permalink
refactor ct cli to use SDK coin format (#1977)
Browse files Browse the repository at this point in the history
* refactor ct cli to use coin format like e.g. 1usei

* update integration tests

* formatting

* update integration tests

* update integration tests - 2
  • Loading branch information
dssei authored and mj850 committed Dec 6, 2024
1 parent 8f1b057 commit cb36ad7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
env: INIT_ACCOUNT_CODE

# Deposit to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit uatom 500000 --from ctapplytest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 500000uatom --from ctapplytest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

# Query the initial account state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
env: INIT_ACCOUNT_CODE

# Deposit to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit uatom 500000 --from ctclosetest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 500000uatom --from ctclosetest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

# Attempt to close the account
Expand Down Expand Up @@ -74,7 +74,7 @@
env: INITIAL_AVAILABLE_BALANCE

# Withdraw all funds from the account
- cmd: printf "12345678\n" | seid tx ct withdraw uatom $INITIAL_AVAILABLE_BALANCE --from ctclosetest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct withdraw ${INITIAL_AVAILABLE_BALANCE}uatom --from ctclosetest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: WITHDRAW_CODE

# Attempt to close the account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
env: INITIAL_BANK_BALANCE

# Deposit to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit uatom 500000 --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 500000uatom --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

# Query the account to verify the new account state
Expand Down Expand Up @@ -80,7 +80,7 @@
env: TEST_ADDR

# Deposit to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit notexists 500000 --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 500000notexists --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

verifiers:
Expand All @@ -105,7 +105,7 @@
env: DEPOSIT_AMOUNT

# Attempt to deposit to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit uatom $DEPOSIT_AMOUNT --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit ${DEPOSIT_AMOUNT}uatom --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

verifiers:
Expand All @@ -129,7 +129,7 @@
- cmd: printf "12345678\n" | seid tx bank send $ADMIN_ADDR $TEST_ADDR 10000000000000000uusdc -b block --fees 2000usei --chain-id sei -y --output json | jq -r ".code"

# Attempt to deposit 2^48 to the confidential token account
- cmd: printf "12345678\n" | seid tx ct deposit uusdc 281474976710656 --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 281474976710656uusdc --from ctdeposittest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE

verifiers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
env: INIT_RECIPIENT_ACCOUNT_CODE

# Deposit to the sender confidential token account and apply the pending balance
- cmd: printf "12345678\n" | seid tx ct deposit uatom $TRANSFER_AMOUNT --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit ${TRANSFER_AMOUNT}uatom --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE
- cmd: printf "12345678\n" | seid tx ct apply-pending-balance uatom --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: APPLY_PENDING_BALANCE_CODE
Expand All @@ -50,7 +50,7 @@
env: INITIAL_RECIPIENT_AVAILABLE_BALANCE

# Transfer from the confidential token account
- cmd: printf "12345678\n" | seid tx ct transfer uatom $RECIPIENT_ADDR $TRANSFER_AMOUNT --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct transfer $RECIPIENT_ADDR ${TRANSFER_AMOUNT}uatom --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: TRANSFER_CODE

# Query the sender account to verify the new account state
Expand Down Expand Up @@ -126,7 +126,7 @@
env: INITIAL_AVAILABLE_BALANCE

# Attempt to transfer more than the available balance
- cmd: printf "12345678\n" | seid tx ct transfer uatom $RECIPIENT_ADDR $((INITIAL_AVAILABLE_BALANCE + 1)) --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct transfer $RECIPIENT_ADDR $((INITIAL_AVAILABLE_BALANCE + 1))uatom --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: TRANSFER_CODE

verifiers:
Expand All @@ -145,7 +145,7 @@
env: RECIPIENT_ADDR

# Attempt to transfer from an uninitialized account
- cmd: printf "12345678\n" | seid tx ct transfer notexists $RECIPIENT_ADDR 50000 --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct transfer $RECIPIENT_ADDR 50000notexists --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: TRANSFER_CODE

verifiers:
Expand All @@ -171,13 +171,13 @@
- cmd: printf "12345678\n" | seid tx bank send $ADMIN_ADDR $SENDER_ADDR 100000uusdc -b block --fees 2000usei --chain-id sei -y --output json | jq -r ".code"

# Deposit to the sender confidential token account and apply the pending balance
- cmd: printf "12345678\n" | seid tx ct deposit uusdc 50000 --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit 50000uusdc --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE
- cmd: printf "12345678\n" | seid tx ct apply-pending-balance uusdc --from ctsender --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: APPLY_PENDING_BALANCE_CODE

# Attempt to transfer from an uninitialized account
- cmd: printf "12345678\n" | seid tx ct transfer uusdc $RECIPIENT_ADDR 50000 --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct transfer $RECIPIENT_ADDR 50000uusdc --from ctsender --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: TRANSFER_CODE

verifiers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
env: INIT_ACCOUNT_CODE

# Deposit to the confidential token account and apply the pending balance
- cmd: printf "12345678\n" | seid tx ct deposit uatom $WITHDRAW_AMOUNT --from ctwithdrawtest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct deposit ${WITHDRAW_AMOUNT}uatom --from ctwithdrawtest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: DEPOSIT_CODE
- cmd: printf "12345678\n" | seid tx ct apply-pending-balance uatom --from ctwithdrawtest --fees 4000usei --chain-id sei -b block -y --output json | jq -r ".code"
env: APPLY_PENDING_BALANCE_CODE
Expand All @@ -37,7 +37,7 @@
env: INITIAL_BANK_BALANCE

# Withdraw from the confidential token account
- cmd: printf "12345678\n" | seid tx ct withdraw uatom $WITHDRAW_AMOUNT --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct withdraw ${WITHDRAW_AMOUNT}uatom --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: WITHDRAW_CODE

# Query the account to verify the new account state
Expand Down Expand Up @@ -97,7 +97,7 @@
env: INITIAL_AVAILABLE_BALANCE

# Attempt to withdraw more than the available balance
- cmd: printf "12345678\n" | seid tx ct withdraw uatom $((INITIAL_AVAILABLE_BALANCE + 1)) --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct withdraw $((INITIAL_AVAILABLE_BALANCE + 1))uatom --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: WITHDRAW_CODE

verifiers:
Expand All @@ -114,7 +114,7 @@
env: TEST_ADDR

# Attempt to withdraw from an uninitialized account
- cmd: printf "12345678\n" | seid tx ct withdraw notexists 50000 --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
- cmd: printf "12345678\n" | seid tx ct withdraw 50000notexists --from ctwithdrawtest --fees 40000usei --gas 1500000 --chain-id sei -b block -y --output json | jq -r ".code"
env: WITHDRAW_CODE

verifiers:
Expand Down
66 changes: 21 additions & 45 deletions x/confidentialtransfers/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"math/big"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand All @@ -21,10 +19,6 @@ import (
"github.com/spf13/cobra"
)

const (
FlagPrivateKey = "private-key"
)

// NewTxCmd returns a root CLI command handler for all x/confidentialtransfers transaction commands.
func NewTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Expand Down Expand Up @@ -187,11 +181,11 @@ func makeCloseAccountCmd(cmd *cobra.Command, args []string) error {
// NewTransferTxCmd returns a CLI command handler for creating a MsgTransfer transaction.
func NewTransferTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [denom] [to_address] [amount] [flags]",
Use: "transfer [to_address] [amount] [flags]",
Short: "Make a confidential transfer to another address",
Long: `Transfer command create a confidential transfer of the specified amount of the specified denomination to the specified address.
passed in. To add auditors to the transaction, pass the --auditors flag with a comma separated list of auditor addresses.`,
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(2),
RunE: makeTransferCmd,
}

Expand Down Expand Up @@ -220,29 +214,23 @@ func makeTransferCmd(cmd *cobra.Command, args []string) error {
}

fromAddress := clientCtx.GetFromAddress().String()
denom := args[0]
err = sdk.ValidateDenom(denom)
if err != nil {
return fmt.Errorf("invalid denom: %v", err)
}

toAddress := args[1]
toAddress := args[0]
_, err = sdk.AccAddressFromBech32(toAddress)
if err != nil {
return fmt.Errorf("invalid address: %v", err)
}

amount, err := strconv.ParseUint(args[2], 10, 64)
coin, err := sdk.ParseCoinNormalized(args[1])
if err != nil {
return err
}

senderAccount, err := getAccount(queryClient, fromAddress, denom)
senderAccount, err := getAccount(queryClient, fromAddress, coin.Denom)
if err != nil {
return err
}

recipientAccount, err := getAccount(queryClient, toAddress, denom)
recipientAccount, err := getAccount(queryClient, toAddress, coin.Denom)
if err != nil {
return err
}
Expand All @@ -254,7 +242,7 @@ func makeTransferCmd(cmd *cobra.Command, args []string) error {

auditors := make([]types.AuditorInput, len(auditorAddrs))
for i, auditorAddr := range auditorAddrs {
auditorAccount, err := getAccount(queryClient, auditorAddr, denom)
auditorAccount, err := getAccount(queryClient, auditorAddr, coin.Denom)
if err != nil {
return err
}
Expand All @@ -268,10 +256,10 @@ func makeTransferCmd(cmd *cobra.Command, args []string) error {
privKey,
fromAddress,
toAddress,
denom,
coin.Denom,
senderAccount.DecryptableAvailableBalance,
senderAccount.AvailableBalance,
amount,
coin.Amount.Uint64(),
&recipientAccount.PublicKey,
auditors)

Expand All @@ -291,11 +279,11 @@ func makeTransferCmd(cmd *cobra.Command, args []string) error {
// NewWithdrawTxCmd returns a CLI command handler for creating a MsgWithdraw transaction.
func NewWithdrawTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw [denom] [amount] [flags]",
Use: "withdraw [amount] [flags]",
Short: "Withdraw from confidential transfers account",
Long: `Withdraws the specified amount from the confidential transfers account for the specified denomination and address
passed in --from flag.`,
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(1),
RunE: makeWithdrawCmd,
}

Expand Down Expand Up @@ -323,29 +311,23 @@ func makeWithdrawCmd(cmd *cobra.Command, args []string) error {
}
address := clientCtx.GetFromAddress().String()

denom := args[0]
err = sdk.ValidateDenom(denom)
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return fmt.Errorf("invalid denom: %v", err)
}

amount, isValid := new(big.Int).SetString(args[1], 10)
if !isValid {
return fmt.Errorf("invalid amount: %v", args[1])
return err
}

account, err := getAccount(queryClient, address, denom)
account, err := getAccount(queryClient, address, coin.Denom)
if err != nil {
return err
}

withdraw, err := types.NewWithdraw(
*privKey,
account.AvailableBalance,
denom,
coin.Denom,
address,
account.DecryptableAvailableBalance,
amount)
coin.Amount.BigInt())

if err != nil {
return err
Expand All @@ -363,11 +345,11 @@ func makeWithdrawCmd(cmd *cobra.Command, args []string) error {
// NewDepositTxCmd returns a CLI command handler for creating a MsgDeposit transaction.
func NewDepositTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit [denom] [amount] [flags]",
Use: "deposit [amount] [flags]",
Short: "Deposit funds into confidential transfers account",
Long: `Deposit the specified amount into the confidential transfers account for the specified denomination and address
passed in --from flag.`,
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(1),
RunE: makeDepositCmd,
}

Expand All @@ -383,21 +365,15 @@ func makeDepositCmd(cmd *cobra.Command, args []string) error {
}

address := clientCtx.GetFromAddress().String()
denom := args[0]
err = sdk.ValidateDenom(denom)
if err != nil {
return fmt.Errorf("invalid denom: %v", err)
}

amount, err := strconv.ParseUint(args[1], 10, 64)
coin, err := sdk.ParseCoinNormalized(args[0])
if err != nil {
return err
}

msg := &types.MsgDeposit{
FromAddress: address,
Denom: denom,
Amount: amount,
Denom: coin.Denom,
Amount: coin.Amount.Uint64(),
}

if err = msg.ValidateBasic(); err != nil {
Expand Down

0 comments on commit cb36ad7

Please sign in to comment.