core: append transactions to the block in GetBlock()
We want to get a full block, so it has to have transactions inside. Unfortunately our tests were used to this wrong behavior and utilized completely bogus transactions without data that couldn't be persisted, so fix that also.
This commit is contained in:
parent
d007cc00cc
commit
258f397b9a
5 changed files with 28 additions and 13 deletions
|
@ -84,8 +84,8 @@ func TestHashBlockEqualsHashHeader(t *testing.T) {
|
|||
func TestBlockVerify(t *testing.T) {
|
||||
block := newBlock(
|
||||
0,
|
||||
newTX(transaction.MinerType),
|
||||
newTX(transaction.IssueType),
|
||||
newMinerTX(),
|
||||
newIssueTX(),
|
||||
)
|
||||
assert.True(t, block.Verify(false))
|
||||
|
||||
|
|
|
@ -523,6 +523,13 @@ func (bc *Blockchain) GetBlock(hash util.Uint256) (*Block, error) {
|
|||
if len(block.Transactions) == 0 {
|
||||
return nil, fmt.Errorf("only header is available")
|
||||
}
|
||||
for _, tx := range block.Transactions {
|
||||
stx, _, err := bc.GetTransaction(tx.Hash())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
*tx = *stx
|
||||
}
|
||||
return block, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/CityOfZion/neo-go/config"
|
||||
"github.com/CityOfZion/neo-go/pkg/core/storage"
|
||||
"github.com/CityOfZion/neo-go/pkg/core/transaction"
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -39,9 +38,9 @@ func TestAddHeaders(t *testing.T) {
|
|||
func TestAddBlock(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
blocks := []*Block{
|
||||
newBlock(1, newTX(transaction.MinerType)),
|
||||
newBlock(2, newTX(transaction.MinerType)),
|
||||
newBlock(3, newTX(transaction.MinerType)),
|
||||
newBlock(1, newMinerTX()),
|
||||
newBlock(2, newMinerTX()),
|
||||
newBlock(3, newMinerTX()),
|
||||
}
|
||||
|
||||
for i := 0; i < len(blocks); i++ {
|
||||
|
@ -70,7 +69,7 @@ func TestAddBlock(t *testing.T) {
|
|||
|
||||
func TestGetHeader(t *testing.T) {
|
||||
bc := newTestChain(t)
|
||||
block := newBlock(1, newTX(transaction.MinerType))
|
||||
block := newBlock(1, newMinerTX())
|
||||
err := bc.AddBlock(block)
|
||||
assert.Nil(t, err)
|
||||
|
||||
|
|
|
@ -40,14 +40,22 @@ func newBlock(index uint32, txs ...*transaction.Transaction) *Block {
|
|||
func makeBlocks(n int) []*Block {
|
||||
blocks := make([]*Block, n)
|
||||
for i := 0; i < n; i++ {
|
||||
blocks[i] = newBlock(uint32(i+1), newTX(transaction.MinerType))
|
||||
blocks[i] = newBlock(uint32(i+1), newMinerTX())
|
||||
}
|
||||
return blocks
|
||||
}
|
||||
|
||||
func newTX(t transaction.TXType) *transaction.Transaction {
|
||||
func newMinerTX() *transaction.Transaction {
|
||||
return &transaction.Transaction{
|
||||
Type: t,
|
||||
Type: transaction.MinerType,
|
||||
Data: &transaction.MinerTX{},
|
||||
}
|
||||
}
|
||||
|
||||
func newIssueTX() *transaction.Transaction {
|
||||
return &transaction.Transaction{
|
||||
Type: transaction.IssueType,
|
||||
Data: &transaction.IssueTX{},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -172,14 +172,15 @@ func initBlocks(t *testing.T, chain *core.Blockchain) {
|
|||
func makeBlocks(n int) []*core.Block {
|
||||
blocks := make([]*core.Block, n)
|
||||
for i := 0; i < n; i++ {
|
||||
blocks[i] = newBlock(uint32(i+1), newTX(transaction.MinerType))
|
||||
blocks[i] = newBlock(uint32(i+1), newMinerTX())
|
||||
}
|
||||
return blocks
|
||||
}
|
||||
|
||||
func newTX(t transaction.TXType) *transaction.Transaction {
|
||||
func newMinerTX() *transaction.Transaction {
|
||||
return &transaction.Transaction{
|
||||
Type: t,
|
||||
Type: transaction.MinerType,
|
||||
Data: &transaction.MinerTX{},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue