@ -6,11 +6,17 @@ import (
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/bls/ffi/go/bls"
blockfactory "github.com/harmony-one/harmony/block/factory"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/hash"
"github.com/harmony-one/harmony/crypto/hash"
chain2 "github.com/harmony-one/harmony/internal/chain"
common2 "github.com/harmony-one/harmony/internal/common"
common2 "github.com/harmony-one/harmony/internal/common"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/numeric"
"github.com/harmony-one/harmony/numeric"
"github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/shard"
staking "github.com/harmony-one/harmony/staking/types"
staking "github.com/harmony-one/harmony/staking/types"
@ -23,6 +29,25 @@ var (
twelveK = new ( big . Int ) . Mul ( big . NewInt ( 12000 ) , big . NewInt ( 1e18 ) )
twelveK = new ( big . Int ) . Mul ( big . NewInt ( 12000 ) , big . NewInt ( 1e18 ) )
)
)
func createChain ( database * ethdb . MemDatabase ) * BlockChain {
key , _ := crypto . GenerateKey ( )
gspec := Genesis {
Config : params . TestChainConfig ,
Factory : blockfactory . ForTest ,
Alloc : GenesisAlloc {
crypto . PubkeyToAddress ( key . PublicKey ) : {
Balance : big . NewInt ( 8e18 ) ,
} ,
} ,
GasLimit : 1e18 ,
ShardID : 0 ,
}
genesis := gspec . MustCommit ( database )
_ = genesis
chain , _ := NewBlockChain ( database , nil , gspec . Config , chain2 . Engine , vm . Config { } , nil )
return chain
}
func generateBLSKeySigPair ( ) ( shard . BLSPublicKey , shard . BLSSignature ) {
func generateBLSKeySigPair ( ) ( shard . BLSPublicKey , shard . BLSSignature ) {
p := & bls . PublicKey { }
p := & bls . PublicKey { }
p . DeserializeHexStr ( testBLSPubKey )
p . DeserializeHexStr ( testBLSPubKey )
@ -75,11 +100,13 @@ func createValidator() *staking.CreateValidator {
// Test CV1: create validator
// Test CV1: create validator
func TestCV1 ( t * testing . T ) {
func TestCV1 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -87,18 +114,20 @@ func TestCV1(t *testing.T) {
// Test CV3: validator already exists
// Test CV3: validator already exists
func TestCV3 ( t * testing . T ) {
func TestCV3 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
statedb . SetValidatorFlag ( msg . ValidatorAddress )
statedb . SetValidatorFlag ( msg . ValidatorAddress )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; ! strings . Contains ( err . Error ( ) , errValidatorExist . Error ( ) ) {
) ; ! strings . Contains ( err . Error ( ) , errValidatorExist . Error ( ) ) {
t . Error ( "expected" , errValidatorExist , "got" , err )
t . Error ( "expected" , errValidatorExist , "got" , err )
}
}
@ -106,13 +135,15 @@ func TestCV3(t *testing.T) {
// Test CV9: name == 140 characters
// Test CV9: name == 140 characters
func TestCV9 ( t * testing . T ) {
func TestCV9 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
// name length: 140 characters
// name length: 140 characters
msg . Name = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
msg . Name = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -120,13 +151,15 @@ func TestCV9(t *testing.T) {
// Test CV10: identity == 140 characters
// Test CV10: identity == 140 characters
func TestCV10 ( t * testing . T ) {
func TestCV10 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
// identity length: 140 characters
// identity length: 140 characters
msg . Identity = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
msg . Identity = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -134,13 +167,15 @@ func TestCV10(t *testing.T) {
// Test CV11: website == 140 characters
// Test CV11: website == 140 characters
func TestCV11 ( t * testing . T ) {
func TestCV11 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
// website length: 140 characters
// website length: 140 characters
msg . Website = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
msg . Website = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -148,13 +183,15 @@ func TestCV11(t *testing.T) {
// Test CV12: security == 140 characters
// Test CV12: security == 140 characters
func TestCV12 ( t * testing . T ) {
func TestCV12 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
// security contact length: 140 characters
// security contact length: 140 characters
msg . SecurityContact = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
msg . SecurityContact = "Helloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -162,13 +199,15 @@ func TestCV12(t *testing.T) {
// Test CV13: details == 280 characters
// Test CV13: details == 280 characters
func TestCV13 ( t * testing . T ) {
func TestCV13 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
// details length: 280 characters
// details length: 280 characters
msg . Details = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjoweHlloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuedbfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
msg . Details = "HelloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuebfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjoweHlloiwfhwifbwfbcerghveugbviuscbhwiefbcusidbcifwefhgciwefherhbfiwuehfciwiuedbfcuyiewfhwieufwiweifhcwefhwefhwidsffevjnononwondqmeofniowfndjowe"
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -176,14 +215,16 @@ func TestCV13(t *testing.T) {
// Test CV14: commission rate <= max rate & max change rate <= max rate
// Test CV14: commission rate <= max rate & max change rate <= max rate
func TestCV14 ( t * testing . T ) {
func TestCV14 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate == max rate && max change rate == max rate
// commission rate == max rate && max change rate == max rate
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0.5" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0.5" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0.5" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0.5" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -191,13 +232,15 @@ func TestCV14(t *testing.T) {
// Test CV15: commission rate > max rate
// Test CV15: commission rate > max rate
func TestCV15 ( t * testing . T ) {
func TestCV15 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate: 0.6 > max rate: 0.5
// commission rate: 0.6 > max rate: 0.5
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0.6" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0.6" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "commission rate and change rate can not be larger than max commission rate" , "got" , nil )
t . Error ( "expected" , "commission rate and change rate can not be larger than max commission rate" , "got" , nil )
}
}
@ -205,13 +248,15 @@ func TestCV15(t *testing.T) {
// Test CV16: max change rate > max rate
// Test CV16: max change rate > max rate
func TestCV16 ( t * testing . T ) {
func TestCV16 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max change rate: 0.6 > max rate: 0.5
// max change rate: 0.6 > max rate: 0.5
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0.6" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0.6" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "commission rate and change rate can not be larger than max commission rate" , "got" , nil )
t . Error ( "expected" , "commission rate and change rate can not be larger than max commission rate" , "got" , nil )
}
}
@ -219,13 +264,15 @@ func TestCV16(t *testing.T) {
// Test CV17: max rate == 1
// Test CV17: max rate == 1
func TestCV17 ( t * testing . T ) {
func TestCV17 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max rate == 1
// max rate == 1
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -233,7 +280,9 @@ func TestCV17(t *testing.T) {
// Test CV18: max rate == 1 && max change rate == 1 && commission rate == 0
// Test CV18: max rate == 1 && max change rate == 1 && commission rate == 0
func TestCV18 ( t * testing . T ) {
func TestCV18 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max rate == 1 && max change rate == 1 && commission rate == 0
// max rate == 1 && max change rate == 1 && commission rate == 0
@ -241,7 +290,7 @@ func TestCV18(t *testing.T) {
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "1" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -249,13 +298,15 @@ func TestCV18(t *testing.T) {
// Test CV19: commission rate == 0
// Test CV19: commission rate == 0
func TestCV19 ( t * testing . T ) {
func TestCV19 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate == 0
// commission rate == 0
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -263,13 +314,15 @@ func TestCV19(t *testing.T) {
// Test CV20: max change rate == 0
// Test CV20: max change rate == 0
func TestCV20 ( t * testing . T ) {
func TestCV20 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate == 0
// commission rate == 0
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -277,7 +330,9 @@ func TestCV20(t *testing.T) {
// Test CV21: max change rate == 0 & max rate == 0 & commission rate == 0
// Test CV21: max change rate == 0 & max rate == 0 & commission rate == 0
func TestCV21 ( t * testing . T ) {
func TestCV21 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max change rate == 0 & max rate == 0 & commission rate == 0
// max change rate == 0 & max rate == 0 & commission rate == 0
@ -285,7 +340,7 @@ func TestCV21(t *testing.T) {
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "0" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "0" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -293,14 +348,16 @@ func TestCV21(t *testing.T) {
// Test CV22: max change rate == 1 & max rate == 1
// Test CV22: max change rate == 1 & max rate == 1
func TestCV22 ( t * testing . T ) {
func TestCV22 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max change rate == 1 & max rate == 1
// max change rate == 1 & max rate == 1
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -308,13 +365,15 @@ func TestCV22(t *testing.T) {
// Test CV23: commission rate < 0
// Test CV23: commission rate < 0
func TestCV23 ( t * testing . T ) {
func TestCV23 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate < 0
// commission rate < 0
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "-0.1" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "-0.1" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:-0.100000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:-0.100000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -322,13 +381,15 @@ func TestCV23(t *testing.T) {
// Test CV24: max rate < 0
// Test CV24: max rate < 0
func TestCV24 ( t * testing . T ) {
func TestCV24 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max rate < 0
// max rate < 0
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "-0.001" )
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "-0.001" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:-0.001000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:-0.001000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -336,13 +397,15 @@ func TestCV24(t *testing.T) {
// Test CV25: max change rate < 0
// Test CV25: max change rate < 0
func TestCV25 ( t * testing . T ) {
func TestCV25 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max rate < 0
// max rate < 0
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "-0.001" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "-0.001" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:-0.001000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:-0.001000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -350,13 +413,15 @@ func TestCV25(t *testing.T) {
// Test CV26: commission rate > 1
// Test CV26: commission rate > 1
func TestCV26 ( t * testing . T ) {
func TestCV26 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// commission rate > 1
// commission rate > 1
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "1.01" )
msg . CommissionRates . Rate , _ = numeric . NewDecFromStr ( "1.01" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -364,13 +429,15 @@ func TestCV26(t *testing.T) {
// Test CV27: max rate > 1
// Test CV27: max rate > 1
func TestCV27 ( t * testing . T ) {
func TestCV27 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max rate > 1
// max rate > 1
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1.01" )
msg . CommissionRates . MaxRate , _ = numeric . NewDecFromStr ( "1.01" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -378,13 +445,15 @@ func TestCV27(t *testing.T) {
// Test CV28: max change rate > 1
// Test CV28: max change rate > 1
func TestCV28 ( t * testing . T ) {
func TestCV28 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// max change rate > 1
// max change rate > 1
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1.01" )
msg . CommissionRates . MaxChangeRate , _ = numeric . NewDecFromStr ( "1.01" )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
t . Error ( "expected" , "rate:1.01000000000000000: commission rate, change rate and max rate should be within 0-100 percent" , "got" , nil )
}
}
@ -392,14 +461,16 @@ func TestCV28(t *testing.T) {
// Test CV29: amount > MinSelfDelegation
// Test CV29: amount > MinSelfDelegation
func TestCV29 ( t * testing . T ) {
func TestCV29 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , twelveK )
statedb . AddBalance ( msg . ValidatorAddress , twelveK )
// amount > MinSelfDelegation
// amount > MinSelfDelegation
msg . Amount = twelveK
msg . Amount = twelveK
msg . MinSelfDelegation = tenK
msg . MinSelfDelegation = tenK
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -407,14 +478,16 @@ func TestCV29(t *testing.T) {
// Test CV30: amount == MinSelfDelegation
// Test CV30: amount == MinSelfDelegation
func TestCV30 ( t * testing . T ) {
func TestCV30 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// amount > MinSelfDelegation
// amount > MinSelfDelegation
msg . Amount = tenK
msg . Amount = tenK
msg . MinSelfDelegation = tenK
msg . MinSelfDelegation = tenK
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err != nil {
) ; err != nil {
t . Error ( "expected" , nil , "got" , err )
t . Error ( "expected" , nil , "got" , err )
}
}
@ -422,14 +495,16 @@ func TestCV30(t *testing.T) {
// Test CV31: amount < MinSelfDelegation
// Test CV31: amount < MinSelfDelegation
func TestCV31 ( t * testing . T ) {
func TestCV31 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// amount > MinSelfDelegation
// amount > MinSelfDelegation
msg . Amount = twelveK
msg . Amount = twelveK
msg . MinSelfDelegation = tenK
msg . MinSelfDelegation = tenK
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "min_self_delegation 5000000000000000000, after delegation amount 4000000000000000000: self delegation can not be less than min_self_delegation" , "got" , nil )
t . Error ( "expected" , "min_self_delegation 5000000000000000000, after delegation amount 4000000000000000000: self delegation can not be less than min_self_delegation" , "got" , nil )
}
}
@ -437,14 +512,16 @@ func TestCV31(t *testing.T) {
// Test CV32: MaxTotalDelegation < MinSelfDelegation
// Test CV32: MaxTotalDelegation < MinSelfDelegation
func TestCV32 ( t * testing . T ) {
func TestCV32 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// MaxTotalDelegation < MinSelfDelegation
// MaxTotalDelegation < MinSelfDelegation
msg . MaxTotalDelegation = tenK
msg . MaxTotalDelegation = tenK
msg . MinSelfDelegation = twelveK
msg . MinSelfDelegation = twelveK
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "max_total_delegation can not be less than min_self_delegation" , "got" , nil )
t . Error ( "expected" , "max_total_delegation can not be less than min_self_delegation" , "got" , nil )
}
}
@ -452,13 +529,15 @@ func TestCV32(t *testing.T) {
// Test CV33: MinSelfDelegation < 1 ONE
// Test CV33: MinSelfDelegation < 1 ONE
func TestCV33 ( t * testing . T ) {
func TestCV33 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// MinSelfDelegation < 10,000 ONE
// MinSelfDelegation < 10,000 ONE
msg . MinSelfDelegation = big . NewInt ( 1e18 )
msg . MinSelfDelegation = big . NewInt ( 1e18 )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "delegation-given 1000000000000000000: min_self_delegation has to be greater than 10,000 ONE" , "got" , nil )
t . Error ( "expected" , "delegation-given 1000000000000000000: min_self_delegation has to be greater than 10,000 ONE" , "got" , nil )
}
}
@ -466,13 +545,15 @@ func TestCV33(t *testing.T) {
// Test CV34: MinSelfDelegation not specified
// Test CV34: MinSelfDelegation not specified
func TestCV34 ( t * testing . T ) {
func TestCV34 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// MinSelfDelegation not specified
// MinSelfDelegation not specified
msg . MinSelfDelegation = nil
msg . MinSelfDelegation = nil
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "MinSelfDelegation can not be nil" , "got" , nil )
t . Error ( "expected" , "MinSelfDelegation can not be nil" , "got" , nil )
}
}
@ -480,13 +561,15 @@ func TestCV34(t *testing.T) {
// Test CV35: MinSelfDelegation < 0
// Test CV35: MinSelfDelegation < 0
func TestCV35 ( t * testing . T ) {
func TestCV35 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// MinSelfDelegation < 0
// MinSelfDelegation < 0
msg . MinSelfDelegation = big . NewInt ( - 1 )
msg . MinSelfDelegation = big . NewInt ( - 1 )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "delegation-given -1: min_self_delegation has to be greater than 1 ONE" , "got" , nil )
t . Error ( "expected" , "delegation-given -1: min_self_delegation has to be greater than 1 ONE" , "got" , nil )
}
}
@ -494,14 +577,16 @@ func TestCV35(t *testing.T) {
// Test CV36: amount > MaxTotalDelegation
// Test CV36: amount > MaxTotalDelegation
func TestCV36 ( t * testing . T ) {
func TestCV36 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// amount > MaxTotalDelegation
// amount > MaxTotalDelegation
msg . Amount = big . NewInt ( 4e18 )
msg . Amount = big . NewInt ( 4e18 )
msg . MaxTotalDelegation = big . NewInt ( 3e18 )
msg . MaxTotalDelegation = big . NewInt ( 3e18 )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "total delegation can not be bigger than max_total_delegation" , "got" , nil )
t . Error ( "expected" , "total delegation can not be bigger than max_total_delegation" , "got" , nil )
}
}
@ -509,13 +594,15 @@ func TestCV36(t *testing.T) {
// Test CV39: MaxTotalDelegation < 0
// Test CV39: MaxTotalDelegation < 0
func TestCV39 ( t * testing . T ) {
func TestCV39 ( t * testing . T ) {
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( ethdb . NewMemDatabase ( ) ) )
database := ethdb . NewMemDatabase ( )
statedb , _ := state . New ( common . Hash { } , state . NewDatabase ( database ) )
chain := createChain ( database )
msg := createValidator ( )
msg := createValidator ( )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
statedb . AddBalance ( msg . ValidatorAddress , tenK )
// MaxTotalDelegation < 0
// MaxTotalDelegation < 0
msg . MaxTotalDelegation = big . NewInt ( - 1 )
msg . MaxTotalDelegation = big . NewInt ( - 1 )
if _ , err := VerifyAndCreateValidatorFromMsg (
if _ , err := VerifyAndCreateValidatorFromMsg (
statedb , postStakingEpoch , big . NewInt ( 0 ) , msg ,
statedb , chain , postStakingEpoch , big . NewInt ( 0 ) , msg ,
) ; err == nil {
) ; err == nil {
t . Error ( "expected" , "max_total_delegation can not be less than min_self_delegation" , "got" , nil )
t . Error ( "expected" , "max_total_delegation can not be less than min_self_delegation" , "got" , nil )
}
}