use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class TransactionCreateSpecificationTests method deployInternalAvmContractOnTopOfAddressWithNonceUsingAvmVersion1_DeployAndRequireSuccess.
@Test
public void deployInternalAvmContractOnTopOfAddressWithNonceUsingAvmVersion1_DeployAndRequireSuccess() throws VmFatalException {
AvmTestConfig.clearConfigurations();
AvmTestConfig.supportOnlyAvmVersion1();
// Deploy AVM contract.
AionTransaction deployTxAvm = BlockchainTestUtils.deployAvmContractTransaction(AvmContract.DEPLOY_INTERNAL, resourceProvider.factoryForVersion1, SENDER_KEY, BigInteger.ZERO);
AionAddress contract = TxUtil.calculateContractAddress(deployTxAvm);
Pair<Block, ImportResult> resultImport = BlockchainTestUtils.addMiningBlock(blockchain, blockchain.getBestBlock(), List.of(deployTxAvm));
assertThat(resultImport.getRight()).isEqualTo(ImportResult.IMPORTED_BEST);
// Call AVM contract to deploy new internal AVM contract (version with required success).
long internalLimit = 1_000_000;
AionTransaction deployInternal = BlockchainTestUtils.callSimpleAvmContractTransaction(resourceProvider.factoryForVersion1, SENDER_KEY, BigInteger.ONE, contract, "deployAndRequireSuccess", deployTxAvm.getData(), internalLimit);
AionAddress internalContract = new AionAddress(Hex.decode("a0268090998a99666b72cc452b9307438a34341047d9e0d7b92c9207bf413655"));
assertThat(blockchain.getRepository().hasAccountState(internalContract)).isFalse();
// Manipulate the repository to have a non-default nonce value.
RepositoryCache cache = blockchain.getRepository().startTracking();
cache.createAccount(internalContract);
cache.setNonce(internalContract, BigInteger.TEN);
cache.flushTo(cache.getParent(), true);
// Check assumptions about contract state.
AccountState contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getNonce()).isEqualTo(BigInteger.TEN);
assertThat(contractState.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
// Next, process the deploy transaction with fork040 enabled.
AionTxExecSummary result = executeTransaction(deployInternal, true);
assertThat(result.isFailed()).isFalse();
assertThat(result.isRejected()).isFalse();
assertThat(result.getReceipt().getError()).isEmpty();
assertThat(result.getNrgUsed()).isLessThan(BigInteger.valueOf(deployInternal.getEnergyLimit()));
assertThat(result.getLogs()).isEmpty();
InternalTransaction itx = result.getInternalTransactions().get(0);
assertThat(itx.isCreate).isTrue();
assertThat(TxUtil.calculateContractAddress(itx)).isEqualTo(internalContract);
assertThat(itx.isRejected).isFalse();
assertThat(itx.energyLimit).isEqualTo(internalLimit);
assertThat(result.getNrgUsed()).isLessThan(BigInteger.valueOf(itx.energyLimit));
contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getNonce()).isEqualTo(BigInteger.TEN);
assertThat(contractState.getStateRoot()).isNotEqualTo(EMPTY_TRIE_HASH);
assertThat(contractState.getCodeHash()).isNotEqualTo(EMPTY_DATA_HASH);
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class TransactionRejectionSpecificationTests method testBalanceTransferToFvmContract_withInsufficientBalance.
@Test
public void testBalanceTransferToFvmContract_withInsufficientBalance() throws VmFatalException, IOException {
BigInteger amount = SENDER_BALANCE.add(BigInteger.ONE);
BigInteger initialBalance = blockchain.getRepository().getBalance(SENDER_ADDR);
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// Deploy an FVM contract.
AionTransaction deploy = BlockchainTestUtils.deployFvmTickerContractTransaction(SENDER_KEY, BigInteger.ZERO);
ImportResult importResult = BlockchainTestUtils.addMiningBlock(this.blockchain, blockchain.getBestBlock(), List.of(deploy)).getRight();
assertThat(importResult).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contract = TxUtil.calculateContractAddress(deploy);
assertThat(blockchain.getRepository().hasAccountState(contract)).isTrue();
// Make balance transfer transaction to deployed contract.
AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.ONE.toByteArray(), contract, amount.toByteArray(), new byte[] {}, 2_000_000, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
AionTxExecSummary result = executeTransaction(transaction);
assertThat(result.isRejected()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo(FastVmResultCode.INSUFFICIENT_BALANCE.toString());
assertThat(result.getNrgUsed()).isEqualTo(BigInteger.ZERO);
assertThat(result.getLogs()).isEmpty();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class TransactionRejectionSpecificationTests method testBalanceTransferToAvmContract_withInsufficientBalance.
@Test
public void testBalanceTransferToAvmContract_withInsufficientBalance() throws VmFatalException {
BigInteger amount = SENDER_BALANCE.add(BigInteger.ONE);
BigInteger initialBalance = blockchain.getRepository().getBalance(SENDER_ADDR);
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// Deploy an AVM contract.
AionTransaction deploy = BlockchainTestUtils.deployAvmContractTransaction(AvmContract.HELLO_WORLD, resourceProvider.factoryForVersion2, SENDER_KEY, BigInteger.ZERO);
ImportResult importResult = BlockchainTestUtils.addMiningBlock(this.blockchain, blockchain.getBestBlock(), List.of(deploy)).getRight();
assertThat(importResult).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contract = TxUtil.calculateContractAddress(deploy);
assertThat(blockchain.getRepository().hasAccountState(contract)).isTrue();
// Make balance transfer transaction to deployed contract.
AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.ONE.toByteArray(), contract, amount.toByteArray(), new byte[] {}, 2_000_000, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
AionTxExecSummary result = executeTransaction(transaction);
assertThat(result.isRejected()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo("Rejected: insufficient balance");
assertThat(result.getNrgUsed()).isEqualTo(BigInteger.ZERO);
assertThat(result.getLogs()).isEmpty();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class TransactionRejectionSpecificationTests method testDeployFvmContract_withInvalidEnergyLimit.
@Test
public void testDeployFvmContract_withInvalidEnergyLimit() throws VmFatalException, IOException {
BigInteger initialBalance = blockchain.getRepository().getBalance(SENDER_ADDR);
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// Deploy an FVM contract.
AionTransaction deploy = BlockchainTestUtils.deployFvmTickerContractTransaction(SENDER_KEY, BigInteger.ZERO);
ImportResult importResult = BlockchainTestUtils.addMiningBlock(this.blockchain, blockchain.getBestBlock(), List.of(deploy)).getRight();
assertThat(importResult).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contract = TxUtil.calculateContractAddress(deploy);
assertThat(blockchain.getRepository().hasAccountState(contract)).isTrue();
// Make balance transfer transaction to deployed contract with large energy limit.
AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.ONE.toByteArray(), null, BigInteger.ZERO.toByteArray(), deploy.getData(), 5_000_001, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
AionTxExecSummary result = executeTransaction(transaction);
assertThat(result.isRejected()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo(FastVmResultCode.INVALID_NRG_LIMIT.toString());
assertThat(result.getNrgUsed()).isEqualTo(BigInteger.ZERO);
assertThat(result.getLogs()).isEmpty();
// Make balance transfer transaction to deployed contract with small energy limit.
transaction = AionTransaction.create(SENDER_KEY, BigInteger.ONE.toByteArray(), null, BigInteger.ZERO.toByteArray(), deploy.getData(), 199_999, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
result = executeTransaction(transaction);
assertThat(result.isRejected()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo(FastVmResultCode.INVALID_NRG_LIMIT.toString());
assertThat(result.getNrgUsed()).isEqualTo(BigInteger.ZERO);
assertThat(result.getLogs()).isEmpty();
}
use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.
the class TransactionRejectionSpecificationTests method testBalanceTransferToFvmContract_withIncorrectNonce.
@Test
public void testBalanceTransferToFvmContract_withIncorrectNonce() throws VmFatalException, IOException {
BigInteger amount = SENDER_BALANCE.divide(BigInteger.TEN);
BigInteger initialBalance = blockchain.getRepository().getBalance(SENDER_ADDR);
assertThat(initialBalance).isEqualTo(SENDER_BALANCE);
assertThat(this.blockchain.getMinerCoinbase().toByteArray()).isEqualTo(MINER);
// Deploy an FVM contract.
AionTransaction deploy = BlockchainTestUtils.deployFvmTickerContractTransaction(SENDER_KEY, BigInteger.ZERO);
ImportResult importResult = BlockchainTestUtils.addMiningBlock(this.blockchain, blockchain.getBestBlock(), List.of(deploy)).getRight();
assertThat(importResult).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress contract = TxUtil.calculateContractAddress(deploy);
assertThat(blockchain.getRepository().hasAccountState(contract)).isTrue();
// Make balance transfer transaction to deployed contract.
AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.TWO.toByteArray(), contract, amount.toByteArray(), new byte[] {}, 2_000_000, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
// Process the transaction.
AionTxExecSummary result = executeTransaction(transaction);
assertThat(result.isRejected()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo(FastVmResultCode.INVALID_NONCE.toString());
assertThat(result.getNrgUsed()).isEqualTo(BigInteger.ZERO);
assertThat(result.getLogs()).isEmpty();
}
Aggregations