use of org.aion.zero.impl.sync.TrieNodeWrapper in project aion by aionnetwork.
the class ResponseTrieDataHandlerTest method testReceive_correctMessage.
@Test
public void testReceive_correctMessage() {
Logger log = mock(Logger.class);
when(log.isDebugEnabled()).thenReturn(true);
BlockingQueue<TrieNodeWrapper> receivedQueue = new LinkedBlockingQueue<>();
ResponseTrieDataHandler handler = new ResponseTrieDataHandler(log, receivedQueue);
// receive correct message
byte[] encoding = RLP.encodeList(RLP.encodeElement(nodeKey), RLP.encodeElement(leafValue), RLP.encodeList(new byte[0]), RLP.encodeString(STATE.toString()));
handler.receive(peerId, displayId, encoding);
ResponseTrieData response = ResponseTrieData.decode(encoding);
verify(log, times(1)).debug("<res-trie response={} peer={}>", response, displayId);
TrieNodeWrapper node = new TrieNodeWrapper(peerId, displayId, response);
assertThat(receivedQueue).containsExactly(node);
}
use of org.aion.zero.impl.sync.TrieNodeWrapper in project aion by aionnetwork.
the class ResponseTrieDataHandlerTest method testReceive_emptyMessage.
@Test
public void testReceive_emptyMessage() {
Logger log = mock(Logger.class);
BlockingQueue<TrieNodeWrapper> receivedQueue = mock(LinkedBlockingQueue.class);
ResponseTrieDataHandler handler = new ResponseTrieDataHandler(log, receivedQueue);
// receive empty message
handler.receive(peerId, displayId, new byte[0]);
verify(log, times(1)).debug("<res-trie empty message from peer={}>", displayId);
verifyZeroInteractions(receivedQueue);
}
use of org.aion.zero.impl.sync.TrieNodeWrapper in project aion by aionnetwork.
the class ResponseTrieDataHandlerTest method testHeader.
@Test
public void testHeader() {
Logger log = mock(Logger.class);
BlockingQueue<TrieNodeWrapper> receivedQueue = mock(LinkedBlockingQueue.class);
ResponseTrieDataHandler handler = new ResponseTrieDataHandler(log, receivedQueue);
// check handler header
assertThat(handler.getHeader().getVer()).isEqualTo(Ver.V1);
assertThat(handler.getHeader().getAction()).isEqualTo(Act.RESPONSE_TRIE_DATA);
}
use of org.aion.zero.impl.sync.TrieNodeWrapper in project aion by aionnetwork.
the class ResponseTrieDataHandlerTest method testReceive_incorrectMessage_withTrace.
@Test
public void testReceive_incorrectMessage_withTrace() {
Logger log = mock(Logger.class);
when(log.isTraceEnabled()).thenReturn(true);
BlockingQueue<TrieNodeWrapper> receivedQueue = mock(LinkedBlockingQueue.class);
ResponseTrieDataHandler handler = new ResponseTrieDataHandler(log, receivedQueue);
// receive incorrect message
byte[] outOfOderEncoding = RLP.encodeList(RLP.encodeList(RLP.encodeList(RLP.encodeElement(nodeKey), RLP.encodeElement(leafValue)), RLP.encodeList(RLP.encodeElement(altNodeKey), RLP.encodeElement(leafValue))), RLP.encodeElement(nodeKey), RLP.encodeElement(leafValue), RLP.encodeString(STATE.toString()));
handler.receive(peerId, displayId, outOfOderEncoding);
verify(log, times(1)).trace("<res-trie decode-error for msg={} peer={}>", Arrays.toString(outOfOderEncoding), displayId);
verify(log, times(1)).error("<res-trie decode-error msg-bytes={} peer={}>", outOfOderEncoding.length, displayId);
verifyZeroInteractions(receivedQueue);
}
use of org.aion.zero.impl.sync.TrieNodeWrapper in project aion by aionnetwork.
the class ResponseTrieDataHandlerTest method testReceive_nullMessage.
@Test
public void testReceive_nullMessage() {
Logger log = mock(Logger.class);
BlockingQueue<TrieNodeWrapper> receivedQueue = mock(LinkedBlockingQueue.class);
ResponseTrieDataHandler handler = new ResponseTrieDataHandler(log, receivedQueue);
// receive null message
handler.receive(peerId, displayId, null);
verify(log, times(1)).debug("<res-trie empty message from peer={}>", displayId);
verifyZeroInteractions(receivedQueue);
}
Aggregations