2018-06-26 19:00:12 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-09-13 11:17:32 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-07-03 21:21:36 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-09-10 15:37:03 -07:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-07-03 21:21:36 -07:00
|
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
2018-06-26 19:00:12 -07:00
|
|
|
)
|
|
|
|
|
2019-02-07 17:41:23 -08:00
|
|
|
func TestValidatorTestEquivalent(t *testing.T) {
|
2018-07-03 21:21:36 -07:00
|
|
|
val1 := NewValidator(addr1, pk1, Description{})
|
|
|
|
val2 := NewValidator(addr1, pk1, Description{})
|
|
|
|
|
2019-02-07 17:41:23 -08:00
|
|
|
ok := val1.TestEquivalent(val2)
|
2018-07-03 21:21:36 -07:00
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
val2 = NewValidator(addr2, pk2, Description{})
|
|
|
|
|
2019-02-07 17:41:23 -08:00
|
|
|
ok = val1.TestEquivalent(val2)
|
2018-07-03 21:21:36 -07:00
|
|
|
require.False(t, ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateDescription(t *testing.T) {
|
|
|
|
d1 := Description{
|
2018-07-25 16:05:43 -07:00
|
|
|
Website: "https://validator.cosmos",
|
|
|
|
Details: "Test validator",
|
|
|
|
}
|
|
|
|
|
|
|
|
d2 := Description{
|
2018-07-26 10:49:58 -07:00
|
|
|
Moniker: DoNotModifyDesc,
|
|
|
|
Identity: DoNotModifyDesc,
|
|
|
|
Website: DoNotModifyDesc,
|
|
|
|
Details: DoNotModifyDesc,
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
2018-07-25 16:05:43 -07:00
|
|
|
|
|
|
|
d3 := Description{
|
|
|
|
Moniker: "",
|
|
|
|
Identity: "",
|
|
|
|
Website: "",
|
|
|
|
Details: "",
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
d, err := d1.UpdateDescription(d2)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.Equal(t, d, d1)
|
2018-07-25 16:05:43 -07:00
|
|
|
|
|
|
|
d, err = d1.UpdateDescription(d3)
|
|
|
|
require.Nil(t, err)
|
|
|
|
require.Equal(t, d, d3)
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
|
|
|
|
2018-10-03 08:48:23 -07:00
|
|
|
func TestABCIValidatorUpdate(t *testing.T) {
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
2018-07-03 21:21:36 -07:00
|
|
|
|
2018-10-03 08:48:23 -07:00
|
|
|
abciVal := validator.ABCIValidatorUpdate()
|
2018-09-08 01:44:58 -07:00
|
|
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, validator.BondedTokens().Int64(), abciVal.Power)
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
|
|
|
|
2018-10-03 08:48:23 -07:00
|
|
|
func TestABCIValidatorUpdateZero(t *testing.T) {
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
2018-07-03 21:21:36 -07:00
|
|
|
|
2018-10-03 08:48:23 -07:00
|
|
|
abciVal := validator.ABCIValidatorUpdateZero()
|
2018-09-08 01:44:58 -07:00
|
|
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
2018-07-03 21:21:36 -07:00
|
|
|
require.Equal(t, int64(0), abciVal.Power)
|
|
|
|
}
|
|
|
|
|
2019-03-06 10:54:12 -08:00
|
|
|
func TestShareTokens(t *testing.T) {
|
|
|
|
validator := Validator{
|
|
|
|
OperatorAddress: addr1,
|
|
|
|
ConsPubKey: pk1,
|
|
|
|
Status: sdk.Bonded,
|
|
|
|
Tokens: sdk.NewInt(100),
|
|
|
|
DelegatorShares: sdk.NewDec(100),
|
|
|
|
}
|
2019-03-25 14:13:02 -07:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(50), validator.TokensFromShares(sdk.NewDec(50))))
|
2019-03-06 10:54:12 -08:00
|
|
|
|
|
|
|
validator.Tokens = sdk.NewInt(50)
|
2019-03-25 14:13:02 -07:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(25), validator.TokensFromShares(sdk.NewDec(50))))
|
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(5), validator.TokensFromShares(sdk.NewDec(10))))
|
2019-03-06 10:54:12 -08:00
|
|
|
}
|
|
|
|
|
2018-07-13 13:46:14 -07:00
|
|
|
func TestRemoveTokens(t *testing.T) {
|
2018-07-03 21:21:36 -07:00
|
|
|
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := Validator{
|
2019-02-25 07:16:52 -08:00
|
|
|
OperatorAddress: addr1,
|
2018-09-08 01:44:58 -07:00
|
|
|
ConsPubKey: pk1,
|
2018-07-13 13:46:14 -07:00
|
|
|
Status: sdk.Bonded,
|
2019-01-02 12:29:47 -08:00
|
|
|
Tokens: sdk.NewInt(100),
|
2018-08-14 17:15:02 -07:00
|
|
|
DelegatorShares: sdk.NewDec(100),
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
|
|
|
|
2018-07-13 13:46:14 -07:00
|
|
|
pool := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
pool.NotBondedTokens = sdk.NewInt(10)
|
2018-07-13 13:46:14 -07:00
|
|
|
pool.BondedTokens = validator.BondedTokens()
|
|
|
|
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Bonded)
|
|
|
|
require.Equal(t, sdk.Bonded, validator.Status)
|
|
|
|
|
|
|
|
// remove tokens and test check everything
|
2019-01-02 12:29:47 -08:00
|
|
|
validator, pool = validator.RemoveTokens(pool, sdk.NewInt(10))
|
|
|
|
require.Equal(t, int64(90), validator.Tokens.Int64())
|
|
|
|
require.Equal(t, int64(90), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(20), pool.NotBondedTokens.Int64())
|
2018-07-13 13:46:14 -07:00
|
|
|
|
|
|
|
// update validator to unbonded and remove some more tokens
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Unbonded)
|
|
|
|
require.Equal(t, sdk.Unbonded, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, int64(0), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(110), pool.NotBondedTokens.Int64())
|
2018-07-13 13:46:14 -07:00
|
|
|
|
2019-01-02 12:29:47 -08:00
|
|
|
validator, pool = validator.RemoveTokens(pool, sdk.NewInt(10))
|
|
|
|
require.Equal(t, int64(80), validator.Tokens.Int64())
|
|
|
|
require.Equal(t, int64(0), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(110), pool.NotBondedTokens.Int64())
|
2018-07-03 21:21:36 -07:00
|
|
|
}
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
func TestAddTokensValidatorBonded(t *testing.T) {
|
|
|
|
pool := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
pool.NotBondedTokens = sdk.NewInt(10)
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Bonded)
|
2018-08-27 15:18:18 -07:00
|
|
|
validator, pool, delShares := validator.AddTokensFromDel(pool, sdk.NewInt(10))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-14 17:15:02 -07:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
2019-01-02 12:29:47 -08:00
|
|
|
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.BondedTokens()))
|
2019-03-06 10:54:12 -08:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddTokensValidatorUnbonding(t *testing.T) {
|
|
|
|
pool := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
pool.NotBondedTokens = sdk.NewInt(10)
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Unbonding)
|
2018-08-27 15:18:18 -07:00
|
|
|
validator, pool, delShares := validator.AddTokensFromDel(pool, sdk.NewInt(10))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-14 17:15:02 -07:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
2018-07-13 13:46:14 -07:00
|
|
|
assert.Equal(t, sdk.Unbonding, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
2019-03-06 10:54:12 -08:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddTokensValidatorUnbonded(t *testing.T) {
|
|
|
|
pool := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
pool.NotBondedTokens = sdk.NewInt(10)
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Unbonded)
|
2018-08-27 15:18:18 -07:00
|
|
|
validator, pool, delShares := validator.AddTokensFromDel(pool, sdk.NewInt(10))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2018-08-14 17:15:02 -07:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), delShares))
|
2018-07-13 13:46:14 -07:00
|
|
|
assert.Equal(t, sdk.Unbonded, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
assert.True(sdk.IntEq(t, sdk.NewInt(10), validator.Tokens))
|
2019-03-06 10:54:12 -08:00
|
|
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO refactor to make simpler like the AddToken tests above
|
|
|
|
func TestRemoveDelShares(t *testing.T) {
|
|
|
|
valA := Validator{
|
2019-02-25 07:16:52 -08:00
|
|
|
OperatorAddress: addr1,
|
2018-09-08 01:44:58 -07:00
|
|
|
ConsPubKey: pk1,
|
2018-07-13 13:46:14 -07:00
|
|
|
Status: sdk.Bonded,
|
2019-01-02 12:29:47 -08:00
|
|
|
Tokens: sdk.NewInt(100),
|
2018-08-14 17:15:02 -07:00
|
|
|
DelegatorShares: sdk.NewDec(100),
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
2018-07-13 13:46:14 -07:00
|
|
|
poolA := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
poolA.NotBondedTokens = sdk.NewInt(10)
|
2018-07-13 13:46:14 -07:00
|
|
|
poolA.BondedTokens = valA.BondedTokens()
|
|
|
|
|
|
|
|
// Remove delegator shares
|
2018-08-14 17:15:02 -07:00
|
|
|
valB, poolB, coinsB := valA.RemoveDelShares(poolA, sdk.NewDec(10))
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, int64(10), coinsB.Int64())
|
|
|
|
require.Equal(t, int64(90), valB.DelegatorShares.RoundInt64())
|
|
|
|
require.Equal(t, int64(90), valB.BondedTokens().Int64())
|
|
|
|
require.Equal(t, int64(90), poolB.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(20), poolB.NotBondedTokens.Int64())
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
// conservation of tokens
|
2019-01-02 12:29:47 -08:00
|
|
|
require.True(sdk.IntEq(t,
|
2019-01-21 16:52:03 -08:00
|
|
|
poolB.NotBondedTokens.Add(poolB.BondedTokens),
|
|
|
|
poolA.NotBondedTokens.Add(poolA.BondedTokens)))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
// specific case from random tests
|
2019-01-02 12:29:47 -08:00
|
|
|
poolTokens := sdk.NewInt(5102)
|
2018-08-14 17:15:02 -07:00
|
|
|
delShares := sdk.NewDec(115)
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := Validator{
|
2019-02-25 07:16:52 -08:00
|
|
|
OperatorAddress: addr1,
|
2018-09-08 01:44:58 -07:00
|
|
|
ConsPubKey: pk1,
|
2018-07-13 13:46:14 -07:00
|
|
|
Status: sdk.Bonded,
|
|
|
|
Tokens: poolTokens,
|
2018-06-26 19:00:12 -07:00
|
|
|
DelegatorShares: delShares,
|
|
|
|
}
|
|
|
|
pool := Pool{
|
2019-01-23 03:37:03 -08:00
|
|
|
BondedTokens: sdk.NewInt(248305),
|
|
|
|
NotBondedTokens: sdk.NewInt(232147),
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
2018-08-14 17:15:02 -07:00
|
|
|
shares := sdk.NewDec(29)
|
2018-07-13 13:46:14 -07:00
|
|
|
_, newPool, tokens := validator.RemoveDelShares(pool, shares)
|
2018-08-14 17:15:02 -07:00
|
|
|
|
2019-01-02 12:29:47 -08:00
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(1286), tokens))
|
2018-08-14 17:15:02 -07:00
|
|
|
|
2019-01-02 12:29:47 -08:00
|
|
|
require.True(sdk.IntEq(t,
|
2019-01-21 16:52:03 -08:00
|
|
|
newPool.NotBondedTokens.Add(newPool.BondedTokens),
|
|
|
|
pool.NotBondedTokens.Add(pool.BondedTokens)))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2019-03-06 10:54:12 -08:00
|
|
|
func TestAddTokensFromDel(t *testing.T) {
|
|
|
|
val := NewValidator(addr1, pk1, Description{})
|
|
|
|
pool := InitialPool()
|
|
|
|
pool.NotBondedTokens = sdk.NewInt(10)
|
|
|
|
|
|
|
|
val, pool, shares := val.AddTokensFromDel(pool, sdk.NewInt(6))
|
|
|
|
require.True(sdk.DecEq(t, sdk.NewDec(6), shares))
|
|
|
|
require.True(sdk.DecEq(t, sdk.NewDec(6), val.DelegatorShares))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(6), val.Tokens))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(0), pool.BondedTokens))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(10), pool.NotBondedTokens))
|
|
|
|
|
|
|
|
val, pool, shares = val.AddTokensFromDel(pool, sdk.NewInt(3))
|
|
|
|
require.True(sdk.DecEq(t, sdk.NewDec(3), shares))
|
|
|
|
require.True(sdk.DecEq(t, sdk.NewDec(9), val.DelegatorShares))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(9), val.Tokens))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(0), pool.BondedTokens))
|
|
|
|
require.True(sdk.IntEq(t, sdk.NewInt(10), pool.NotBondedTokens))
|
|
|
|
}
|
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
func TestUpdateStatus(t *testing.T) {
|
|
|
|
pool := InitialPool()
|
2019-01-21 16:52:03 -08:00
|
|
|
pool.NotBondedTokens = sdk.NewInt(100)
|
2018-07-13 13:46:14 -07:00
|
|
|
|
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
2018-08-27 15:18:18 -07:00
|
|
|
validator, pool, _ = validator.AddTokensFromDel(pool, sdk.NewInt(100))
|
2018-07-13 13:46:14 -07:00
|
|
|
require.Equal(t, sdk.Unbonded, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, int64(100), validator.Tokens.Int64())
|
|
|
|
require.Equal(t, int64(0), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(100), pool.NotBondedTokens.Int64())
|
2018-07-13 13:46:14 -07:00
|
|
|
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Bonded)
|
|
|
|
require.Equal(t, sdk.Bonded, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, int64(100), validator.Tokens.Int64())
|
|
|
|
require.Equal(t, int64(100), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(0), pool.NotBondedTokens.Int64())
|
2018-07-13 13:46:14 -07:00
|
|
|
|
|
|
|
validator, pool = validator.UpdateStatus(pool, sdk.Unbonding)
|
|
|
|
require.Equal(t, sdk.Unbonding, validator.Status)
|
2019-01-02 12:29:47 -08:00
|
|
|
require.Equal(t, int64(100), validator.Tokens.Int64())
|
|
|
|
require.Equal(t, int64(0), pool.BondedTokens.Int64())
|
2019-01-21 16:52:03 -08:00
|
|
|
require.Equal(t, int64(100), pool.NotBondedTokens.Int64())
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPossibleOverflow(t *testing.T) {
|
2019-01-02 12:29:47 -08:00
|
|
|
poolTokens := sdk.NewInt(2159)
|
2018-08-14 17:15:02 -07:00
|
|
|
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
|
2018-07-13 13:46:14 -07:00
|
|
|
validator := Validator{
|
2019-02-25 07:16:52 -08:00
|
|
|
OperatorAddress: addr1,
|
2018-09-08 01:44:58 -07:00
|
|
|
ConsPubKey: pk1,
|
2018-07-13 13:46:14 -07:00
|
|
|
Status: sdk.Bonded,
|
|
|
|
Tokens: poolTokens,
|
2018-06-26 19:00:12 -07:00
|
|
|
DelegatorShares: delShares,
|
|
|
|
}
|
|
|
|
pool := Pool{
|
2019-01-23 03:37:03 -08:00
|
|
|
NotBondedTokens: sdk.NewInt(100),
|
|
|
|
BondedTokens: poolTokens,
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
tokens := int64(71)
|
2018-08-27 15:18:18 -07:00
|
|
|
newValidator, _, _ := validator.AddTokensFromDel(pool, sdk.NewInt(tokens))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2019-03-06 10:54:12 -08:00
|
|
|
require.False(t, newValidator.DelegatorShares.IsNegative())
|
|
|
|
require.False(t, newValidator.Tokens.IsNegative())
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
|
|
|
|
2018-09-10 15:37:03 -07:00
|
|
|
func TestValidatorMarshalUnmarshalJSON(t *testing.T) {
|
|
|
|
validator := NewValidator(addr1, pk1, Description{})
|
2018-09-13 11:17:32 -07:00
|
|
|
js, err := codec.Cdc.MarshalJSON(validator)
|
2018-09-10 15:37:03 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, js)
|
|
|
|
require.Contains(t, string(js), "\"consensus_pubkey\":\"cosmosvalconspu")
|
|
|
|
got := &Validator{}
|
2018-09-13 11:17:32 -07:00
|
|
|
err = codec.Cdc.UnmarshalJSON(js, got)
|
2018-09-10 15:37:03 -07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, validator, *got)
|
|
|
|
}
|
2018-09-24 15:23:58 -07:00
|
|
|
|
|
|
|
func TestValidatorSetInitialCommission(t *testing.T) {
|
|
|
|
val := NewValidator(addr1, pk1, Description{})
|
|
|
|
testCases := []struct {
|
|
|
|
validator Validator
|
|
|
|
commission Commission
|
|
|
|
expectedErr bool
|
|
|
|
}{
|
|
|
|
{val, NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), false},
|
|
|
|
{val, NewCommission(sdk.ZeroDec(), sdk.NewDecWithPrec(-1, 1), sdk.ZeroDec()), true},
|
|
|
|
{val, NewCommission(sdk.ZeroDec(), sdk.NewDec(15000000000), sdk.ZeroDec()), true},
|
|
|
|
{val, NewCommission(sdk.NewDecWithPrec(-1, 1), sdk.ZeroDec(), sdk.ZeroDec()), true},
|
|
|
|
{val, NewCommission(sdk.NewDecWithPrec(2, 1), sdk.NewDecWithPrec(1, 1), sdk.ZeroDec()), true},
|
|
|
|
{val, NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.NewDecWithPrec(-1, 1)), true},
|
|
|
|
{val, NewCommission(sdk.ZeroDec(), sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(2, 1)), true},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range testCases {
|
|
|
|
val, err := tc.validator.SetInitialCommission(tc.commission)
|
|
|
|
|
|
|
|
if tc.expectedErr {
|
|
|
|
require.Error(t, err,
|
|
|
|
"expected error for test case #%d with commission: %s", i, tc.commission,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err,
|
|
|
|
"unexpected error for test case #%d with commission: %s", i, tc.commission,
|
|
|
|
)
|
|
|
|
require.Equal(t, tc.commission, val.Commission,
|
|
|
|
"invalid validator commission for test case #%d with commission: %s", i, tc.commission,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|