almost done!
This commit is contained in:
committed by
Ethan Frey
parent
7a37b9b9a9
commit
23615c5d37
@@ -1,6 +1,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -11,6 +13,7 @@ import (
|
||||
"github.com/tendermint/basecoin/docs/guide/counter/plugins/counter"
|
||||
"github.com/tendermint/basecoin/modules/auth"
|
||||
"github.com/tendermint/basecoin/modules/coin"
|
||||
"github.com/tendermint/basecoin/modules/nonce"
|
||||
)
|
||||
|
||||
//CounterTxCmd is the CLI command to execute the counter
|
||||
@@ -55,6 +58,10 @@ func counterTx(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//get the nonce accounts
|
||||
var addr []byte
|
||||
nonceAccount := []basecoin.Actor{basecoin.NewActor(counter.NameCounter, addr)}
|
||||
|
||||
// TODO: make this more flexible for middleware
|
||||
tx, err = bcmd.WrapFeeTx(tx)
|
||||
if err != nil {
|
||||
@@ -65,6 +72,13 @@ func counterTx(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//add the nonce tx layer to the tx
|
||||
seq := viper.GetInt(FlagSequence)
|
||||
if seq < 0 {
|
||||
return fmt.Errorf("sequence must be greater than 0")
|
||||
}
|
||||
tx = nonce.NewTx(uint32(seq), nonceAccount, tx)
|
||||
|
||||
stx := auth.NewSig(tx)
|
||||
|
||||
// Sign if needed and post. This it the work-horse
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/tendermint/basecoin/modules/base"
|
||||
"github.com/tendermint/basecoin/modules/coin"
|
||||
"github.com/tendermint/basecoin/modules/fee"
|
||||
"github.com/tendermint/basecoin/modules/nonce"
|
||||
"github.com/tendermint/basecoin/stack"
|
||||
"github.com/tendermint/basecoin/state"
|
||||
)
|
||||
@@ -101,6 +102,7 @@ func NewHandler(feeDenom string) basecoin.Handler {
|
||||
base.Logger{},
|
||||
stack.Recovery{},
|
||||
auth.Signatures{},
|
||||
nonce.ReplayCheck{},
|
||||
base.Chain{},
|
||||
fee.NewSimpleFeeMiddleware(coin.Coin{feeDenom, 0}, fee.Bank),
|
||||
).Use(dispatcher)
|
||||
|
||||
@@ -7,10 +7,12 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/basecoin"
|
||||
"github.com/tendermint/basecoin/app"
|
||||
"github.com/tendermint/basecoin/modules/auth"
|
||||
"github.com/tendermint/basecoin/modules/base"
|
||||
"github.com/tendermint/basecoin/modules/coin"
|
||||
"github.com/tendermint/basecoin/modules/nonce"
|
||||
"github.com/tendermint/go-wire"
|
||||
eyescli "github.com/tendermint/merkleeyes/client"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
@@ -40,9 +42,10 @@ func TestCounterPlugin(t *testing.T) {
|
||||
require.Equal(t, "Success", log)
|
||||
|
||||
// Deliver a CounterTx
|
||||
DeliverCounterTx := func(valid bool, counterFee coin.Coins) abci.Result {
|
||||
DeliverCounterTx := func(valid bool, counterFee coin.Coins, sequence uint32) abci.Result {
|
||||
tx := NewTx(valid, counterFee)
|
||||
tx = base.NewChainTx(chainID, 0, tx)
|
||||
tx = nonce.NewTx(sequence, []basecoin.Actor{acct.Actor()}, tx)
|
||||
stx := auth.NewSig(tx)
|
||||
auth.Sign(stx, acct.Key)
|
||||
txBytes := wire.BinaryBytes(stx.Wrap())
|
||||
@@ -50,18 +53,18 @@ func TestCounterPlugin(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test a basic send, no fee
|
||||
res := DeliverCounterTx(true, nil)
|
||||
res := DeliverCounterTx(true, nil, 1)
|
||||
assert.True(res.IsOK(), res.String())
|
||||
|
||||
// Test an invalid send, no fee
|
||||
res = DeliverCounterTx(false, nil)
|
||||
res = DeliverCounterTx(false, nil, 2)
|
||||
assert.True(res.IsErr(), res.String())
|
||||
|
||||
// Test an invalid send, with supported fee
|
||||
res = DeliverCounterTx(true, coin.Coins{{"gold", 100}})
|
||||
res = DeliverCounterTx(true, coin.Coins{{"gold", 100}}, 2)
|
||||
assert.True(res.IsOK(), res.String())
|
||||
|
||||
// Test unsupported fee
|
||||
res = DeliverCounterTx(true, coin.Coins{{"silver", 100}})
|
||||
res = DeliverCounterTx(true, coin.Coins{{"silver", 100}}, 3)
|
||||
assert.True(res.IsErr(), res.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user