From fb70c82157e5e1274fc26d714f4c06900a215b01 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 11 Aug 2020 20:56:39 +0300 Subject: [PATCH] transaction: there are no valid attributes defined for preview3 --- integration/performance_test.go | 5 ----- pkg/core/interop_neo_test.go | 7 ------- pkg/core/mempool/mem_pool_test.go | 19 +++++++------------ pkg/core/transaction/attr_usage.go | 7 +++---- pkg/core/transaction/attribute.go | 17 ++++++----------- pkg/core/transaction/attrusage_string.go | 24 ------------------------ 6 files changed, 16 insertions(+), 63 deletions(-) delete mode 100644 pkg/core/transaction/attrusage_string.go diff --git a/integration/performance_test.go b/integration/performance_test.go index dccf1748d..c2d9b5f6d 100644 --- a/integration/performance_test.go +++ b/integration/performance_test.go @@ -86,11 +86,6 @@ func getTX(t *testing.B, wif *keys.WIF) *transaction.Transaction { Scopes: transaction.FeeOnly, }, } - tx.Attributes = append(tx.Attributes, - transaction.Attribute{ - Usage: transaction.DescriptionURL, - Data: []byte(randString(10)), - }) return tx } diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index 582101c9c..a36b89edc 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -303,13 +303,6 @@ func createVMAndTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interop.Con script := []byte{byte(opcode.PUSH1), byte(opcode.RET)} tx := transaction.New(netmode.UnitTestNet, script, 0) - bytes := make([]byte, 1) - attributes := append(tx.Attributes, transaction.Attribute{ - Usage: transaction.DescriptionURL, - Data: bytes, - }) - - tx.Attributes = attributes tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3, 4}}} chain := newTestChain(t) context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet), nil, tx) diff --git a/pkg/core/mempool/mem_pool_test.go b/pkg/core/mempool/mem_pool_test.go index 8ba90e62c..ad404dcd7 100644 --- a/pkg/core/mempool/mem_pool_test.go +++ b/pkg/core/mempool/mem_pool_test.go @@ -68,28 +68,23 @@ func TestOverCapacity(t *testing.T) { require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) + bigScript := make([]byte, 64) + bigScript[0] = byte(opcode.PUSH1) + bigScript[1] = byte(opcode.RET) // Fees are also prioritized. for i := 0; i < mempoolSize; i++ { - tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx.Attributes = append(tx.Attributes, transaction.Attribute{ - Usage: transaction.DescriptionURL, - Data: util.Uint256{1, 2, 3, 4}.BytesBE(), - }) + tx := transaction.New(netmode.UnitTestNet, bigScript, 0) tx.NetworkFee = 10000 tx.Nonce = txcnt tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} txcnt++ - // size is 84, networkFee is 10000 => feePerByte is 119 + // size is ~90, networkFee is 10000 => feePerByte is 119 require.NoError(t, mp.Add(tx, fs)) require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) } // Less prioritized txes are not allowed anymore. - tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) - tx.Attributes = append(tx.Attributes, transaction.Attribute{ - Usage: transaction.DescriptionURL, - Data: util.Uint256{1, 2, 3, 4}.BytesBE(), - }) + tx := transaction.New(netmode.UnitTestNet, bigScript, 0) tx.NetworkFee = 100 tx.Nonce = txcnt tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} @@ -104,7 +99,7 @@ func TestOverCapacity(t *testing.T) { tx.NetworkFee = 7000 tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} txcnt++ - // size is 51 (no attributes), networkFee is 7000 (<10000) + // size is ~51 (small script), networkFee is 7000 (<10000) // => feePerByte is 137 (>119) require.NoError(t, mp.Add(tx, fs)) require.Equal(t, mempoolSize, mp.Count()) diff --git a/pkg/core/transaction/attr_usage.go b/pkg/core/transaction/attr_usage.go index b8a2faf8f..ab9a5f6da 100644 --- a/pkg/core/transaction/attr_usage.go +++ b/pkg/core/transaction/attr_usage.go @@ -5,7 +5,6 @@ package transaction // AttrUsage represents the purpose of the attribute. type AttrUsage uint8 -// List of valid attribute usages. -const ( - DescriptionURL AttrUsage = 0x81 -) +// List of valid attribute usages (none for preview3). +//const ( +//) diff --git a/pkg/core/transaction/attribute.go b/pkg/core/transaction/attribute.go index 6e3f9bf76..d0ef1d3c6 100644 --- a/pkg/core/transaction/attribute.go +++ b/pkg/core/transaction/attribute.go @@ -3,7 +3,6 @@ package transaction import ( "encoding/base64" "encoding/json" - "errors" "fmt" "github.com/nspcc-dev/neo-go/pkg/io" @@ -26,15 +25,14 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) { attr.Usage = AttrUsage(br.ReadB()) var datasize uint64 + /** + switch attr.Usage { - case DescriptionURL: - // It's not VarUint as per C# implementation, dunno why - var urllen = br.ReadB() - datasize = uint64(urllen) default: br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Usage)) return } + */ attr.Data = make([]byte, datasize) br.ReadBytes(attr.Data) } @@ -43,9 +41,6 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) { func (attr *Attribute) EncodeBinary(bw *io.BinWriter) { bw.WriteB(byte(attr.Usage)) switch attr.Usage { - case DescriptionURL: - bw.WriteB(byte(len(attr.Data))) - bw.WriteBytes(attr.Data) default: bw.Err = fmt.Errorf("failed encoding TX attribute usage: 0x%2x", attr.Usage) } @@ -54,7 +49,7 @@ func (attr *Attribute) EncodeBinary(bw *io.BinWriter) { // MarshalJSON implements the json Marshaller interface. func (attr *Attribute) MarshalJSON() ([]byte, error) { return json.Marshal(attrJSON{ - Usage: attr.Usage.String(), + Usage: "", // attr.Usage.String() when we're to have some real attributes Data: base64.StdEncoding.EncodeToString(attr.Data), }) } @@ -70,13 +65,13 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error { if err != nil { return err } + /** switch aj.Usage { - case "DescriptionURL": - attr.Usage = DescriptionURL default: return errors.New("wrong Usage") } + */ attr.Data = binData return nil } diff --git a/pkg/core/transaction/attrusage_string.go b/pkg/core/transaction/attrusage_string.go deleted file mode 100644 index 6e8ebac8f..000000000 --- a/pkg/core/transaction/attrusage_string.go +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated by "stringer -type=AttrUsage"; DO NOT EDIT. - -package transaction - -import "strconv" - -func _() { - // An "invalid array index" compiler error signifies that the constant values have changed. - // Re-run the stringer command to generate them again. - var x [1]struct{} - _ = x[DescriptionURL-129] -} - -const _AttrUsage_name = "DescriptionURL" - -var _AttrUsage_index = [...]uint8{0, 14} - -func (i AttrUsage) String() string { - i -= 129 - if i >= AttrUsage(len(_AttrUsage_index)-1) { - return "AttrUsage(" + strconv.FormatInt(int64(i+129), 10) + ")" - } - return _AttrUsage_name[_AttrUsage_index[i]:_AttrUsage_index[i+1]] -}