*: drop miner transaction

1. Completely remove miner transaction

2. Change validation rule for block: block without transactions is
valid.
This commit is contained in:
Anna Shaleva 2020-04-22 20:42:38 +03:00
parent 55fd9f8d24
commit 29d321b5e1
24 changed files with 128 additions and 314 deletions

View file

@ -48,7 +48,7 @@ func TestNeoBlock_Setters(t *testing.T) {
b.SetPrevHash(util.Uint256{9, 8, 7})
require.Equal(t, util.Uint256{9, 8, 7}, b.PrevHash())
txx := []block.Transaction{transaction.NewMinerTX()}
txx := []block.Transaction{transaction.NewIssueTX()}
b.SetTransactions(txx)
require.Equal(t, txx, b.Transactions())
}

View file

@ -2,7 +2,6 @@ package consensus
import (
"errors"
"math/rand"
"sort"
"time"
@ -10,7 +9,6 @@ import (
"github.com/nspcc-dev/dbft/block"
"github.com/nspcc-dev/dbft/crypto"
"github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/neo-go/pkg/core"
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
@ -276,7 +274,6 @@ func (s *service) OnPayload(cp *Payload) {
switch cp.Type() {
case payload.PrepareRequestType:
req := cp.GetPrepareRequest().(*prepareRequest)
s.txx.Add(&req.minerTx)
s.lastProposal = req.transactionHashes
}
@ -316,12 +313,6 @@ func (s *service) GetPayload(h util.Uint256) *Payload {
}
func (s *service) broadcast(p payload.ConsensusPayload) {
switch p.Type() {
case payload.PrepareRequestType:
pr := p.GetPrepareRequest().(*prepareRequest)
pr.minerTx = *s.txx.Get(pr.transactionHashes[0]).(*transaction.Transaction)
}
if err := p.(*Payload).Sign(s.dbft.Priv.(*privateKey)); err != nil {
s.log.Warn("can't sign consensus payload", zap.Error(err))
}
@ -442,40 +433,11 @@ func (s *service) getVerifiedTx(count int) []block.Transaction {
txx = s.Config.Chain.ApplyPolicyToTxSet(txx)
}
res := make([]block.Transaction, len(txx)+1)
var netFee util.Fixed8
res := make([]block.Transaction, len(txx))
for i := range txx {
res[i+1] = txx[i].Tx
netFee += txx[i].Fee
res[i] = txx[i].Tx
}
var txOuts []transaction.Output
if netFee != 0 {
sh := s.wallet.GetChangeAddress()
if sh.Equals(util.Uint160{}) {
pk := s.dbft.Pub.(*publicKey)
sh = pk.GetScriptHash()
}
txOuts = []transaction.Output{{
AssetID: core.UtilityTokenID(),
Amount: netFee,
ScriptHash: sh,
}}
}
for {
minerTx := transaction.NewMinerTX()
minerTx.Outputs = txOuts
minerTx.ValidUntilBlock = s.dbft.BlockIndex
minerTx.Nonce = rand.Uint32()
res[0] = minerTx
if tx, _, _ := s.Chain.GetTransaction(res[0].Hash()); tx == nil {
break
}
}
s.txx.Add(res[0])
return res
}

View file

@ -22,7 +22,7 @@ import (
func TestNewService(t *testing.T) {
srv := newTestService(t)
tx := transaction.NewMinerTX()
tx := transaction.NewContractTX()
tx.ValidUntilBlock = 1
addSender(t, tx)
signTx(t, tx)
@ -30,8 +30,8 @@ func TestNewService(t *testing.T) {
var txx []block.Transaction
require.NotPanics(t, func() { txx = srv.getVerifiedTx(1) })
require.Len(t, txx, 2)
require.Equal(t, tx, txx[1])
require.Len(t, txx, 1)
require.Equal(t, tx, txx[0])
srv.Chain.Close()
}
@ -39,7 +39,8 @@ func TestService_GetVerified(t *testing.T) {
srv := newTestService(t)
var txs []*transaction.Transaction
for i := 0; i < 4; i++ {
tx := transaction.NewMinerTXWithNonce(123 + uint32(i))
tx := transaction.NewContractTX()
tx.Nonce = 123 + uint32(i)
tx.ValidUntilBlock = 1
txs = append(txs, tx)
}
@ -52,7 +53,9 @@ func TestService_GetVerified(t *testing.T) {
p := new(Payload)
p.message = &message{}
p.SetType(payload.PrepareRequestType)
p.SetPayload(&prepareRequest{transactionHashes: hashes, minerTx: *transaction.NewMinerTXWithNonce(999)})
tx := transaction.NewContractTX()
tx.Nonce = 999
p.SetPayload(&prepareRequest{transactionHashes: hashes})
p.SetValidatorIndex(1)
priv, _ := getTestValidator(1)
@ -65,8 +68,8 @@ func TestService_GetVerified(t *testing.T) {
t.Run("new transactions will be proposed in case of failure", func(t *testing.T) {
txx := srv.getVerifiedTx(10)
require.Equal(t, 2, len(txx), "there is only 1 tx in mempool")
require.Equal(t, txs[3], txx[1])
require.Equal(t, 1, len(txx), "there is only 1 tx in mempool")
require.Equal(t, txs[3], txx[0])
})
t.Run("more than half of the last proposal will be reused", func(t *testing.T) {
@ -117,7 +120,8 @@ func TestService_getTx(t *testing.T) {
srv := newTestService(t)
t.Run("transaction in mempool", func(t *testing.T) {
tx := transaction.NewMinerTXWithNonce(1234)
tx := transaction.NewContractTX()
tx.Nonce = 1234
tx.ValidUntilBlock = 1
addSender(t, tx)
signTx(t, tx)
@ -133,7 +137,8 @@ func TestService_getTx(t *testing.T) {
})
t.Run("transaction in local cache", func(t *testing.T) {
tx := transaction.NewMinerTXWithNonce(4321)
tx := transaction.NewContractTX()
tx.Nonce = 4321
tx.ValidUntilBlock = 1
h := tx.Hash()

View file

@ -246,11 +246,9 @@ func randomPrepareRequest(t *testing.T) *prepareRequest {
timestamp: rand.Uint64(),
nonce: rand.Uint64(),
transactionHashes: make([]util.Uint256, txCount),
minerTx: *transaction.NewMinerTX(),
}
req.transactionHashes[0] = req.minerTx.Hash()
for i := 1; i < txCount; i++ {
for i := 0; i < txCount; i++ {
req.transactionHashes[i] = random.Uint256()
}
req.nextConsensus = random.Uint160()

View file

@ -2,7 +2,6 @@ package consensus
import (
"github.com/nspcc-dev/dbft/payload"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
)
@ -12,7 +11,6 @@ type prepareRequest struct {
timestamp uint64
nonce uint64
transactionHashes []util.Uint256
minerTx transaction.Transaction
nextConsensus util.Uint160
}
@ -24,7 +22,6 @@ func (p *prepareRequest) EncodeBinary(w *io.BinWriter) {
w.WriteU64LE(p.nonce)
w.WriteBytes(p.nextConsensus[:])
w.WriteArray(p.transactionHashes)
p.minerTx.EncodeBinary(w)
}
// DecodeBinary implements io.Serializable interface.
@ -33,7 +30,6 @@ func (p *prepareRequest) DecodeBinary(r *io.BinReader) {
p.nonce = r.ReadU64LE()
r.ReadBytes(p.nextConsensus[:])
r.ReadArray(&p.transactionHashes)
p.minerTx.DecodeBinary(r)
}
// Timestamp implements payload.PrepareRequest interface.

View file

@ -5,7 +5,6 @@ import (
"github.com/nspcc-dev/dbft/crypto"
"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/util"
"github.com/stretchr/testify/require"
@ -32,7 +31,6 @@ func TestRecoveryMessage_Setters(t *testing.T) {
timestamp: 87,
nonce: 321,
transactionHashes: []util.Uint256{{1}},
minerTx: *transaction.NewMinerTX(),
nextConsensus: util.Uint160{1, 2},
}
p1 := new(Payload)

View file

@ -2,7 +2,6 @@ package block
import (
"errors"
"fmt"
"github.com/Workiva/go-datastructures/queue"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
@ -57,20 +56,6 @@ func (b *Block) RebuildMerkleRoot() error {
// Verify verifies the integrity of the block.
func (b *Block) Verify() error {
// There has to be some transaction inside.
if len(b.Transactions) == 0 {
return errors.New("no transactions")
}
// The first TX has to be a miner transaction.
if b.Transactions[0].Type != transaction.MinerType {
return fmt.Errorf("the first transaction is %s", b.Transactions[0].Type)
}
// If the first TX is a minerTX then all others cant.
for _, tx := range b.Transactions[1:] {
if tx.Type == transaction.MinerType {
return fmt.Errorf("miner transaction %s is not the first one", tx.Hash().StringLE())
}
}
merkle, err := b.computeMerkleTree()
if err != nil {
return err

View file

@ -84,7 +84,6 @@ func newDumbBlock() *Block {
Nonce: 1111,
},
Transactions: []*transaction.Transaction{
transaction.NewMinerTX(),
transaction.NewIssueTX(),
},
}
@ -102,25 +101,9 @@ func TestBlockVerify(t *testing.T) {
assert.Nil(t, block.RebuildMerkleRoot())
assert.Nil(t, block.Verify())
block.Transactions = []*transaction.Transaction{
transaction.NewIssueTX(),
transaction.NewMinerTX(),
}
block.Transactions = []*transaction.Transaction{}
assert.NoError(t, block.RebuildMerkleRoot())
assert.NotNil(t, block.Verify())
block.Transactions = []*transaction.Transaction{
transaction.NewIssueTX(),
transaction.NewMinerTX(),
}
assert.NoError(t, block.RebuildMerkleRoot())
assert.NotNil(t, block.Verify())
block.Transactions = []*transaction.Transaction{
transaction.NewMinerTX(),
transaction.NewIssueTX(),
transaction.NewIssueTX(),
}
assert.NotNil(t, block.Verify())
assert.Nil(t, block.Verify())
}
//TODO NEO3.0: Update binary

View file

@ -914,9 +914,6 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*block.Block, error) {
if err != nil {
return nil, err
}
if len(block.Transactions) == 0 {
return nil, fmt.Errorf("only header is available")
}
for _, tx := range block.Transactions {
stx, _, err := bc.dao.GetTransaction(tx.Hash())
if err != nil {
@ -1118,7 +1115,7 @@ func (bc *Blockchain) FeePerByte(t *transaction.Transaction) util.Fixed8 {
// NetworkFee returns network fee.
func (bc *Blockchain) NetworkFee(t *transaction.Transaction) util.Fixed8 {
// https://github.com/neo-project/neo/blob/master-2.x/neo/Network/P2P/Payloads/ClaimTransaction.cs#L16
if t.Type == transaction.ClaimType || t.Type == transaction.MinerType {
if t.Type == transaction.ClaimType {
return 0
}
@ -1455,7 +1452,7 @@ func (bc *Blockchain) verifyResults(t *transaction.Transaction, results []*trans
}
switch t.Type {
case transaction.MinerType, transaction.ClaimType:
case transaction.ClaimType:
for _, r := range resultsIssue {
if r.AssetID != UtilityTokenID() {
return errors.New("miner or claim tx issues non-utility tokens")

View file

@ -97,7 +97,7 @@ func TestScriptFromWitness(t *testing.T) {
func TestGetHeader(t *testing.T) {
bc := newTestChain(t)
tx := transaction.NewMinerTX()
tx := transaction.NewContractTX()
tx.ValidUntilBlock = bc.BlockHeight() + 1
assert.Nil(t, addSender(tx))
assert.Nil(t, signTx(bc, tx))

View file

@ -83,17 +83,7 @@ func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
lastHash := bc.topBlock.Load().(*block.Block).Hash()
lastIndex := bc.topBlock.Load().(*block.Block).Index
for i := 0; i < n; i++ {
minerTx := transaction.NewMinerTXWithNonce(uint32(1234 + i))
minerTx.ValidUntilBlock = lastIndex + uint32(i) + 1
err := addSender(minerTx)
if err != nil {
return nil, err
}
err = signTx(bc, minerTx)
if err != nil {
return nil, err
}
blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash, minerTx)
blocks[i] = newBlock(bc.config, uint32(i)+lastIndex+1, lastHash)
if err := bc.AddBlock(blocks[i]); err != nil {
return blocks, err
}
@ -146,7 +136,6 @@ func newDumbBlock() *block.Block {
Nonce: 1111,
},
Transactions: []*transaction.Transaction{
{Type: transaction.MinerType},
{Type: transaction.IssueType},
},
}
@ -181,13 +170,6 @@ func TestCreateBasicChain(t *testing.T) {
return testNonce
}
// Creates new miner tx with specified validUntilBlock field
nextMinerTx := func(validUntilBlock uint32) *transaction.Transaction {
minerTx := transaction.NewMinerTXWithNonce(getNextNonce())
minerTx.ValidUntilBlock = validUntilBlock
return minerTx
}
var neoAmount = util.Fixed8FromInt64(99999000)
var neoRemainder = util.Fixed8FromInt64(100000000) - neoAmount
bc := newTestChain(t)
@ -201,8 +183,8 @@ func TestCreateBasicChain(t *testing.T) {
// use output of issue tx from genesis block as an input
genesisBlock, err := bc.GetBlock(bc.GetHeaderHash(0))
require.NoError(t, err)
require.Equal(t, 5, len(genesisBlock.Transactions))
h := genesisBlock.Transactions[3].Hash()
require.Equal(t, 4, len(genesisBlock.Transactions))
h := genesisBlock.Transactions[2].Hash()
txMoveNeo.AddInput(&transaction.Input{
PrevHash: h,
PrevIndex: 0,
@ -225,12 +207,8 @@ func TestCreateBasicChain(t *testing.T) {
Position: 1,
})
txMoveNeo.Data = new(transaction.ContractTX)
minerTx := nextMinerTx(validUntilBlock)
minerTx.Sender = neoOwner
require.NoError(t, signTx(bc, minerTx, txMoveNeo))
b := bc.newBlock(minerTx, txMoveNeo)
require.NoError(t, signTx(bc, txMoveNeo))
b := bc.newBlock(txMoveNeo)
require.NoError(t, bc.AddBlock(b))
t.Logf("txMoveNeo: %s", txMoveNeo.Hash().StringLE())
@ -264,10 +242,7 @@ func TestCreateBasicChain(t *testing.T) {
})
txNeoRound.Data = new(transaction.ContractTX)
require.NoError(t, acc0.SignTx(txNeoRound))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, txNeoRound)
b = bc.newBlock(txNeoRound)
require.NoError(t, bc.AddBlock(b))
t.Logf("txNeoRound: %s", txNeoRound.Hash().StringLE())
@ -291,10 +266,7 @@ func TestCreateBasicChain(t *testing.T) {
Position: 0,
})
require.NoError(t, acc0.SignTx(txClaim))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, txClaim)
b = bc.newBlock(txClaim)
require.NoError(t, bc.AddBlock(b))
t.Logf("txClaim: %s", txClaim.Hash().StringLE())
@ -337,10 +309,7 @@ func TestCreateBasicChain(t *testing.T) {
})
gasOwned -= invFee
require.NoError(t, acc0.SignTx(txDeploy))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, txDeploy)
b = bc.newBlock(txDeploy)
require.NoError(t, bc.AddBlock(b))
t.Logf("txDeploy: %s", txDeploy.Hash().StringLE())
@ -353,10 +322,7 @@ func TestCreateBasicChain(t *testing.T) {
txInv.ValidUntilBlock = validUntilBlock
txInv.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(txInv))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, txInv)
b = bc.newBlock(txInv)
require.NoError(t, bc.AddBlock(b))
t.Logf("txInv: %s", txInv.Hash().StringLE())
@ -382,10 +348,7 @@ func TestCreateBasicChain(t *testing.T) {
})
require.NoError(t, acc0.SignTx(txNeo0to1))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, txNeo0to1)
b = bc.newBlock(txNeo0to1)
require.NoError(t, bc.AddBlock(b))
sh := hash.Hash160(avm)
@ -402,10 +365,7 @@ func TestCreateBasicChain(t *testing.T) {
transferTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(transferTx))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, initTx, transferTx)
b = bc.newBlock(initTx, transferTx)
require.NoError(t, bc.AddBlock(b))
transferTx = newNEP5Transfer(sh, priv0.GetScriptHash(), priv1.GetScriptHash(), 123)
@ -414,10 +374,7 @@ func TestCreateBasicChain(t *testing.T) {
transferTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(transferTx))
minerTx = nextMinerTx(validUntilBlock)
minerTx.Sender = priv0ScriptHash
require.NoError(t, acc0.SignTx(minerTx))
b = bc.newBlock(minerTx, transferTx)
b = bc.newBlock(transferTx)
require.NoError(t, bc.AddBlock(b))
if saveChain {

View file

@ -36,7 +36,8 @@ func (fs *FeerStub) SystemFee(*transaction.Transaction) util.Fixed8 {
func testMemPoolAddRemoveWithFeer(t *testing.T, fs Feer) {
mp := NewMemPool(10)
tx := transaction.NewMinerTXWithNonce(0)
tx := transaction.NewContractTX()
tx.Nonce = 0
_, _, ok := mp.TryGetValue(tx.Hash())
require.Equal(t, false, ok)
require.NoError(t, mp.Add(tx, fs))
@ -72,8 +73,8 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
mpLessClaims := func(i, j int) bool {
return mp.claims[i].Cmp(mp.claims[j]) < 0
}
txm1 := transaction.NewMinerTXWithNonce(1)
txm1 := transaction.NewContractTX()
txm1.Nonce = 1
txc1, claim1 := newClaimTX()
for i := 0; i < 5; i++ {
txm1.Inputs = append(txm1.Inputs, transaction.Input{PrevHash: hash1, PrevIndex: uint16(100 - i)})
@ -87,7 +88,8 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
assert.Equal(t, len(claim1.Claims), len(mp.claims))
assert.True(t, sort.SliceIsSorted(mp.claims, mpLessClaims))
txm2 := transaction.NewMinerTXWithNonce(1)
txm2 := transaction.NewContractTX()
txm2.Nonce = 1
txc2, claim2 := newClaimTX()
for i := 0; i < 10; i++ {
txm2.Inputs = append(txm2.Inputs, transaction.Input{PrevHash: hash2, PrevIndex: uint16(i)})
@ -128,19 +130,22 @@ func TestMemPoolAddRemoveWithInputsAndClaims(t *testing.T) {
func TestMemPoolVerifyInputs(t *testing.T) {
mp := NewMemPool(10)
tx := transaction.NewMinerTXWithNonce(1)
tx := transaction.NewContractTX()
tx.Nonce = 1
inhash1 := random.Uint256()
tx.Inputs = append(tx.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 0})
require.Equal(t, true, mp.Verify(tx))
require.NoError(t, mp.Add(tx, &FeerStub{}))
tx2 := transaction.NewMinerTXWithNonce(2)
tx2 := transaction.NewContractTX()
tx2.Nonce = 2
inhash2 := random.Uint256()
tx2.Inputs = append(tx2.Inputs, transaction.Input{PrevHash: inhash2, PrevIndex: 0})
require.Equal(t, true, mp.Verify(tx2))
require.NoError(t, mp.Add(tx2, &FeerStub{}))
tx3 := transaction.NewMinerTXWithNonce(3)
tx3 := transaction.NewContractTX()
tx3.Nonce = 3
// Different index number, but the same PrevHash as in tx1.
tx3.Inputs = append(tx3.Inputs, transaction.Input{PrevHash: inhash1, PrevIndex: 1})
require.Equal(t, true, mp.Verify(tx3))
@ -211,7 +216,8 @@ func TestOverCapacity(t *testing.T) {
mp := NewMemPool(mempoolSize)
for i := 0; i < mempoolSize; i++ {
tx := transaction.NewMinerTXWithNonce(uint32(i))
tx := transaction.NewContractTX()
tx.Nonce = uint32(i)
require.NoError(t, mp.Add(tx, fs))
}
txcnt := uint32(mempoolSize)
@ -231,7 +237,8 @@ func TestOverCapacity(t *testing.T) {
// Fees are also prioritized.
fs.netFee = util.Fixed8FromFloat(0.0001)
for i := 0; i < mempoolSize-1; i++ {
tx := transaction.NewMinerTXWithNonce(txcnt)
tx := transaction.NewContractTX()
tx.Nonce = txcnt
txcnt++
require.NoError(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
@ -239,7 +246,8 @@ func TestOverCapacity(t *testing.T) {
}
// Less prioritized txes are not allowed anymore.
fs.netFee = util.Fixed8FromFloat(0.00001)
tx := transaction.NewMinerTXWithNonce(txcnt)
tx := transaction.NewContractTX()
tx.Nonce = txcnt
txcnt++
require.Error(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
@ -250,7 +258,8 @@ func TestOverCapacity(t *testing.T) {
// Low net fee, but higher per-byte fee is still a better combination.
fs.perByteFee = util.Fixed8FromFloat(0.001)
tx = transaction.NewMinerTXWithNonce(txcnt)
tx = transaction.NewContractTX()
tx.Nonce = txcnt
txcnt++
require.NoError(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
@ -259,7 +268,8 @@ func TestOverCapacity(t *testing.T) {
// High priority always wins over low priority.
fs.lowPriority = false
for i := 0; i < mempoolSize; i++ {
tx := transaction.NewMinerTXWithNonce(txcnt)
tx := transaction.NewContractTX()
tx.Nonce = txcnt
txcnt++
require.NoError(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
@ -267,7 +277,8 @@ func TestOverCapacity(t *testing.T) {
}
// Good luck with low priority now.
fs.lowPriority = true
tx = transaction.NewMinerTXWithNonce(txcnt)
tx = transaction.NewContractTX()
tx.Nonce = txcnt
require.Error(t, mp.Add(tx, fs))
require.Equal(t, mempoolSize, mp.Count())
require.Equal(t, true, sort.IsSorted(sort.Reverse(mp.verifiedTxes)))
@ -280,7 +291,8 @@ func TestGetVerified(t *testing.T) {
txes := make([]*transaction.Transaction, 0, mempoolSize)
for i := 0; i < mempoolSize; i++ {
tx := transaction.NewMinerTXWithNonce(uint32(i))
tx := transaction.NewContractTX()
tx.Nonce = uint32(i)
txes = append(txes, tx)
require.NoError(t, mp.Add(tx, fs))
}
@ -305,7 +317,8 @@ func TestRemoveStale(t *testing.T) {
txes1 := make([]*transaction.Transaction, 0, mempoolSize/2)
txes2 := make([]*transaction.Transaction, 0, mempoolSize/2)
for i := 0; i < mempoolSize; i++ {
tx := transaction.NewMinerTXWithNonce(uint32(i))
tx := transaction.NewContractTX()
tx.Nonce = uint32(i)
if i%2 == 0 {
txes1 = append(txes1, tx)
} else {

View file

@ -2,7 +2,6 @@ package core
import (
"errors"
"math/rand"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
@ -90,13 +89,11 @@ func TestNativeContract_Invoke(t *testing.T) {
emit.AppCallWithOperationAndArgs(w.BinWriter, tn.Metadata().Hash, "sum", int64(14), int64(28))
script := w.Bytes()
tx := transaction.NewInvocationTX(script, 0)
mn := transaction.NewMinerTXWithNonce(rand.Uint32())
validUntil := chain.blockHeight + 1
tx.ValidUntilBlock = validUntil
mn.ValidUntilBlock = validUntil
require.NoError(t, addSender(tx, mn))
require.NoError(t, signTx(chain, tx, mn))
b := chain.newBlock(mn, tx)
require.NoError(t, addSender(tx))
require.NoError(t, signTx(chain, tx))
b := chain.newBlock(tx)
require.NoError(t, chain.AddBlock(b))
res, err := chain.GetAppExecResult(tx.Hash())

View file

@ -1,38 +0,0 @@
package transaction
import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io"
)
// MinerTX represents a miner transaction.
type MinerTX struct{}
// 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.
func (tx *MinerTX) DecodeBinary(r *io.BinReader) {
}
// EncodeBinary implements Serializable interface.
func (tx *MinerTX) EncodeBinary(w *io.BinWriter) {
}

View file

@ -1,21 +0,0 @@
package transaction
// TODO NEO3.0: Update binary
/*
func TestEncodeDecodeMiner(t *testing.T) {
// transaction from mainnet a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264
rawtx := "0000fcd30e22000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60c8000000000000001f72e68b4e39602912106d53b229378a082784b200"
tx := decodeTransaction(rawtx, t)
assert.Equal(t, MinerType, tx.Type)
assert.IsType(t, tx.Data, &MinerTX{})
assert.Equal(t, 0, int(tx.Version))
assert.Equal(t, uint32(571397116), tx.Nonce)
assert.Equal(t, "a1f219dc6be4c35eca172e65e02d4591045220221b1543f1a4b67b9e9442c264", tx.Hash().StringLE())
// Encode
data, err := testserdes.EncodeBinary(tx)
assert.NoError(t, err)
assert.Equal(t, rawtx, hex.EncodeToString(data))
}
*/

View file

@ -148,9 +148,6 @@ func (t *Transaction) decodeData(r *io.BinReader) {
case InvocationType:
t.Data = &InvocationTX{Version: t.Version}
t.Data.(*InvocationTX).DecodeBinary(r)
case MinerType:
t.Data = &MinerTX{}
t.Data.(*MinerTX).DecodeBinary(r)
case ClaimType:
t.Data = &ClaimTX{}
t.Data.(*ClaimTX).DecodeBinary(r)
@ -335,8 +332,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
}
t.Sender = sender
switch tx.Type {
case MinerType:
t.Data = &MinerTX{}
case ClaimType:
t.Data = &ClaimTX{
Claims: tx.Claims,

View file

@ -120,12 +120,6 @@ func TestMarshalUnmarshalJSONContractTX(t *testing.T) {
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}
func TestMarshalUnmarshalJSONMinerTX(t *testing.T) {
tx := NewMinerTX()
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}
func TestMarshalUnmarshalJSONClaimTX(t *testing.T) {
tx := &Transaction{
Type: ClaimType,

View file

@ -11,7 +11,6 @@ type TXType uint8
// Constants for all valid transaction types.
const (
MinerType TXType = 0x00
IssueType TXType = 0x01
ClaimType TXType = 0x02
RegisterType TXType = 0x40
@ -22,8 +21,6 @@ const (
// String implements the stringer interface.
func (t TXType) String() string {
switch t {
case MinerType:
return "MinerTransaction"
case IssueType:
return "IssueTransaction"
case ClaimType:
@ -58,8 +55,6 @@ func (t *TXType) UnmarshalJSON(data []byte) error {
// TXTypeFromString searches for TXType by string name.
func TXTypeFromString(jsonString string) (TXType, error) {
switch jsonString = strings.TrimSpace(jsonString); jsonString {
case "MinerTransaction":
return MinerType, nil
case "IssueTransaction":
return IssueType, nil
case "ClaimTransaction":

View file

@ -59,9 +59,6 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
}
scriptOut := hash.Hash160(rawScript)
minerTx := transaction.NewMinerTXWithNonce(2083236893)
minerTx.Sender = hash.Hash160([]byte{byte(opcode.PUSH1)})
issueTx := transaction.NewIssueTX()
// TODO NEO3.0: nonce should be constant to avoid variability of genesis block
issueTx.Nonce = 0
@ -83,7 +80,6 @@ func createGenesisBlock(cfg config.ProtocolConfiguration) (*block.Block, error)
b := &block.Block{
Base: base,
Transactions: []*transaction.Transaction{
minerTx,
&governingTokenTX,
&utilityTokenTX,
issueTx,

View file

@ -20,7 +20,7 @@ func TestGenesisBlockMainNet(t *testing.T) {
// 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 := "4dce83edc5bb9cbdf23d37cfb81dd3c8fc0c331c608d2d893289ae36a62a41eb"
expect := "16ffda4cc6a9b0a0ca63f1571f7724418c43f014e2eb4e8614b4938ccf0f20f6"
assert.Equal(t, expect, block.Hash().StringLE())
}

View file

@ -803,9 +803,6 @@ func (s *Server) relayBlock(b *block.Block) {
// verifyAndPoolTX verifies the TX and adds it to the local mempool.
func (s *Server) verifyAndPoolTX(t *transaction.Transaction) RelayReason {
if t.Type == transaction.MinerType {
return RelayInvalid
}
if err := s.chain.PoolTx(t); err != nil {
switch err {
case core.ErrAlreadyExists:

View file

@ -136,17 +136,17 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (interface{}, error) {
return c.GetBlockByIndex(5)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000000062af8cd56d179044215cc8611f75bd96d896f1026c5b42994ae7707df8d82bd3c9f774f449fec7135b506faffaaeee603e2b82e01dec7d0f706789aa1bb983ae0ec7a25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c7763594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000000000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"000000005b25cf560918b13cc7a10071cf616426a103d58498171567aaa116af69179aa3c05c359ade4316392d69d5ca01f8860f8bdebbe1a8f752edd68d9a6a2d204fe752cca25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000008000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab794130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
result: func(c *Client) interface{} { return &block.Block{} },
check: func(t *testing.T, c *Client, result interface{}) {
res, ok := result.(*block.Block)
require.True(t, ok)
assert.Equal(t, uint32(0), res.Version)
assert.Equal(t, "424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9", res.Hash().StringLE())
assert.Equal(t, "d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62", res.PrevHash.StringLE())
assert.Equal(t, "ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9", res.MerkleRoot.StringLE())
assert.Equal(t, "81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb", res.Hash().StringLE())
assert.Equal(t, "a39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b", res.PrevHash.StringLE())
assert.Equal(t, "e74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0", res.MerkleRoot.StringLE())
assert.Equal(t, 1, len(res.Transactions))
assert.Equal(t, "ae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54", res.Transactions[0].Hash().StringLE())
assert.Equal(t, "69d95138263dc54c07826ef1d76f9eb32ff6bf7fc3fc3281194b46ec7683ceb3", res.Transactions[0].Hash().StringLE())
},
},
{
@ -154,25 +154,25 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
invoke: func(c *Client) (i interface{}, err error) {
return c.GetBlockByIndexVerbose(5)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9","size":977,"version":0,"nextblockhash":"0xc2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3","previousblockhash":"0xd32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62","merkleroot":"0xae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9","time":1587726094,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0xae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54","size":450,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb","size":977,"version":0,"nextblockhash":"0xd08e408909ae24de3470a3f231f966e15719910cb7b1a30f356b3e784c1ddf6a","previousblockhash":"0xa39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b","merkleroot":"0xe74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0","time":1587727442,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf8","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0x69d95138263dc54c07826ef1d76f9eb32ff6bf7fc3fc3281194b46ec7683ceb3","size":450,"type":"ContractTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
result: func(c *Client) interface{} {
hash, err := util.Uint256DecodeStringLE("424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9")
hash, err := util.Uint256DecodeStringLE("81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb")
if err != nil {
panic(err)
}
nextBlockHash, err := util.Uint256DecodeStringLE("c2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3")
nextBlockHash, err := util.Uint256DecodeStringLE("d08e408909ae24de3470a3f231f966e15719910cb7b1a30f356b3e784c1ddf6a")
if err != nil {
panic(err)
}
prevBlockHash, err := util.Uint256DecodeStringLE("d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62")
prevBlockHash, err := util.Uint256DecodeStringLE("a39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b")
if err != nil {
panic(err)
}
merkleRoot, err := util.Uint256DecodeStringLE("ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9")
merkleRoot, err := util.Uint256DecodeStringLE("e74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0")
if err != nil {
panic(err)
}
invScript, err := hex.DecodeString("0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635")
invScript, err := hex.DecodeString("0c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf8")
if err != nil {
panic(err)
}
@ -184,7 +184,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil {
panic(err)
}
txInvScript, err := hex.DecodeString("0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce")
txInvScript, err := hex.DecodeString("0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7")
if err != nil {
panic(err)
}
@ -192,7 +192,8 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil {
panic(err)
}
tx := transaction.NewMinerTXWithNonce(1237)
tx := transaction.NewContractTX()
tx.Nonce = 1237
tx.ValidUntilBlock = 5
tx.Sender = sender
tx.Scripts = []transaction.Witness{
@ -210,7 +211,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
NextBlockHash: &nextBlockHash,
PreviousBlockHash: prevBlockHash,
MerkleRoot: merkleRoot,
Time: 1587726094,
Time: 1587727442,
Index: 5,
NextConsensus: "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy",
Confirmations: 203,
@ -241,47 +242,47 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
}
return c.GetBlockByHash(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000000062af8cd56d179044215cc8611f75bd96d896f1026c5b42994ae7707df8d82bd3c9f774f449fec7135b506faffaaeee603e2b82e01dec7d0f706789aa1bb983ae0ec7a25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c7763594130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000000000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce94130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"000000005b25cf560918b13cc7a10071cf616426a103d58498171567aaa116af69179aa3c05c359ade4316392d69d5ca01f8860f8bdebbe1a8f752edd68d9a6a2d204fe752cca25e0000000005000000e903736ceceeceae1806eee0e3ec61e7cce476ce01fd08010c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf894130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb020057040000000000008000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab794130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
result: func(c *Client) interface{} { return &block.Block{} },
check: func(t *testing.T, c *Client, result interface{}) {
res, ok := result.(*block.Block)
require.True(t, ok)
assert.Equal(t, uint32(0), res.Version)
assert.Equal(t, "424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9", res.Hash().StringLE())
assert.Equal(t, "d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62", res.PrevHash.StringLE())
assert.Equal(t, "ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9", res.MerkleRoot.StringLE())
assert.Equal(t, "81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb", res.Hash().StringLE())
assert.Equal(t, "a39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b", res.PrevHash.StringLE())
assert.Equal(t, "e74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0", res.MerkleRoot.StringLE())
assert.Equal(t, 1, len(res.Transactions))
assert.Equal(t, "ae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54", res.Transactions[0].Hash().StringLE())
assert.Equal(t, "69d95138263dc54c07826ef1d76f9eb32ff6bf7fc3fc3281194b46ec7683ceb3", res.Transactions[0].Hash().StringLE())
},
},
{
name: "byHash_verbose_positive",
invoke: func(c *Client) (i interface{}, err error) {
hash, err := util.Uint256DecodeStringLE("e9f71b58764157f1e2c3e29f217e654b57956ee7c8a60496b03ea85e39084b42")
hash, err := util.Uint256DecodeStringLE("bb09d40563c7141215b024b0959aec00a3ab316248c2ee31f32ea4c3cf4db781")
if err != nil {
panic(err)
}
return c.GetBlockByHashVerbose(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9","size":977,"version":0,"nextblockhash":"0xc2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3","previousblockhash":"0xd32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62","merkleroot":"0xae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9","time":1587726094,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0xae63e96d984673b038c83cfcb94323e37bdab29a53921823544b50df9f7edb54","size":450,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"hash":"0x81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb","size":977,"version":0,"nextblockhash":"0xd08e408909ae24de3470a3f231f966e15719910cb7b1a30f356b3e784c1ddf6a","previousblockhash":"0xa39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b","merkleroot":"0xe74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0","time":1587727442,"index":5,"consensus_data":{"primary":0,"nonce":"0000000000000457"},"nextconsensus":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","confirmations":203,"script":{"invocation":"0c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf8","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"},"tx":[{"sys_fee":"0","net_fee":"0","txid":"0x69d95138263dc54c07826ef1d76f9eb32ff6bf7fc3fc3281194b46ec7683ceb3","size":450,"type":"ContractTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}]}}`,
result: func(c *Client) interface{} {
hash, err := util.Uint256DecodeStringLE("424b08395ea83eb09604a6c8e76e95574b657e219fe2c3e2f1574176581bf7e9")
hash, err := util.Uint256DecodeStringLE("81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb")
if err != nil {
panic(err)
}
nextBlockHash, err := util.Uint256DecodeStringLE("c2ce96d861414ad229101cc9afaec4ae500f730a2180b54bd14a8dd6147bc8c3")
nextBlockHash, err := util.Uint256DecodeStringLE("d08e408909ae24de3470a3f231f966e15719910cb7b1a30f356b3e784c1ddf6a")
if err != nil {
panic(err)
}
prevBlockHash, err := util.Uint256DecodeStringLE("d32bd8f87d70e74a99425b6c02f196d896bd751f61c85c214490176dd58caf62")
prevBlockHash, err := util.Uint256DecodeStringLE("a39a1769af16a1aa6715179884d503a1266461cf7100a1c73cb1180956cf255b")
if err != nil {
panic(err)
}
merkleRoot, err := util.Uint256DecodeStringLE("ae83b91baa8967700f7dec1de0822b3e60eeaefaaf6f505b13c7fe49f474f7c9")
merkleRoot, err := util.Uint256DecodeStringLE("e74f202d6a9a8dd6ed52f7a8e1bbde8b0f86f801cad5692d391643de9a355cc0")
if err != nil {
panic(err)
}
invScript, err := hex.DecodeString("0c408e48ace06fdd7d9bf536b6cb683f7edd336c60a707df8110f69121273fe7e0353e574c55abf2961ac4f7f2bfef44af07e6121f42e5e2115517b29060e3a7dd3e0c40d56609addaa61f06d9df159f7008ffb889d605742baaf7f95a8283469d6e5a4a76c5814f24efa0452e3c6723d88e43833e917551808d05aca8d46a17f25c72440c40fa0b66a2a41933e39685f7cbf45ba0cef286b3eed5f7d1cb60db4bac3a9c55212efb5b1f4a4c5512b2562f8e0a2ebfbc8951734ca53243ec963bd6839773f5910c40c1c0de79304d8ad7e204dceb880325694e5c34abb25ff23beb61e931ecf384e4f06c13a5ea56273c400ecac9408a3eb8e8cf3b0b358f7b2b6ac5120bb5c77635")
invScript, err := hex.DecodeString("0c407f70912fdcd0ce9a70963110eb39ef73ed02512ea63bc1c55577474df8f364a874999b16666888f8a3ca69873054a31ab42dd1fee1ed8605ff65edb39797e34e0c40d59459cb1cc8270d9a813aa444852a5d7714aed0b25373ec07549349c6db32b6c8c2e43cdd7b1ad2a4154cb5ff1222d9d7010877016a59775abdd2c08f253c850c4048b65cb58e0d58f2dd0f5db3b195c5784933d6179d8317217ba46f9deac9a667bffb1afd0dd86bdae6267af4c2605f7401849a0b980fcecfeae95df7f5ca6e140c406d9b1942c5aa80070ad484b3dd76421a3f46327670bea94e3ecb3a94eef8843a75195b55872a7c503acb01ab368cdaa11a9e5fb80d55bbd6b861233ba84edcf8")
if err != nil {
panic(err)
}
@ -293,7 +294,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil {
panic(err)
}
txInvScript, err := hex.DecodeString("0c40a9c72069ad0365a8f0787a236ec60293a9846172e9cdeaeb665586d6c72545bcfa694422f8ccd3e76bce7e27ac8099cc9b3f6322bcfeaf971c9b481a1a308a350c4048f7c2a176a7c8eb73f881aacb0a5bc52bb3b2eeeb2341031496aaadbc043dda02d8c79935ac27ecda0dc7c2561af056946e82ff1a819b56461ad32fce83ab960c4036a238579bbe505150f2ea2e4172eb83cfd614af00c1cfe36791a1eb12cb5565f37668fa09a0fcb2528fffe377c96ec9d63d18aa19a5d6c24c5c97034d1811250c4007c3826543bc03b3b6cecf48fb30ff24033c1aad7a946ac6c54e7fa90173ff3b0fe181936079fc0e7030bdde2b655ae3a7101b8a0bd85fc98de83bb72739a9ce")
txInvScript, err := hex.DecodeString("0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7")
if err != nil {
panic(err)
}
@ -301,7 +302,8 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
if err != nil {
panic(err)
}
tx := transaction.NewMinerTXWithNonce(1237)
tx := transaction.NewContractTX()
tx.Nonce = 1237
tx.ValidUntilBlock = 5
tx.Sender = sender
tx.Scripts = []transaction.Witness{
@ -319,7 +321,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
NextBlockHash: &nextBlockHash,
PreviousBlockHash: prevBlockHash,
MerkleRoot: merkleRoot,
Time: 1587726094,
Time: 1587727442,
Index: 5,
NextConsensus: "Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy",
Confirmations: 203,
@ -651,51 +653,52 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
{
name: "positive",
invoke: func(c *Client) (i interface{}, err error) {
hash, err := util.Uint256DecodeStringLE("675b5bd2a90a1f5e74b2e4386162240318f86534f4d3061722ba78b4fe10fe53")
hash, err := util.Uint256DecodeStringLE("b3ce8376ec464b198132fcc37fbff62fb39e6fd7f16e82074cc53d263851d969")
if err != nil {
panic(err)
}
return c.GetRawTransaction(hash)
},
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"0000d5040000d60ac443bb800fb08261e75fa5925d747d4858610500000000000001fd040140947358ca2dd7543c3ff3f6ea1389a72c3d5ee99f47a9d0ef70bd84a9f57384e76271efc682f6741568c55907b1794b9f520f7d35f39382303bf0206945b5009a409f467419a886aebe6b482e6d5787981d98b58b82959a2858045bf5683665a5c25c502481b2d9655c902c5dcc147546bed58175c2ed16f328cc21e999e19741554063cab34f1613932947a1c346416b12b1ca724198016acc5fd760597539eed74f2069cfe2a8383e99595aefa3234d79d64a39e3f4c64e8cea800469a6f790999c408e2438fab244bdb79e67f6dab9cde0063e523bd0c175657a66e84897cd15eec8bf358661666679bf50334664872616faa366825f36873b16dd2add64c418cd5794534c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e4c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd624c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc24c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee6995450683073b3bb"}`,
serverResponse: `{"id":1,"jsonrpc":"2.0","result":"8000d5040000e903736ceceeceae1806eee0e3ec61e7cce476ce0500000000000001fd08010c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab794130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}`,
result: func(c *Client) interface{} { return &transaction.Transaction{} },
check: func(t *testing.T, c *Client, result interface{}) {
res, ok := result.(*transaction.Transaction)
require.True(t, ok)
assert.Equal(t, uint8(0), res.Version)
assert.Equal(t, "675b5bd2a90a1f5e74b2e4386162240318f86534f4d3061722ba78b4fe10fe53", res.Hash().StringBE())
assert.Equal(t, transaction.MinerType, res.Type)
assert.Equal(t, "b3ce8376ec464b198132fcc37fbff62fb39e6fd7f16e82074cc53d263851d969", res.Hash().StringBE())
assert.Equal(t, transaction.ContractType, res.Type)
assert.Equal(t, false, res.Trimmed)
},
},
{
name: "verbose_positive",
invoke: func(c *Client) (interface{}, error) {
hash, err := util.Uint256DecodeStringLE("265f271088384b2f696e34bea0c8e02cf226351800c0866c1586be521536e579")
hash, err := util.Uint256DecodeStringLE("b3ce8376ec464b198132fcc37fbff62fb39e6fd7f16e82074cc53d263851d969")
if err != nil {
panic(err)
}
return c.GetRawTransactionVerbose(hash)
},
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sys_fee":"0","net_fee":"0","blockhash":"0x66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906","confirmations":205,"blocktime":1587379353,"txid":"0x79e5361552be86156c86c000183526f22ce0c8a0be346e692f4b388810275f26","size":437,"type":"MinerTransaction","version":0,"nonce":1237,"sender":"AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd","verification":"532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae"}]}}`,
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"sys_fee":"0","net_fee":"0","blockhash":"0x81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb","confirmations":205,"blocktime":1587727442,"txid":"0x69d95138263dc54c07826ef1d76f9eb32ff6bf7fc3fc3281194b46ec7683ceb3","size":450,"type":"ContractTransaction","version":0,"nonce":1237,"sender":"Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy","valid_until_block":5,"attributes":[],"vin":[],"vout":[],"scripts":[{"invocation":"0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7","verification":"130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb"}]}}`,
result: func(c *Client) interface{} {
blockHash, err := util.Uint256DecodeStringLE("66d1c140fbdc0eaa47e69a6a9c5034ebc3a449db98da565191ab863d1a079906")
blockHash, err := util.Uint256DecodeStringLE("81b74dcfc3a42ef331eec2486231aba300ec9a95b024b0151214c76305d409bb")
if err != nil {
panic(err)
}
sender, err := address.StringToUint160("AZ81H31DMWzbSnFDLFkzh9vHwaDLayV7fU")
sender, err := address.StringToUint160("Ad1wDxzcRiRSryvJobNV211Tv7UUiziPXy")
if err != nil {
panic(err)
}
invocation, err := hex.DecodeString("40f50121bb6ec9d8e0d1c15eea66b2ff7b51bb1bc4b3da27d9eac1d46b59e6a319bb1db4eb710c7f1931b0c2deaa2389a0fc3fe8c761cec40906b7973450c43173402dc082417a6815e722216de0b857eda6c846bf435088d543d2ab89f1dd92488e87b4d2c6508b0db945cbe6968e85c1c6d57274bfc898e82876c5cb08613da5d64053100f0162a41709a37305c300e7d6ac0d46575aab98dade7375b8d9ca980086594f1288dc68da0e0e42913d1c68024f63442a79c9478971d3ad93c5467ec53040a1c3a772a88b09cba8cc8ec3b46c0c0db6ac86519a7fd7db29b43d34e804a22d8839eaeb35e2a1e05d591fbad4ae290b90c6dc02dddbe28b2b3bf0fec2a337dd")
invocation, err := hex.DecodeString("0c40ae62dadb95b21628921adb9ee14e8c1f20d68b9d6ffba218f8e403af70126449435a53525cd6f1d1c871e64a91025866cd8a413ec70e3cde0ddf62931aa22baa0c40c3e09fc8ad46789d645240634ef40bd180e0dba75beae07a37dc2e899b68b4b3b3a67d076ea9444ed143dbb3264702914a4662ff95859d32c9b5bb5bdc9ec1d60c40b2511115482bd860d85f57103fb8cce2cb45ba8461d4e164685b426cb5df1525e6f09dd7aa23db0fec2241bde7c925e22f3cba3824ea461455515dc2a1455f5e0c40c0aee2528e7fd75a0434f4d67da58507e8d349ca29e01e7eafa9f283e8b8c05d06587db7234f111730c14c8a4bfb7a1ffd9493b9696c71e68966c6bf4a832ab7")
if err != nil {
panic(err)
}
verification, err := hex.DecodeString("532102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd622102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc22103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee69954ae")
verification, err := hex.DecodeString("130c2102103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e0c2102a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd620c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20c2103d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699140b683073b3bb")
if err != nil {
panic(err)
}
tx := transaction.NewMinerTXWithNonce(1237)
tx := transaction.NewContractTX()
tx.Nonce = 1237
tx.ValidUntilBlock = 5
tx.Sender = sender
tx.Scripts = []transaction.Witness{
@ -714,7 +717,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
NetFee: 0,
Blockhash: blockHash,
Confirmations: 205,
Timestamp: uint64(1587379353),
Timestamp: uint64(1587727442),
},
}
},
@ -909,7 +912,7 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
{
name: "positive",
invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(transaction.NewMinerTX())
return nil, c.SendRawTransaction(transaction.NewContractTX())
},
serverResponse: `{"jsonrpc":"2.0","id":1,"result":true}`,
result: func(c *Client) interface{} {
@ -1030,7 +1033,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
{
name: "sendrawtransaction_bad_server_answer",
invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(transaction.NewMinerTX())
return nil, c.SendRawTransaction(transaction.NewContractTX())
},
},
{
@ -1416,7 +1419,7 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
{
name: "sendrawtransaction_unmarshalling_error",
invoke: func(c *Client) (interface{}, error) {
return nil, c.SendRawTransaction(transaction.NewMinerTX())
return nil, c.SendRawTransaction(transaction.NewContractTX())
},
},
{

View file

@ -53,12 +53,12 @@ var rpcTestCases = map[string][]rpcTestCase{
"getapplicationlog": {
{
name: "positive",
params: `["4108062977676178e8453a8ef84a702e01bb35af8a65c7529d04704fcb5f1e0e"]`,
params: `["fe1a3678b16eca35209acf85397708eb0f1668e4045ad4cd5d2453d3bc0a0a6d"]`,
result: func(e *executor) interface{} { return &result.ApplicationLog{} },
check: func(t *testing.T, e *executor, acc interface{}) {
res, ok := acc.(*result.ApplicationLog)
require.True(t, ok)
expectedTxHash, err := util.Uint256DecodeStringLE("4108062977676178e8453a8ef84a702e01bb35af8a65c7529d04704fcb5f1e0e")
expectedTxHash, err := util.Uint256DecodeStringLE("fe1a3678b16eca35209acf85397708eb0f1668e4045ad4cd5d2453d3bc0a0a6d")
require.NoError(t, err)
assert.Equal(t, expectedTxHash, res.TxHash)
assert.Equal(t, 1, len(res.Executions))
@ -338,11 +338,11 @@ var rpcTestCases = map[string][]rpcTestCase{
assert.Equal(t, block.Hash(), res.Hash)
for i := range res.Tx {
tx := res.Tx[i]
require.Equal(t, transaction.MinerType, tx.Transaction.Type)
require.Equal(t, transaction.ContractType, tx.Transaction.Type)
miner := block.Transactions[i]
actualTx := block.Transactions[i]
require.True(t, ok)
require.Equal(t, miner.Nonce, tx.Transaction.Nonce)
require.Equal(t, actualTx.Nonce, tx.Transaction.Nonce)
require.Equal(t, block.Transactions[i].Hash(), tx.Transaction.Hash())
}
},
@ -743,7 +743,7 @@ var rpcTestCases = map[string][]rpcTestCase{
"sendrawtransaction": {
{
name: "positive",
params: `["80001300000075a94799633ed955dd85a8af314a5b435ab51903b00400000001eb15931b0544cbb9a283f934ab89a23e73cf90b9ca097bb327a0bcdcddf8ce2e010001f5bc5a9ac7b85a47be381260a06b5a1e7a667ce8f7d7c8baa5cfc6465571377a0030d3dec386230075a94799633ed955dd85a8af314a5b435ab5190301420c4082632495e555507a056eae951ad1893f27163dde40505340f6cf9578e20c3d7ec0c7e00f93cb2e770a7ce3e8a2910deabdd01fd966507a7a29106dd2add583ee290c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4"]`,
params: `["80000b00000075a94799633ed955dd85a8af314a5b435ab51903b004000000011e4db58df4326140a371d0b0cabecea70226b93157dfb561c73ba8db599ebcb6010001f5bc5a9ac7b85a47be381260a06b5a1e7a667ce8f7d7c8baa5cfc6465571377a0030d3dec386230075a94799633ed955dd85a8af314a5b435ab5190301420c401b3040b6eea83bfbd555554c94e7a0e6077922769f3ac19c1183e14dfd1d6ef6a87658b5499921ac59ae2d2acac10d8f0f6147620e27616bb5b7305fb36b6ce0290c2102b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc20b680a906ad4"]`,
result: func(e *executor) interface{} {
v := true
return &v
@ -857,7 +857,8 @@ func TestRPC(t *testing.T) {
require.NoError(t, err)
newTx := func() *transaction.Transaction {
height := chain.BlockHeight()
tx := transaction.NewMinerTXWithNonce(height + 1)
tx := transaction.NewContractTX()
tx.Nonce = height + 1
tx.ValidUntilBlock = height + 10
tx.Sender = acc.PrivateKey().GetScriptHash()
require.NoError(t, acc.SignTx(tx))
@ -882,7 +883,7 @@ func TestRPC(t *testing.T) {
t.Run("getrawtransaction", func(t *testing.T) {
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
TXHash := block.Transactions[1].Hash()
TXHash := block.Transactions[0].Hash()
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s"]}"`, TXHash.StringLE())
body := doRPCCall(rpc, handler, t)
result := checkErrGetResult(t, body, false)
@ -894,7 +895,7 @@ func TestRPC(t *testing.T) {
t.Run("getrawtransaction 2 arguments", func(t *testing.T) {
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
TXHash := block.Transactions[1].Hash()
TXHash := block.Transactions[0].Hash()
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s", 0]}"`, TXHash.StringLE())
body := doRPCCall(rpc, handler, t)
result := checkErrGetResult(t, body, false)
@ -906,7 +907,7 @@ func TestRPC(t *testing.T) {
t.Run("getrawtransaction 2 arguments, verbose", func(t *testing.T) {
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
TXHash := block.Transactions[1].Hash()
TXHash := block.Transactions[0].Hash()
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "getrawtransaction", "params": ["%s", 1]}"`, TXHash.StringLE())
body := doRPCCall(rpc, handler, t)
txOut := checkErrGetResult(t, body, false)
@ -979,7 +980,8 @@ func TestRPC(t *testing.T) {
t.Run("gettxout", func(t *testing.T) {
block, _ := chain.GetBlock(chain.GetHeaderHash(0))
tx := block.Transactions[3]
require.Equal(t, 4, len(block.Transactions))
tx := block.Transactions[2]
rpc := fmt.Sprintf(`{"jsonrpc": "2.0", "id": 1, "method": "gettxout", "params": [%s, %d]}"`,
`"`+tx.Hash().StringLE()+`"`, 0)
body := doRPCCall(rpc, handler, t)
@ -1002,7 +1004,7 @@ func TestRPC(t *testing.T) {
expected = append(expected, tx.Tx.Hash())
}
for i := 0; i < 5; i++ {
tx := transaction.NewMinerTX()
tx := transaction.NewContractTX()
assert.NoError(t, mp.Add(tx, &FeerStub{}))
expected = append(expected, tx.Hash())
}

Binary file not shown.