Merge pull request #844 from nspcc-dev/neo3/nonce

core: add nonce field to transaction
This commit is contained in:
Roman Khimov 2020-04-14 16:24:02 +03:00 committed by GitHub
commit 1e3c36433f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 372 additions and 344 deletions

View file

@ -263,10 +263,7 @@ func claimGas(ctx *cli.Context) error {
}) })
} }
tx := &transaction.Transaction{ tx := transaction.NewClaimTX(&claim)
Type: transaction.ClaimType,
Data: &claim,
}
tx.AddOutput(&transaction.Output{ tx.AddOutput(&transaction.Output{
AssetID: core.UtilityTokenID(), AssetID: core.UtilityTokenID(),

View file

@ -77,20 +77,8 @@ func getTX(t *testing.B, wif *keys.WIF) *transaction.Transaction {
fromAddressHash, err := address.StringToUint160(fromAddress) fromAddressHash, err := address.StringToUint160(fromAddress)
require.NoError(t, err) require.NoError(t, err)
tx := &transaction.Transaction{ tx := transaction.NewInvocationTX([]byte{0x51}, 1)
Type: transaction.InvocationType, tx.Version = 0
Version: 0,
Data: &transaction.InvocationTX{
Script: []byte{0x51},
Gas: 1,
Version: 1,
},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
}
tx.Attributes = append(tx.Attributes, tx.Attributes = append(tx.Attributes,
transaction.Attribute{ transaction.Attribute{
Usage: transaction.Description, Usage: transaction.Description,

View file

@ -6,6 +6,7 @@ import (
"github.com/nspcc-dev/dbft/block" "github.com/nspcc-dev/dbft/block"
"github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -42,7 +43,7 @@ func TestNeoBlock_Setters(t *testing.T) {
b.SetPrevHash(util.Uint256{9, 8, 7}) b.SetPrevHash(util.Uint256{9, 8, 7})
require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash()) require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
txx := []block.Transaction{newMinerTx(123)} txx := []block.Transaction{transaction.NewMinerTX()}
b.SetTransactions(txx) b.SetTransactions(txx)
require.Equal(t, txx, b.Transactions()) require.Equal(t, txx, b.Transactions())
} }

View file

@ -2,7 +2,6 @@ package consensus
import ( import (
"errors" "errors"
"math/rand"
"sort" "sort"
"time" "time"
@ -453,17 +452,9 @@ func (s *service) getVerifiedTx(count int) []block.Transaction {
}} }}
} }
for { for {
nonce := rand.Uint32() minerTx := transaction.NewMinerTX()
res[0] = &transaction.Transaction{ minerTx.Outputs = txOuts
Type: transaction.MinerType, res[0] = minerTx
Version: 0,
Data: &transaction.MinerTX{Nonce: nonce},
Attributes: nil,
Inputs: nil,
Outputs: txOuts,
Scripts: nil,
Trimmed: false,
}
if tx, _, _ := s.Chain.GetTransaction(res[0].Hash()); tx == nil { if tx, _, _ := s.Chain.GetTransaction(res[0].Hash()); tx == nil {
break break

View file

@ -18,10 +18,7 @@ import (
func TestNewService(t *testing.T) { func TestNewService(t *testing.T) {
srv := newTestService(t) srv := newTestService(t)
tx := &transaction.Transaction{ tx := transaction.NewMinerTX()
Type: transaction.MinerType,
Data: &transaction.MinerTX{Nonce: 12345},
}
require.NoError(t, srv.Chain.PoolTx(tx)) require.NoError(t, srv.Chain.PoolTx(tx))
var txx []block.Transaction var txx []block.Transaction
@ -34,10 +31,10 @@ func TestNewService(t *testing.T) {
func TestService_GetVerified(t *testing.T) { func TestService_GetVerified(t *testing.T) {
srv := newTestService(t) srv := newTestService(t)
txs := []*transaction.Transaction{ txs := []*transaction.Transaction{
newMinerTx(1), transaction.NewMinerTXWithNonce(123),
newMinerTx(2), transaction.NewMinerTXWithNonce(124),
newMinerTx(3), transaction.NewMinerTXWithNonce(125),
newMinerTx(4), transaction.NewMinerTXWithNonce(126),
} }
require.NoError(t, srv.Chain.PoolTx(txs[3])) require.NoError(t, srv.Chain.PoolTx(txs[3]))
@ -45,7 +42,7 @@ func TestService_GetVerified(t *testing.T) {
p := new(Payload) p := new(Payload)
p.SetType(payload.PrepareRequestType) p.SetType(payload.PrepareRequestType)
p.SetPayload(&prepareRequest{transactionHashes: hashes, minerTx: *newMinerTx(999)}) p.SetPayload(&prepareRequest{transactionHashes: hashes, minerTx: *transaction.NewMinerTXWithNonce(999)})
p.SetValidatorIndex(1) p.SetValidatorIndex(1)
priv, _ := getTestValidator(1) priv, _ := getTestValidator(1)
@ -109,7 +106,7 @@ func TestService_getTx(t *testing.T) {
srv := newTestService(t) srv := newTestService(t)
t.Run("transaction in mempool", func(t *testing.T) { t.Run("transaction in mempool", func(t *testing.T) {
tx := newMinerTx(1234) tx := transaction.NewMinerTXWithNonce(1234)
h := tx.Hash() h := tx.Hash()
require.Equal(t, nil, srv.getTx(h)) require.Equal(t, nil, srv.getTx(h))
@ -122,7 +119,7 @@ func TestService_getTx(t *testing.T) {
}) })
t.Run("transaction in local cache", func(t *testing.T) { t.Run("transaction in local cache", func(t *testing.T) {
tx := newMinerTx(4321) tx := transaction.NewMinerTXWithNonce(4321)
h := tx.Hash() h := tx.Hash()
require.Equal(t, nil, srv.getTx(h)) require.Equal(t, nil, srv.getTx(h))

View file

@ -230,7 +230,7 @@ func randomPrepareRequest(t *testing.T) *prepareRequest {
timestamp: rand.Uint32(), timestamp: rand.Uint32(),
nonce: rand.Uint64(), nonce: rand.Uint64(),
transactionHashes: make([]util.Uint256, txCount), transactionHashes: make([]util.Uint256, txCount),
minerTx: *newMinerTx(rand.Uint32()), minerTx: *transaction.NewMinerTX(),
} }
req.transactionHashes[0] = req.minerTx.Hash() req.transactionHashes[0] = req.minerTx.Hash()
@ -303,18 +303,3 @@ func TestMessageType_String(t *testing.T) {
require.Equal(t, "RecoveryRequest", recoveryRequestType.String()) require.Equal(t, "RecoveryRequest", recoveryRequestType.String())
require.Equal(t, "UNKNOWN(0xff)", messageType(0xff).String()) require.Equal(t, "UNKNOWN(0xff)", messageType(0xff).String())
} }
func newMinerTx(nonce uint32) *transaction.Transaction {
return &transaction.Transaction{
Type: transaction.MinerType,
Version: 0,
Data: &transaction.MinerTX{
Nonce: rand.Uint32(),
},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
}
}

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/payload" "github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -33,7 +34,7 @@ func TestRecoveryMessage_Setters(t *testing.T) {
timestamp: 87, timestamp: 87,
nonce: 321, nonce: 321,
transactionHashes: []util.Uint256{{1}}, transactionHashes: []util.Uint256{{1}},
minerTx: *newMinerTx(123), minerTx: *transaction.NewMinerTX(),
nextConsensus: util.Uint160{1, 2}, nextConsensus: util.Uint160{1, 2},
} }
p1 := new(Payload) p1 := new(Payload)

File diff suppressed because one or more lines are too long

View file

@ -98,7 +98,7 @@ func TestScriptFromWitness(t *testing.T) {
func TestGetHeader(t *testing.T) { func TestGetHeader(t *testing.T) {
bc := newTestChain(t) bc := newTestChain(t)
block := bc.newBlock(newMinerTX()) block := bc.newBlock(transaction.NewMinerTX())
err := bc.AddBlock(block) err := bc.AddBlock(block)
assert.Nil(t, err) assert.Nil(t, err)

View file

@ -276,7 +276,7 @@ func TestGetCurrentHeaderHeight_Store(t *testing.T) {
func TestStoreAsTransaction(t *testing.T) { func TestStoreAsTransaction(t *testing.T) {
dao := NewSimple(storage.NewMemoryStore()) dao := NewSimple(storage.NewMemoryStore())
tx := &transaction.Transaction{Type: transaction.IssueType, Data: &transaction.IssueTX{}} tx := transaction.NewIssueTX()
hash := tx.Hash() hash := tx.Hash()
err := dao.StoreAsTransaction(tx, 0) err := dao.StoreAsTransaction(tx, 0)
require.NoError(t, err) require.NoError(t, err)

View file

@ -96,7 +96,7 @@ func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
lastHash := bc.topBlock.Load().(*block.Block).Hash() lastHash := bc.topBlock.Load().(*block.Block).Hash()
lastIndex := bc.topBlock.Load().(*block.Block).Index lastIndex := bc.topBlock.Load().(*block.Block).Index
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash, newMinerTX()) blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash, transaction.NewMinerTXWithNonce(uint32(1234+i)))
if err := bc.AddBlock(blocks[i]); err != nil { if err := bc.AddBlock(blocks[i]); err != nil {
return blocks, err return blocks, err
} }
@ -105,13 +105,6 @@ func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
return blocks, nil return blocks, nil
} }
func newMinerTX() *transaction.Transaction {
return &transaction.Transaction{
Type: transaction.MinerType,
Data: &transaction.MinerTX{},
}
}
func getDecodedBlock(t *testing.T, i int) *block.Block { func getDecodedBlock(t *testing.T, i int) *block.Block {
data, err := getBlockData(i) data, err := getBlockData(i)
require.NoError(t, err) require.NoError(t, err)
@ -175,14 +168,28 @@ func TestCreateBasicChain(t *testing.T) {
// To make enough GAS. // To make enough GAS.
const numOfEmptyBlocks = 200 const numOfEmptyBlocks = 200
// To be incremented after each created transaction to keep chain constant.
var testNonce uint32 = 1
// Use as nonce when new transaction is created to avoid random data in tests.
getNextNonce := func() uint32 {
testNonce++
return testNonce
}
var neoAmount = util.Fixed8FromInt64(99999000) var neoAmount = util.Fixed8FromInt64(99999000)
var neoRemainder = util.Fixed8FromInt64(100000000) - neoAmount var neoRemainder = util.Fixed8FromInt64(100000000) - neoAmount
bc := newTestChain(t) bc := newTestChain(t)
// Move almost all NEO to one simple account. // Move almost all NEO to one simple account.
txMoveNeo := transaction.NewContractTX() txMoveNeo := transaction.NewContractTX()
h, err := util.Uint256DecodeStringBE("6da730b566db183bfceb863b780cd92dee2b497e5a023c322c1eaca81cf9ad7a") txMoveNeo.Nonce = getNextNonce()
// use output of issue tx from genesis block as an input
genesisBlock, err := bc.GetBlock(bc.GetHeaderHash(0))
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 4, len(genesisBlock.Transactions))
h := genesisBlock.Transactions[3].Hash()
txMoveNeo.AddInput(&transaction.Input{ txMoveNeo.AddInput(&transaction.Input{
PrevHash: h, PrevHash: h,
PrevIndex: 0, PrevIndex: 0,
@ -225,7 +232,7 @@ func TestCreateBasicChain(t *testing.T) {
VerificationScript: rawScript, VerificationScript: rawScript,
}} }}
b := bc.newBlock(newMinerTX(), txMoveNeo) b := bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txMoveNeo)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE()) t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE())
@ -244,6 +251,7 @@ func TestCreateBasicChain(t *testing.T) {
// Make a NEO roundtrip (send to myself) and claim GAS. // Make a NEO roundtrip (send to myself) and claim GAS.
txNeoRound := transaction.NewContractTX() txNeoRound := transaction.NewContractTX()
txNeoRound.Nonce = getNextNonce()
txNeoRound.AddInput(&transaction.Input{ txNeoRound.AddInput(&transaction.Input{
PrevHash: txMoveNeo.Hash(), PrevHash: txMoveNeo.Hash(),
PrevIndex: 0, PrevIndex: 0,
@ -256,16 +264,17 @@ func TestCreateBasicChain(t *testing.T) {
}) })
txNeoRound.Data = new(transaction.ContractTX) txNeoRound.Data = new(transaction.ContractTX)
require.NoError(t, acc0.SignTx(txNeoRound)) require.NoError(t, acc0.SignTx(txNeoRound))
b = bc.newBlock(newMinerTX(), txNeoRound) b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txNeoRound)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
t.Logf("txNeoRound: %s", txNeoRound.Hash().StringLE()) t.Logf("txNeoRound: %s", txNeoRound.Hash().StringLE())
txClaim := &transaction.Transaction{Type: transaction.ClaimType}
claim := new(transaction.ClaimTX) claim := new(transaction.ClaimTX)
claim.Claims = append(claim.Claims, transaction.Input{ claim.Claims = append(claim.Claims, transaction.Input{
PrevHash: txMoveNeo.Hash(), PrevHash: txMoveNeo.Hash(),
PrevIndex: 0, PrevIndex: 0,
}) })
txClaim := transaction.NewClaimTX(claim)
txClaim.Nonce = getNextNonce()
txClaim.Data = claim txClaim.Data = claim
neoGas, sysGas, err := bc.CalculateClaimable(neoAmount, 1, bc.BlockHeight()) neoGas, sysGas, err := bc.CalculateClaimable(neoAmount, 1, bc.BlockHeight())
require.NoError(t, err) require.NoError(t, err)
@ -277,7 +286,7 @@ func TestCreateBasicChain(t *testing.T) {
Position: 0, Position: 0,
}) })
require.NoError(t, acc0.SignTx(txClaim)) require.NoError(t, acc0.SignTx(txClaim))
b = bc.newBlock(newMinerTX(), txClaim) b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txClaim)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
t.Logf("txClaim: %s", txClaim.Hash().StringLE()) t.Logf("txClaim: %s", txClaim.Hash().StringLE())
@ -305,6 +314,7 @@ func TestCreateBasicChain(t *testing.T) {
invFee := util.Fixed8FromFloat(100) invFee := util.Fixed8FromFloat(100)
txDeploy := transaction.NewInvocationTX(txScript, invFee) txDeploy := transaction.NewInvocationTX(txScript, invFee)
txDeploy.Nonce = getNextNonce()
txDeploy.AddInput(&transaction.Input{ txDeploy.AddInput(&transaction.Input{
PrevHash: txClaim.Hash(), PrevHash: txClaim.Hash(),
PrevIndex: 0, PrevIndex: 0,
@ -317,7 +327,7 @@ func TestCreateBasicChain(t *testing.T) {
}) })
gasOwned -= invFee gasOwned -= invFee
require.NoError(t, acc0.SignTx(txDeploy)) require.NoError(t, acc0.SignTx(txDeploy))
b = bc.newBlock(newMinerTX(), txDeploy) b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txDeploy)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
t.Logf("txDeploy: %s", txDeploy.Hash().StringLE()) t.Logf("txDeploy: %s", txDeploy.Hash().StringLE())
@ -326,13 +336,15 @@ func TestCreateBasicChain(t *testing.T) {
emit.AppCallWithOperationAndArgs(script.BinWriter, hash.Hash160(avm), "Put", "testkey", "testvalue") emit.AppCallWithOperationAndArgs(script.BinWriter, hash.Hash160(avm), "Put", "testkey", "testvalue")
txInv := transaction.NewInvocationTX(script.Bytes(), 0) txInv := transaction.NewInvocationTX(script.Bytes(), 0)
b = bc.newBlock(newMinerTX(), txInv) txInv.Nonce = getNextNonce()
b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txInv)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
t.Logf("txInv: %s", txInv.Hash().StringLE()) t.Logf("txInv: %s", txInv.Hash().StringLE())
priv1, err := keys.NewPrivateKeyFromWIF(privNetKeys[1]) priv1, err := keys.NewPrivateKeyFromWIF(privNetKeys[1])
require.NoError(t, err) require.NoError(t, err)
txNeo0to1 := transaction.NewContractTX() txNeo0to1 := transaction.NewContractTX()
txNeo0to1.Nonce = getNextNonce()
txNeo0to1.Data = new(transaction.ContractTX) txNeo0to1.Data = new(transaction.ContractTX)
txNeo0to1.AddInput(&transaction.Input{ txNeo0to1.AddInput(&transaction.Input{
PrevHash: txNeoRound.Hash(), PrevHash: txNeoRound.Hash(),
@ -350,20 +362,23 @@ func TestCreateBasicChain(t *testing.T) {
}) })
require.NoError(t, acc0.SignTx(txNeo0to1)) require.NoError(t, acc0.SignTx(txNeo0to1))
b = bc.newBlock(newMinerTX(), txNeo0to1) b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), txNeo0to1)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
sh := hash.Hash160(avm) sh := hash.Hash160(avm)
w := io.NewBufBinWriter() w := io.NewBufBinWriter()
emit.AppCallWithOperationAndArgs(w.BinWriter, sh, "init") emit.AppCallWithOperationAndArgs(w.BinWriter, sh, "init")
initTx := transaction.NewInvocationTX(w.Bytes(), 0) initTx := transaction.NewInvocationTX(w.Bytes(), 0)
initTx.Nonce = getNextNonce()
transferTx := newNEP5Transfer(sh, sh, priv0.GetScriptHash(), 1000) transferTx := newNEP5Transfer(sh, sh, priv0.GetScriptHash(), 1000)
transferTx.Nonce = getNextNonce()
b = bc.newBlock(newMinerTX(), initTx, transferTx) b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), initTx, transferTx)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
transferTx = newNEP5Transfer(sh, priv0.GetScriptHash(), priv1.GetScriptHash(), 123) transferTx = newNEP5Transfer(sh, priv0.GetScriptHash(), priv1.GetScriptHash(), 123)
b = bc.newBlock(newMinerTX(), transferTx) transferTx.Nonce = getNextNonce()
b = bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce()), transferTx)
require.NoError(t, bc.AddBlock(b)) require.NoError(t, bc.AddBlock(b))
if saveChain { if saveChain {
@ -388,14 +403,33 @@ func TestCreateBasicChain(t *testing.T) {
} }
} }
// Make a NEO roundtrip (send to myself) and claim GAS.
txNeoRound = transaction.NewContractTX()
txNeoRound.Nonce = getNextNonce()
txNeoRound.AddInput(&transaction.Input{
PrevHash: txNeo0to1.Hash(),
PrevIndex: 1,
})
txNeoRound.AddOutput(&transaction.Output{
AssetID: GoverningTokenID(),
Amount: neoAmount - util.Fixed8FromInt64(1000),
ScriptHash: priv0.GetScriptHash(),
Position: 0,
})
txNeoRound.Data = new(transaction.ContractTX)
require.NoError(t, acc0.SignTx(txNeoRound))
bw := io.NewBufBinWriter()
txNeoRound.EncodeBinary(bw.BinWriter)
t.Logf("sendrawtransaction: %s", hex.EncodeToString(bw.Bytes()))
// Blocks for `submitblock` test. If you are planning to modify test chain from `testblocks.acc`, // Blocks for `submitblock` test. If you are planning to modify test chain from `testblocks.acc`,
// please, update params value of `empty block` and `positive` tests. // please, update params value of `empty block` and `positive` tests.
var blocks []*block.Block var blocks []*block.Block
blocks = append(blocks, bc.newBlock(), bc.newBlock(newMinerTX())) blocks = append(blocks, bc.newBlock(), bc.newBlock(transaction.NewMinerTXWithNonce(getNextNonce())))
for _, b := range blocks { for i, b := range blocks {
data, err := testserdes.EncodeBinary(b) data, err := testserdes.EncodeBinary(b)
require.NoError(t, err) require.NoError(t, err)
t.Log(hex.EncodeToString(data)) t.Logf("\nblock %v for submitblock test:\n%s", i, hex.EncodeToString(data))
} }
} }

View file

@ -36,7 +36,7 @@ func (fs *FeerStub) SystemFee(*transaction.Transaction) util.Fixed8 {
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) { func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
mp := NewMemPool(10) mp := NewMemPool(10)
tx := newMinerTX(0) tx := transaction.NewMinerTXWithNonce(0)
_, _, ok := mp.TryGetValue(tx.Hash()) _, _, ok := mp.TryGetValue(tx.Hash())
require.Equal(t, false, ok) require.Equal(t, false, ok)
require.NoError(t, mp.Add(tx, fs)) require.NoError(t, mp.Add(tx, fs))
@ -73,7 +73,7 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
return mp.claims[i].Cmp(mp.claims[j]) < 0 return mp.claims[i].Cmp(mp.claims[j]) < 0
} }
txm1 := newMinerTX(1) txm1 := transaction.NewMinerTXWithNonce(1)
txc1, claim1 := newClaimTX() txc1, claim1 := newClaimTX()
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
txm1.Inputs = append(txm1.Inputs, transaction.Input{PrevHash: hash1, PrevIndex: uint16(100 - i)}) txm1.Inputs = append(txm1.Inputs, transaction.Input{PrevHash: hash1, PrevIndex: uint16(100 - i)})
@ -87,7 +87,7 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
assert.Equal(t, len(claim1.Claims), len(mp.claims)) assert.Equal(t, len(claim1.Claims), len(mp.claims))
assert.True(t, sort.SliceIsSorted(mp.claims, mpLessClaims)) assert.True(t, sort.SliceIsSorted(mp.claims, mpLessClaims))
txm2 := newMinerTX(1) txm2 := transaction.NewMinerTXWithNonce(1)
txc2, claim2 := newClaimTX() txc2, claim2 := newClaimTX()
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
txm2.Inputs = append(txm2.Inputs, transaction.Input{PrevHash: hash2, PrevIndex: uint16(i)}) txm2.Inputs = append(txm2.Inputs, transaction.Input{PrevHash: hash2, PrevIndex: uint16(i)})
@ -128,19 +128,19 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
func TestMemPoolVerifyInputs(t *testing.T) { func TestMemPoolVerifyInputs(t *testing.T) {
mp := NewMemPool(10) mp := NewMemPool(10)
tx := newMinerTX(1) tx := transaction.NewMinerTXWithNonce(1)
inhash1 := random.Uint256() inhash1 := random.Uint256()
tx.Inputs = append(tx.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 0}) tx.Inputs = append(tx.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 0})
require.Equal(t, true, mp.Verify(tx)) require.Equal(t, true, mp.Verify(tx))
require.NoError(t, mp.Add(tx, &FeerStub{})) require.NoError(t, mp.Add(tx, &FeerStub{}))
tx2 := newMinerTX(2) tx2 := transaction.NewMinerTXWithNonce(2)
inhash2 := random.Uint256() inhash2 := random.Uint256()
tx2.Inputs = append(tx2.Inputs, transaction.Input{PrevHash: inhash2, PrevIndex: 0}) tx2.Inputs = append(tx2.Inputs, transaction.Input{PrevHash: inhash2, PrevIndex: 0})
require.Equal(t, true, mp.Verify(tx2)) require.Equal(t, true, mp.Verify(tx2))
require.NoError(t, mp.Add(tx2, &FeerStub{})) require.NoError(t, mp.Add(tx2, &FeerStub{}))
tx3 := newMinerTX(3) tx3 := transaction.NewMinerTXWithNonce(3)
// Different index number, but the same PrevHash as in tx1. // Different index number, but the same PrevHash as in tx1.
tx3.Inputs = append(tx3.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 1}) tx3.Inputs = append(tx3.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 1})
require.Equal(t, true, mp.Verify(tx3)) require.Equal(t, true, mp.Verify(tx3))
@ -189,32 +189,20 @@ func TestMemPoolVerifyIssue(t *testing.T) {
} }
func newIssueTX() *transaction.Transaction { func newIssueTX() *transaction.Transaction {
return &transaction.Transaction{ tx := transaction.NewIssueTX()
Type: transaction.IssueType, tx.Outputs = []transaction.Output{
Data: &transaction.IssueTX{}, {
Outputs: []transaction.Output{ AssetID: random.Uint256(),
{ Amount: util.Fixed8FromInt64(42),
AssetID: random.Uint256(), ScriptHash: random.Uint160(),
Amount: util.Fixed8FromInt64(42),
ScriptHash: random.Uint160(),
},
}, },
} }
} return tx
func newMinerTX(i uint32) *transaction.Transaction {
return &transaction.Transaction{
Type: transaction.MinerType,
Data: &transaction.MinerTX{Nonce: i},
}
} }
func newClaimTX() (*transaction.Transaction, *transaction.ClaimTX) { func newClaimTX() (*transaction.Transaction, *transaction.ClaimTX) {
cl := &transaction.ClaimTX{} cl := &transaction.ClaimTX{}
return &transaction.Transaction{ return transaction.NewClaimTX(cl), cl
Type: transaction.ClaimType,
Data: cl,
}, cl
} }
func TestOverCapacity(t *testing.T) { func TestOverCapacity(t *testing.T) {
@ -223,7 +211,7 @@ func TestOverCapacity(t *testing.T) {
mp := NewMemPool(mempoolSize) mp := NewMemPool(mempoolSize)
for i := 0; i < mempoolSize; i++ { for i := 0; i < mempoolSize; i++ {
tx := newMinerTX(uint32(i)) tx := transaction.NewMinerTXWithNonce(uint32(i))
require.NoError(t, mp.Add(tx, fs)) require.NoError(t, mp.Add(tx, fs))
} }
txcnt := uint32(mempoolSize) txcnt := uint32(mempoolSize)
@ -243,7 +231,7 @@ func TestOverCapacity(t *testing.T) {
// Fees are also prioritized. // Fees are also prioritized.
fs.netFee = util.Fixed8FromFloat(0.0001) fs.netFee = util.Fixed8FromFloat(0.0001)
for i := 0; i < mempoolSize-1; i++ { for i := 0; i < mempoolSize-1; i++ {
tx := newMinerTX(txcnt) tx := transaction.NewMinerTXWithNonce(txcnt)
txcnt++ txcnt++
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())
@ -251,7 +239,7 @@ func TestOverCapacity(t *testing.T) {
} }
// Less prioritized txes are not allowed anymore. // Less prioritized txes are not allowed anymore.
fs.netFee = util.Fixed8FromFloat(0.00001) fs.netFee = util.Fixed8FromFloat(0.00001)
tx := newMinerTX(txcnt) tx := transaction.NewMinerTXWithNonce(txcnt)
txcnt++ txcnt++
require.Error(t, mp.Add(tx, fs)) require.Error(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count()) require.Equal(t, mempoolSize, mp.Count())
@ -262,7 +250,7 @@ func TestOverCapacity(t *testing.T) {
// Low net fee, but higher per-byte fee is still a better combination. // Low net fee, but higher per-byte fee is still a better combination.
fs.perByteFee = util.Fixed8FromFloat(0.001) fs.perByteFee = util.Fixed8FromFloat(0.001)
tx = newMinerTX(txcnt) tx = transaction.NewMinerTXWithNonce(txcnt)
txcnt++ txcnt++
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())
@ -271,7 +259,7 @@ func TestOverCapacity(t *testing.T) {
// High priority always wins over low priority. // High priority always wins over low priority.
fs.lowPriority = false fs.lowPriority = false
for i := 0; i < mempoolSize; i++ { for i := 0; i < mempoolSize; i++ {
tx := newMinerTX(txcnt) tx := transaction.NewMinerTXWithNonce(txcnt)
txcnt++ txcnt++
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())
@ -279,7 +267,7 @@ func TestOverCapacity(t *testing.T) {
} }
// Good luck with low priority now. // Good luck with low priority now.
fs.lowPriority = true fs.lowPriority = true
tx = newMinerTX(txcnt) tx = transaction.NewMinerTXWithNonce(txcnt)
require.Error(t, mp.Add(tx, fs)) require.Error(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)))
@ -292,7 +280,7 @@ func TestGetVerified(t *testing.T) {
txes := make([]*transaction.Transaction, 0, mempoolSize) txes := make([]*transaction.Transaction, 0, mempoolSize)
for i := 0; i < mempoolSize; i++ { for i := 0; i < mempoolSize; i++ {
tx := newMinerTX(uint32(i)) tx := transaction.NewMinerTXWithNonce(uint32(i))
txes = append(txes, tx) txes = append(txes, tx)
require.NoError(t, mp.Add(tx, fs)) require.NoError(t, mp.Add(tx, fs))
} }
@ -317,7 +305,7 @@ func TestRemoveStale(t *testing.T) {
txes1 := make([]*transaction.Transaction, 0, mempoolSize/2) txes1 := make([]*transaction.Transaction, 0, mempoolSize/2)
txes2 := make([]*transaction.Transaction, 0, mempoolSize/2) txes2 := make([]*transaction.Transaction, 0, mempoolSize/2)
for i := 0; i < mempoolSize; i++ { for i := 0; i < mempoolSize; i++ {
tx := newMinerTX(uint32(i)) tx := transaction.NewMinerTXWithNonce(uint32(i))
if i%2 == 0 { if i%2 == 0 {
txes1 = append(txes1, tx) txes1 = append(txes1, tx)
} else { } else {

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
@ -9,6 +11,21 @@ type ClaimTX struct {
Claims []Input Claims []Input
} }
// NewClaimTX creates Transaction of ClaimType type.
func NewClaimTX(claim *ClaimTX) *Transaction {
return &Transaction{
Type: ClaimType,
Version: 0,
Nonce: rand.Uint32(),
Data: claim,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *ClaimTX) DecodeBinary(br *io.BinReader) { func (tx *ClaimTX) DecodeBinary(br *io.BinReader) {
br.ReadArray(&tx.Claims) br.ReadArray(&tx.Claims)

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
@ -11,7 +13,15 @@ type ContractTX struct{}
// NewContractTX creates Transaction of ContractType type. // NewContractTX creates Transaction of ContractType type.
func NewContractTX() *Transaction { func NewContractTX() *Transaction {
return &Transaction{ return &Transaction{
Type: ContractType, Type: ContractType,
Version: 0,
Nonce: rand.Uint32(),
Data: &ContractTX{},
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
} }
} }

View file

@ -1,15 +1,8 @@
package transaction package transaction
import ( //TODO NEO3.0: Update binary
"encoding/hex" /*
"testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecodeContract(t *testing.T) { func TestEncodeDecodeContract(t *testing.T) {
// mainnet transaction: bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79 // mainnet transaction: bdf6cc3b9af12a7565bda80933a75ee8cef1bc771d0d58effc08e4c8b436da79
rawtx := "80000001888da99f8f497fd65c4325786a09511159c279af4e7eb532e9edd628c87cc1ee0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50082167010000000a8666b4830229d6a1a9b80f6088059191c122d2b0141409e79e132290c82916a88f1a3db5cf9f3248b780cfece938ab0f0812d0e188f3a489c7d1a23def86bd69d863ae67de753b2c2392e9497eadc8eb9fc43aa52c645232103e2f6a334e05002624cf616f01a62cff2844c34a3b08ca16048c259097e315078ac" rawtx := "80000001888da99f8f497fd65c4325786a09511159c279af4e7eb532e9edd628c87cc1ee0000019b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc50082167010000000a8666b4830229d6a1a9b80f6088059191c122d2b0141409e79e132290c82916a88f1a3db5cf9f3248b780cfece938ab0f0812d0e188f3a489c7d1a23def86bd69d863ae67de753b2c2392e9497eadc8eb9fc43aa52c645232103e2f6a334e05002624cf616f01a62cff2844c34a3b08ca16048c259097e315078ac"
tx := decodeTransaction(rawtx, t) tx := decodeTransaction(rawtx, t)
@ -34,3 +27,4 @@ func TestEncodeDecodeContract(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, rawtx, hex.EncodeToString(data)) assert.Equal(t, rawtx, hex.EncodeToString(data))
} }
*/

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
@ -15,6 +17,21 @@ type EnrollmentTX struct {
PublicKey keys.PublicKey PublicKey keys.PublicKey
} }
// NewEnrollmentTX creates Transaction of EnrollmentType type.
func NewEnrollmentTX(enrollment *EnrollmentTX) *Transaction {
return &Transaction{
Type: EnrollmentType,
Version: 0,
Nonce: rand.Uint32(),
Data: enrollment,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *EnrollmentTX) DecodeBinary(r *io.BinReader) { func (tx *EnrollmentTX) DecodeBinary(r *io.BinReader) {
tx.PublicKey.DecodeBinary(r) tx.PublicKey.DecodeBinary(r)

View file

@ -1,13 +1,7 @@
package transaction package transaction
import ( //TODO NEO3.0: Update bynary
"encoding/hex" /*
"testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecodeEnrollment(t *testing.T) { func TestEncodeDecodeEnrollment(t *testing.T) {
rawtx := "200002ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f60001d3d3b7028d61fea3b7803fda3d7f0a1f7262d38e5e1c8987b0313e0a94574151000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60005441d11600000050ac4949596f5b62fef7be4d1c3e494e6048ed4a01414079d78189d591097b17657a62240c93595e8233dc81157ea2cd477813f09a11fd72845e6bd97c5a3dda125985ea3d5feca387e9933649a9a671a69ab3f6301df6232102ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f6ac" rawtx := "200002ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f60001d3d3b7028d61fea3b7803fda3d7f0a1f7262d38e5e1c8987b0313e0a94574151000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60005441d11600000050ac4949596f5b62fef7be4d1c3e494e6048ed4a01414079d78189d591097b17657a62240c93595e8233dc81157ea2cd477813f09a11fd72845e6bd97c5a3dda125985ea3d5feca387e9933649a9a671a69ab3f6301df6232102ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f6ac"
tx := decodeTransaction(rawtx, t) tx := decodeTransaction(rawtx, t)
@ -20,3 +14,4 @@ func TestEncodeDecodeEnrollment(t *testing.T) {
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
assert.Equal(t, rawtx, hex.EncodeToString(data)) assert.Equal(t, rawtx, hex.EncodeToString(data))
} }
*/

View file

@ -4,11 +4,11 @@ import (
"encoding/hex" "encoding/hex"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var ( var (
//TODO NEO3.0: Update binary
// https://neotracker.io/tx/2c6a45547b3898318e400e541628990a07acb00f3b9a15a8e966ae49525304da // https://neotracker.io/tx/2c6a45547b3898318e400e541628990a07acb00f3b9a15a8e966ae49525304da
rawClaimTX = "020004bc67ba325d6412ff4c55b10f7e9afb54bbb2228d201b37363c3d697ac7c198f70300591cd454d7318d2087c0196abfbbd1573230380672f0f0cd004dcb4857e58cbd010031bcfbed573f5318437e95edd603922a4455ff3326a979fdd1c149a84c4cb0290000b51eb6159c58cac4fe23d90e292ad2bcb7002b0da2c474e81e1889c0649d2c490000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c603b555f00000000005d9de59d99c0d1f6ed1496444473f4a0b538302f014140456349cec43053009accdb7781b0799c6b591c812768804ab0a0b56b5eae7a97694227fcd33e70899c075848b2cee8fae733faac6865b484d3f7df8949e2aadb232103945fae1ed3c31d778f149192b76734fcc951b400ba3598faa81ff92ebe477eacac" rawClaimTX = "020004bc67ba325d6412ff4c55b10f7e9afb54bbb2228d201b37363c3d697ac7c198f70300591cd454d7318d2087c0196abfbbd1573230380672f0f0cd004dcb4857e58cbd010031bcfbed573f5318437e95edd603922a4455ff3326a979fdd1c149a84c4cb0290000b51eb6159c58cac4fe23d90e292ad2bcb7002b0da2c474e81e1889c0649d2c490000000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c603b555f00000000005d9de59d99c0d1f6ed1496444473f4a0b538302f014140456349cec43053009accdb7781b0799c6b591c812768804ab0a0b56b5eae7a97694227fcd33e70899c075848b2cee8fae733faac6865b484d3f7df8949e2aadb232103945fae1ed3c31d778f149192b76734fcc951b400ba3598faa81ff92ebe477eacac"
// https://neotracker.io/tx/fe4b3af60677204c57e573a57bdc97bc5059b05ad85b1474f84431f88d910f64 // https://neotracker.io/tx/fe4b3af60677204c57e573a57bdc97bc5059b05ad85b1474f84431f88d910f64
@ -20,7 +20,7 @@ var (
func decodeTransaction(rawTX string, t *testing.T) *Transaction { func decodeTransaction(rawTX string, t *testing.T) *Transaction {
b, err1 := hex.DecodeString(rawTX) b, err1 := hex.DecodeString(rawTX)
assert.Nil(t, err1) assert.Nil(t, err1)
tx := &Transaction{} tx, err := NewTransactionFromBytes(b)
assert.NoError(t, testserdes.DecodeBinary(b, tx)) assert.NoError(t, err)
return tx return tx
} }

View file

@ -2,6 +2,7 @@ package transaction
import ( import (
"errors" "errors"
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -23,6 +24,7 @@ func NewInvocationTX(script []byte, gas util.Fixed8) *Transaction {
return &Transaction{ return &Transaction{
Type: InvocationType, Type: InvocationType,
Version: 1, Version: 1,
Nonce: rand.Uint32(),
Data: &InvocationTX{ Data: &InvocationTX{
Script: script, Script: script,
Gas: gas, Gas: gas,

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
@ -8,6 +10,21 @@ import (
// This TX has not special attributes. // This TX has not special attributes.
type IssueTX struct{} type IssueTX struct{}
// NewIssueTX creates Transaction of IssueType type.
func NewIssueTX() *Transaction {
return &Transaction{
Type: IssueType,
Version: 0,
Nonce: rand.Uint32(),
Data: &IssueTX{},
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *IssueTX) DecodeBinary(r *io.BinReader) { func (tx *IssueTX) DecodeBinary(r *io.BinReader) {
} }

View file

@ -1,21 +1,38 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
// MinerTX represents a miner transaction. // MinerTX represents a miner transaction.
type MinerTX struct { type MinerTX struct{}
// Random number to avoid hash collision.
Nonce uint32 // NewMinerTX creates Transaction of MinerType type.
func NewMinerTX() *Transaction {
return NewMinerTXWithNonce(rand.Uint32())
}
// NewMinerTXWithNonce creates Transaction of MinerType type with specified nonce.
func NewMinerTXWithNonce(nonce uint32) *Transaction {
return &Transaction{
Type: MinerType,
Version: 0,
Nonce: nonce,
Data: &MinerTX{},
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
} }
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *MinerTX) DecodeBinary(r *io.BinReader) { func (tx *MinerTX) DecodeBinary(r *io.BinReader) {
tx.Nonce = r.ReadU32LE()
} }
// EncodeBinary implements Serializable interface. // EncodeBinary implements Serializable interface.
func (tx *MinerTX) EncodeBinary(w *io.BinWriter) { func (tx *MinerTX) EncodeBinary(w *io.BinWriter) {
w.WriteU32LE(tx.Nonce)
} }

View file

@ -15,8 +15,7 @@ func TestEncodeDecodeMiner(t *testing.T) {
assert.Equal(t, MinerType, tx.Type) assert.Equal(t, MinerType, tx.Type)
assert.IsType(t, tx.Data, &MinerTX{}) assert.IsType(t, tx.Data, &MinerTX{})
assert.Equal(t, 0, int(tx.Version)) assert.Equal(t, 0, int(tx.Version))
m := tx.Data.(*MinerTX) assert.Equal(t, uint32(571397116), tx.Nonce)
assert.Equal(t, uint32(571397116), m.Nonce)
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", tx.Hash().StringLE()) assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", tx.Hash().StringLE())

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -21,6 +23,21 @@ type PublishTX struct {
Version uint8 // Version of the parent struct Transaction. Used in reading NeedStorage flag. Version uint8 // Version of the parent struct Transaction. Used in reading NeedStorage flag.
} }
// NewPublishTX creates Transaction of PublishType type.
func NewPublishTX(publish *PublishTX) *Transaction {
return &Transaction{
Type: PublishType,
Version: 0,
Nonce: rand.Uint32(),
Data: publish,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *PublishTX) DecodeBinary(br *io.BinReader) { func (tx *PublishTX) DecodeBinary(br *io.BinReader) {
tx.Script = br.ReadVarBytes() tx.Script = br.ReadVarBytes()

View file

@ -2,6 +2,7 @@ package transaction
import ( import (
"encoding/json" "encoding/json"
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
@ -30,6 +31,21 @@ type RegisterTX struct {
Admin util.Uint160 Admin util.Uint160
} }
// NewRegisterTX creates Transaction of RegisterType type.
func NewRegisterTX(register *RegisterTX) *Transaction {
return &Transaction{
Type: RegisterType,
Version: 0,
Nonce: rand.Uint32(),
Data: register,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *RegisterTX) DecodeBinary(br *io.BinReader) { func (tx *RegisterTX) DecodeBinary(br *io.BinReader) {
tx.AssetType = AssetType(br.ReadB()) tx.AssetType = AssetType(br.ReadB())

View file

@ -1,39 +1,29 @@
package transaction package transaction
import ( import (
"encoding/hex"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestRegisterTX(t *testing.T) { func TestRegisterTX(t *testing.T) {
someuint160, _ := util.Uint160DecodeStringBE("4d3b96ae1bcc5a585e075e3b81920210dec16302") someuint160, _ := util.Uint160DecodeStringBE("4d3b96ae1bcc5a585e075e3b81920210dec16302")
tx := &Transaction{ registerTx := &RegisterTX{
Type: RegisterType, AssetType: UtilityToken,
Version: 0, Name: "this is some token I created",
Data: &RegisterTX{ Amount: util.Fixed8FromInt64(1000000),
AssetType: UtilityToken, Precision: 8,
Name: "this is some token I created", Admin: someuint160,
Amount: util.Fixed8FromInt64(1000000),
Precision: 8,
Admin: someuint160,
},
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
} }
tx := NewRegisterTX(registerTx)
_ = tx.Hash() _ = tx.Hash()
testserdes.EncodeDecodeBinary(t, tx, new(Transaction)) testserdes.EncodeDecodeBinary(t, tx, new(Transaction))
} }
//TODO NEO3.0: update binary
/*
func TestDecodeRegisterTXFromRawString(t *testing.T) { func TestDecodeRegisterTXFromRawString(t *testing.T) {
rawTX := "400000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000" rawTX := "400000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000"
b, err := hex.DecodeString(rawTX) b, err := hex.DecodeString(rawTX)
@ -53,3 +43,4 @@ func TestDecodeRegisterTXFromRawString(t *testing.T) {
testserdes.EncodeDecodeBinary(t, tx, new(Transaction)) testserdes.EncodeDecodeBinary(t, tx, new(Transaction))
} }
*/

View file

@ -1,6 +1,8 @@
package transaction package transaction
import ( import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
) )
@ -9,6 +11,21 @@ type StateTX struct {
Descriptors []*StateDescriptor Descriptors []*StateDescriptor
} }
// NewStateTX creates Transaction of StateType type.
func NewStateTX(state *StateTX) *Transaction {
return &Transaction{
Type: StateType,
Version: 0,
Nonce: rand.Uint32(),
Data: state,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface. // DecodeBinary implements Serializable interface.
func (tx *StateTX) DecodeBinary(r *io.BinReader) { func (tx *StateTX) DecodeBinary(r *io.BinReader) {
r.ReadArray(&tx.Descriptors) r.ReadArray(&tx.Descriptors)

View file

@ -1,13 +1,7 @@
package transaction package transaction
import ( //TODO NEO3.0: Update binary
"encoding/hex" /*
"testing"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/stretchr/testify/assert"
)
func TestEncodeDecodeState(t *testing.T) { func TestEncodeDecodeState(t *testing.T) {
// transaction taken from testnet 8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724 // transaction taken from testnet 8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724
rawtx := "900001482103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c10a5265676973746572656401010001cb4184f0a96e72656c1fbdd4f75cca567519e909fd43cefcec13d6c6abcb92a1000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6000b8fb050109000071f9cf7f0ec74ec0b0f28a92b12e1081574c0af00141408780d7b3c0aadc5398153df5e2f1cf159db21b8b0f34d3994d865433f79fafac41683783c48aef510b67660e3157b701b9ca4dd9946a385d578fba7dd26f4849232103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c1ac" rawtx := "900001482103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c10a5265676973746572656401010001cb4184f0a96e72656c1fbdd4f75cca567519e909fd43cefcec13d6c6abcb92a1000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6000b8fb050109000071f9cf7f0ec74ec0b0f28a92b12e1081574c0af00141408780d7b3c0aadc5398153df5e2f1cf159db21b8b0f34d3994d865433f79fafac41683783c48aef510b67660e3157b701b9ca4dd9946a385d578fba7dd26f4849232103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c1ac"
@ -34,3 +28,4 @@ func TestEncodeDecodeState(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, rawtx, hex.EncodeToString(data)) assert.Equal(t, rawtx, hex.EncodeToString(data))
} }
*/

View file

@ -27,6 +27,9 @@ type Transaction struct {
// The trading version which is currently 0. // The trading version which is currently 0.
Version uint8 Version uint8
// Random number to avoid hash collision.
Nonce uint32
// Data specific to the type of the transaction. // Data specific to the type of the transaction.
// This is always a pointer to a <Type>Transaction. // This is always a pointer to a <Type>Transaction.
Data TXer Data TXer
@ -107,6 +110,7 @@ func (t *Transaction) AddVerificationHash(addr util.Uint160) {
func (t *Transaction) DecodeBinary(br *io.BinReader) { func (t *Transaction) DecodeBinary(br *io.BinReader) {
t.Type = TXType(br.ReadB()) t.Type = TXType(br.ReadB())
t.Version = uint8(br.ReadB()) t.Version = uint8(br.ReadB())
t.Nonce = br.ReadU32LE()
t.decodeData(br) t.decodeData(br)
br.ReadArray(&t.Attributes) br.ReadArray(&t.Attributes)
@ -177,6 +181,7 @@ func (t *Transaction) encodeHashableFields(bw *io.BinWriter) {
} }
bw.WriteB(byte(t.Type)) bw.WriteB(byte(t.Type))
bw.WriteB(byte(t.Version)) bw.WriteB(byte(t.Version))
bw.WriteU32LE(t.Nonce)
// Underlying TXer. // Underlying TXer.
if !noData { if !noData {
@ -238,6 +243,17 @@ func (t *Transaction) Bytes() []byte {
return buf.Bytes() return buf.Bytes()
} }
// NewTransactionFromBytes decodes byte array into *Transaction
func NewTransactionFromBytes(b []byte) (*Transaction, error) {
tx := &Transaction{}
r := io.NewBinReaderFromBuf(b)
tx.DecodeBinary(r)
if r.Err != nil {
return nil, r.Err
}
return tx, nil
}
// transactionJSON is a wrapper for Transaction and // transactionJSON is a wrapper for Transaction and
// used for correct marhalling of transaction.Data // used for correct marhalling of transaction.Data
type transactionJSON struct { type transactionJSON struct {
@ -245,6 +261,7 @@ type transactionJSON struct {
Size int `json:"size"` Size int `json:"size"`
Type TXType `json:"type"` Type TXType `json:"type"`
Version uint8 `json:"version"` Version uint8 `json:"version"`
Nonce uint32 `json:"nonce"`
Attributes []Attribute `json:"attributes"` Attributes []Attribute `json:"attributes"`
Inputs []Input `json:"vin"` Inputs []Input `json:"vin"`
Outputs []Output `json:"vout"` Outputs []Output `json:"vout"`
@ -254,7 +271,6 @@ type transactionJSON struct {
PublicKey *keys.PublicKey `json:"pubkey,omitempty"` PublicKey *keys.PublicKey `json:"pubkey,omitempty"`
Script string `json:"script,omitempty"` Script string `json:"script,omitempty"`
Gas util.Fixed8 `json:"gas,omitempty"` Gas util.Fixed8 `json:"gas,omitempty"`
Nonce uint32 `json:"nonce,omitempty"`
Contract *publishedContract `json:"contract,omitempty"` Contract *publishedContract `json:"contract,omitempty"`
Asset *registeredAsset `json:"asset,omitempty"` Asset *registeredAsset `json:"asset,omitempty"`
Descriptors []*StateDescriptor `json:"descriptors,omitempty"` Descriptors []*StateDescriptor `json:"descriptors,omitempty"`
@ -267,14 +283,13 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
Size: io.GetVarSize(t), Size: io.GetVarSize(t),
Type: t.Type, Type: t.Type,
Version: t.Version, Version: t.Version,
Nonce: t.Nonce,
Attributes: t.Attributes, Attributes: t.Attributes,
Inputs: t.Inputs, Inputs: t.Inputs,
Outputs: t.Outputs, Outputs: t.Outputs,
Scripts: t.Scripts, Scripts: t.Scripts,
} }
switch t.Type { switch t.Type {
case MinerType:
tx.Nonce = t.Data.(*MinerTX).Nonce
case ClaimType: case ClaimType:
tx.Claims = t.Data.(*ClaimTX).Claims tx.Claims = t.Data.(*ClaimTX).Claims
case EnrollmentType: case EnrollmentType:
@ -322,15 +337,14 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
} }
t.Type = tx.Type t.Type = tx.Type
t.Version = tx.Version t.Version = tx.Version
t.Nonce = tx.Nonce
t.Attributes = tx.Attributes t.Attributes = tx.Attributes
t.Inputs = tx.Inputs t.Inputs = tx.Inputs
t.Outputs = tx.Outputs t.Outputs = tx.Outputs
t.Scripts = tx.Scripts t.Scripts = tx.Scripts
switch tx.Type { switch tx.Type {
case MinerType: case MinerType:
t.Data = &MinerTX{ t.Data = &MinerTX{}
Nonce: tx.Nonce,
}
case ClaimType: case ClaimType:
t.Data = &ClaimTX{ t.Data = &ClaimTX{
Claims: tx.Claims, Claims: tx.Claims,

View file

@ -5,7 +5,6 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes" "github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -36,6 +35,8 @@ func TestWitnessEncodeDecode(t *testing.T) {
t.Log(len(witDecode.InvocationScript)) t.Log(len(witDecode.InvocationScript))
} }
// TODO NEO3.0: update binary
/*
func TestDecodeEncodeClaimTX(t *testing.T) { func TestDecodeEncodeClaimTX(t *testing.T) {
tx := decodeTransaction(rawClaimTX, t) tx := decodeTransaction(rawClaimTX, t)
assert.Equal(t, tx.Type, ClaimType) assert.Equal(t, tx.Type, ClaimType)
@ -85,6 +86,7 @@ func TestDecodeEncodeInvocationTX(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, rawInvocationTX, hex.EncodeToString(data)) assert.Equal(t, rawInvocationTX, hex.EncodeToString(data))
} }
*/
func TestNewInvocationTX(t *testing.T) { func TestNewInvocationTX(t *testing.T) {
script := []byte{0x51} script := []byte{0x51}
@ -98,6 +100,8 @@ func TestNewInvocationTX(t *testing.T) {
testserdes.EncodeDecodeBinary(t, tx, new(Transaction)) testserdes.EncodeDecodeBinary(t, tx, new(Transaction))
} }
// TODO NEO3.0: Update binary
/*
func TestDecodePublishTX(t *testing.T) { func TestDecodePublishTX(t *testing.T) {
expectedTXData := &PublishTX{} expectedTXData := &PublishTX{}
expectedTXData.Name = "Lock" expectedTXData.Name = "Lock"
@ -150,6 +154,7 @@ func TestDecodePublishTX(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, rawPublishTX, hex.EncodeToString(data)) assert.Equal(t, rawPublishTX, hex.EncodeToString(data))
} }
*/
func TestEncodingTXWithNoData(t *testing.T) { func TestEncodingTXWithNoData(t *testing.T) {
_, err := testserdes.EncodeBinary(new(Transaction)) _, err := testserdes.EncodeBinary(new(Transaction))
@ -173,16 +178,7 @@ func TestMarshalUnmarshalJSONContractTX(t *testing.T) {
} }
func TestMarshalUnmarshalJSONMinerTX(t *testing.T) { func TestMarshalUnmarshalJSONMinerTX(t *testing.T) {
tx := &Transaction{ tx := NewMinerTX()
Type: MinerType,
Version: 0,
Data: &MinerTX{Nonce: 12345},
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction)) testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
} }

View file

@ -58,39 +58,32 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
} }
scriptOut := hash.Hash160(rawScript) scriptOut := hash.Hash160(rawScript)
minerTx := transaction.NewMinerTXWithNonce(2083236893)
issueTx := transaction.NewIssueTX()
// TODO NEO3.0: nonce should be constant to avoid variability of genesis block
issueTx.Nonce = 0
issueTx.Outputs = []transaction.Output{
{
AssetID: governingTokenTX.Hash(),
Amount: governingTokenTX.Data.(*transaction.RegisterTX).Amount,
ScriptHash: scriptOut,
},
}
issueTx.Scripts = []transaction.Witness{
{
InvocationScript: []byte{},
VerificationScript: []byte{byte(opcode.PUSHT)},
},
}
b := &block.Block{ b := &block.Block{
Base: base, Base: base,
Transactions: []*transaction.Transaction{ Transactions: []*transaction.Transaction{
{ minerTx,
Type: transaction.MinerType,
Data: &transaction.MinerTX{
Nonce: 2083236893,
},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
},
&governingTokenTX, &governingTokenTX,
&utilityTokenTX, &utilityTokenTX,
{ issueTx,
Type: transaction.IssueType,
Data: &transaction.IssueTX{}, // no fields.
Inputs: []transaction.Input{},
Outputs: []transaction.Output{
{
AssetID: governingTokenTX.Hash(),
Amount: governingTokenTX.Data.(*transaction.RegisterTX).Amount,
ScriptHash: scriptOut,
},
},
Scripts: []transaction.Witness{
{
InvocationScript: []byte{},
VerificationScript: []byte{byte(opcode.PUSHT)},
},
},
},
}, },
} }
@ -111,14 +104,9 @@ func init() {
Admin: admin, Admin: admin,
} }
governingTokenTX = transaction.Transaction{ governingTokenTX = *transaction.NewRegisterTX(registerTX)
Type: transaction.RegisterType, // TODO NEO3.0: nonce should be constant to avoid variability of token hash
Data: registerTX, governingTokenTX.Nonce = 0
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
}
admin = hash.Hash160([]byte{byte(opcode.PUSHF)}) admin = hash.Hash160([]byte{byte(opcode.PUSHF)})
registerTX = &transaction.RegisterTX{ registerTX = &transaction.RegisterTX{
@ -128,14 +116,9 @@ func init() {
Precision: 8, Precision: 8,
Admin: admin, Admin: admin,
} }
utilityTokenTX = transaction.Transaction{ utilityTokenTX = *transaction.NewRegisterTX(registerTX)
Type: transaction.RegisterType, // TODO NEO3.0: nonce should be constant to avoid variability of token hash
Data: registerTX, utilityTokenTX.Nonce = 0
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
}
} }
// GoverningTokenID returns the governing token (NEO) hash. // GoverningTokenID returns the governing token (NEO) hash.

View file

@ -16,7 +16,11 @@ func TestGenesisBlockMainNet(t *testing.T) {
block, err := createGenesisBlock(cfg.ProtocolConfiguration) block, err := createGenesisBlock(cfg.ProtocolConfiguration)
require.NoError(t, err) require.NoError(t, err)
expect := "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf" //TODO: After we added Nonce field to transaction.Transaction, goveringTockenTx and UtilityTockenTx hashes
// have been changed. Consequently, hash of the genesis block has been changed.
// Update expected genesis block hash for better times.
// Old hash is "d42561e3d30e15be6400b6df2f328e02d2bf6354c41dce433bc57687c82144bf"
expect := "8c5e44474b2b942286071254fd4bffddd3febd0511b101e566331b5f8f041902"
assert.Equal(t, expect, block.Hash().StringLE()) assert.Equal(t, expect, block.Hash().StringLE())
} }
@ -40,11 +44,17 @@ func TestGetConsensusAddressMainNet(t *testing.T) {
} }
func TestUtilityTokenTX(t *testing.T) { func TestUtilityTokenTX(t *testing.T) {
expect := "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7" //TODO: After we added Nonce field to transaction.Transaction, UtilityTockenTx hash
// has been changed. Update it for better times.
// Old hash is "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"
expect := "057ea06225860f0f7e69cca1e0052652918629929591b8138a516431be144ba8"
assert.Equal(t, expect, UtilityTokenID().StringLE()) assert.Equal(t, expect, UtilityTokenID().StringLE())
} }
func TestGoverningTokenTX(t *testing.T) { func TestGoverningTokenTX(t *testing.T) {
expect := "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b" //TODO: After we added Nonce field to transaction.Transaction, GoveringTockenTx hash
// has been changed. Update it for better times.
// Old hash is "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"
expect := "cd3a3b5654465238c3a4ac30eeb1bfd1171378d59b27f7d2e6893ce9d6150825"
assert.Equal(t, expect, GoverningTokenID().StringLE()) assert.Equal(t, expect, GoverningTokenID().StringLE())
} }

View file

@ -279,11 +279,9 @@ func (c *Client) GetRawTransaction(hash util.Uint256) (*transaction.Transaction,
if err != nil { if err != nil {
return nil, err return nil, err
} }
r := io.NewBinReaderFromBuf(txBytes) tx, err := transaction.NewTransactionFromBytes(txBytes)
tx := new(transaction.Transaction) if err != nil {
tx.DecodeBinary(r) return nil, err
if r.Err != nil {
return nil, r.Err
} }
return tx, nil return tx, nil
} }

View file

@ -37,7 +37,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return c.GetAccountState("") return c.GetAccountState("")
}, },
serverResponse: `{"jsonrpc":"2.0","id": 1,"result":{"version":0,"script_hash":"0x1179716da2e9523d153a35fb3ad10c561b1e5b1a","frozen":false,"votes":[],"balances":[{"asset":"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","value":"94"}]}}`, serverResponse: `{"jsonrpc":"2.0","id": 1,"result":{"version":0,"script_hash":"0x1179716da2e9523d153a35fb3ad10c561b1e5b1a","frozen":false,"votes":[],"balances":[{"asset":"0xcd3a3b5654465238c3a4ac30eeb1bfd1171378d59b27f7d2e6893ce9d6150825","value":"94"}]}}`,
result: func(c *Client) interface{} { result: func(c *Client) interface{} {
scriptHash, err := util.Uint160DecodeStringLE("1179716da2e9523d153a35fb3ad10c561b1e5b1a") scriptHash, err := util.Uint160DecodeStringLE("1179716da2e9523d153a35fb3ad10c561b1e5b1a")
if err != nil { if err != nil {
@ -96,7 +96,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return c.GetAssetState(util.Uint256{}) return c.GetAssetState(util.Uint256{})
}, },
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":"0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","type":0,"name":"NEO","amount":"100000000","available":"100000000","precision":0,"owner":"00","admin":"Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":4000000,"is_frozen":false}}`, serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"id":"0xcd3a3b5654465238c3a4ac30eeb1bfd1171378d59b27f7d2e6893ce9d6150825","type":0,"name":"NEO","amount":"100000000","available":"100000000","precision":0,"owner":"00","admin":"Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt","issuer":"AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM","expiration":4000000,"is_frozen":false}}`,
result: func(c *Client) interface{} { result: func(c *Client) interface{} {
return &result.AssetState{ return &result.AssetState{
ID: core.GoverningTokenID(), ID: core.GoverningTokenID(),
@ -180,16 +180,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil { if err != nil {
panic(err) panic(err)
} }
tx := &transaction.Transaction{ tx := transaction.NewMinerTXWithNonce(4266257741)
Type: transaction.MinerType,
Version: 0,
Data: &transaction.MinerTX{Nonce: 4266257741},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
}
// Update hashes for correct result comparison. // Update hashes for correct result comparison.
_ = tx.Hash() _ = tx.Hash()
return &result.Block{ return &result.Block{
@ -275,16 +266,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil { if err != nil {
panic(err) panic(err)
} }
tx := &transaction.Transaction{ tx := transaction.NewMinerTXWithNonce(4266257741)
Type: transaction.MinerType,
Version: 0,
Data: &transaction.MinerTX{Nonce: 4266257741},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
}
// Update hashes for correct result comparison. // Update hashes for correct result comparison.
_ = tx.Hash() _ = tx.Hash()
return &result.Block{ return &result.Block{
@ -656,16 +638,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil { if err != nil {
panic(err) panic(err)
} }
tx := &transaction.Transaction{ tx := transaction.NewMinerTXWithNonce(4266257741)
Type: transaction.MinerType,
Version: 0,
Data: &transaction.MinerTX{Nonce: 4266257741},
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
}
// Update hashes for correct result comparison. // Update hashes for correct result comparison.
_ = tx.Hash() _ = tx.Hash()
@ -871,16 +844,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
{ {
name: "positive", name: "positive",
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(&transaction.Transaction{ return nil, c.SendRawTransaction(transaction.NewMinerTX())
Type: transaction.MinerType,
Version: 0,
Data: nil,
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
})
}, },
serverResponse: `{"jsonrpc":"2.0","id":1,"result":true}`, serverResponse: `{"jsonrpc":"2.0","id":1,"result":true}`,
result: func(c *Client) interface{} { result: func(c *Client) interface{} {
@ -1001,16 +965,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
{ {
name: "sendrawtransaction_bad_server_answer", name: "sendrawtransaction_bad_server_answer",
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(&transaction.Transaction{ return nil, c.SendRawTransaction(transaction.NewMinerTX())
Type: transaction.MinerType,
Version: 0,
Data: nil,
Attributes: []transaction.Attribute{},
Inputs: []transaction.Input{},
Outputs: []transaction.Output{},
Scripts: []transaction.Witness{},
Trimmed: false,
})
}, },
}, },
{ {
@ -1396,16 +1351,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
{ {
name: "sendrawtransaction_unmarshalling_error", name: "sendrawtransaction_unmarshalling_error",
invoke: func(c *Client) (interface{}, error) { invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(&transaction.Transaction{ return nil, c.SendRawTransaction(transaction.NewMinerTX())
Type: 0,
Version: 0,
Data: nil,
Attributes: nil,
Inputs: nil,
Outputs: nil,
Scripts: nil,
Trimmed: false,
})
}, },
}, },
{ {

View file

@ -932,10 +932,8 @@ func (s *Server) sendrawtransaction(reqParams request.Params) (interface{}, erro
} else if byteTx, err := reqParams[0].GetBytesHex(); err != nil { } else if byteTx, err := reqParams[0].GetBytesHex(); err != nil {
return nil, response.ErrInvalidParams return nil, response.ErrInvalidParams
} else { } else {
r := io.NewBinReaderFromBuf(byteTx) tx, err := transaction.NewTransactionFromBytes(byteTx)
tx := &transaction.Transaction{} if err != nil {
tx.DecodeBinary(r)
if r.Err != nil {
return nil, response.ErrInvalidParams return nil, response.ErrInvalidParams
} }
relayReason := s.coreServer.RelayTxn(tx) relayReason := s.coreServer.RelayTxn(tx)

View file

@ -17,7 +17,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/internal/random"
"github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/rpc/response" "github.com/nspcc-dev/neo-go/pkg/rpc/response"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result" "github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
@ -50,14 +49,14 @@ var rpcTestCases = map[string][]rpcTestCase{
"getapplicationlog": { "getapplicationlog": {
{ {
name: "positive", name: "positive",
params: `["93670859cc8a42f6ea994869c944879678d33d7501d388f5a446a8c7de147df7"]`, params: `["0d77a6c348097c4b29fd9d0fe8657c621bc7d804034c71272e3c4f13775138f2"]`,
result: func(e *executor) interface{} { return &result.ApplicationLog{} }, result: func(e *executor) interface{} { return &result.ApplicationLog{} },
check: func(t *testing.T, e *executor, acc interface{}) { check: func(t *testing.T, e *executor, acc interface{}) {
res, ok := acc.(*result.ApplicationLog) res, ok := acc.(*result.ApplicationLog)
require.True(t, ok) require.True(t, ok)
expectedTxHash, err := util.Uint256DecodeStringLE("93670859cc8a42f6ea994869c944879678d33d7501d388f5a446a8c7de147df7") expectedTxHash, err := util.Uint256DecodeStringLE("0d77a6c348097c4b29fd9d0fe8657c621bc7d804034c71272e3c4f13775138f2")
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, expectedTxHash, res.TxHash) assert.Equal(t, expectedTxHash, res.TxHash)
assert.Equal(t, 1, len(res.Executions)) assert.Equal(t, 1, len(res.Executions))
@ -252,7 +251,7 @@ var rpcTestCases = map[string][]rpcTestCase{
"getassetstate": { "getassetstate": {
{ {
name: "positive", name: "positive",
params: `["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"]`, params: `["057ea06225860f0f7e69cca1e0052652918629929591b8138a516431be144ba8"]`,
result: func(e *executor) interface{} { return &result.AssetState{} }, result: func(e *executor) interface{} { return &result.AssetState{} },
check: func(t *testing.T, e *executor, as interface{}) { check: func(t *testing.T, e *executor, as interface{}) {
res, ok := as.(*result.AssetState) res, ok := as.(*result.AssetState)
@ -339,9 +338,9 @@ var rpcTestCases = map[string][]rpcTestCase{
tx := res.Tx[i] tx := res.Tx[i]
require.Equal(t, transaction.MinerType, tx.Transaction.Type) require.Equal(t, transaction.MinerType, tx.Transaction.Type)
miner, ok := block.Transactions[i].Data.(*transaction.MinerTX) miner := block.Transactions[i]
require.True(t, ok) require.True(t, ok)
require.Equal(t, miner.Nonce, tx.Transaction.Data.(*transaction.MinerTX).Nonce) require.Equal(t, miner.Nonce, tx.Transaction.Nonce)
require.Equal(t, block.Transactions[i].Hash(), tx.Transaction.Hash()) require.Equal(t, block.Transactions[i].Hash(), tx.Transaction.Hash())
} }
}, },
@ -406,25 +405,25 @@ var rpcTestCases = map[string][]rpcTestCase{
"getblockheader": { "getblockheader": {
{ {
name: "positive, no verbose", name: "positive, no verbose",
params: `["614a9085dc55fd0539ad3a9d68d8b8e7c52328da905c87bfe8cfca57a5c3c02f"]`, params: `["7c32645dab0d87cfaddd5db053e2430c669f807e9efc2b91d1f50a824893352f"]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee651cb8a5e010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd04014057de8968705f020995662b60c15133846425ea2f786757f2a0fd8845f0d33f6ec35b2ef77a882e4d7560d7667dbf9a6c4b74a51d9e4c52ddce26dd6731047bb340720cd95db06a799c3d121a3b75347c002b0fdc09b45bc2dd5f7fd79c6f674ca9a97cf9c7aff2c8a6ec9f0eefab29a2ae1a758b122f83f4dc34b4d6fa1266b5ae407987727d9a5345d45966e0a6b8e372efc4ce3695c73a2d2f94ba00eee1ce0a75d86ffa60bcfc673c8abc971bf2576ed9c82d5371a235d0168a2fed1ef722f06740c2385bbb75ca72665a2d4f7a9b6ef7f529cd90d55b08bfbaccf4edeee86343e915bb25c5deca6ce2fd9114c44a8963bdfc430d987923caa8ed5f6fb20f81fabe8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00" expected := "000000002534685cc322d339f957ea368a654bf30b834be4cac0b8441375cce2a37630625507db78d2a2f3130c6073bd68f57202248fdc8966fa8706e88eb0fc61df74085384945e010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140b622b3bdddb8c5e52ae8b4bce5665eb6e2aca950ba72386ea0d37e364af2c7fc40f009c47e1a2140bee90d1e2f81c705d6f2499fe6230b27d1f225c45f38d3c440ec01e743024c2c63dccb2ca4a555eeadb2e6115fe6bc42a8d5c17093828e4ea779b36c6d1535c70c047c709183fc1c93139153291dd0edb614dd3e17d67038dd400f7635816214254b7fba0bb480e2a0ab149c84854adcb542124e67f4cedbf551690f8048271c3f05bbe50f576dcbaf3607afffa2551480cdc24908df0fd47c60408d724d6cfb9bf99e38dc42974f084d110057d3f23a04f5bbf99f5712dad17ae842416bb3e30fee034a317280565cb772f8a61fd09cb05e76db27c5fc7722819f8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
return &expected return &expected
}, },
}, },
{ {
name: "positive, verbose 0", name: "positive, verbose 0",
params: `["614a9085dc55fd0539ad3a9d68d8b8e7c52328da905c87bfe8cfca57a5c3c02f", 0]`, params: `["7c32645dab0d87cfaddd5db053e2430c669f807e9efc2b91d1f50a824893352f", 0]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
expected := "00000000999086db552ba8f84734bddca55b25a8d3d8c5f866f941209169c38d35376e995f2f29c4685140d85073fec705089706553eae4de3c95d9d8d425af36e597ee651cb8a5e010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd04014057de8968705f020995662b60c15133846425ea2f786757f2a0fd8845f0d33f6ec35b2ef77a882e4d7560d7667dbf9a6c4b74a51d9e4c52ddce26dd6731047bb340720cd95db06a799c3d121a3b75347c002b0fdc09b45bc2dd5f7fd79c6f674ca9a97cf9c7aff2c8a6ec9f0eefab29a2ae1a758b122f83f4dc34b4d6fa1266b5ae407987727d9a5345d45966e0a6b8e372efc4ce3695c73a2d2f94ba00eee1ce0a75d86ffa60bcfc673c8abc971bf2576ed9c82d5371a235d0168a2fed1ef722f06740c2385bbb75ca72665a2d4f7a9b6ef7f529cd90d55b08bfbaccf4edeee86343e915bb25c5deca6ce2fd9114c44a8963bdfc430d987923caa8ed5f6fb20f81fabe8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00" expected := "000000002534685cc322d339f957ea368a654bf30b834be4cac0b8441375cce2a37630625507db78d2a2f3130c6073bd68f57202248fdc8966fa8706e88eb0fc61df74085384945e010000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140b622b3bdddb8c5e52ae8b4bce5665eb6e2aca950ba72386ea0d37e364af2c7fc40f009c47e1a2140bee90d1e2f81c705d6f2499fe6230b27d1f225c45f38d3c440ec01e743024c2c63dccb2ca4a555eeadb2e6115fe6bc42a8d5c17093828e4ea779b36c6d1535c70c047c709183fc1c93139153291dd0edb614dd3e17d67038dd400f7635816214254b7fba0bb480e2a0ab149c84854adcb542124e67f4cedbf551690f8048271c3f05bbe50f576dcbaf3607afffa2551480cdc24908df0fd47c60408d724d6cfb9bf99e38dc42974f084d110057d3f23a04f5bbf99f5712dad17ae842416bb3e30fee034a317280565cb772f8a61fd09cb05e76db27c5fc7722819f8b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"
return &expected return &expected
}, },
}, },
{ {
name: "positive, verbose !=0", name: "positive, verbose !=0",
params: `["614a9085dc55fd0539ad3a9d68d8b8e7c52328da905c87bfe8cfca57a5c3c02f", 2]`, params: `["7c32645dab0d87cfaddd5db053e2430c669f807e9efc2b91d1f50a824893352f", 2]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
hash, err := util.Uint256DecodeStringLE("614a9085dc55fd0539ad3a9d68d8b8e7c52328da905c87bfe8cfca57a5c3c02f") hash, err := util.Uint256DecodeStringLE("7c32645dab0d87cfaddd5db053e2430c669f807e9efc2b91d1f50a824893352f")
if err != nil { if err != nil {
panic("can not decode hash parameter") panic("can not decode hash parameter")
} }
@ -521,7 +520,7 @@ var rpcTestCases = map[string][]rpcTestCase{
params: `["AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU"]`, params: `["AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU"]`,
result: func(*executor) interface{} { result: func(*executor) interface{} {
// hash of the issueTx // hash of the issueTx
h, _ := util.Uint256DecodeStringBE("6da730b566db183bfceb863b780cd92dee2b497e5a023c322c1eaca81cf9ad7a") h, _ := util.Uint256DecodeStringBE("6a46738cd6f821d3b2d96e68c3feb5fcfe81d08a711baadbb68cbfb034fa29c5")
amount := util.Fixed8FromInt64(1 * 8) // (endHeight - startHeight) * genAmount[0] amount := util.Fixed8FromInt64(1 * 8) // (endHeight - startHeight) * genAmount[0]
return &result.ClaimableInfo{ return &result.ClaimableInfo{
Spents: []result.Claimable{ Spents: []result.Claimable{
@ -580,9 +579,9 @@ var rpcTestCases = map[string][]rpcTestCase{
"gettransactionheight": { "gettransactionheight": {
{ {
name: "poositive", name: "poositive",
params: `["3fee783413c27849c8ee2656fd757a7483de64f4e78bd7897f30ecdf42ce788b"]`, params: `["3fe72668fa667b8bb0a77ac2375402d52fafc18e6d0a4c12a401dc69bdf515c2"]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
h := 202 h := 1
return &h return &h
}, },
}, },
@ -792,7 +791,7 @@ var rpcTestCases = map[string][]rpcTestCase{
"sendrawtransaction": { "sendrawtransaction": {
{ {
name: "positive", name: "positive",
params: `["d1001b00046e616d6567d3d8602814a429a91afdbaa3914884a1c90c733101201cc9c05cefffe6cdd7b182816a9152ec218d2ec000000141403387ef7940a5764259621e655b3c621a6aafd869a611ad64adcc364d8dd1edf84e00a7f8b11b630a377eaef02791d1c289d711c08b7ad04ff0d6c9caca22cfe6232103cbb45da6072c14761c9da545749d9cfd863f860c351066d16df480602a2024c6ac"]`, params: `["80001300000000015b090ad71ea0c192adc820401b2edc6a197788ee8e5e42a9c5e5e00d700c5da1010001250815d6e93c89e6d2f7279bd5781317d1bfb1ee30aca4c338524654563b3acd0030d3dec38623002baa76ad534b886cb87c6b3720a34943d9000fa90141409646e3dd0dd87685eadac1f682fa63db83729f780a7b2e739cb372ceeaadb3f19260060b34c83fec46e48a6288b2bc5c641e75d1cb358e9c185425a2e6e3fdab232102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2ac"]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
v := true v := true
return &v return &v
@ -821,8 +820,9 @@ var rpcTestCases = map[string][]rpcTestCase{
}, },
"submitblock": { "submitblock": {
{ {
// If you are planning to modify test chain from `testblocks.acc`, please, update param value (first block)
name: "empty block", name: "empty block",
params: `["00000000399183d238a2a5a11ae4f2263fa5372a2fc488ad1bb0782b83e66d7fc89637d9000000000000000000000000000000000000000000000000000000000000000021cc8a5ed10000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd04014090fb6263dc6a3009947999d1320844fb08929748ef3c0a6647194a637dea2c4454bfc97cafb1ce46f7df25529ff5f195f62fc455d929b4e89d5a974ad0f6bfdd40b9d36fceb1e3cadbcc88d2d0b6f481c6c3af45fa20b91682d7aed6493bdeed7ee602aeb7f50ea09b6ee5332f9f95f180fa6b3033be4a6c1208e40d75fe73c8804005dcc45a2a94c036597381e6fd3c4f76977f61fdc25f7e99d60577a970a6eeb543b6133b9b6387ec60babe25fb8dd4bfe9874e06c864f21059664c9b4a0f214c40fde0dfd49c32920d2a17bad0acd68b25180aeb137f82fdbd5794ece3d42bf699539928a30413fc9fd367b34465189a740ff41f0861318847fbc77cbe005bb6918b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"]`, params: `["00000000565f6b8fab486930d5ece5feb93060f010b556b2d4aa618878326ed93604ed6400000000000000000000000000000000000000000000000000000000000000002385945ed10000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd0401408313b36a61c137d327bec8791dfbb22ae9627fbcd2b023236f65188376f1ff4913c554b276cf7e84c5446fb495df2ed7cd34577ef9a4f9dd0dd27654aa53abe040acf3d5327c50e08bf97d794b6ec021223b8c493f9b71f8844446a01a99e555d517d30b84cbb2a5dcbafb5171373f4d0e6c8aea54f46901455d62545f75bdd2a640c359e2365bfe6f9b7b58a09e7e78f2bee85dbb4f823f9bee31b297cb2eb804eb4a5f1858a729d9676ab2c63b91bee5726c7b38086a04f3fe0ca23155331c476840dfddf4c173a374aacff6d2f37b327256556aa37d7c38c41dfda1f42d25f33d921b41da271aa27f7872f7b2b0b00f90a7ee83f5823ea1cc4f9db90a0100a8b7868b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae00"]`,
fail: true, fail: true,
}, },
{ {
@ -847,8 +847,8 @@ var rpcTestCases = map[string][]rpcTestCase{
}, },
{ {
name: "positive", name: "positive",
// If you are planning to modify test chain from `testblocks.acc`, please, update param value // If you are planning to modify test chain from `testblocks.acc`, please, update param value (second block)
params: `["00000000399183d238a2a5a11ae4f2263fa5372a2fc488ad1bb0782b83e66d7fc89637d9edb908054ac1409be5f77d5369c6e03490b2f6676d68d0b3370f8159e0fdadf921cc8a5ed10000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd0401401b2c9a188c2bf0b14c59dca4c2fccc14664d815204573824d2bc7899aed43e4023d321ce28551875e7459de494d368ffe0d8b04502694640dfe0db795a52b3c340c06924f3f0de04045ab09cb51a7944219fe9f69fbf9c9770fed7712930b1a0e58dd13e78c76afff1c7d7316cf5ff55981917f8c243a33858163557a3f7d0270f4057675127a0355f24ffa2c28b742def8d4c39b4ef79b098028da182a48385608472d3fbed598b806f60b834196222b4d1bc2a65cf465de7fcedba4103dd510ae54036f06134debb8bbecfef297fb98070e242d5eefd607622110adc645d90d40779065819871c739598f04b9ee7311ebaaa048ac403a19542c5b0d2ccf1ba5e16968b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae0100000000000000000000"]`, params: `["00000000565f6b8fab486930d5ece5feb93060f010b556b2d4aa618878326ed93604ed645c23aae5b26be3d759680239a4276be0d2e76de303ef3fda96da97e8a3f6a0f12385945ed10000005704000000000000be48d3a3f5d10013ab9ffee489706078714f1ea201fd040140accd1571b3c25e4a6ec80f3bfc8ca3360f51232ed615b756e88424c1c083bd4c0d37f98156c8b87a36710467a75ff3938acea5bbd6a683d439004e2a30665562405de64537c7a411055504bec46851101a3ee9a3db02a7fb0feff781bee43a71ff7e76e03f273437bb94ad1f58dbe29eff32d9299bae0f48860a89a74ed5a48900400a337ce23f8dd767d043ba2b0886ba25d3905a1493ba70a96b297179914d096dfb8621f40e5efa63205af46b8ae71198846affcf02b9137752fcf3d54a683faa408d54fcd4d5235ff48b8dbe7d6f2e0b75ea3dc1bcd563ae44c8c8df201f5039fd30357d8c6709a0639a4aef07a223ca2ae21a74494808bc8b8f2955e7b26bdd148b532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae0100001400000000000000"]`,
result: func(e *executor) interface{} { result: func(e *executor) interface{} {
v := true v := true
return &v return &v
@ -921,7 +921,7 @@ func TestRPC(t *testing.T) {
var res string var res string
err := json.Unmarshal(result, &res) err := json.Unmarshal(result, &res)
require.NoErrorf(t, err, "could not parse response: %s", result) require.NoErrorf(t, err, "could not parse response: %s", result)
assert.Equal(t, "400000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000", res) assert.Equal(t, "40000000000000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000", res)
}) })
t.Run("getrawtransaction 2 arguments", func(t *testing.T) { t.Run("getrawtransaction 2 arguments", func(t *testing.T) {
@ -933,7 +933,7 @@ func TestRPC(t *testing.T) {
var res string var res string
err := json.Unmarshal(result, &res) err := json.Unmarshal(result, &res)
require.NoErrorf(t, err, "could not parse response: %s", result) require.NoErrorf(t, err, "could not parse response: %s", result)
assert.Equal(t, "400000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000", res) assert.Equal(t, "40000000000000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000", res)
}) })
t.Run("getrawtransaction 2 arguments, verbose", func(t *testing.T) { t.Run("getrawtransaction 2 arguments, verbose", func(t *testing.T) {
@ -973,7 +973,7 @@ func TestRPC(t *testing.T) {
err := json.Unmarshal(res, &txOut) err := json.Unmarshal(res, &txOut)
require.NoErrorf(t, err, "could not parse response: %s", res) require.NoErrorf(t, err, "could not parse response: %s", res)
assert.Equal(t, 0, txOut.N) assert.Equal(t, 0, txOut.N)
assert.Equal(t, "0x9b7cffdaa674beae0f930ebe6085af9093e5fe56b34a5c220ccdcf6efc336fc5", txOut.Asset) assert.Equal(t, "0x250815d6e93c89e6d2f7279bd5781317d1bfb1ee30aca4c338524654563b3acd", txOut.Asset)
assert.Equal(t, util.Fixed8FromInt64(100000000), txOut.Value) assert.Equal(t, util.Fixed8FromInt64(100000000), txOut.Value)
assert.Equal(t, "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU", txOut.Address) assert.Equal(t, "AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU", txOut.Address)
}) })
@ -986,12 +986,7 @@ func TestRPC(t *testing.T) {
expected = append(expected, tx.Tx.Hash()) expected = append(expected, tx.Tx.Hash())
} }
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
tx := &transaction.Transaction{ tx := transaction.NewMinerTX()
Type: transaction.MinerType,
Data: &transaction.MinerTX{
Nonce: uint32(random.Int(0, 1000000000)),
},
}
assert.NoError(t, mp.Add(tx, &FeerStub{})) assert.NoError(t, mp.Add(tx, &FeerStub{}))
expected = append(expected, tx.Hash()) expected = append(expected, tx.Hash())
} }

Binary file not shown.