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);
}
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();
}
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();
}
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();
}
Aggregations