Search in sources :

Example 11 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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());
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 12 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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());
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 13 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class OpcodeIntegTest method testOpcodesActors.

// ============================= test CALL, CALLCODE, DELEGATECALL =============================
@Test
public void testOpcodesActors() throws Exception {
    RepositoryCache repo = blockchain.getRepository().startTracking();
    AionAddress callerContract = deployContract(repo, "Caller", "Opcodes.sol", BigInteger.ZERO);
    AionAddress calleeContract = deployContract(repo, "Callee", "Opcodes.sol", BigInteger.ZERO);
    System.err.println("Deployer: " + deployer);
    System.err.println("Caller: " + callerContract);
    System.err.println("Callee: " + calleeContract);
    long nrg = 1_000_000;
    long nrgPrice = 1;
    BigInteger nonce = BigInteger.TWO;
    byte[] input = ByteUtil.merge(Hex.decode("fc68521a"), calleeContract.toByteArray());
    AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), callerContract, 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());
    // We examine the logs to determine the expected state. We expect to see
    // owner-caller-origin-data as follows for each opcode:
    // 
    // CALL             -->     CALLEE-CALLER-DEPLOYER-ZERO
    // CALLCODE         -->     CALLER-CALLER-DEPLOYER-ZERO
    // DELEGATECALL     -->     CALLER-DEPLOYER-DEPLOYER-ZERO
    List<Log> logs = summary.getReceipt().getLogInfoList();
    assertEquals(3, logs.size());
    verifyLogData(logs.get(0).copyOfData(), calleeContract, callerContract, deployer);
    verifyLogData(logs.get(1).copyOfData(), callerContract, callerContract, deployer);
    verifyLogData(logs.get(2).copyOfData(), callerContract, deployer, deployer);
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 14 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class OpcodeIntegTest method testDelegateCallActors.

@Test
public void testDelegateCallActors() 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);
    BigInteger n = new BigInteger("23786523");
    // Deployer calls contract D which performs DELEGATECALL to call contract E.
    long nrg = 1_000_000;
    long nrgPrice = 1;
    BigInteger value = new BigInteger("4364463");
    BigInteger nonce = BigInteger.TWO;
    byte[] input = // use DELEGATECALL on E.
    ByteUtil.merge(Hex.decode("32817e1d"), E.toByteArray());
    // pass in 'n' also.
    input = ByteUtil.merge(input, new DataWord(n).getData());
    AionTransaction tx = AionTransaction.create(deployerKey, nonce.toByteArray(), D, value.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 there to be one internal transaction and it should look like deployer sent to
    // D.
    List<InternalTransaction> internalTxs = summary.getInternalTransactions();
    assertEquals(1, internalTxs.size());
    assertEquals(deployer, internalTxs.get(0).sender);
    assertEquals(D, internalTxs.get(0).destination);
}
Also used : AionAddress(org.aion.types.AionAddress) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) InternalTransaction(org.aion.types.InternalTransaction) Test(org.junit.Test)

Example 15 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class OpcodeIntegTest method testRevertAtBottomLevel.

@Test
public void testRevertAtBottomLevel() 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("8256cff3"), new DataWord(5).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(5).getData(), logs.get(1).copyOfData());
    assertArrayEquals(new DataWord(4).getData(), logs.get(2).copyOfData());
    assertArrayEquals(new DataWord(3).getData(), logs.get(3).copyOfData());
    assertArrayEquals(new DataWord(2).getData(), logs.get(4).copyOfData());
    assertArrayEquals(new DataWord(2).getData(), logs.get(5).copyOfData());
    assertArrayEquals(new DataWord(2).getData(), logs.get(6).copyOfData());
    assertArrayEquals(new DataWord(2).getData(), logs.get(7).copyOfData());
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) DataWord(org.aion.util.types.DataWord) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Aggregations

RepositoryCache (org.aion.base.db.RepositoryCache)120 Test (org.junit.Test)102 AionAddress (org.aion.types.AionAddress)90 AionTransaction (org.aion.base.AionTransaction)89 AionTxExecSummary (org.aion.base.AionTxExecSummary)72 BigInteger (java.math.BigInteger)43 MiningBlock (org.aion.zero.impl.types.MiningBlock)41 AccountState (org.aion.base.AccountState)38 DataWord (org.aion.util.types.DataWord)23 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)23 ImportResult (org.aion.zero.impl.core.ImportResult)22 InternalTransaction (org.aion.types.InternalTransaction)18 Block (org.aion.zero.impl.types.Block)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)16 BlockContext (org.aion.zero.impl.types.BlockContext)15 SolidityType (org.aion.solidity.SolidityType)10 ArrayList (java.util.ArrayList)8 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)7 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)6