use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class FvmBulkTransactionTest method getDeployedTickerCountValue.
private int getDeployedTickerCountValue(ECKey sender, BigInteger nonce, AionAddress contract) {
// This hash will call the 'getTicker' function of the deployed contract (giving us the
// count).
byte[] callBytes = Hex.decode("c0004213");
AionTransaction transaction = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, new byte[0], callBytes, 2_000_000, this.energyPrice, TransactionTypes.DEFAULT, null);
AionBlockSummary summary = sendTransactionsInBulkInSingleBlock(Collections.singletonList(transaction));
return new DataWord(summary.getReceipts().get(0).getTransactionOutput()).intValue();
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class InternalTransactionTest method testLogs.
@Test
public void testLogs() throws InterruptedException {
String contractA = "0x605060405234156100105760006000fd5b610015565b61013c806100246000396000f30060506040526000356c01000000000000000000000000900463ffffffff1680632d7df21a146100335761002d565b60006000fd5b341561003f5760006000fd5b61006660048080806010013590359091602001909192908035906010019091905050610068565b005b7fc1599bd9a91e57420b9b93745d7475dc054736a3f2becd4f08b450b7012e125760405160405180910390a1828282600060405180806f662829000000000000000000000000008152601001506003019050604051809103902090506c01000000000000000000000000900491906040518363ffffffff166c01000000000000000000000000028152600401600060405180830381858a8a89f195505050505050505b5050505600a165627a7a723058205e51c42347e4353247e8419ef6cda02250d358868e2cb3782d0d5d74065f2ef70029";
String contractB = "0x605060405234156100105760006000fd5b610015565b60cb806100236000396000f30060506040526000356c01000000000000000000000000900463ffffffff16806326121ff014603157602b565b60006000fd5b3415603c5760006000fd5b60426044565b005b600060007f45b3fe4256d6d198dc4c34457a04e8c048ce54df933a93061f1a0e386b52f7a260405160405180910390a160009150600090505b6103e8811015609a57808201915081505b8080600101915050607d565b5b50505600a165627a7a72305820b2bf8aef36001079d347d250e50b098ad52629336644a841d19db288f30667470029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
// ======================
// DEPLOY
// ======================
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx1 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx2 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractB), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx1, tx2), false);
ImportResult result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionAddress addressA = TxUtil.calculateContractAddress(tx1);
System.out.println("contract A = " + addressA);
AionAddress addressB = TxUtil.calculateContractAddress(tx2);
System.out.println("contract B = " + addressB);
Thread.sleep(1000);
// ======================
// CALL B
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx3 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressB, new byte[0], ByteUtil.hexStringToBytes("0x26121ff0"), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx3), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
AionTxInfo info = bc.getTransactionInfo(tx3.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(1, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
// ======================
// CALL A (calls B, 80k)
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx4 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressA, new byte[0], ByteUtil.merge(ByteUtil.hexStringToBytes("0x2d7df21a"), addressB.toByteArray(), new DataWord(80_000).getData()), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx4), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
info = bc.getTransactionInfo(tx4.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(2, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
// ======================
// CALL A (calls B, 20k)
// ======================
nonce = nonce.add(BigInteger.ONE);
AionTransaction tx6 = AionTransaction.create(deployerAccount, nonce.toByteArray(), addressA, new byte[0], ByteUtil.merge(ByteUtil.hexStringToBytes("0x2d7df21a"), addressB.toByteArray(), new DataWord(20_000).getData()), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx6), false);
result = bc.tryToConnect(context.block);
assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST);
info = bc.getTransactionInfo(tx6.getTransactionHash());
System.out.println(info.getReceipt());
assertEquals(1, info.getReceipt().getLogInfoList().size());
Thread.sleep(1000);
}
use of org.aion.util.types.DataWord 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);
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class TransactionExecutorTest method extractActualOutput.
private byte[] extractActualOutput(byte[] rawOutput) {
// I'm guessing: first data word is the number of bytes that follows. Then those following
// bytes denote the size of the output, which follows these last bytes.
int len = new DataWord(Arrays.copyOfRange(rawOutput, 0, DataWord.BYTES)).intValue();
byte[] outputLen = new byte[len];
System.arraycopy(rawOutput, DataWord.BYTES, outputLen, 0, len);
int outputSize = new BigInteger(outputLen).intValue();
byte[] out = new byte[outputSize];
System.arraycopy(rawOutput, DataWord.BYTES + len, out, 0, outputSize);
return out;
}
use of org.aion.util.types.DataWord in project aion by aionnetwork.
the class ContractIntegTest method testRecursiveStackoverflow.
@Test
public void testRecursiveStackoverflow() throws Exception {
String contractName = "Recursive";
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);
AionAddress contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce);
if (txType == TransactionTypes.AVM_CREATE_CODE) {
assertNull(contract);
return;
}
deployerBalance = repo.getBalance(deployer);
deployerNonce = repo.getNonce(deployer);
// First recurse 1 time less than the max and verify this is ok.
// Note that 128 == FvmConstants.MAX_CALL_DEPTH
int numRecurses = 127;
byte[] input = ByteUtil.merge(Hex.decode("2d7df21a"), contract.toByteArray());
input = ByteUtil.merge(input, new DataWord(numRecurses + 1).getData());
tx = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, BigInteger.ZERO.toByteArray(), input, 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());
BigInteger txCost = BigInteger.valueOf(summary.getNrgUsed().longValue()).multiply(BigInteger.valueOf(nrgPrice));
assertEquals(deployerBalance.subtract(txCost), repo.getBalance(deployer));
deployerBalance = repo.getBalance(deployer);
deployerNonce = repo.getNonce(deployer);
repo.flushTo(blockchain.getRepository(), true);
repo = blockchain.getRepository().startTracking();
// Now recurse the max amount of times and ensure we fail.
// Note that 128 == FvmConstants.MAX_CALL_DEPTH
numRecurses = 128;
input = ByteUtil.merge(Hex.decode("2d7df21a"), contract.toByteArray());
input = ByteUtil.merge(input, new DataWord(numRecurses + 1).getData());
nonce = nonce.add(BigInteger.ONE);
tx = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, txType, null);
assertFalse(tx.isContractCreationTransaction());
block = makeBlock(tx);
summary = executeTransaction(tx, block, repo);
assertEquals("reverted", summary.getReceipt().getError());
assertNotEquals(nrg, summary.getNrgUsed().longValue());
txCost = BigInteger.valueOf(summary.getNrgUsed().longValue()).multiply(BigInteger.valueOf(nrgPrice));
assertEquals(deployerBalance.subtract(txCost), repo.getBalance(deployer));
}
Aggregations