Skip to content

Commit

Permalink
do not allow a minimal fee to not have a ticker
Browse files Browse the repository at this point in the history
resolve #369
  • Loading branch information
husio committed Mar 7, 2019
1 parent 6c73a6c commit 11f33fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions x/cash/staticfee.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ func (d FeeDecorator) extractFee(ctx weave.Context, tx weave.Tx, store weave.KVS
}

cmp := gconf.Coin(store, GconfMinimalFee)
// minimum has no currency -> accept everything
if cmp.IsZero() {
return finfo, nil
}
if cmp.Ticker == "" {
cmp.Ticker = fee.Ticker
return nil, errors.Wrap(coin.ErrInvalidCurrency, "no ticker")
}

if !fee.SameType(cmp) {
return nil, coin.ErrInvalidCurrency.Newf("%s vs fee %s", cmp.Ticker, fee.Ticker)

Expand Down
9 changes: 8 additions & 1 deletion x/cash/staticfee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ func TestFees(t *testing.T) {
min: min,
expect: errors.ErrUnauthorized.Is,
},
"can pay in any fee": {
"fee without an empty ticker is not accepted": {
signers: []weave.Condition{perm},
initState: []orm.Object{must(WalletWith(perm.Address(), &cash))},
fee: &FeeInfo{Fees: &min},
min: coin.NewCoin(0, 1000, ""),
expect: coin.ErrInvalidCurrency.Is,
},
"no fee (zero value) is acceptable": {
signers: []weave.Condition{perm},
initState: []orm.Object{must(WalletWith(perm.Address(), &cash))},
fee: &FeeInfo{Fees: coin.NewCoinp(0, 1, "FOO")},
min: coin.NewCoin(0, 0, ""),
expect: noErr,
},
"wrong currency checked": {
Expand Down

0 comments on commit 11f33fb

Please sign in to comment.