From 7b76f30251f5b3053b57a0f72674436e3e045ebe Mon Sep 17 00:00:00 2001 From: mantre Date: Fri, 8 Mar 2024 02:07:07 +0800 Subject: [PATCH] fix!: accept small bond to existing validator --- execution/executor/bond.go | 7 ++++--- execution/executor/bond_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/execution/executor/bond.go b/execution/executor/bond.go index 62e9cef68..9c9edac89 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 392baa073..647e91421 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, 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") +}