Skip to content

Commit

Permalink
remove duplicated account check and test (cosmos#4068)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedekunze authored and alessio committed Apr 10, 2019
1 parent 02a0e39 commit eb51a6f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4068 Remove redundant account check on `gaiacli`
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 @@ -224,6 +224,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

0 comments on commit eb51a6f

Please sign in to comment.