forked from TrueCloudLab/neoneo-go
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,19 +232,14 @@ 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
|
hash := block.Hash()
|
||||||
for i := 0; i < 2; i++ {
|
header, err := bc.GetHeader(hash)
|
||||||
hash := block.Hash()
|
require.NoError(t, err)
|
||||||
header, err := bc.GetHeader(hash)
|
assert.Equal(t, &block.Header, header)
|
||||||
require.NoError(t, err)
|
|
||||||
assert.Equal(t, &block.Header, header)
|
|
||||||
|
|
||||||
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,16 +247,11 @@ 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 i := 0; i < len(blocks); i++ {
|
||||||
for j := 0; j < 2; j++ {
|
block, err := bc.GetBlock(blocks[i].Hash())
|
||||||
for i := 0; i < len(blocks); i++ {
|
require.NoErrorf(t, err, "can't get block %d: %s", i, err)
|
||||||
block, err := bc.GetBlock(blocks[i].Hash())
|
assert.Equal(t, blocks[i].Index, block.Index)
|
||||||
require.NoErrorf(t, err, "can't get block %d: %s, attempt %d", i, err, j)
|
assert.Equal(t, blocks[i].Hash(), block.Hash())
|
||||||
assert.Equal(t, blocks[i].Index, block.Index)
|
|
||||||
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) {
|
||||||
|
@ -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 i := 0; i < len(blocks); i++ {
|
||||||
for j := 0; j < 2; j++ {
|
assert.True(t, bc.HasBlock(blocks[i].Hash()))
|
||||||
for i := 0; i < len(blocks); i++ {
|
|
||||||
assert.True(t, bc.HasBlock(blocks[i].Hash()))
|
|
||||||
}
|
|
||||||
newBlock := bc.newBlock()
|
|
||||||
assert.False(t, bc.HasBlock(newBlock.Hash()))
|
|
||||||
_, err = bc.persist(true)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
}
|
}
|
||||||
|
newBlock := bc.newBlock()
|
||||||
|
assert.False(t, bc.HasBlock(newBlock.Hash()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTransaction(t *testing.T) {
|
func TestGetTransaction(t *testing.T) {
|
||||||
|
@ -1349,18 +1334,13 @@ 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
|
tx, height, err := bc.GetTransaction(block.Transactions[0].Hash())
|
||||||
for j := 0; j < 2; j++ {
|
require.Nil(t, err)
|
||||||
tx, height, err := bc.GetTransaction(block.Transactions[0].Hash())
|
assert.Equal(t, block.Index, height)
|
||||||
require.Nil(t, err)
|
assert.Equal(t, txSize, tx.Size())
|
||||||
assert.Equal(t, block.Index, height)
|
assert.Equal(t, block.Transactions[0], tx)
|
||||||
assert.Equal(t, txSize, tx.Size())
|
assert.Equal(t, 1, io.GetVarSize(tx.Attributes))
|
||||||
assert.Equal(t, block.Transactions[0], tx)
|
assert.Equal(t, 1, io.GetVarSize(tx.Scripts))
|
||||||
assert.Equal(t, 1, io.GetVarSize(tx.Attributes))
|
|
||||||
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