transaction: there are no valid attributes defined for preview3

This commit is contained in:
Roman Khimov 2020-08-11 20:56:39 +03:00
parent b1034d8ed6
commit fb70c82157
6 changed files with 16 additions and 63 deletions

View file

@ -86,11 +86,6 @@ func getTX(t *testing.B, wif *keys.WIF) *transaction.Transaction {
Scopes: transaction.FeeOnly, Scopes: transaction.FeeOnly,
}, },
} }
tx.Attributes = append(tx.Attributes,
transaction.Attribute{
Usage: transaction.DescriptionURL,
Data: []byte(randString(10)),
})
return tx return tx
} }

View file

@ -303,13 +303,6 @@ func createVMAndTX(t *testing.T) (*vm.VM, *transaction.Transaction, *interop.Con
script := []byte{byte(opcode.PUSH1), byte(opcode.RET)} script := []byte{byte(opcode.PUSH1), byte(opcode.RET)}
tx := transaction.New(netmode.UnitTestNet, script, 0) 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}}} tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3, 4}}}
chain := newTestChain(t) chain := newTestChain(t)
context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet), nil, tx) context := chain.newInteropContext(trigger.Application, dao.NewSimple(storage.NewMemoryStore(), netmode.UnitTestNet), nil, tx)

View file

@ -68,28 +68,23 @@ func TestOverCapacity(t *testing.T) {
require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, mempoolSize, mp.Count())
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) 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. // Fees are also prioritized.
for i := 0; i < mempoolSize; i++ { for i := 0; i < mempoolSize; i++ {
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx := transaction.New(netmode.UnitTestNet, bigScript, 0)
tx.Attributes = append(tx.Attributes, transaction.Attribute{
Usage: transaction.DescriptionURL,
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
})
tx.NetworkFee = 10000 tx.NetworkFee = 10000
tx.Nonce = txcnt tx.Nonce = txcnt
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}
txcnt++ 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.NoError(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, mempoolSize, mp.Count())
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes))) require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
} }
// Less prioritized txes are not allowed anymore. // Less prioritized txes are not allowed anymore.
tx := transaction.New(netmode.UnitTestNet, []byte{byte(opcode.PUSH1)}, 0) tx := transaction.New(netmode.UnitTestNet, bigScript, 0)
tx.Attributes = append(tx.Attributes, transaction.Attribute{
Usage: transaction.DescriptionURL,
Data: util.Uint256{1, 2, 3, 4}.BytesBE(),
})
tx.NetworkFee = 100 tx.NetworkFee = 100
tx.Nonce = txcnt tx.Nonce = txcnt
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}
@ -104,7 +99,7 @@ func TestOverCapacity(t *testing.T) {
tx.NetworkFee = 7000 tx.NetworkFee = 7000
tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}} tx.Signers = []transaction.Signer{{Account: util.Uint160{1, 2, 3}}}
txcnt++ txcnt++
// size is 51 (no attributes), networkFee is 7000 (<10000) // size is ~51 (small script), networkFee is 7000 (<10000)
// => feePerByte is 137 (>119) // => feePerByte is 137 (>119)
require.NoError(t, mp.Add(tx, fs)) require.NoError(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, mempoolSize, mp.Count())

View file

@ -5,7 +5,6 @@ package transaction
// AttrUsage represents the purpose of the attribute. // AttrUsage represents the purpose of the attribute.
type AttrUsage uint8 type AttrUsage uint8
// List of valid attribute usages. // List of valid attribute usages (none for preview3).
const ( //const (
DescriptionURL AttrUsage = 0x81 //)
)

View file

@ -3,7 +3,6 @@ package transaction
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
@ -26,15 +25,14 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {
attr.Usage = AttrUsage(br.ReadB()) attr.Usage = AttrUsage(br.ReadB())
var datasize uint64 var datasize uint64
/**
switch attr.Usage { switch attr.Usage {
case DescriptionURL:
// It's not VarUint as per C# implementation, dunno why
var urllen = br.ReadB()
datasize = uint64(urllen)
default: default:
br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Usage)) br.Err = fmt.Errorf("failed decoding TX attribute usage: 0x%2x", int(attr.Usage))
return return
} }
*/
attr.Data = make([]byte, datasize) attr.Data = make([]byte, datasize)
br.ReadBytes(attr.Data) br.ReadBytes(attr.Data)
} }
@ -43,9 +41,6 @@ func (attr *Attribute) DecodeBinary(br *io.BinReader) {
func (attr *Attribute) EncodeBinary(bw *io.BinWriter) { func (attr *Attribute) EncodeBinary(bw *io.BinWriter) {
bw.WriteB(byte(attr.Usage)) bw.WriteB(byte(attr.Usage))
switch attr.Usage { switch attr.Usage {
case DescriptionURL:
bw.WriteB(byte(len(attr.Data)))
bw.WriteBytes(attr.Data)
default: default:
bw.Err = fmt.Errorf("failed encoding TX attribute usage: 0x%2x", attr.Usage) 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. // MarshalJSON implements the json Marshaller interface.
func (attr *Attribute) MarshalJSON() ([]byte, error) { func (attr *Attribute) MarshalJSON() ([]byte, error) {
return json.Marshal(attrJSON{ 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), Data: base64.StdEncoding.EncodeToString(attr.Data),
}) })
} }
@ -70,13 +65,13 @@ func (attr *Attribute) UnmarshalJSON(data []byte) error {
if err != nil { if err != nil {
return err return err
} }
/**
switch aj.Usage { switch aj.Usage {
case "DescriptionURL":
attr.Usage = DescriptionURL
default: default:
return errors.New("wrong Usage") return errors.New("wrong Usage")
} }
*/
attr.Data = binData attr.Data = binData
return nil return nil
} }

View file

@ -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]]
}