use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForBlockOnMainchainAndBeaconHashNotGiven.
@Test
public void validateTxForBlockOnMainchainAndBeaconHashNotGiven() {
long unityForkNumber = 2;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
Block block = mock(Block.class);
byte[] blockParent = ByteUtil.hexStringToBytes("0x1333333333333333333333333333333333333333333333333333333333333337");
when(block.getParentHash()).thenReturn(blockParent);
when(blockchain.isMainChain(blockParent)).thenReturn(true);
AionTransaction tx = AionTransaction.createWithoutKey(// nonce - any val
new byte[] { 1 }, new AionAddress(// sender - any val
ByteUtil.hexStringToBytes("0xa000000000000000000000000000000000000000000000000000000000000000")), new AionAddress(// destination - any val
ByteUtil.hexStringToBytes("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")), // value - any val
new byte[] { 1 }, // data - any val
new byte[] {}, // energyLimit - any val
1l, // energyPrice - any val
1l, // type - any val
(byte) 1, // beacon hash - not present
null);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
when(block.getNumber()).thenReturn(unityForkNumber - 1);
assertWithMessage("validation should pass if beacon hash not present").that(unit.validateTxForBlock(tx, block)).isTrue();
when(block.getNumber()).thenReturn(unityForkNumber);
assertWithMessage("validation should pass if beacon hash not present").that(unit.validateTxForBlock(tx, block)).isTrue();
when(block.getNumber()).thenReturn(unityForkNumber + 1);
assertWithMessage("validation should pass if beacon hash not present").that(unit.validateTxForBlock(tx, block)).isTrue();
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForPendingStateWithoutBeaconHash.
@Test
public void validateTxForPendingStateWithoutBeaconHash() {
long unityForkNumber = 3;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
Block bestBlock = mock(Block.class);
when(blockchain.getBestBlock()).thenReturn(bestBlock);
AionTransaction tx = AionTransaction.createWithoutKey(// nonce - any val
new byte[] { 1 }, new AionAddress(// sender - any val
ByteUtil.hexStringToBytes("0xa000000000000000000000000000000000000000000000000000000000000000")), new AionAddress(// destination - any val
ByteUtil.hexStringToBytes("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")), // value - any val
new byte[] { 1 }, // data - any val
new byte[] {}, // energyLimit - any val
1l, // energyPrice - any val
1l, // type - any val
(byte) 1, // beacon hash - absent
null);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
when(bestBlock.getNumber()).thenReturn(unityForkNumber - 2);
assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
when(bestBlock.getNumber()).thenReturn(unityForkNumber - 1);
assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
when(bestBlock.getNumber()).thenReturn(unityForkNumber);
assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestTrieDataHandlerTest method testReceive_incorrectMessage.
@Test
public void testReceive_incorrectMessage() {
Logger log = mock(Logger.class);
when(log.isTraceEnabled()).thenReturn(false);
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);
verifyZeroInteractions(chain);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain 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);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RpcTest method testGetSeed.
@Test
public void testGetSeed() {
IAionBlockchain chain = impl.aionHub.getBlockchain();
Block block = chain.getBestBlock();
List<AionTransaction> txs = Collections.emptyList();
// expand chain to reach fork point
block = chain.createNewMiningBlock(block, txs, false);
ImportResult result = chain.tryToConnect(block);
assertEquals(ImportResult.IMPORTED_BEST, result);
block = chain.createNewMiningBlock(block, txs, false);
result = chain.tryToConnect(block);
assertEquals(ImportResult.IMPORTED_BEST, result);
byte[] seed = api.getseed();
assertNotNull(seed);
assertArrayEquals(seed, new byte[64]);
}
Aggregations