mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-27 15:42:54 +00:00
consensus: assume non-nil message in decodeData
`nil` message is occuring only in tests to check that no unnecessary decoding is done on errors.
This commit is contained in:
parent
445354012a
commit
3025b42c65
3 changed files with 4 additions and 8 deletions
|
@ -340,7 +340,7 @@ func (t messageType) String() string {
|
|||
|
||||
// decode data of payload into it's message
|
||||
func (p *Payload) decodeData() error {
|
||||
m := new(message)
|
||||
m := p.message
|
||||
br := io.NewBinReaderFromBuf(p.data)
|
||||
m.DecodeBinary(br)
|
||||
if br.Err != nil {
|
||||
|
|
|
@ -102,6 +102,7 @@ func TestConsensusPayload_Serializable(t *testing.T) {
|
|||
require.NoError(t, testserdes.DecodeBinary(data, actual))
|
||||
// message is nil after decoding as we didn't yet call decodeData
|
||||
require.Nil(t, actual.message)
|
||||
actual.message = new(message)
|
||||
// message should now be decoded from actual.data byte array
|
||||
assert.NoError(t, actual.decodeData())
|
||||
assert.NotNil(t, actual.MarshalUnsigned())
|
||||
|
@ -152,7 +153,7 @@ func TestConsensusPayload_DecodeBinaryInvalid(t *testing.T) {
|
|||
buf[delimeterIndex] = 1
|
||||
buf[lenIndex] = 34
|
||||
buf[typeIndex] = byte(prepareResponseType)
|
||||
p := new(Payload)
|
||||
p := &Payload{message: new(message)}
|
||||
require.NoError(t, testserdes.DecodeBinary(buf, p))
|
||||
// decode `data` into `message`
|
||||
_ = p.Hash()
|
||||
|
@ -161,7 +162,7 @@ func TestConsensusPayload_DecodeBinaryInvalid(t *testing.T) {
|
|||
|
||||
// invalid type
|
||||
buf[typeIndex] = 0xFF
|
||||
actual := new(Payload)
|
||||
actual := &Payload{message: new(message)}
|
||||
require.NoError(t, testserdes.DecodeBinary(buf, actual))
|
||||
require.Error(t, actual.decodeData())
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
|
|||
|
||||
r := &recoveryMessage{}
|
||||
p := NewPayload(netmode.UnitTestNet)
|
||||
p.message = &message{}
|
||||
p.SetType(payload.RecoveryMessageType)
|
||||
p.SetPayload(r)
|
||||
// sign payload to have verification script
|
||||
|
@ -35,7 +34,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
|
|||
transactionHashes: []util.Uint256{{1}},
|
||||
}
|
||||
p1 := NewPayload(netmode.UnitTestNet)
|
||||
p1.message = &message{}
|
||||
p1.SetType(payload.PrepareRequestType)
|
||||
p1.SetPayload(req)
|
||||
p1.SetValidatorIndex(0)
|
||||
|
@ -43,7 +41,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
|
|||
|
||||
t.Run("prepare response is added", func(t *testing.T) {
|
||||
p2 := NewPayload(netmode.UnitTestNet)
|
||||
p2.message = &message{}
|
||||
p2.SetType(payload.PrepareResponseType)
|
||||
p2.SetPayload(&prepareResponse{
|
||||
preparationHash: p1.Hash(),
|
||||
|
@ -80,7 +77,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
|
|||
|
||||
t.Run("change view is added", func(t *testing.T) {
|
||||
p3 := NewPayload(netmode.UnitTestNet)
|
||||
p3.message = &message{}
|
||||
p3.SetType(payload.ChangeViewType)
|
||||
p3.SetPayload(&changeView{
|
||||
newViewNumber: 1,
|
||||
|
@ -103,7 +99,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
|
|||
|
||||
t.Run("commit is added", func(t *testing.T) {
|
||||
p4 := NewPayload(netmode.UnitTestNet)
|
||||
p4.message = &message{}
|
||||
p4.SetType(payload.CommitType)
|
||||
p4.SetPayload(randomMessage(t, commitType))
|
||||
p4.SetValidatorIndex(3)
|
||||
|
|
Loading…
Reference in a new issue