use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class OldTxExecutorTest method testCallTransaction.
@Test
public void testCallTransaction() throws Exception {
Compiler.Result r = Compiler.getInstance().compile(ContractUtils.readContract("Ticker.sol"), Options.ABI, Options.BIN);
CompilationResult cr = CompilationResult.parse(r.output);
// deployer
String deployer = cr.contracts.get("Ticker").bin;
// contract
String contract = deployer.substring(deployer.indexOf("60506040", 1));
byte[] txNonce = BigInteger.ZERO.toByteArray();
AionAddress to = AddressUtils.wrapAddress("2222222222222222222222222222222222222222222222222222222222222222");
byte[] value = BigInteger.ZERO.toByteArray();
byte[] data = Hex.decode("c0004213");
long nrg = new DataWord(100000L).longValue();
long nrgPrice = DataWord.ONE.longValue();
AionTransaction tx = AionTransaction.create(deployerKey, txNonce, to, value, data, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
MiningBlock block = createDummyBlock();
AionRepositoryImpl repo = blockchain.getRepository();
RepositoryCache cache = repo.startTracking();
cache.addBalance(tx.getSenderAddress(), BigInteger.valueOf(100_000).multiply(BigInteger.valueOf(tx.getEnergyPrice())));
cache.createAccount(to);
cache.saveCode(to, Hex.decode(contract));
cache.saveVmType(to, InternalVmType.FVM);
cache.flushTo(repo, true);
AionTxReceipt receipt = executeTransaction(repo, block, tx).getReceipt();
System.out.println(receipt);
assertArrayEquals(Hex.decode("00000000000000000000000000000000"), receipt.getTransactionOutput());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class OldTxExecutorTest 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.base.AionTransaction in project aion by aionnetwork.
the class OpcodeIntegTest method testCallcodeActors.
@Test
public void testCallcodeActors() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO);
AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO);
// Deployer calls contract D which performs CALLCODE to call contract E. From the
// perspective
// of the internal transaction, however, it looks like D calls D.
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.TWO;
byte[] input = // use CALLCODE on E.
ByteUtil.merge(Hex.decode("5cce9fc2"), E.toByteArray());
// pass in 'n' also.
input = ByteUtil.merge(input, new DataWord(0).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
assertEquals(deployer, tx.getSenderAddress());
assertEquals(D, tx.getDestinationAddress());
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// We expect that the internal transaction is sent from D to D.
List<InternalTransaction> internalTxs = summary.getInternalTransactions();
assertEquals(1, internalTxs.size());
assertEquals(D, internalTxs.get(0).sender);
assertEquals(D, internalTxs.get(0).destination);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class OpcodeIntegTest method testNoRevert.
// ====================== test repo & track flushing over multiple levels ======================
@Test
public void testNoRevert() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO);
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.ONE;
byte[] input = ByteUtil.merge(Hex.decode("f854bb89"), new DataWord(6).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// Check that the logs from our internal transactions are as we expect.
List<Log> logs = summary.getReceipt().getLogInfoList();
assertEquals(12, logs.size());
assertArrayEquals(new DataWord(0).getData(), logs.get(0).copyOfData());
assertArrayEquals(new DataWord(6).getData(), logs.get(1).copyOfData());
assertArrayEquals(new DataWord(5).getData(), logs.get(2).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(3).copyOfData());
assertArrayEquals(new DataWord(3).getData(), logs.get(4).copyOfData());
assertArrayEquals(new DataWord(2).getData(), logs.get(5).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(6).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(7).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(8).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(9).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(10).copyOfData());
assertArrayEquals(new DataWord(1).getData(), logs.get(11).copyOfData());
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class OpcodeIntegTest method testRevertAtMidLevel.
@Test
public void testRevertAtMidLevel() throws Exception {
RepositoryCache repo = blockchain.getRepository().startTracking();
AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO);
long nrg = 1_000_000;
long nrgPrice = 1;
BigInteger nonce = BigInteger.ONE;
byte[] input = ByteUtil.merge(Hex.decode("10462fd0"), new DataWord(7).getData());
AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, BigInteger.ZERO.toByteArray(), input, nrg, nrgPrice, TransactionTypes.DEFAULT, null);
BlockContext context = blockchain.createNewMiningBlockContext(blockchain.getBestBlock(), Collections.singletonList(tx), false);
AionTxExecSummary summary = executeTransaction(tx, context.block, repo);
assertEquals("", summary.getReceipt().getError());
assertEquals(summary.getNrgUsed().longValue(), summary.getNrgUsed().longValue());
// Check that the logs from our internal transactions are as we expect.
List<Log> logs = summary.getReceipt().getLogInfoList();
assertEquals(8, logs.size());
assertArrayEquals(new DataWord(0).getData(), logs.get(0).copyOfData());
assertArrayEquals(new DataWord(7).getData(), logs.get(1).copyOfData());
assertArrayEquals(new DataWord(6).getData(), logs.get(2).copyOfData());
assertArrayEquals(new DataWord(5).getData(), logs.get(3).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(4).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(5).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(6).copyOfData());
assertArrayEquals(new DataWord(4).getData(), logs.get(7).copyOfData());
}
Aggregations