diff --git a/execution/executor/bond.go b/execution/executor/bond.go index 4cbd2a609..d4c090fc5 100644 --- a/execution/executor/bond.go +++ b/execution/executor/bond.go @@ -30,6 +30,10 @@ func (e *BondExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error { return errors.Errorf(errors.ErrInvalidPublicKey, "public key is not set") } + if pld.Stake < sb.Params().MinimumStake { + return errors.Errorf(errors.ErrInvalidTx, + "validator's stake can't be less than %v", sb.Params().MinimumStake) + } receiverVal = sb.MakeNewValidator(pld.PublicKey) } else if pld.PublicKey != nil { return errors.Errorf(errors.ErrInvalidPublicKey, @@ -64,9 +68,6 @@ func (e *BondExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error { if receiverVal.Stake()+pld.Stake > sb.Params().MaximumStake { return errors.Errorf(errors.ErrInvalidAmount, "validator's stake can't be more than %v", sb.Params().MaximumStake) - } else if pld.Stake < sb.Params().MinimumStake { - return errors.Errorf(errors.ErrInvalidTx, - "validator's stake can't be less than %v", sb.Params().MinimumStake) } senderAcc.SubtractFromBalance(pld.Stake + trx.Fee()) diff --git a/execution/executor/bond_test.go b/execution/executor/bond_test.go index b40aa0dfd..a3e68717c 100644 --- a/execution/executor/bond_test.go +++ b/execution/executor/bond_test.go @@ -191,3 +191,19 @@ func TestPowerDeltaBond(t *testing.T) { assert.Equal(t, int64(amt), td.sandbox.PowerDelta()) } + +func TestSmallBond(t *testing.T) { + td := setup(t) + exe := NewBondExecutor(false) + + senderAddr, _ := td.sandbox.TestStore.RandomTestAcc() + receiverVal := td.sandbox.TestStore.RandomTestVal() + receiverAddr := receiverVal.Address() + fee := td.sandbox.Params().MaximumFee + lockTime := td.sandbox.CurrentHeight() + trx := tx.NewBondTx(lockTime, senderAddr, + receiverAddr, nil, 1, fee, "ok") + + err := exe.Execute(trx, td.sandbox) + assert.NoError(t, err, "Ok") +}