Search in sources :

Example 6 with ResponseTrieData

use of org.aion.zero.impl.sync.msg.ResponseTrieData in project aion by aionnetwork.

the class RequestTrieDataHandlerTest method testReceive_correctMessage_limitZero_akaMaxBatchSize.

@Test
public void testReceive_correctMessage_limitZero_akaMaxBatchSize() {
    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, TRIE_DATA_REQUEST_MAXIMUM_BATCH_SIZE, STATE)).thenReturn(multipleReferences);
    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(0));
    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, TRIE_DATA_REQUEST_MAXIMUM_BATCH_SIZE, STATE);
    ResponseTrieData expectedResponse = new ResponseTrieData(wrappedNodeKey, leafValue, multipleReferences, STATE);
    verify(p2p, times(1)).send(peerId, displayId, expectedResponse);
}
Also used : ResponseTrieData(org.aion.zero.impl.sync.msg.ResponseTrieData) IAionBlockchain(org.aion.zero.impl.blockchain.IAionBlockchain) Logger(org.slf4j.Logger) IP2pMgr(org.aion.p2p.IP2pMgr) Test(org.junit.Test)

Aggregations

ResponseTrieData (org.aion.zero.impl.sync.msg.ResponseTrieData)6 Test (org.junit.Test)5 Logger (org.slf4j.Logger)4 IP2pMgr (org.aion.p2p.IP2pMgr)3 IAionBlockchain (org.aion.zero.impl.blockchain.IAionBlockchain)3 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)1 DatabaseType (org.aion.zero.impl.sync.DatabaseType)1 TrieNodeWrapper (org.aion.zero.impl.sync.TrieNodeWrapper)1 RequestTrieData (org.aion.zero.impl.sync.msg.RequestTrieData)1