Search in sources :

Example 56 with AionTxExecSummary

use of org.aion.base.AionTxExecSummary 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();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 57 with AionTxExecSummary

use of org.aion.base.AionTxExecSummary 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();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 58 with AionTxExecSummary

use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.

the class TransactionRejectionSpecificationTests method testBalanceTransferToPrecompiledContract_withInvalidEnergyLimit.

@Test
public void testBalanceTransferToPrecompiledContract_withInvalidEnergyLimit() throws VmFatalException {
    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);
    // ensure bridge is viewed as precompiled contract
    AionAddress bridge = AddressUtils.wrapAddress("0000000000000000000000000000000000000000000000000000000000000200");
    assertThat(ContractInfo.isPrecompiledContract(bridge)).isTrue();
    // Make balance transfer transaction to precompiled contract with large energy limit.
    AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.ZERO.toByteArray(), bridge, amount.toByteArray(), new byte[] {}, 2_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 precompiled contract with small energy limit.
    transaction = AionTransaction.create(SENDER_KEY, BigInteger.ZERO.toByteArray(), bridge, amount.toByteArray(), new byte[] {}, 20_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();
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 59 with AionTxExecSummary

use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.

the class TransactionRejectionSpecificationTests method testBalanceTransferToFvmContract_withInvalidEnergyLimit.

@Test
public void testBalanceTransferToFvmContract_withInvalidEnergyLimit() 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 with large energy limit.
    AionTransaction transaction = AionTransaction.create(SENDER_KEY, BigInteger.ONE.toByteArray(), contract, amount.toByteArray(), new byte[] {}, 2_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(), contract, amount.toByteArray(), new byte[] {}, 20_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();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 60 with AionTxExecSummary

use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.

the class TransactionCreateSpecificationTests method deployFvmContractOnTopOfAddressWithCodeBeforeFork040.

@Test
public void deployFvmContractOnTopOfAddressWithCodeBeforeFork040() throws VmFatalException {
    // Deploy FVM contract.
    String contractCode = "0x605060405234156100105760006000fd5b5b600a600060005081909090555060006000505460016000506000600060005054815260100190815260100160002090506000508190909055506064600260005060000160005081909090555060c8600260005060010160005081909090555060026000506001016000505460016000506000600260005060000160005054815260100190815260100160002090506000508190909055505b6100ae565b610184806100bd6000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680631677b0ff14610049578063209652551461007657806362eb702a146100a057610043565b60006000fd5b34156100555760006000fd5b61007460048080359060100190919080359060100190919050506100c4565b005b34156100825760006000fd5b61008a610111565b6040518082815260100191505060405180910390f35b34156100ac5760006000fd5b6100c26004808035906010019091905050610123565b005b8160026000506000016000508190909055508060026000506001016000508190909055508082016001600050600084815260100190815260100160002090506000508190909055505b5050565b60006000600050549050610120565b90565b806000600050819090905550600181016001600050600083815260100190815260100160002090506000508190909055505b505600a165627a7a723058205b6e690d70d3703337452467437dc7c4e863ee4ad34b24cc516e2afa71e334700029";
    AionTransaction deployTxFVM = AionTransaction.create(SENDER_KEY, BigInteger.ZERO.toByteArray(), null, BigInteger.ZERO.toByteArray(), ByteUtil.hexStringToBytes(contractCode), 5_000_000L, ENERGY_PRICE, TransactionTypes.DEFAULT, null);
    AionAddress fvmContract = TxUtil.calculateContractAddress(deployTxFVM);
    // Manipulate the repository to have a non-default code value.
    RepositoryCache cache = blockchain.getRepository().startTracking();
    cache.createAccount(fvmContract);
    cache.saveCode(fvmContract, new byte[] { 1, 2, 3, 4 });
    cache.saveVmType(fvmContract, InternalVmType.FVM);
    cache.flushTo(cache.getParent(), true);
    // Check assumptions about contract state.
    AccountState contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
    assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
    assertThat(contractState.getCodeHash()).isNotEqualTo(EMPTY_DATA_HASH);
    byte[] oldCode = contractState.getCodeHash();
    // Next, process the deploy transaction with fork040 disabled.
    AionTxExecSummary result = executeTransaction(deployTxFVM, false);
    assertThat(result.isFailed()).isTrue();
    assertThat(result.getReceipt().getError()).isEqualTo(FastVmResultCode.FAILURE.toString());
    assertThat(result.getNrgUsed()).isEqualTo(BigInteger.valueOf(deployTxFVM.getEnergyLimit()));
    assertThat(result.getLogs()).isEmpty();
    contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(fvmContract);
    assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getStateRoot()).isEqualTo(EMPTY_TRIE_HASH);
    assertThat(contractState.getCodeHash()).isEqualTo(oldCode);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) AccountState(org.aion.base.AccountState) Test(org.junit.Test)

Aggregations

AionTxExecSummary (org.aion.base.AionTxExecSummary)121 AionTransaction (org.aion.base.AionTransaction)103 AionAddress (org.aion.types.AionAddress)98 Test (org.junit.Test)97 RepositoryCache (org.aion.base.db.RepositoryCache)72 BigInteger (java.math.BigInteger)66 AccountState (org.aion.base.AccountState)37 ImportResult (org.aion.zero.impl.core.ImportResult)31 MiningBlock (org.aion.zero.impl.types.MiningBlock)26 ArrayList (java.util.ArrayList)22 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)22 InternalTransaction (org.aion.types.InternalTransaction)20 Block (org.aion.zero.impl.types.Block)20 BlockContext (org.aion.zero.impl.types.BlockContext)19 DataWord (org.aion.util.types.DataWord)18 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)18 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 Bloom (org.aion.base.Bloom)5 ECKey (org.aion.crypto.ECKey)5