Search in sources :

Example 6 with IAionBlockchain

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

Example 7 with IAionBlockchain

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

Example 8 with IAionBlockchain

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

Example 9 with IAionBlockchain

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

Example 10 with IAionBlockchain

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

IAionBlockchain (org.aion.zero.impl.blockchain.IAionBlockchain)35 Test (org.junit.Test)35 IP2pMgr (org.aion.p2p.IP2pMgr)24 Logger (org.slf4j.Logger)24 Block (org.aion.zero.impl.types.Block)18 AionTransaction (org.aion.base.AionTransaction)11 AionAddress (org.aion.types.AionAddress)10 ForkUtility (org.aion.zero.impl.forks.ForkUtility)10 ResponseBlocks (org.aion.zero.impl.sync.msg.ResponseBlocks)7 RequestBlocks (org.aion.zero.impl.sync.msg.RequestBlocks)5 ResponseTrieData (org.aion.zero.impl.sync.msg.ResponseTrieData)3 LinkedList (java.util.LinkedList)2 ImportResult (org.aion.zero.impl.core.ImportResult)1