Search in sources :

Example 1 with TrieNodeWrapper

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);
}
Also used : TrieNodeWrapper(org.aion.zero.impl.sync.TrieNodeWrapper) ResponseTrieData(org.aion.zero.impl.sync.msg.ResponseTrieData) Logger(org.slf4j.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Test(org.junit.Test)

Example 2 with TrieNodeWrapper

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);
}
Also used : TrieNodeWrapper(org.aion.zero.impl.sync.TrieNodeWrapper) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 3 with TrieNodeWrapper

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);
}
Also used : TrieNodeWrapper(org.aion.zero.impl.sync.TrieNodeWrapper) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 4 with TrieNodeWrapper

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);
}
Also used : TrieNodeWrapper(org.aion.zero.impl.sync.TrieNodeWrapper) Logger(org.slf4j.Logger) Test(org.junit.Test)

Example 5 with TrieNodeWrapper

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);
}
Also used : TrieNodeWrapper(org.aion.zero.impl.sync.TrieNodeWrapper) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

TrieNodeWrapper (org.aion.zero.impl.sync.TrieNodeWrapper)6 Test (org.junit.Test)6 Logger (org.slf4j.Logger)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ResponseTrieData (org.aion.zero.impl.sync.msg.ResponseTrieData)1