Search in sources :

Example 46 with Block

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();
}
Also used : MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 47 with Block

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();
}
Also used : MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 48 with Block

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();
}
Also used : MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 49 with Block

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();
}
Also used : MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Example 50 with Block

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();
}
Also used : MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Aggregations

Block (org.aion.zero.impl.types.Block)283 MiningBlock (org.aion.zero.impl.types.MiningBlock)155 Test (org.junit.Test)148 AionTransaction (org.aion.base.AionTransaction)106 ImportResult (org.aion.zero.impl.core.ImportResult)86 ArrayList (java.util.ArrayList)63 AionAddress (org.aion.types.AionAddress)61 StakingBlock (org.aion.zero.impl.types.StakingBlock)58 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)57 BigInteger (java.math.BigInteger)55 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)34 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)30 AionTxReceipt (org.aion.base.AionTxReceipt)29 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)28 AccountState (org.aion.base.AccountState)26 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)26 JSONArray (org.json.JSONArray)26 JSONObject (org.json.JSONObject)26 MiningBlockHeader (org.aion.zero.impl.types.MiningBlockHeader)22 AionTxExecSummary (org.aion.base.AionTxExecSummary)20