Cleaned up fees and errors a bit from feedback
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package fee
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
e := ErrInsufficientFees()
|
||||
assert.True(IsInsufficientFeesErr(e))
|
||||
assert.False(IsWrongFeeDenomErr(e))
|
||||
|
||||
e2 := ErrWrongFeeDenom("atom")
|
||||
assert.False(IsInsufficientFeesErr(e2))
|
||||
assert.True(IsWrongFeeDenomErr(e2))
|
||||
}
|
||||
@@ -5,11 +5,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
abci "github.com/tendermint/abci/types"
|
||||
|
||||
"github.com/tendermint/basecoin/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
errInsufficientFees = fmt.Errorf("Insufficient Fees")
|
||||
errWrongFeeDenom = fmt.Errorf("Required fee denomination")
|
||||
)
|
||||
|
||||
func ErrInsufficientFees() errors.TMError {
|
||||
@@ -18,3 +20,10 @@ func ErrInsufficientFees() errors.TMError {
|
||||
func IsInsufficientFeesErr(err error) bool {
|
||||
return errors.IsSameError(errInsufficientFees, err)
|
||||
}
|
||||
|
||||
func ErrWrongFeeDenom(denom string) errors.TMError {
|
||||
return errors.WithMessage(denom, errWrongFeeDenom, abci.CodeType_BaseInvalidInput)
|
||||
}
|
||||
func IsWrongFeeDenomErr(err error) bool {
|
||||
return errors.IsSameError(errWrongFeeDenom, err)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@ var Bank = basecoin.Actor{App: NameFee, Address: []byte("bank")}
|
||||
// SimpleFeeMiddleware - middleware for fee checking, constant amount
|
||||
// It used modules.coin to move the money
|
||||
type SimpleFeeMiddleware struct {
|
||||
MinFee coin.Coin //
|
||||
// the fee must be the same denomination and >= this amount
|
||||
// if the amount is 0, then the fee tx wrapper is optional
|
||||
MinFee coin.Coin
|
||||
// all fees go here, which could be a dump (Bank) or something reachable
|
||||
// by other app logic
|
||||
Collector basecoin.Actor
|
||||
stack.PassOption
|
||||
}
|
||||
@@ -60,8 +64,11 @@ func (h SimpleFeeMiddleware) doTx(ctx basecoin.Context, store state.KVStore, tx
|
||||
return res, errors.ErrInvalidFormat(TypeFees, tx)
|
||||
}
|
||||
|
||||
// see if it is big enough...
|
||||
// see if it is the proper denom and big enough
|
||||
fee := feeTx.Fee
|
||||
if fee.Denom != h.MinFee.Denom {
|
||||
return res, ErrWrongFeeDenom(h.MinFee.Denom)
|
||||
}
|
||||
if !fee.IsGTE(h.MinFee) {
|
||||
return res, ErrInsufficientFees()
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
|
||||
"github.com/tendermint/basecoin"
|
||||
"github.com/tendermint/basecoin/modules/coin"
|
||||
"github.com/tendermint/basecoin/modules/fee"
|
||||
"github.com/tendermint/basecoin/stack"
|
||||
"github.com/tendermint/basecoin/state"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
func TestFeeChecks(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user