Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: accept small bond to existing validator #1152

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions execution/executor/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down
16 changes: 16 additions & 0 deletions execution/executor/bond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading