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);
}
}
}
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);
}
}
}
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));
}
}
}
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;
}
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();
}
Aggregations