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

feat!: adding MinimumStake parameter #574

Merged
merged 8 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions execution/executor/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func (e *BondExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error {
if receiverVal.Stake()+pld.Stake > sb.Params().MaximumStake {
return errors.Errorf(errors.ErrInvalidTx,
"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.IncSequence()
Expand Down
8 changes: 8 additions & 0 deletions execution/executor/bond_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func TestExecuteBondTx(t *testing.T) {
assert.Error(t, exe.Execute(trx, td.sandbox), "Execute again, should fail")
})

t.Run("Should fail, amount less than MinimumStake", func(t *testing.T) {
trx := tx.NewBondTx(td.stamp500000, senderAcc.Sequence()+1, senderAddr,
receiverAddr, pub, 1000, fee, "less than MinimumStake")

err := exe.Execute(trx, td.sandbox)
assert.Equal(t, errors.Code(err), errors.ErrInvalidTx)
})

t.Run("Should fail, public key should not set for existing validators", func(t *testing.T) {
trx := tx.NewBondTx(td.stamp500000, senderAcc.Sequence()+2, senderAddr,
receiverAddr, pub, amt, fee, "with public key")
Expand Down
2 changes: 2 additions & 0 deletions types/param/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Params struct {
FeeFraction float64 `cbor:"9,keyasint"`
MinimumFee int64 `cbor:"10,keyasint"`
MaximumFee int64 `cbor:"11,keyasint"`
MinimumStake int64 `cobr:"12,keyasint"`
MaximumStake int64 `cbor:"12,keyasint"`
kehiy marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -30,6 +31,7 @@ func DefaultParams() Params {
FeeFraction: 0.0001,
MinimumFee: 1000,
MaximumFee: 1000000,
MinimumStake: 1000000000,
MaximumStake: 1000000000000,
}
}
Expand Down