use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class AionImplTest method testAddNewBlockSameAsTheBestBlock.
@Test
public void testAddNewBlockSameAsTheBestBlock() {
doReturn(blockHeight).when(newBlock).getNumber();
doCallRealMethod().when(chainImpl).addNewBlock(newBlock);
ImportResult result = chainImpl.addNewBlock(newBlock);
assertThat(result.equals(ImportResult.INVALID_BLOCK)).isTrue();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class AionImplTest method testAddNewBlockLessThenTheBestBlock.
@Test
public void testAddNewBlockLessThenTheBestBlock() {
doReturn(blockHeight - 1).when(newBlock).getNumber();
doCallRealMethod().when(chainImpl).addNewBlock(newBlock);
ImportResult result = chainImpl.addNewBlock(newBlock);
assertThat(result.equals(ImportResult.INVALID_BLOCK)).isTrue();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class SignatureSchemeSwapForkTest method testRejectFvmContractDeploy.
@Test
// We ignore this test due to the FVM contract deploy is not disable in ver1.6
@Ignore
public void testRejectFvmContractDeploy() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
// setup Unity fork and AVM
long unityForkBlock = 2;
long signatureSwapForkBlockHeight = unityForkBlock + 3;
setupAVM(unityForkBlock);
TestResourceProvider resourceProvider = TestResourceProvider.initializeAndCreateNewProvider(AvmPathManager.getPathOfProjectRootDirectory());
// setup an identical blockchains
StandaloneBlockchain blockchain = setupIdenticalBlockchain(unityForkBlock, signatureSwapForkBlockHeight);
// create block with staker registry
Block blockWithRegistry = BlockchainTestUtils.generateNextMiningBlockWithStakerRegistry(blockchain, blockchain.getGenesis(), resourceProvider, stakingRegistryOwner);
// import block on firstChain
Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(blockWithRegistry);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
assertThat(result.getRight().getReceipts().get(0).isSuccessful()).isTrue();
assertThat(result.getRight().getReceipts().get(0).getLogInfoList()).isNotEmpty();
assertThat(result.getRight().getReceipts().get(0).getEnergyUsed()).isEqualTo(1_225_655L);
// set the staking contract address in the staking genesis
AionTransaction deploy = blockWithRegistry.getTransactionsList().get(0);
AionAddress contract = TxUtil.calculateContractAddress(deploy.getSenderAddress().toByteArray(), deploy.getNonceBI());
blockchain.getGenesis().setStakingContractAddress(contract);
// create Unity block with stakers
Block block2Unity = BlockchainTestUtils.generateNextMiningBlockWithStakers(blockchain, blockchain.getBestBlock(), resourceProvider, stakers, MIN_SELF_STAKE);
// import block2Unity on blockchain
result = blockchain.tryToConnectAndFetchSummary(block2Unity);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
verifyReceipts(result.getRight().getReceipts(), 3, true);
// create staking block
Block block3Staking = BlockchainTestUtils.generateNextStakingBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList(), stakers.get(0));
assertThat(block3Staking).isNotNull();
// import block3Staking on blockchain
result = blockchain.tryToConnectAndFetchSummary(block3Staking);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// create next mining block
AionTransaction tx = BlockchainTestUtils.deployFvmTickerContractTransaction(accounts.get(4), BigInteger.ZERO);
Block block4Mining = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), Collections.singletonList(tx));
assertThat(block4Mining.getTransactionsList().size() == 1).isTrue();
// import block4Mining on blockchain
result = blockchain.tryToConnectAndFetchSummary(block4Mining);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// create the first signatureSchemeSwap block
tx = BlockchainTestUtils.deployFvmTickerContractTransaction(accounts.get(5), BigInteger.ZERO);
Block block5SignatureSchemeSwapStaking = BlockchainTestUtils.generateNextStakingBlock(blockchain, blockchain.getBestBlock(), Collections.singletonList(tx), stakers.get(0));
assertThat(block5SignatureSchemeSwapStaking).isNotNull();
assertThat(block5SignatureSchemeSwapStaking.getTransactionsList().size() == 0).isTrue();
// import block5SignatureSchemeSwapStaking on blockchain
result = blockchain.tryToConnectAndFetchSummary(block5SignatureSchemeSwapStaking);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// create next mining block with rejected transaction
Block block6Mining = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), Collections.singletonList(tx));
assertThat(block6Mining.getTransactionsList().size() == 0).isTrue();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class SignatureSchemeSwapForkTest method testSigatureSchemeSwapForkWithFallbackTransaction.
@Test
public void testSigatureSchemeSwapForkWithFallbackTransaction() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
// setup Unity fork and AVM
long unityForkBlock = 2;
long signatureSwapForkBlockHeight = unityForkBlock + 3;
setupAVM(unityForkBlock);
TestResourceProvider resourceProvider = TestResourceProvider.initializeAndCreateNewProvider(AvmPathManager.getPathOfProjectRootDirectory());
// setup an identical blockchains
StandaloneBlockchain blockchain = setupIdenticalBlockchain(unityForkBlock, signatureSwapForkBlockHeight);
// create block with staker registry
Block blockWithRegistry = BlockchainTestUtils.generateNextMiningBlockWithStakerRegistry(blockchain, blockchain.getGenesis(), resourceProvider, stakingRegistryOwner);
// import block on firstChain
Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(blockWithRegistry);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
assertThat(result.getRight().getReceipts().get(0).isSuccessful()).isTrue();
assertThat(result.getRight().getReceipts().get(0).getLogInfoList()).isNotEmpty();
assertThat(result.getRight().getReceipts().get(0).getEnergyUsed()).isEqualTo(1_225_655L);
// set the staking contract address in the staking genesis
AionTransaction deploy = blockWithRegistry.getTransactionsList().get(0);
AionAddress contract = TxUtil.calculateContractAddress(deploy.getSenderAddress().toByteArray(), deploy.getNonceBI());
blockchain.getGenesis().setStakingContractAddress(contract);
// create Unity block with stakers
Block block2Unity = BlockchainTestUtils.generateNextMiningBlockWithStakers(blockchain, blockchain.getBestBlock(), resourceProvider, stakers, MIN_SELF_STAKE);
// import block2Unity on blockchain
result = blockchain.tryToConnectAndFetchSummary(block2Unity);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
verifyReceipts(result.getRight().getReceipts(), 3, true);
// create staking block
Block block3Staking = BlockchainTestUtils.generateNextStakingBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList(), stakers.get(0));
assertThat(block3Staking).isNotNull();
// import block3Staking on blockchain
result = blockchain.tryToConnectAndFetchSummary(block3Staking);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// create an invalid transaction for the hardfork fallback.
List<AionTransaction> fallbackTx = BlockchainTestUtils.generateTransactions(1, accounts, blockchain.getRepository(), true);
List<byte[]> fallbackTxHash = new ArrayList<>();
for (AionTransaction a : fallbackTx) {
fallbackTxHash.add(a.getTransactionHash());
}
// cracking the config settings
CfgAion.inst().getFork().setRollbackTx(fallbackTxHash);
// create next mining block
Block block4Mining = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), fallbackTx);
// import block4Mining on blockchain
result = blockchain.tryToConnectAndFetchSummary(block4Mining);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// Check the transaction has been processed
assertThat(fallbackTx.get(0).getValueBI().equals(blockchain.getRepository().getBalance(fallbackTx.get(0).getDestinationAddress())));
BigInteger senderBalance = blockchain.getRepository().getBalance(fallbackTx.get(0).getSenderAddress());
// create the first signatureSchemeSwap block
Block block5SignatureSchemeSwapStaking = BlockchainTestUtils.generateNextStakingBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList(), stakers.get(0));
assertThat(block5SignatureSchemeSwapStaking).isNotNull();
// import block5SignatureSchemeSwapStaking on blockchain
result = blockchain.tryToConnectAndFetchSummary(block5SignatureSchemeSwapStaking);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// Check the invalid account has been fallbacked
assertThat(blockchain.getRepository().getAccountState(fallbackTx.get(0).getDestinationAddress()) == null);
BigInteger senderBalanceNew = blockchain.getRepository().getBalance(fallbackTx.get(0).getSenderAddress());
assertThat(senderBalanceNew.equals(senderBalance.add(fallbackTx.get(0).getValueBI())));
// create next mining block
Block block6Mining = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList());
// import block6Mining on blockchain
result = blockchain.tryToConnectAndFetchSummary(block6Mining);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
// create next staking block
Block block7Staking = BlockchainTestUtils.generateNextStakingBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList(), stakers.get(0));
// import block7Staking on blockchain
result = blockchain.tryToConnectAndFetchSummary(block7Staking);
assertThat(result.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class StandaloneBlockchainTest method testBlockChainShutdownhook.
@Test
public void testBlockChainShutdownhook() {
exit.expectSystemExitWithStatus(SystemExitCodes.NORMAL);
StandaloneBlockchain.Builder builder = new StandaloneBlockchain.Builder();
StandaloneBlockchain.Bundle bundle = builder.withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain sb = bundle.bc;
AionBlockchainImpl.shutdownHook = 2;
Block block1 = sb.createBlock(sb.genesis, Collections.EMPTY_LIST, false, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
ImportResult result = sb.tryToConnect(block1);
assertThat(result.isBest()).isTrue();
Block block2 = sb.createBlock(block1, Collections.EMPTY_LIST, false, TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()));
// expect the system will be shutdown when import the block2
sb.tryToConnect(new BlockWrapper(block2));
}
Aggregations