2019-11-28 16:06:09 +00:00
|
|
|
package state
|
2019-11-25 17:39:11 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
"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),
|
|
|
|
}
|
|
|
|
buf := io.NewBufBinWriter()
|
|
|
|
state.EncodeBinary(buf.BinWriter)
|
|
|
|
require.NoError(t, buf.Err)
|
|
|
|
|
2019-11-28 16:06:09 +00:00
|
|
|
decodedState := &Validator{}
|
2019-11-25 17:39:11 +00:00
|
|
|
reader := io.NewBinReaderFromBuf(buf.Bytes())
|
|
|
|
decodedState.DecodeBinary(reader)
|
|
|
|
require.NoError(t, reader.Err)
|
|
|
|
require.Equal(t, state, decodedState)
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
}
|