mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 23:25:22 +00:00
transaction: there are no valid attributes defined for preview3
This commit is contained in:
parent
b1034d8ed6
commit
fb70c82157
6 changed files with 16 additions and 63 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 (
|
||||
//)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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]]
|
||||
}
|
Loading…
Reference in a new issue