Search in sources :

Example 26 with BlockHeader

use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.

the class ResBlocksHeaders method encode.

@Override
public byte[] encode() {
    List<byte[]> tempList = new ArrayList<>();
    for (BlockHeader blockHeader : this.blockHeaders) {
        tempList.add(blockHeader.getEncoded());
    }
    byte[][] bytesArray = tempList.toArray(new byte[tempList.size()][]);
    return RLP.encodeList(bytesArray);
}
Also used : ArrayList(java.util.ArrayList) BlockHeader(org.aion.zero.impl.types.BlockHeader)

Example 27 with BlockHeader

use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.

the class SyncHeaderRequestManagerTest method testDropHeaders_withEmptyList.

@Test
public void testDropHeaders_withEmptyList() {
    List<BlockHeader> list = mock(List.class);
    when(list.size()).thenReturn(10);
    BlockHeader header = mock(BlockHeader.class);
    when(header.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
    when(list.get(0)).thenReturn(header);
    // headers stored for size 10
    srm.storeHeaders(1, list);
    // remove the list using the matching method
    srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH);
    // attempting to drop the list for size 11
    assertThat(srm.dropHeaders(1, list)).isFalse();
}
Also used : BlockHeader(org.aion.zero.impl.types.BlockHeader) Test(org.junit.Test)

Example 28 with BlockHeader

use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.

the class SyncHeaderRequestManagerTest method test_receivedHeaderManagement.

@Test
public void test_receivedHeaderManagement() {
    List<BlockHeader> list = mock(List.class);
    when(list.size()).thenReturn(10);
    BlockHeader header = mock(BlockHeader.class);
    when(header.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
    when(list.get(0)).thenReturn(header);
    srm.storeHeaders(1, list);
    assertThat(srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH)).isEqualTo(list);
    // ensure the headers were dropped
    assertThat(srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH)).isNull();
}
Also used : BlockHeader(org.aion.zero.impl.types.BlockHeader) Test(org.junit.Test)

Example 29 with BlockHeader

use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.

the class SyncHeaderRequestManagerTest method test_storeMultipleThenRetrieveAllWithSameSize.

@Test
public void test_storeMultipleThenRetrieveAllWithSameSize() {
    BlockHeader header = mock(BlockHeader.class);
    when(header.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
    List<BlockHeader> list = mock(List.class);
    when(list.size()).thenReturn(10);
    when(list.get(0)).thenReturn(header);
    srm.storeHeaders(1, list);
    List<BlockHeader> list2 = mock(List.class);
    when(list2.size()).thenReturn(10);
    when(list2.get(0)).thenReturn(header);
    srm.storeHeaders(1, list2);
    // removes the stored headers in the order they were added
    assertThat(srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH)).isEqualTo(list);
    assertThat(srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH)).isEqualTo(list2);
    // ensure the headers were dropped
    assertThat(srm.matchAndDropHeaders(1, 10, EMPTY_TRIE_HASH)).isNull();
}
Also used : BlockHeader(org.aion.zero.impl.types.BlockHeader) Test(org.junit.Test)

Aggregations

BlockHeader (org.aion.zero.impl.types.BlockHeader)29 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 MiningBlockHeader (org.aion.zero.impl.types.MiningBlockHeader)14 ReqBlocksBodies (org.aion.zero.impl.sync.msg.ReqBlocksBodies)8 Block (org.aion.zero.impl.types.Block)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 BigInteger (java.math.BigInteger)3 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)3 INode (org.aion.p2p.INode)3 SharedRLPList (org.aion.rlp.SharedRLPList)3 GenesisStakingBlock (org.aion.zero.impl.types.GenesisStakingBlock)3 MiningBlock (org.aion.zero.impl.types.MiningBlock)3 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)3 StakingBlock (org.aion.zero.impl.types.StakingBlock)3 StakingBlockHeader (org.aion.zero.impl.types.StakingBlockHeader)3 BlockDetailsValidator.isValidBlock (org.aion.zero.impl.valid.BlockDetailsValidator.isValidBlock)3 List (java.util.List)2 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1