use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class AionBlockStoreTest method testGetBlockByHashWithInfo_withNullInput.
@Test
public void testGetBlockByHashWithInfo_withNullInput() {
AionBlockStore store = new AionBlockStore(index, blocks, false);
Block block = store.getBlockByHashWithInfo(null);
assertThat(block).isNull();
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class AionBlockStoreTest method testGetThreeGenerationBlocksByHashWithInfo.
@Test
public void testGetThreeGenerationBlocksByHashWithInfo() {
Block greatGrandparent = consecutiveBlocks.get(0);
Block grandparent = consecutiveBlocks.get(1);
Block parent = consecutiveBlocks.get(2);
AionBlockStore store = new AionBlockStore(index, blocks, false);
// does not require accurate total difficulty
store.saveBlock(greatGrandparent, BigInteger.ONE, true);
store.saveBlock(grandparent, BigInteger.TWO, true);
store.saveBlock(parent, BigInteger.TEN, true);
Block[] blocks = store.getThreeGenerationBlocksByHashWithInfo(parent.getHash());
assertThat(blocks.length).isEqualTo(3);
assertThat(blocks[0]).isEqualTo(parent);
assertThat(blocks[0].getTotalDifficulty()).isEqualTo(BigInteger.TEN);
assertThat(blocks[0].isMainChain()).isTrue();
assertThat(blocks[1]).isEqualTo(grandparent);
assertThat(blocks[1].getTotalDifficulty()).isEqualTo(BigInteger.TWO);
assertThat(blocks[1].isMainChain()).isTrue();
assertThat(blocks[2]).isEqualTo(greatGrandparent);
assertThat(blocks[2].getTotalDifficulty()).isEqualTo(BigInteger.ONE);
assertThat(blocks[2].isMainChain()).isTrue();
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class AionBlockStoreTest method testGetBlocksByRange_withAscendingOrderAndIncorrectHeight.
@Test
public void testGetBlocksByRange_withAscendingOrderAndIncorrectHeight() {
Block first = consecutiveBlocks.get(0);
Block last = consecutiveBlocks.get(1);
Block best = consecutiveBlocks.get(2);
AionBlockStore store = spy(new AionBlockStore(index, blocks, false));
when(store.getChainBlockByNumber(first.getNumber())).thenReturn(first);
when(store.getChainBlockByNumber(last.getNumber())).thenReturn(null);
when(store.getBestBlock()).thenReturn(best);
// the returned list is null due to corrupt kernel
assertThat(store.getBlocksByRange(first.getNumber(), last.getNumber())).isNull();
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class AionBlockStoreTest method testGetBlocksByRange_withAscendingOrderAndNullBest.
@Test
public void testGetBlocksByRange_withAscendingOrderAndNullBest() {
Block first = consecutiveBlocks.get(0);
Block last = consecutiveBlocks.get(3);
AionBlockStore store = spy(new AionBlockStore(index, blocks, false));
when(store.getChainBlockByNumber(first.getNumber())).thenReturn(first);
when(store.getChainBlockByNumber(last.getNumber())).thenReturn(null);
when(store.getBestBlock()).thenReturn(null);
when(store.getBlocksByRange(first.getNumber(), last.getNumber())).thenCallRealMethod();
// the returned list is null due to corrupt kernel
assertThat(store.getBlocksByRange(first.getNumber(), last.getNumber())).isNull();
}
use of org.aion.zero.impl.types.Block in project aion by aionnetwork.
the class AionBlockStoreTest method testGetBlockByHashWithInfo_withSideChain.
@Test
public void testGetBlockByHashWithInfo_withSideChain() {
Block givenBlock = consecutiveBlocks.get(0);
BigInteger totalDifficulty = BigInteger.TWO;
BigInteger sideTotalDifficulty = BigInteger.TEN;
Block sideBlock = BlockUtil.newBlockFromRlp(givenBlock.getEncoded());
sideBlock.updateHeaderDifficulty(sideTotalDifficulty.toByteArray());
assertThat(givenBlock.getHash()).isNotEqualTo(sideBlock.getHash());
assertThat(givenBlock.getEncoded()).isNotEqualTo(sideBlock.getEncoded());
AionBlockStore store = new AionBlockStore(index, blocks, false);
// does not require accurate total difficulty
store.saveBlock(givenBlock, totalDifficulty, false);
store.saveBlock(sideBlock, sideTotalDifficulty, true);
Block block = store.getBlockByHashWithInfo(givenBlock.getHash());
assertThat(block).isEqualTo(givenBlock);
assertThat(block.getTotalDifficulty()).isEqualTo(totalDifficulty);
assertThat(block.isMainChain()).isFalse();
}
Aggregations