From 8d0ed9259cd5fb9d94b0334ef56b93e3a3d5a7cd Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 23 Oct 2019 11:49:43 +0300 Subject: [PATCH] transaction: fix invocation TX consistency in NewInvocationTX() NewInvocationTX() returned a version number one transaction that actually failed to pass that version down to the invocation data which lead to serialization/deserialization inconsistency. --- pkg/core/transaction/invocation.go | 3 ++- pkg/core/transaction/transaction_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/core/transaction/invocation.go b/pkg/core/transaction/invocation.go index 2ac3550e0..a0d82cb58 100644 --- a/pkg/core/transaction/invocation.go +++ b/pkg/core/transaction/invocation.go @@ -22,7 +22,8 @@ func NewInvocationTX(script []byte) *Transaction { Type: InvocationType, Version: 1, Data: &InvocationTX{ - Script: script, + Script: script, + Version: 1, }, Attributes: []*Attribute{}, Inputs: []*Input{}, diff --git a/pkg/core/transaction/transaction_test.go b/pkg/core/transaction/transaction_test.go index 2c416c570..4d5ef35ac 100644 --- a/pkg/core/transaction/transaction_test.go +++ b/pkg/core/transaction/transaction_test.go @@ -96,6 +96,25 @@ func TestDecodeEncodeInvocationTX(t *testing.T) { assert.Equal(t, rawInvocationTX, hex.EncodeToString(buf.Bytes())) } +func TestNewInvocationTX(t *testing.T) { + script := []byte{0x51} + tx := NewInvocationTX(script) + txData := tx.Data.(*InvocationTX) + assert.Equal(t, InvocationType, tx.Type) + assert.Equal(t, tx.Version, txData.Version) + assert.Equal(t, script, txData.Script) + buf := io.NewBufBinWriter() + // Update hash fields to match tx2 that is gonna autoupdate them on decode. + _ = tx.Hash() + tx.EncodeBinary(buf.BinWriter) + assert.Nil(t, buf.Err) + var tx2 Transaction + r := io.NewBinReaderFromBuf(buf.Bytes()) + tx2.DecodeBinary(r) + assert.Nil(t, r.Err) + assert.Equal(t, *tx, tx2) +} + func TestDecodePublishTX(t *testing.T) { expectedTXData := &PublishTX{} expectedTXData.Name = "Lock"