Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplicated account check and test #4068

Merged
merged 7 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant account check on `gaiacli`
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ func TestGaiaCLISend(t *testing.T) {
success, _, _ := f.TxSend(keyFoo, barAddr, sdk.NewCoin(denom, sendTokens), "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxSend(
fooAddr.String(), barAddr, sdk.NewCoin(denom, sendTokens), "--generate-only=true",
)
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

// Check state didn't change
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(sendTokens), fooAcc.GetCoins().AmountOf(denom))
Expand Down
11 changes: 0 additions & 11 deletions x/bank/client/cli/sendtx.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
Expand Down Expand Up @@ -47,15 +45,6 @@ func SendTxCmd(cdc *codec.Codec) *cobra.Command {
}

from := cliCtx.GetFromAddress()
account, err := cliCtx.GetAccount(from)
if err != nil {
return err
}

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(coins) {
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

// build and sign the transaction, then broadcast to Tendermint
msg := bank.NewMsgSend(from, to, coins)
Expand Down
25 changes: 2 additions & 23 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,15 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
WithCodec(cdc).
WithAccountDecoder(cdc)

// Get from address
// Get proposer address
from := cliCtx.GetFromAddress()

// Pull associated account
account, err := cliCtx.GetAccount(from)
if err != nil {
return err
}

// Find deposit amount
amount, err := sdk.ParseCoins(proposal.Deposit)
if err != nil {
return err
}

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(amount) {
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

proposalType, err := gov.ProposalTypeFromString(proposal.Type)
if err != nil {
return err
Expand Down Expand Up @@ -152,25 +141,15 @@ $ gaiacli tx gov deposit 1 10stake --from mykey
return fmt.Errorf("Failed to fetch proposal-id %d: %s", proposalID, err)
}

// Get depositor address
from := cliCtx.GetFromAddress()

// Fetch associated account
account, err := cliCtx.GetAccount(from)
if err != nil {
return err
}

// Get amount of coins
amount, err := sdk.ParseCoins(args[1])
if err != nil {
return err
}

// ensure account has enough coins
if !account.GetCoins().IsAllGTE(amount) {
return fmt.Errorf("address %s doesn't have enough coins to pay for this transaction", from)
}

msg := gov.NewMsgDeposit(from, proposalID, amount)
err = msg.ValidateBasic()
if err != nil {
Expand Down