mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-30 15:01:35 +00:00
9abda40171
Frequently one needs to check if struct serializes/deserializes properly. This commit implements helpers for such cases including: 1. JSON 2. io.Serializable interface
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package state
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidatorState_DecodeEncodeBinary(t *testing.T) {
|
|
state := &Validator{
|
|
PublicKey: &keys.PublicKey{},
|
|
Registered: false,
|
|
Votes: util.Fixed8(10),
|
|
}
|
|
|
|
testserdes.EncodeDecodeBinary(t, state, new(Validator))
|
|
}
|
|
|
|
func TestRegisteredAndHasVotes_Registered(t *testing.T) {
|
|
state := &Validator{
|
|
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) {
|
|
state := &Validator{
|
|
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) {
|
|
state := &Validator{
|
|
PublicKey: &keys.PublicKey{
|
|
X: big.NewInt(1),
|
|
Y: big.NewInt(1),
|
|
},
|
|
Registered: false,
|
|
Votes: 1,
|
|
}
|
|
require.False(t, state.RegisteredAndHasVotes())
|
|
}
|