Search in sources :

Example 31 with AionTxReceipt

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

the class BlockchainForkingTest method verifyReceipts.

public void verifyReceipts(List<AionTxReceipt> stakerRegistrationReceipts, int expectedSize, boolean checkEnergy) {
    assertThat(stakerRegistrationReceipts.size()).isEqualTo(expectedSize);
    for (AionTxReceipt receipt : stakerRegistrationReceipts) {
        assertThat(receipt.isSuccessful()).isTrue();
        assertThat(receipt.getLogInfoList()).isNotEmpty();
        if (checkEnergy) {
            // the value below can differ slightly depending on the address of the caller
            assertThat(receipt.getEnergyUsed()).isAtLeast(180_000L);
        }
    }
}
Also used : AionTxReceipt(org.aion.base.AionTxReceipt)

Example 32 with AionTxReceipt

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

the class BlockchainPruningTest method verifyReceipts.

public void verifyReceipts(List<AionTxReceipt> stakerRegistrationReceipts, int expectedSize, boolean checkEnergy) {
    assertThat(stakerRegistrationReceipts.size()).isEqualTo(expectedSize);
    for (AionTxReceipt receipt : stakerRegistrationReceipts) {
        assertThat(receipt.isSuccessful()).isTrue();
        assertThat(receipt.getLogInfoList()).isNotEmpty();
        if (checkEnergy) {
            // the value below can differ slightly depending on the address of the caller
            assertThat(receipt.getEnergyUsed()).isAtLeast(180_000L);
        }
    }
}
Also used : AionTxReceipt(org.aion.base.AionTxReceipt)

Example 33 with AionTxReceipt

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

the class TxTest method testTxInfoToJsonDetails.

@Test
public void testTxInfoToJsonDetails() {
    byte[] emptyByteArray = new byte[32];
    Arrays.fill(emptyByteArray, (byte) 0);
    AionAddress coinBase = new AionAddress(Arrays.copyOf(emptyByteArray, 32));
    byte[] parentHash = HashUtil.h256("parent".getBytes());
    byte[] bloom = BloomFilter.create().getBloomFilterBytes();
    byte[] difficulty = BigInteger.TEN.toByteArray();
    long blockNumber = 1;
    long timestamp = System.currentTimeMillis();
    byte[] extraData = new byte[0];
    byte[] nonce = BigInteger.valueOf(100).toByteArray();
    byte[] receiptsRoot = Arrays.copyOf(emptyByteArray, 32);
    byte[] transactionsRoot = Arrays.copyOf(emptyByteArray, 32);
    byte[] stateRoot = Arrays.copyOf(emptyByteArray, 32);
    byte[] solution = new byte[256];
    long nrgConsumed = 0L;
    long nrgLimit = 0;
    byte[] txNonce = ByteUtil.bigIntegerToBytes(BigInteger.ONE);
    AionAddress to = new AionAddress(emptyByteArray);
    AionAddress from = new AionAddress(emptyByteArray);
    byte[] value = ByteUtil.bigIntegerToBytes(BigInteger.TEN);
    byte[] data = Arrays.copyOf(emptyByteArray, 32);
    long txNrgLimit = 10L;
    long txNrgPrice = 10L;
    byte type = 0b1;
    long txNrgUsed = 5L;
    AionTransaction transaction = AionTransaction.createWithoutKey(txNonce, from, to, value, data, txNrgLimit, txNrgPrice, type, null);
    AionTxReceipt txReceipt = new AionTxReceipt();
    txReceipt.setTransaction(transaction);
    txReceipt.setNrgUsed(txNrgUsed);
    MiningBlock block = new MiningBlock(parentHash, coinBase, bloom, difficulty, blockNumber, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, List.of(transaction), solution, nrgConsumed, nrgLimit);
    byte[] hash = block.getHash();
    JSONObject object = Tx.aionTxInfoToDetailsJSON(AionTxInfo.newInstance(txReceipt, block.getHashWrapper(), 0), block);
    assertNotNull(object);
    assertEquals(ByteUtil.byteArrayToLong(txNonce), object.get("nonce"));
    assertEquals(StringUtils.toJsonHex(data), object.get("input"));
    assertEquals(StringUtils.toJsonHex(to.toByteArray()), object.get("to"));
    assertEquals(StringUtils.toJsonHex(from.toByteArray()), object.get("from"));
    assertEquals(txNrgLimit, object.get("nrg"));
    assertEquals(StringUtils.toJsonHex(value), object.get("value"));
    assertEquals(StringUtils.toJsonHex(txNrgPrice), object.get("nrgPrice"));
    assertEquals(new NumericalValue(transaction.getTimestamp()).toHexString(), object.get("timestamp"));
    assertEquals(StringUtils.toJsonHex(blockNumber), object.get("blockNumber"));
    assertEquals(StringUtils.toJsonHex(hash), object.get("blockHash"));
    assertEquals("", object.get("error"));
    assertEquals(new NumericalValue(value).toHexString(), object.get("value"));
    assertFalse(object.getBoolean("hasInternalTransactions"));
    assertTrue(object.getJSONArray("logs").isEmpty());
    assertEquals(new NumericalValue(txNrgUsed).toHexString(), object.get("nrgUsed"));
    assertEquals(new NumericalValue(txNrgUsed).toHexString(), object.get("gasUsed"));
    byte[] onesArray = new byte[32];
    byte[] twosArray = new byte[32];
    Arrays.fill(onesArray, (byte) 1);
    Arrays.fill(twosArray, (byte) 2);
    byte[] logData = new byte[32];
    Arrays.fill(logData, (byte) 7);
    List<byte[]> topics = List.of(onesArray, twosArray);
    Log txLog = Log.topicsAndData(to.toByteArray(), topics, logData);
    AionTransaction transactionWithLog = AionTransaction.createWithoutKey(txNonce, from, to, value, data, txNrgLimit, txNrgPrice, type, null);
    AionTxReceipt txReceiptWithLog = new AionTxReceipt();
    txReceiptWithLog.setLogs(List.of(txLog));
    txReceiptWithLog.setTransaction(transactionWithLog);
    txReceiptWithLog.setNrgUsed(txNrgUsed);
    MiningBlock blockWithLog = new MiningBlock(parentHash, coinBase, bloom, difficulty, blockNumber, timestamp, extraData, nonce, receiptsRoot, transactionsRoot, stateRoot, List.of(transactionWithLog), solution, nrgConsumed, nrgLimit);
    JSONObject jsonWithLogs = Tx.aionTxInfoToDetailsJSON(AionTxInfo.newInstance(txReceiptWithLog, blockWithLog.getHashWrapper(), 0), blockWithLog);
    assertNotNull(jsonWithLogs);
    List<Object> jsonArray = jsonWithLogs.getJSONArray("logs").toList();
    for (Object log : jsonArray) {
        assertEquals(StringUtils.toJsonHex(to.toByteArray()), ((Map) log).get("address"));
        assertEquals(StringUtils.toJsonHex(logData), ((Map) log).get("data"));
        ArrayList jsonTopics = (ArrayList) ((Map) log).get("topics");
        for (int i = 0; i < topics.size(); i++) {
            assertEquals(StringUtils.toJsonHex(topics.get(i)), jsonTopics.get(i));
        }
    }
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) AionTxReceipt(org.aion.base.AionTxReceipt) Test(org.junit.Test)

Example 34 with AionTxReceipt

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

the class AionPendingStateImpl method createDroppedReceipt.

private AionTxReceipt createDroppedReceipt(AionTransaction tx, String error) {
    AionTxReceipt txReceipt = new AionTxReceipt();
    txReceipt.setTransaction(tx);
    txReceipt.setError(error);
    return txReceipt;
}
Also used : AionTxReceipt(org.aion.base.AionTxReceipt)

Example 35 with AionTxReceipt

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

the class AionPendingStateImpl method rerunTxsInPool.

private void rerunTxsInPool(Block block) {
    addRepayTxToTxPool();
    List<AionTransaction> pendingTxl = txPool.snapshotAll();
    LOGGER_TX.info("rerunTxsInPool - snapshotAll tx[{}]", pendingTxl.size());
    if (!pendingTxl.isEmpty()) {
        for (AionTransaction tx : pendingTxl) {
            LOGGER_TX.debug("rerunTxsInPool - loop: {}", tx);
            AionTxExecSummary txSum = executeTx(tx);
            AionTxReceipt receipt = txSum.getReceipt();
            receipt.setTransaction(tx);
            if (txSum.isRejected()) {
                LOGGER_TX.debug("Invalid transaction in txPool: {}", tx);
                txPool.remove(new PooledTransaction(tx, receipt.getEnergyUsed()));
                removeBackupDBPendingTx(tx.getTransactionHash());
                fireTxUpdate(receipt, PendingTransactionState.DROPPED, block);
            } else {
                if (repayTransaction.contains(tx)) {
                    txPool.updatePoolTransaction(new PooledTransaction(tx, receipt.getEnergyUsed()));
                }
                fireTxUpdate(receipt, PendingTransactionState.PENDING, block);
            }
        }
    }
    repayTransaction.clear();
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) AionTransaction(org.aion.base.AionTransaction) PooledTransaction(org.aion.base.PooledTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Aggregations

AionTxReceipt (org.aion.base.AionTxReceipt)111 Test (org.junit.Test)76 AionTransaction (org.aion.base.AionTransaction)74 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)61 AionAddress (org.aion.types.AionAddress)56 BigInteger (java.math.BigInteger)53 ImportResult (org.aion.zero.impl.core.ImportResult)50 MiningBlock (org.aion.zero.impl.types.MiningBlock)43 ArrayList (java.util.ArrayList)24 Block (org.aion.zero.impl.types.Block)24 AionTxExecSummary (org.aion.base.AionTxExecSummary)17 RepositoryCache (org.aion.base.db.RepositoryCache)17 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)15 Builder (org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder)14 ECKey (org.aion.crypto.ECKey)12 SolidityType (org.aion.solidity.SolidityType)10 AccountState (org.aion.base.AccountState)9 Log (org.aion.types.Log)9 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)7 StakingBlock (org.aion.zero.impl.types.StakingBlock)7