Search in sources :

Example 46 with AionAddress

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

the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnFailure.

@Test
public void testLogAndInternalTransactionsOnFailure() {
    AvmVersion version = AvmVersion.VERSION_1;
    AionAddress contract = deployContract(version, BigInteger.ZERO);
    AionAddress other = deployContract(version, BigInteger.ONE);
    Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsAndFail");
    AionBlockSummary summary = connectResult.getRight();
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    AionTxReceipt receipt = summary.getReceipts().get(0);
    assertFalse(receipt.isSuccessful());
    List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
    List<Log> logs = receipt.getLogInfoList();
    assertEquals(0, logs.size());
    assertEquals(1, internalTransactions.size());
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) AionTxReceipt(org.aion.base.AionTxReceipt) InternalTransaction(org.aion.types.InternalTransaction) AvmVersion(org.aion.avm.stub.AvmVersion) Test(org.junit.Test)

Example 47 with AionAddress

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

the class AvmProviderTest method testBalanceTransferTransactionVersion2WithCoinbaseLock.

@Test
public void testBalanceTransferTransactionVersion2WithCoinbaseLock() throws Exception {
    Assert.assertTrue(AvmProvider.tryAcquireLock(1, TimeUnit.MINUTES));
    AvmProvider.enableAvmVersion(AvmVersion.VERSION_2, this.projectRootDir);
    AvmProvider.startAvm(AvmVersion.VERSION_2, true);
    // Set up the repo and give the sender account some balance.
    RepositoryCache repository = newRepository();
    AionAddress sender = randomAddress();
    AionAddress recipient = randomAddress();
    addBalance(repository, sender, BigInteger.valueOf(1_000_000));
    // Run the transaction.
    RepositoryCache repositoryChild = repository.startTracking();
    IAvmExternalState externalState = newExternalState(AvmVersion.VERSION_2, repositoryChild, newEnergyRules());
    Transaction transaction = newBalanceTransferTransaction(sender, recipient, BigInteger.TEN);
    IAionVirtualMachine avm = AvmProvider.getAvm(AvmVersion.VERSION_2);
    IAvmFutureResult[] futures = avm.run(externalState, new Transaction[] { transaction }, AvmExecutionType.MINING, 0);
    // Assert the result and state changes we expect.
    Assert.assertEquals(1, futures.length);
    TransactionResult result = futures[0].getResult();
    Assert.assertTrue(result.transactionStatus.isSuccess());
    Assert.assertEquals(BigInteger.TEN, repositoryChild.getBalance(recipient));
    AvmProvider.shutdownAvm(AvmVersion.VERSION_2);
    AvmProvider.disableAvmVersion(AvmVersion.VERSION_2);
    AvmProvider.releaseLock();
}
Also used : IAvmExternalState(org.aion.avm.stub.IAvmExternalState) TransactionResult(org.aion.types.TransactionResult) AionAddress(org.aion.types.AionAddress) Transaction(org.aion.types.Transaction) IAvmFutureResult(org.aion.avm.stub.IAvmFutureResult) RepositoryCache(org.aion.base.db.RepositoryCache) IAionVirtualMachine(org.aion.avm.stub.IAionVirtualMachine) Test(org.junit.Test)

Example 48 with AionAddress

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

the class AccountManager method createAccount.

@Override
public AionAddress createAccount(String password) {
    String address = Keystore.create(password);
    ECKey key = Keystore.getKey(address, password);
    logger.debug("<create-success addr={}>", address);
    AionAddress aionAddress = new AionAddress(key.getAddress());
    this.accounts.put(aionAddress, new Account(key, 0));
    return aionAddress;
}
Also used : AionAddress(org.aion.types.AionAddress) ECKey(org.aion.crypto.ECKey)

Example 49 with AionAddress

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

the class SolidityTypeTest 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 50 with AionAddress

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

the class TotalCurrencyContract method executeUpdateTotalBalance.

private PrecompiledTransactionResult executeUpdateTotalBalance(byte[] input, long nrg) {
    // update total portion
    if (nrg < COST) {
        return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("OUT_OF_NRG"), 0);
    }
    if (input.length < 114) {
        return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
    }
    // process input data
    int offset = 0;
    PrecompiledDataWord chainId = PrecompiledDataWord.fromInt(input[0]);
    offset++;
    byte signum = input[1];
    offset++;
    byte[] amount = new byte[16];
    byte[] sign = new byte[96];
    System.arraycopy(input, offset, amount, 0, 16);
    offset += 16;
    System.arraycopy(input, offset, sign, 0, 96);
    IExternalCapabilitiesForPrecompiled capabilities = CapabilitiesProvider.getExternalCapabilities();
    byte[] payload = new byte[18];
    System.arraycopy(input, 0, payload, 0, 18);
    boolean b = capabilities.verifyEd25519Signature(payload, sign);
    if (!b) {
        return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
    }
    // verify public key matches owner
    if (!this.ownerAddress.equals(new AionAddress(capabilities.getEd25519Address(sign)))) {
        return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
    }
    // payload processing
    IPrecompiledDataWord totalCurr = this.externalState.getStorageValue(this.address, chainId);
    BigInteger totalCurrBI = totalCurr == null ? BigInteger.ZERO : BIUtil.toBI(totalCurr.copyOfData());
    BigInteger value = BIUtil.toBI(amount);
    if (signum != 0x0 && signum != 0x1) {
        return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
    }
    BigInteger finalValue;
    if (signum == 0x0) {
        // addition
        finalValue = totalCurrBI.add(value);
    } else {
        // subtraction
        if (value.compareTo(totalCurrBI) > 0) {
            return new PrecompiledTransactionResult(TransactionStatus.nonRevertedFailure("FAILURE"), 0);
        }
        finalValue = totalCurrBI.subtract(value);
    }
    // store result and successful exit
    this.externalState.addStorageValue(this.address, chainId, PrecompiledDataWord.fromBytes(finalValue.toByteArray()));
    return new PrecompiledTransactionResult(TransactionStatus.successful(), nrg - COST);
}
Also used : IExternalCapabilitiesForPrecompiled(org.aion.precompiled.type.IExternalCapabilitiesForPrecompiled) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AionAddress(org.aion.types.AionAddress) IPrecompiledDataWord(org.aion.precompiled.type.IPrecompiledDataWord) BigInteger(java.math.BigInteger) PrecompiledDataWord(org.aion.precompiled.type.PrecompiledDataWord) IPrecompiledDataWord(org.aion.precompiled.type.IPrecompiledDataWord)

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