2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-11-25 17:39:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-03-26 14:43:24 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2019-11-25 17:39:11 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidatorState_DecodeEncodeBinary(t *testing.T) {
|
2019-11-28 16:06:09 +00:00
|
|
|
state := &Validator{
|
2019-11-25 17:39:11 +00:00
|
|
|
PublicKey: &keys.PublicKey{},
|
|
|
|
Registered: false,
|
|
|
|
Votes: util.Fixed8(10),
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:43:24 +00:00
|
|
|
testserdes.EncodeDecodeBinary(t, state, new(Validator))
|
2019-11-25 17:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisteredAndHasVotes_Registered(t *testing.T) {
|
2019-11-28 16:06:09 +00:00
|
|
|
state := &Validator{
|
2019-11-25 17:39:11 +00:00
|
|
|
PublicKey: &keys.PublicKey{
|
|
|
|
X: big.NewInt(1),
|
|
|
|
Y: big.NewInt(1),
|
|
|
|
},
|
|
|
|
Registered: true,
|
|
|
|
Votes: 0,
|
|
|
|
}
|
|
|
|
require.False(t, state.RegisteredAndHasVotes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisteredAndHasVotes_RegisteredWithVotes(t *testing.T) {
|
2019-11-28 16:06:09 +00:00
|
|
|
state := &Validator{
|
2019-11-25 17:39:11 +00:00
|
|
|
PublicKey: &keys.PublicKey{
|
|
|
|
X: big.NewInt(1),
|
|
|
|
Y: big.NewInt(1),
|
|
|
|
},
|
|
|
|
Registered: true,
|
|
|
|
Votes: 1,
|
|
|
|
}
|
|
|
|
require.True(t, state.RegisteredAndHasVotes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRegisteredAndHasVotes_NotRegisteredWithVotes(t *testing.T) {
|
2019-11-28 16:06:09 +00:00
|
|
|
state := &Validator{
|
2019-11-25 17:39:11 +00:00
|
|
|
PublicKey: &keys.PublicKey{
|
|
|
|
X: big.NewInt(1),
|
|
|
|
Y: big.NewInt(1),
|
|
|
|
},
|
|
|
|
Registered: false,
|
|
|
|
Votes: 1,
|
|
|
|
}
|
|
|
|
require.False(t, state.RegisteredAndHasVotes())
|
|
|
|
}
|