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.
This commit is contained in:
Roman Khimov 2019-10-23 11:49:43 +03:00
parent 3fcf0922ea
commit 8d0ed9259c
2 changed files with 21 additions and 1 deletions

View file

@ -22,7 +22,8 @@ func NewInvocationTX(script []byte) *Transaction {
Type: InvocationType, Type: InvocationType,
Version: 1, Version: 1,
Data: &InvocationTX{ Data: &InvocationTX{
Script: script, Script: script,
Version: 1,
}, },
Attributes: []*Attribute{}, Attributes: []*Attribute{},
Inputs: []*Input{}, Inputs: []*Input{},

View file

@ -96,6 +96,25 @@ func TestDecodeEncodeInvocationTX(t *testing.T) {
assert.Equal(t, rawInvocationTX, hex.EncodeToString(buf.Bytes())) 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) { func TestDecodePublishTX(t *testing.T) {
expectedTXData := &PublishTX{} expectedTXData := &PublishTX{}
expectedTXData.Name = "Lock" expectedTXData.Name = "Lock"