Search in sources :

Example 11 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class ContractIntegTest method testFvmEmptyContractWith226160EnergyAfterUnity.

@Test
public void testFvmEmptyContractWith226160EnergyAfterUnity() throws IOException, VmFatalException {
    long unityForkBlock = 2;
    blockchain.forkUtility.enableUnityFork(unityForkBlock);
    ECKey stakingRegistryOwner = accounts.get(1);
    List<ECKey> stakers = new ArrayList<>(accounts);
    stakers.remove(deployerKey);
    stakers.remove(stakingRegistryOwner);
    assertThat(stakers.size()).isEqualTo(8);
    // the default configuration does not apply to this test case
    AvmTestConfig.clearConfigurations();
    AvmTestConfig.supportBothAvmVersions(0, unityForkBlock, 0);
    // populating the chain to be above the Unity for point
    BlockchainTestUtils.generateRandomUnityChain(blockchain, resourceProvider, unityForkBlock + 1, 1, stakers, stakingRegistryOwner, 10);
    String contractName = "EmptyContract";
    byte[] deployCode = getDeployCode(contractName);
    long nrg = 226160;
    long nrgPrice = energyPrice;
    BigInteger value = BigInteger.ZERO;
    BigInteger nonce = BigInteger.ZERO;
    // to == null  signals that this is contract creation.
    AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
    assertTrue(tx.isContractCreationTransaction());
    assertEquals(Builder.DEFAULT_BALANCE, blockchain.getRepository().getBalance(deployer));
    assertEquals(BigInteger.ZERO, blockchain.getRepository().getNonce(deployer));
    // The transaction has invalid energylimit settings
    MiningBlock block = makeBlock(tx);
    RepositoryCache repo = blockchain.getRepository().startTracking();
    AionTxExecSummary summary = BulkExecutor.executeTransactionWithNoPostExecutionWork(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), tx, repo, false, true, false, false, LOGGER_VM, BlockCachingContext.PENDING, block.getNumber() - 1, false, false);
    if (txType == TransactionTypes.DEFAULT) {
        assertEquals("OUT_OF_NRG", summary.getReceipt().getError());
        checkStateOfDeployer(repo, summary, nrgPrice, value, nonce.add(BigInteger.ONE));
        assertEquals(nrg, summary.getReceipt().getEnergyUsed());
    } else if (txType == TransactionTypes.AVM_CREATE_CODE) {
        assertEquals("Failed: invalid data", summary.getReceipt().getError());
        nonce = nonce.add(BigInteger.ONE);
        checkStateOfDeployer(repo, summary, nrgPrice, value, nonce);
        assertEquals(nrg, summary.getReceipt().getEnergyUsed());
    }
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) RepositoryCache(org.aion.base.db.RepositoryCache) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 12 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class OldTxExecutorTest method testCallTransaction.

@Test
public void testCallTransaction() throws Exception {
    Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
    CompilationResult cr = CompilationResult.parse(r.output);
    // deployer
    String deployer = cr.contracts.get("Ticker").bin;
    // contract
    String contract = deployer.substring(deployer.indexOf("60506040", 1));
    byte[] txNonce = BigInteger.ZERO.toByteArray();
    AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
    byte[] value = BigInteger.ZERO.toByteArray();
    byte[] data = Hex.decode("c0004213");
    long nrg = new DataWord(100000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    AionTransaction tx = AionTransaction.create(deployerKey, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
    MiningBlock block = createDummyBlock();
    AionRepositoryImpl repo = blockchain.getRepository();
    RepositoryCache cache = repo.startTracking();
    cache.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
    cache.createAccount(to);
    cache.saveCode(to, Hex.decode(contract));
    cache.saveVmType(to, InternalVmType.FVM);
    cache.flushTo(repo, true);
    AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
    System.out.println(receipt);
    assertArrayEquals(Hex.decode("00000000000000000000000000000000"), receipt.getTransactionOutput());
}
Also used : Compiler(org.aion.solidity.Compiler) AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) AionRepositoryImpl(org.aion.zero.impl.db.AionRepositoryImpl) MiningBlock(org.aion.zero.impl.types.MiningBlock) RepositoryCache(org.aion.base.db.RepositoryCache) CompilationResult(org.aion.solidity.CompilationResult) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 13 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class OldTxExecutorTest method createDummyBlock.

private static MiningBlock createDummyBlock() {
    byte[] parentHash = new byte[32];
    byte[] coinbase = RandomUtils.nextBytes(AionAddress.LENGTH);
    byte[] logsBloom = new byte[256];
    byte[] difficulty = new DataWord(0x1000000L).getData();
    long number = 1;
    long timestamp = System.currentTimeMillis() / 1000;
    byte[] extraData = new byte[0];
    byte[] nonce = new byte[32];
    byte[] receiptsRoot = new byte[32];
    byte[] transactionsRoot = new byte[32];
    byte[] stateRoot = new byte[32];
    List<AionTransaction> transactionsList = Collections.emptyList();
    byte[] solutions = new byte[1408];
    // TODO: set a dummy limit of 5000000 for now
    return new MiningBlock(parentHash, new AionAddress(coinbase), logsBloom, difficulty, number, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, transactionsList, solutions, 0, 5000000);
}
Also used : AionAddress(org.aion.types.AionAddress) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 14 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class StatefulnessTest method sendTransactions.

private AionTxReceipt sendTransactions(AionTransaction... transactions) {
    Block parentBlock = this.blockchain.getBestBlock();
    MiningBlock block = this.blockchain.createBlock(parentBlock, Arrays.asList(transactions), false, parentBlock.getTimestamp());
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
    return connectResult.getRight().getReceipts().get(0);
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 15 with MiningBlock

use of org.aion.zero.impl.types.MiningBlock in project aion by aionnetwork.

the class FvmBulkTransactionTest method sendTransactionsInBulkInSingleBlock.

private AionBlockSummary sendTransactionsInBulkInSingleBlock(List<AionTransaction> transactions) {
    Block parentBlock = this.blockchain.getBestBlock();
    MiningBlock block = this.blockchain.createBlock(parentBlock, transactions, false, parentBlock.getTimestamp());
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
    return connectResult.getRight();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Aggregations

MiningBlock (org.aion.zero.impl.types.MiningBlock)185 Test (org.junit.Test)136 AionTransaction (org.aion.base.AionTransaction)128 ImportResult (org.aion.zero.impl.core.ImportResult)81 AionAddress (org.aion.types.AionAddress)79 BigInteger (java.math.BigInteger)64 Block (org.aion.zero.impl.types.Block)63 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)59 RepositoryCache (org.aion.base.db.RepositoryCache)41 AionTxReceipt (org.aion.base.AionTxReceipt)37 ArrayList (java.util.ArrayList)36 ECKey (org.aion.crypto.ECKey)27 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)27 AionTxExecSummary (org.aion.base.AionTxExecSummary)25 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)24 MiningBlockHeader (org.aion.zero.impl.types.MiningBlockHeader)22 BlockContext (org.aion.zero.impl.types.BlockContext)18 DataWord (org.aion.util.types.DataWord)13 MockDB (org.aion.db.impl.mockdb.MockDB)12 StakingBlock (org.aion.zero.impl.types.StakingBlock)11