Search in sources :

Example 36 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class Benchmark method createDummyBlock.

private static MiningBlock createDummyBlock() {
    byte[] parentHash = new byte[32];
    byte[] coinbase = RandomUtils.nextBytes(AionAddress.LENGTH);
    byte[] logsBloom = new byte[0];
    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[0];
    // 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 37 with AionAddress

use of org.aion.types.AionAddress 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 38 with AionAddress

use of org.aion.types.AionAddress 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 39 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class ContractIntegTest method deployContract.

private AionAddress deployContract(RepositoryCache repo, AionTransaction tx, String contractName, String contractFilename, BigInteger value, long nrg, long nrgPrice, BigInteger nonce, boolean addToBlockChain) throws IOException, VmFatalException {
    assertTrue(tx.isContractCreationTransaction());
    assertEquals(deployerBalance, repo.getBalance(deployer));
    assertEquals(deployerNonce, repo.getNonce(deployer));
    MiningBlock block = makeBlock(tx);
    AionTxExecSummary summary = executeTransaction(tx, block, repo);
    if (!summary.getReceipt().getError().equals("")) {
        return null;
    }
    assertNotEquals(nrg, summary.getNrgUsed().longValue());
    AionAddress contract = TxUtil.calculateContractAddress(tx);
    if (contractFilename == null) {
        checkStateOfNewContract(repo, contractName, contract, summary.getResult(), FastVmResultCode.SUCCESS, value);
    } else {
        checkStateOfNewContract(repo, contractName, contractFilename, contract, summary.getResult(), FastVmResultCode.SUCCESS, value);
    }
    checkStateOfDeployer(repo, summary, nrgPrice, value, nonce);
    if (addToBlockChain) {
        Pair<ImportResult, AionBlockSummary> result = blockchain.tryToConnectAndFetchSummary(block);
        assertTrue(result.getLeft().isSuccessful());
    }
    return contract;
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTxExecSummary(org.aion.base.AionTxExecSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 40 with AionAddress

use of org.aion.types.AionAddress 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)

Aggregations

AionAddress (org.aion.types.AionAddress)491 Test (org.junit.Test)364 AionTransaction (org.aion.base.AionTransaction)275 BigInteger (java.math.BigInteger)194 ImportResult (org.aion.zero.impl.core.ImportResult)110 AionTxExecSummary (org.aion.base.AionTxExecSummary)97 RepositoryCache (org.aion.base.db.RepositoryCache)90 MiningBlock (org.aion.zero.impl.types.MiningBlock)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)80 ArrayList (java.util.ArrayList)76 ECKey (org.aion.crypto.ECKey)74 AionTxReceipt (org.aion.base.AionTxReceipt)60 Block (org.aion.zero.impl.types.Block)60 AccountState (org.aion.base.AccountState)56 HashMap (java.util.HashMap)42 DataWord (org.aion.util.types.DataWord)39 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)36 InternalTransaction (org.aion.types.InternalTransaction)32 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)29 BlockContext (org.aion.zero.impl.types.BlockContext)29