core: replace makeBlocks() with addBlocks() in tests

This simplifies tests a bit.
This commit is contained in:
Evgenii Stratonikov 2020-02-29 17:16:13 +03:00
parent a2b9d85c80
commit 8ca94e23c8
2 changed files with 17 additions and 40 deletions

View file

@ -96,12 +96,15 @@ func newBlock(index uint32, txs ...*transaction.Transaction) *block.Block {
return b
}
func makeBlocks(n int) []*block.Block {
func (bc *Blockchain) genBlocks(n int) ([]*block.Block, error) {
blocks := make([]*block.Block, n)
for i := 0; i < n; i++ {
blocks[i] = newBlock(uint32(i+1), newMinerTX())
blocks[i] = newBlock(uint32(i)+1, newMinerTX())
if err := bc.AddBlock(blocks[i]); err != nil {
return blocks, err
}
}
return blocks
return blocks, nil
}
func newMinerTX() *transaction.Transaction {
@ -175,13 +178,8 @@ func newDumbBlock() *block.Block {
func _(t *testing.T) {
bc := newTestChain(t)
n := 50
blocks := makeBlocks(n)
for i := 0; i < len(blocks); i++ {
if err := bc.AddBlock(blocks[i]); err != nil {
t.Fatal(err)
}
}
_, err := bc.genBlocks(n)
require.NoError(t, err)
tx1 := newMinerTX()