use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class RequestTrieDataHandlerTest method testReceive_emptyMessage.
@Test
public void testReceive_emptyMessage() {
Logger log = mock(Logger.class);
IAionBlockchain chain = mock(AionBlockchainImpl.class);
IP2pMgr p2p = mock(P2pMgr.class);
RequestTrieDataHandler handler = new RequestTrieDataHandler(log, chain, p2p);
// receive empty message
handler.receive(peerId, displayId, new byte[0]);
verify(log, times(1)).debug("<req-trie empty message from peer={}>", displayId);
verifyZeroInteractions(chain);
verifyZeroInteractions(p2p);
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForBlockOnMainchainAndBeaconHashOnMainchain.
@Test
public void validateTxForBlockOnMainchainAndBeaconHashOnMainchain() {
long unityForkNumber = 7;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
byte[] goodBlockHash = ByteUtil.hexStringToBytes("0xcafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe");
when(blockchain.isMainChain(goodBlockHash)).thenReturn(true);
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 - exists in blockstore
goodBlockHash);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
when(block.getNumber()).thenReturn(unityForkNumber - 1);
assertWithMessage("any beacon hash should fail if block_number < unityFork_number").that(unit.validateTxForBlock(tx, block)).isFalse();
when(block.getNumber()).thenReturn(unityForkNumber);
assertWithMessage("beacon hash on chain of new block should fail if block_number = unityFork_number").that(unit.validateTxForBlock(tx, block)).isFalse();
when(block.getNumber()).thenReturn(unityForkNumber + 1);
assertWithMessage("beacon hash on chain of new block should pass if block_number > unityFork_number").that(unit.validateTxForBlock(tx, block)).isTrue();
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForPendingStateWhenBeaconHashOnMainchain.
@Test
public void validateTxForPendingStateWhenBeaconHashOnMainchain() {
long unityForkNumber = 7;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
Block bestBlock = mock(Block.class);
byte[] goodBlockHash = ByteUtil.hexStringToBytes("0xcafecafecafecafecafecafecafecafecafecafecafecafecafecafecafecafe");
when(blockchain.isMainChain(goodBlockHash)).thenReturn(true);
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 - exists in blockstore
goodBlockHash);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
when(bestBlock.getNumber()).thenReturn(unityForkNumber - 2);
assertWithMessage("any beacon hash should fail for pending state if best_block_number+1 < unityFork_number").that(unit.validateTxForPendingState(tx)).isFalse();
when(bestBlock.getNumber()).thenReturn(unityForkNumber - 1);
assertWithMessage("mainchain hash should fail for pending state if best_block_number+1 == unityFork_number").that(unit.validateTxForPendingState(tx)).isFalse();
when(bestBlock.getNumber()).thenReturn(unityForkNumber);
assertWithMessage("mainchain hash should pass for pending state if best_block_number+1 > unityFork_number").that(unit.validateTxForPendingState(tx)).isTrue();
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForBlockOnMainchainAndBeaconHashNotOnMainchain.
@Test
public void validateTxForBlockOnMainchainAndBeaconHashNotOnMainchain() {
long unityForkNumber = 13;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
byte[] nonExistentBlockhash = ByteUtil.hexStringToBytes("0xbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbad0");
when(blockchain.isMainChain(nonExistentBlockhash)).thenReturn(false);
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 - does not exist in blockstore
nonExistentBlockhash);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
when(block.getNumber()).thenReturn(unityForkNumber - 1);
assertWithMessage("any beacon hash should fail if block_number < unityFork_number").that(unit.validateTxForBlock(tx, block)).isFalse();
when(block.getNumber()).thenReturn(unityForkNumber);
assertWithMessage("beacon hash not on chain of new block should fail if block_number = unityFork_number").that(unit.validateTxForBlock(tx, block)).isFalse();
when(block.getNumber()).thenReturn(unityForkNumber + 1);
assertWithMessage("beacon hash not on chain of new block should fail if block_number > unityFork_number").that(unit.validateTxForBlock(tx, block)).isFalse();
}
use of org.aion.zero.impl.blockchain.IAionBlockchain in project aion by aionnetwork.
the class BeaconHashValidatorTest method validateTxForBlockOnSidechainAndBeaconHashNotInDb.
@Test
public void validateTxForBlockOnSidechainAndBeaconHashNotInDb() {
/*
* Visualization of this case (beacon hash not in any chain, * is the new block):
*
* o--o--o---o--o main chain
* |
* \--o--o--* side chain
*/
long unityForkNumber = 2;
ForkUtility forkUtility = new ForkUtility();
forkUtility.enableUnityFork(unityForkNumber);
IAionBlockchain blockchain = mock(IAionBlockchain.class);
byte[] nonExistentBlockhash = ByteUtil.hexStringToBytes("0xbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbad0");
LinkedList<Block> sideChain = mockChain(unityForkNumber, 6, blockchain);
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
nonExistentBlockhash);
BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
assertWithMessage("beacon hash not on chain of new block should fail if block_number = unityFork_number").that(unit.validateTxForBlock(tx, sideChain.get(0))).isFalse();
}
Aggregations