Fix up all tests to handle NewChainTx change
This commit is contained in:
parent
af9ce5b553
commit
100d88d7dd
|
@ -44,7 +44,7 @@ func (at *appTest) getTx(seq int, coins coin.Coins) basecoin.Tx {
|
|||
in := []coin.TxInput{{Address: at.acctIn.Actor(), Coins: coins, Sequence: seq}}
|
||||
out := []coin.TxOutput{{Address: at.acctOut.Actor(), Coins: coins}}
|
||||
tx := coin.NewSendTx(in, out)
|
||||
tx = base.NewChainTx(at.chainID, tx)
|
||||
tx = base.NewChainTx(at.chainID, 0, tx)
|
||||
stx := auth.NewMulti(tx)
|
||||
auth.Sign(stx, at.acctIn.Key)
|
||||
return stx.Wrap()
|
||||
|
|
|
@ -34,6 +34,7 @@ const (
|
|||
FlagAmount = "amount"
|
||||
FlagFee = "fee"
|
||||
FlagGas = "gas"
|
||||
FlagExpires = "expires"
|
||||
FlagSequence = "sequence"
|
||||
)
|
||||
|
||||
|
@ -42,7 +43,8 @@ func init() {
|
|||
flags.String(FlagTo, "", "Destination address for the bits")
|
||||
flags.String(FlagAmount, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
|
||||
flags.String(FlagFee, "0mycoin", "Coins for the transaction fee of the format <amt><coin>")
|
||||
flags.Int64(FlagGas, 0, "Amount of gas for this transaction")
|
||||
flags.Uint64(FlagGas, 0, "Amount of gas for this transaction")
|
||||
flags.Int64(FlagExpires, 0, "Block height at which this tx expires")
|
||||
flags.Int(FlagSequence, -1, "Sequence number for this transaction")
|
||||
}
|
||||
|
||||
|
@ -63,7 +65,12 @@ func doSendTx(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// TODO: make this more flexible for middleware
|
||||
// add the chain info
|
||||
tx = base.NewChainTx(commands.GetChainID(), tx)
|
||||
tx, err = WrapChainTx(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Note: this is single sig (no multi sig yet)
|
||||
stx := auth.NewSig(tx)
|
||||
|
||||
// Sign if needed and post. This it the work-horse
|
||||
|
@ -76,6 +83,16 @@ func doSendTx(cmd *cobra.Command, args []string) error {
|
|||
return txcmd.OutputTx(bres)
|
||||
}
|
||||
|
||||
// WrapChainTx will wrap the tx with a ChainTx from the standard flags
|
||||
func WrapChainTx(tx basecoin.Tx) (res basecoin.Tx, err error) {
|
||||
expires := viper.GetInt64(FlagExpires)
|
||||
if expires < 0 {
|
||||
return res, errors.New("expires must be >= 0")
|
||||
}
|
||||
res = base.NewChainTx(commands.GetChainID(), uint64(expires), tx)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func readSendTxFlags() (tx basecoin.Tx, err error) {
|
||||
// parse to address
|
||||
chain, to, err := parseChainAddress(viper.GetString(FlagTo))
|
||||
|
|
|
@ -4,13 +4,12 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/tendermint/basecoin"
|
||||
"github.com/tendermint/light-client/commands"
|
||||
txcmd "github.com/tendermint/light-client/commands/txs"
|
||||
|
||||
"github.com/tendermint/basecoin"
|
||||
bcmd "github.com/tendermint/basecoin/cmd/basecli/commands"
|
||||
"github.com/tendermint/basecoin/docs/guide/counter/plugins/counter"
|
||||
"github.com/tendermint/basecoin/modules/auth"
|
||||
"github.com/tendermint/basecoin/modules/base"
|
||||
"github.com/tendermint/basecoin/modules/coin"
|
||||
)
|
||||
|
||||
|
@ -57,7 +56,10 @@ func counterTx(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// TODO: make this more flexible for middleware
|
||||
// add the chain info
|
||||
tx = base.NewChainTx(commands.GetChainID(), tx)
|
||||
tx, err = bcmd.WrapChainTx(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stx := auth.NewSig(tx)
|
||||
|
||||
// Sign if needed and post. This it the work-horse
|
||||
|
|
|
@ -42,7 +42,7 @@ func TestCounterPlugin(t *testing.T) {
|
|||
// Deliver a CounterTx
|
||||
DeliverCounterTx := func(valid bool, counterFee coin.Coins, inputSequence int) abci.Result {
|
||||
tx := NewTx(valid, counterFee, inputSequence)
|
||||
tx = base.NewChainTx(chainID, tx)
|
||||
tx = base.NewChainTx(chainID, 0, tx)
|
||||
stx := auth.NewSig(tx)
|
||||
auth.Sign(stx, acct.Key)
|
||||
txBytes := wire.BinaryBytes(stx.Wrap())
|
||||
|
|
|
@ -44,10 +44,19 @@ func (c Chain) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.
|
|||
|
||||
// checkChain makes sure the tx is a Chain Tx and is on the proper chain
|
||||
func (c Chain) checkChain(chainID string, tx basecoin.Tx) (basecoin.Tx, error) {
|
||||
// make sure it is a chaintx
|
||||
ctx, ok := tx.Unwrap().(ChainTx)
|
||||
if !ok {
|
||||
return tx, errors.ErrNoChain()
|
||||
}
|
||||
|
||||
// basic validation
|
||||
err := ctx.ValidateBasic()
|
||||
if err != nil {
|
||||
return tx, err
|
||||
}
|
||||
|
||||
// compare against state
|
||||
if ctx.ChainID != chainID {
|
||||
return tx, errors.ErrWrongChain(ctx.ChainID)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue