core: adjust persist-related Blockchain tests
`newTestChain` runs blockchain, so persist is likely already happened before the first test iteration. Explicit call to persist makes no sence here.
This commit is contained in:
parent
28e936eb95
commit
ff13af804d
1 changed files with 23 additions and 43 deletions
|
@ -232,8 +232,6 @@ func TestGetHeader(t *testing.T) {
|
||||||
err := bc.AddBlock(block)
|
err := bc.AddBlock(block)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// Test unpersisted and persisted access
|
|
||||||
for i := 0; i < 2; i++ {
|
|
||||||
hash := block.Hash()
|
hash := block.Hash()
|
||||||
header, err := bc.GetHeader(hash)
|
header, err := bc.GetHeader(hash)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -242,9 +240,6 @@ func TestGetHeader(t *testing.T) {
|
||||||
b2 := bc.newBlock()
|
b2 := bc.newBlock()
|
||||||
_, err = bc.GetHeader(b2.Hash())
|
_, err = bc.GetHeader(b2.Hash())
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
_, err = bc.persist(false)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBlock(t *testing.T) {
|
func TestGetBlock(t *testing.T) {
|
||||||
|
@ -252,17 +247,12 @@ func TestGetBlock(t *testing.T) {
|
||||||
blocks, err := bc.genBlocks(100)
|
blocks, err := bc.genBlocks(100)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Test unpersisted and persisted access
|
|
||||||
for j := 0; j < 2; j++ {
|
|
||||||
for i := 0; i < len(blocks); i++ {
|
for i := 0; i < len(blocks); i++ {
|
||||||
block, err := bc.GetBlock(blocks[i].Hash())
|
block, err := bc.GetBlock(blocks[i].Hash())
|
||||||
require.NoErrorf(t, err, "can't get block %d: %s, attempt %d", i, err, j)
|
require.NoErrorf(t, err, "can't get block %d: %s", i, err)
|
||||||
assert.Equal(t, blocks[i].Index, block.Index)
|
assert.Equal(t, blocks[i].Index, block.Index)
|
||||||
assert.Equal(t, blocks[i].Hash(), block.Hash())
|
assert.Equal(t, blocks[i].Hash(), block.Hash())
|
||||||
}
|
}
|
||||||
_, err = bc.persist(false)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Run("store only header", func(t *testing.T) {
|
t.Run("store only header", func(t *testing.T) {
|
||||||
t.Run("non-empty block", func(t *testing.T) {
|
t.Run("non-empty block", func(t *testing.T) {
|
||||||
|
@ -1315,16 +1305,11 @@ func TestHasBlock(t *testing.T) {
|
||||||
blocks, err := bc.genBlocks(50)
|
blocks, err := bc.genBlocks(50)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Test unpersisted and persisted access
|
|
||||||
for j := 0; j < 2; j++ {
|
|
||||||
for i := 0; i < len(blocks); i++ {
|
for i := 0; i < len(blocks); i++ {
|
||||||
assert.True(t, bc.HasBlock(blocks[i].Hash()))
|
assert.True(t, bc.HasBlock(blocks[i].Hash()))
|
||||||
}
|
}
|
||||||
newBlock := bc.newBlock()
|
newBlock := bc.newBlock()
|
||||||
assert.False(t, bc.HasBlock(newBlock.Hash()))
|
assert.False(t, bc.HasBlock(newBlock.Hash()))
|
||||||
_, err = bc.persist(true)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTransaction(t *testing.T) {
|
func TestGetTransaction(t *testing.T) {
|
||||||
|
@ -1349,8 +1334,6 @@ func TestGetTransaction(t *testing.T) {
|
||||||
txSize := io.GetVarSize(tx2)
|
txSize := io.GetVarSize(tx2)
|
||||||
assert.Nil(t, bc.AddBlock(block))
|
assert.Nil(t, bc.AddBlock(block))
|
||||||
|
|
||||||
// Test unpersisted and persisted access
|
|
||||||
for j := 0; j < 2; j++ {
|
|
||||||
tx, height, err := bc.GetTransaction(block.Transactions[0].Hash())
|
tx, height, err := bc.GetTransaction(block.Transactions[0].Hash())
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, block.Index, height)
|
assert.Equal(t, block.Index, height)
|
||||||
|
@ -1358,9 +1341,6 @@ func TestGetTransaction(t *testing.T) {
|
||||||
assert.Equal(t, block.Transactions[0], tx)
|
assert.Equal(t, block.Transactions[0], tx)
|
||||||
assert.Equal(t, 1, io.GetVarSize(tx.Attributes))
|
assert.Equal(t, 1, io.GetVarSize(tx.Attributes))
|
||||||
assert.Equal(t, 1, io.GetVarSize(tx.Scripts))
|
assert.Equal(t, 1, io.GetVarSize(tx.Scripts))
|
||||||
_, err = bc.persist(true)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetClaimable(t *testing.T) {
|
func TestGetClaimable(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue