use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestBlocksHandlerTest method testReceive_incorrectMessage_withTrace.
@Test
public void testReceive_incorrectMessage_withTrace() {
Logger log = mock(Logger.class);
when(log.isTraceEnabled()).thenReturn(true);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
IP2pMgr p2p = mock(P2pMgr.class);
RequestBlocksHandler handler = new RequestBlocksHandler(log, chain, p2p);
// receive incorrect message
byte[] incorrectEncoding = RLP.encodeList(RLP.encodeByte(isFalse), RLP.encode(consecutiveBlocks.get(0).getHash()), RLP.encodeInt(10), RLP.encode(Byte.MAX_VALUE + 1));
handler.receive(peerId, displayId, incorrectEncoding);
verify(log, times(1)).error("<request-blocks decode-error msg-bytes={} peer={}>", incorrectEncoding.length, displayId);
verify(log, times(1)).trace("<request-blocks decode-error for msg={} peer={}>", Arrays.toString(incorrectEncoding), displayId);
verifyZeroInteractions(chain);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestBlocksHandlerTest method testReceive_correctMessage_withException_withHeight.
@Test
public void testReceive_correctMessage_withException_withHeight() {
Logger log = mock(Logger.class);
when(log.isDebugEnabled()).thenReturn(true);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
Exception e = new NullPointerException();
when(chain.getBlocksByRange(10L, 1L)).thenThrow(e);
IP2pMgr p2p = mock(P2pMgr.class);
RequestBlocksHandler handler = new RequestBlocksHandler(log, chain, p2p);
// receive correct message
byte[] encoding = RLP.encodeList(RLP.encodeByte(isTrue), RLP.encode(10L), RLP.encodeInt(10), RLP.encodeByte(isTrue));
handler.receive(peerId, displayId, encoding);
verify(log, times(1)).debug("<request-blocks from-block={} count={} order={}>", 10L, 10, "DESC");
verify(log).error("<request-blocks value retrieval failed>", e);
verify(chain, times(1)).getBlocksByRange(10L, 1L);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestTrieDataHandlerTest method testReceive_nullMessage.
@Test
public void testReceive_nullMessage() {
Logger log = mock(Logger.class);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
IP2pMgr p2p = mock(P2pMgr.class);
RequestTrieDataHandler handler = new RequestTrieDataHandler(log, chain, p2p);
// receive null message
handler.receive(peerId, displayId, null);
verify(log, times(1)).debug("<req-trie empty message from peer={}>", displayId);
verifyZeroInteractions(chain);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestTrieDataHandlerTest method testReceive_incorrectMessage_withTrace.
@Test
public void testReceive_incorrectMessage_withTrace() {
Logger log = mock(Logger.class);
when(log.isTraceEnabled()).thenReturn(true);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
IP2pMgr p2p = mock(P2pMgr.class);
RequestTrieDataHandler handler = new RequestTrieDataHandler(log, chain, p2p);
// receive incorrect message
byte[] outOfOderEncoding = RLP.encodeList(RLP.encodeString(STATE.toString()), RLP.encodeElement(nodeKey), RLP.encodeInt(0));
handler.receive(peerId, displayId, outOfOderEncoding);
verify(log, times(1)).error("<req-trie decode-error msg-bytes={} peer={}>", outOfOderEncoding.length, displayId);
verify(log, times(1)).trace("<req-trie decode-error for msg={} peer={}>", Arrays.toString(outOfOderEncoding), displayId);
verifyZeroInteractions(chain);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestTrieDataHandlerTest method testReceive_correctMessage_limitTwo.
@Test
public void testReceive_correctMessage_limitTwo() {
Logger log = mock(Logger.class);
when(log.isDebugEnabled()).thenReturn(true);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
when(chain.getTrieNode(nodeKey, STATE)).thenReturn(leafValue);
when(chain.getReferencedTrieNodes(leafValue, 1, STATE)).thenReturn(singleReference);
IP2pMgr p2p = mock(P2pMgr.class);
RequestTrieDataHandler handler = new RequestTrieDataHandler(log, chain, p2p);
// receive correct message
byte[] encoding = RLP.encodeList(RLP.encodeElement(nodeKey), RLP.encodeString(STATE.toString()), RLP.encodeInt(2));
handler.receive(peerId, displayId, encoding);
verify(log, times(1)).debug("<req-trie from-db={} key={} peer={}>", STATE, wrappedNodeKey, displayId);
verify(chain, times(1)).getTrieNode(nodeKey, STATE);
verify(chain, times(1)).getReferencedTrieNodes(leafValue, 1, STATE);
ResponseTrieData expectedResponse = new ResponseTrieData(wrappedNodeKey, leafValue, singleReference, STATE);
verify(p2p, times(1)).send(peerId, displayId, expectedResponse);
}
Aggregations