Fee handler set by default, tested app level

This commit is contained in:
Ethan Frey
2017-07-12 20:38:54 +02:00
parent 454227393b
commit 36a453ea41
7 changed files with 47 additions and 12 deletions
+3 -1
View File
@@ -14,6 +14,7 @@ import (
"github.com/tendermint/basecoin/modules/auth"
"github.com/tendermint/basecoin/modules/base"
"github.com/tendermint/basecoin/modules/coin"
"github.com/tendermint/basecoin/modules/fee"
"github.com/tendermint/basecoin/stack"
sm "github.com/tendermint/basecoin/state"
"github.com/tendermint/basecoin/version"
@@ -52,7 +53,7 @@ func NewBasecoin(handler basecoin.Handler, eyesCli *eyes.Client, logger log.Logg
}
// DefaultHandler - placeholder to just handle sendtx
func DefaultHandler() basecoin.Handler {
func DefaultHandler(feeDenom string) basecoin.Handler {
// use the default stack
h := coin.NewHandler()
d := stack.NewDispatcher(stack.WrapHandler(h))
@@ -61,6 +62,7 @@ func DefaultHandler() basecoin.Handler {
stack.Recovery{},
auth.Signatures{},
base.Chain{},
fee.NewSimpleFeeMiddleware(coin.Coin{feeDenom, 0}, fee.Bank),
).Use(d)
}
+33 -5
View File
@@ -13,6 +13,7 @@ import (
"github.com/tendermint/basecoin/modules/auth"
"github.com/tendermint/basecoin/modules/base"
"github.com/tendermint/basecoin/modules/coin"
"github.com/tendermint/basecoin/modules/fee"
"github.com/tendermint/basecoin/stack"
"github.com/tendermint/basecoin/state"
wire "github.com/tendermint/go-wire"
@@ -40,17 +41,33 @@ func newAppTest(t *testing.T) *appTest {
return at
}
// make a tx sending 5mycoin from each acctIn to acctOut
func (at *appTest) getTx(coins coin.Coins) basecoin.Tx {
// baseTx is the
func (at *appTest) baseTx(coins coin.Coins) basecoin.Tx {
in := []coin.TxInput{{Address: at.acctIn.Actor(), Coins: coins}}
out := []coin.TxOutput{{Address: at.acctOut.Actor(), Coins: coins}}
tx := coin.NewSendTx(in, out)
tx = base.NewChainTx(at.chainID, 0, tx)
return tx
}
func (at *appTest) signTx(tx basecoin.Tx) basecoin.Tx {
stx := auth.NewMulti(tx)
auth.Sign(stx, at.acctIn.Key)
return stx.Wrap()
}
func (at *appTest) getTx(coins coin.Coins) basecoin.Tx {
tx := at.baseTx(coins)
tx = base.NewChainTx(at.chainID, 0, tx)
return at.signTx(tx)
}
func (at *appTest) feeTx(coins coin.Coins, toll coin.Coin) basecoin.Tx {
tx := at.baseTx(coins)
tx = fee.NewFee(tx, toll, at.acctIn.Actor())
tx = base.NewChainTx(at.chainID, 0, tx)
return at.signTx(tx)
}
// set the account on the app through SetOption
func (at *appTest) initAccount(acct *coin.AccountWithKey) {
res := at.app.SetOption("coin/account", acct.MakeOption())
@@ -67,7 +84,7 @@ func (at *appTest) reset() {
logger := log.NewTMLogger(os.Stdout).With("module", "app")
logger = log.NewTracingLogger(logger)
at.app = NewBasecoin(
DefaultHandler(),
DefaultHandler("mycoin"),
eyesCli,
logger,
)
@@ -124,7 +141,7 @@ func TestSetOption(t *testing.T) {
eyesCli := eyes.NewLocalClient("", 0)
app := NewBasecoin(
DefaultHandler(),
DefaultHandler("atom"),
eyesCli,
log.TestingLogger().With("module", "app"),
)
@@ -212,6 +229,17 @@ func TestTx(t *testing.T) {
assert.True(res.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", res)
assert.Equal(amt.Negative(), diffIn)
assert.Equal(amt, diffOut)
//DeliverTx with fee.... 4 get to recipient, 1 extra taxed
at.reset()
amt = coin.Coins{{"mycoin", 4}}
toll := coin.Coin{"mycoin", 1}
res, diffIn, diffOut = at.exec(t, at.feeTx(amt, toll), false)
assert.True(res.IsOK(), "ExecTx/Good DeliverTx: Expected OK return from ExecTx, Error: %v", res)
payment := amt.Plus(coin.Coins{toll}).Negative()
assert.Equal(payment, diffIn)
assert.Equal(amt, diffOut)
}
func TestQuery(t *testing.T) {
+3 -3
View File
@@ -18,7 +18,7 @@ const genesisAcctFilepath = "./testdata/genesis2.json"
func TestLoadGenesisDoNotFailIfAppOptionsAreMissing(t *testing.T) {
eyesCli := eyescli.NewLocalClient("", 0)
app := NewBasecoin(DefaultHandler(), eyesCli, log.TestingLogger())
app := NewBasecoin(DefaultHandler("mycoin"), eyesCli, log.TestingLogger())
err := app.LoadGenesis("./testdata/genesis3.json")
require.Nil(t, err, "%+v", err)
}
@@ -27,7 +27,7 @@ func TestLoadGenesis(t *testing.T) {
assert, require := assert.New(t), require.New(t)
eyesCli := eyescli.NewLocalClient("", 0)
app := NewBasecoin(DefaultHandler(), eyesCli, log.TestingLogger())
app := NewBasecoin(DefaultHandler("mycoin"), eyesCli, log.TestingLogger())
err := app.LoadGenesis(genesisFilepath)
require.Nil(err, "%+v", err)
@@ -56,7 +56,7 @@ func TestLoadGenesisAccountAddress(t *testing.T) {
assert, require := assert.New(t), require.New(t)
eyesCli := eyescli.NewLocalClient("", 0)
app := NewBasecoin(DefaultHandler(), eyesCli, log.TestingLogger())
app := NewBasecoin(DefaultHandler("mycoin"), eyesCli, log.TestingLogger())
err := app.LoadGenesis(genesisAcctFilepath)
require.Nil(err, "%+v", err)