Search in sources :

Example 41 with AionTransaction

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

the class Benchmark method signTransactions.

private static List<AionTransaction> signTransactions(int num) {
    long t1 = System.currentTimeMillis();
    List<AionTransaction> list = new ArrayList<>();
    long ownerNonce = repo.getNonce(owner).longValue();
    for (int i = 0; i < num; i++) {
        byte[] recipient = RandomUtils.nextBytes(AionAddress.LENGTH);
        recipients.add(recipient);
        // transfer token to random people
        byte[] nonce = BigInteger.valueOf(ownerNonce + i).toByteArray();
        AionAddress to = contract;
        byte[] value = BigInteger.ZERO.toByteArray();
        byte[] data = ByteUtil.merge(Hex.decode("fbb001d6" + "000000000000000000000000"), recipient, BigInteger.ONE.toByteArray());
        long nrg = 1_000_000L;
        long nrgPrice = 10_000_000_000L;
        AionTransaction tx = AionTransaction.create(key, nonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
        list.add(tx);
    }
    long t2 = System.currentTimeMillis();
    timeSignTransactions = t2 - t1;
    return list;
}
Also used : AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction)

Example 42 with AionTransaction

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

the class Benchmark method verifyState.

private static void verifyState() throws VmFatalException {
    long ownerNonce = repo.getNonce(owner).longValue();
    for (int i = 0; i < recipients.size(); i++) {
        byte[] nonce = BigInteger.valueOf(ownerNonce + i).toByteArray();
        AionAddress to = contract;
        byte[] value = BigInteger.ZERO.toByteArray();
        byte[] data = ByteUtil.merge(Hex.decode("70a08231" + "000000000000000000000000"), recipients.get(i));
        long nrg = 1_000_000L;
        long nrgPrice = 10_000_000_000L;
        AionTransaction tx = AionTransaction.create(key, nonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
        AionTxExecSummary summary = executeTransaction(tx);
        assertFalse(summary.isFailed());
        assertEquals(1, new DataWord(summary.getReceipt().getTransactionOutput()).longValue());
    }
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) AionTransaction(org.aion.base.AionTransaction) DataWord(org.aion.util.types.DataWord)

Example 43 with AionTransaction

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

the class Benchmark method executeTransactions.

private static List<AionTxReceipt> executeTransactions(List<AionTransaction> txs) throws VmFatalException {
    long t1 = System.currentTimeMillis();
    List<AionTxReceipt> list = new ArrayList<>();
    for (AionTransaction tx : txs) {
        AionTxExecSummary summary = executeTransaction(tx);
        assertFalse(summary.isFailed());
        list.add(summary.getReceipt());
    }
    long t2 = System.currentTimeMillis();
    timeExecuteTransactions = t2 - t1;
    return list;
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 44 with AionTransaction

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

the class ContractIntegTest method testFvmConstructorIsCalledOnCodeDeployment.

@Test
public void testFvmConstructorIsCalledOnCodeDeployment() throws Exception {
    String contractName = "MultiFeatureContract";
    byte[] deployCode = ContractUtils.getContractDeployer("MultiFeatureContract.sol", "MultiFeatureContract");
    long nrg = 1_000_000;
    long nrgPrice = energyPrice;
    BigInteger value = BigInteger.ONE;
    BigInteger nonce = BigInteger.ZERO;
    AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
    RepositoryCache repo = blockchain.getRepository().startTracking();
    nonce = nonce.add(BigInteger.ONE);
    AionAddress contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce);
    if (txType == TransactionTypes.DEFAULT) {
        // Now call the contract and check that the constructor message was set.
        String getMsgFunctionHash = "ce6d41de";
        tx = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, BigInteger.ZERO.toByteArray(), Hex.decode(getMsgFunctionHash), nrg, nrgPrice, txType, null);
        assertFalse(tx.isContractCreationTransaction());
        MiningBlock block = makeBlock(tx);
        AionTxExecSummary summary = executeTransaction(tx, block, repo);
        assertEquals("", summary.getReceipt().getError());
        assertNotEquals(nrg, summary.getNrgUsed().longValue());
        String expectedMsg = "Im alive!";
        assertEquals(expectedMsg, new String(extractOutput(summary.getResult())));
    } else if (txType == TransactionTypes.AVM_CREATE_CODE) {
        assertNull(contract);
    }
}
Also used : AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 45 with AionTransaction

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

the class ContractIntegTest method tellFvmContractCallWithinDeployingBlock.

@Test
public void tellFvmContractCallWithinDeployingBlock() throws IOException {
    if (txType == TransactionTypes.AVM_CREATE_CODE) {
        return;
    }
    String contractName = "InternalCallContract";
    byte[] deployCode = getDeployCode(contractName);
    long nrg = Constants.NRG_TRANSACTION_MAX;
    long nrgPrice = energyPrice;
    BigInteger value = BigInteger.ZERO;
    BigInteger nonce = BigInteger.ZERO;
    AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice, txType, null);
    RepositoryCache repo = blockchain.getRepository().startTracking();
    nonce = nonce.add(BigInteger.ONE);
    assertTrue(tx.isContractCreationTransaction());
    assertEquals(deployerBalance, repo.getBalance(deployer));
    assertEquals(deployerNonce, repo.getNonce(deployer));
    List<AionTransaction> ls = new ArrayList<>();
    ls.add(tx);
    byte[] input = Arrays.copyOfRange(HashUtil.keccak256("sendValueToContract()".getBytes()), 0, 4);
    AionTransaction tx2 = AionTransaction.create(deployerKey, nonce.toByteArray(), TxUtil.calculateContractAddress(tx), BigInteger.TEN.toByteArray(), input, nrg, nrgPrice, txType, null);
    assertFalse(tx2.isContractCreationTransaction());
    ls.add(tx2);
    BigInteger senderBalance = repo.getBalance(deployer);
    Block parent = blockchain.getBestBlock();
    MiningBlock block = blockchain.createBlock(parent, ls, false, parent.getTimestamp());
    Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
    AionBlockSummary summary = result.getRight();
    assertTrue(result.getLeft().isSuccessful());
    AionAddress contractAddress = TxUtil.calculateContractAddress(tx);
    assertEquals(BigInteger.TEN, blockchain.getRepository().getBalance(contractAddress));
    assertEquals(senderBalance.subtract(BigInteger.TEN).subtract(BigInteger.valueOf(summary.getReceipts().get(0).getEnergyUsed()).multiply(BigInteger.valueOf(nrgPrice))).subtract(BigInteger.valueOf(summary.getReceipts().get(1).getEnergyUsed()).multiply(BigInteger.valueOf(nrgPrice))), blockchain.getRepository().getBalance(deployer));
    repo = blockchain.getRepository().startTracking();
    assertEquals(BigInteger.TWO, repo.getNonce(deployer));
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionAddress(org.aion.types.AionAddress) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) BigInteger(java.math.BigInteger) AionRepositoryCache(org.aion.zero.impl.db.AionRepositoryCache) RepositoryCache(org.aion.base.db.RepositoryCache) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) Test(org.junit.Test)

Aggregations

AionTransaction (org.aion.base.AionTransaction)437 Test (org.junit.Test)308 AionAddress (org.aion.types.AionAddress)273 BigInteger (java.math.BigInteger)174 MiningBlock (org.aion.zero.impl.types.MiningBlock)149 ArrayList (java.util.ArrayList)127 ImportResult (org.aion.zero.impl.core.ImportResult)115 AionTxExecSummary (org.aion.base.AionTxExecSummary)103 Block (org.aion.zero.impl.types.Block)102 RepositoryCache (org.aion.base.db.RepositoryCache)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)87 AionTxReceipt (org.aion.base.AionTxReceipt)75 ECKey (org.aion.crypto.ECKey)52 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)46 BlockContext (org.aion.zero.impl.types.BlockContext)43 PooledTransaction (org.aion.base.PooledTransaction)40 AccountState (org.aion.base.AccountState)39 Properties (java.util.Properties)35 HashMap (java.util.HashMap)33 DataWord (org.aion.util.types.DataWord)29