Search in sources :

Example 11 with Log

use of org.aion.types.Log 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 12 with Log

use of org.aion.types.Log 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 13 with Log

use of org.aion.types.Log 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)

Example 14 with Log

use of org.aion.types.Log in project aion by aionnetwork.

the class BridgeControllerOwnerTest method testTransferOwnership.

@Test
public void testTransferOwnership() {
    byte[] transferOwnership = capabilities.keccak256("ChangedOwner(address)".getBytes());
    byte[] newOwner = capabilities.blake2b("newOwner".getBytes());
    this.controller.initialize();
    this.controller.setNewOwner(OWNER_ADDR.toByteArray(), newOwner);
    // sanity check
    assertThat(this.connector.getNewOwner()).isEqualTo(newOwner);
    ErrCode err = this.controller.acceptOwnership(newOwner);
    assertThat(err).isEqualTo(ErrCode.NO_ERROR);
    assertThat(this.connector.getOwner()).isEqualTo(newOwner);
    // check that an event was properly generated
    assertThat(this.logs.size()).isEqualTo(1);
    Log changedOwnerLog = this.logs.get(0);
    assertThat(changedOwnerLog.copyOfData()).isEqualTo(new byte[0]);
    assertThat(changedOwnerLog.copyOfTopics().get(0)).isEqualTo(transferOwnership);
    assertThat(changedOwnerLog.copyOfTopics().get(1)).isEqualTo(newOwner);
}
Also used : Log(org.aion.types.Log) Test(org.junit.Test)

Example 15 with Log

use of org.aion.types.Log in project aion by aionnetwork.

the class BridgeTransferTest method testBundleMultipleTransferSameRecipient.

// Transfer 511 times, ONE per transfer
// Also thoroughly checks event signatures
@Test
public void testBundleMultipleTransferSameRecipient() {
    final byte[] senderAddress = members[0];
    final byte[] blockHash = capabilities.blake2b("blockHash".getBytes());
    final byte[] recipient = capabilities.blake2b("recipient".getBytes());
    final byte[] aionTransactionHash = capabilities.blake2b("aionTransactionHash".getBytes());
    int transferTotal = 511;
    final BigInteger transferTotalBigInteger = BigInteger.valueOf(transferTotal);
    this.repo.addBalance(CONTRACT_ADDR, transferTotalBigInteger);
    BridgeTransfer[] transfers = new BridgeTransfer[transferTotal];
    for (int i = 0; i < transferTotal; i++) {
        byte[] randomBytes = new byte[32];
        new SecureRandom().nextBytes(randomBytes);
        transfers[i] = BridgeTransfer.getInstance(BigInteger.ONE, recipient, randomBytes);
    }
    ResultHashTuple tuple = executeSignController(senderAddress, blockHash, aionTransactionHash, transfers);
    assertThat(tuple.results.controllerResult).isEqualTo(ErrCode.NO_ERROR);
    assertThat(this.repo.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.ZERO);
    assertThat(this.repo.getBalance(new AionAddress(recipient))).isEqualTo(transferTotalBigInteger);
    // 511 transfer events + 1 distributed event
    assertThat(this.context.getLogs().size()).isEqualTo(512);
    List<Log> logs = this.context.getLogs();
    for (int i = 0; i < 511; i++) {
        List<byte[]> topics = logs.get(i).copyOfTopics();
        assertThat(topics.get(0)).isEqualTo(BridgeEventSig.DISTRIBUTED.getHashed());
        assertThat(topics.get(1)).isEqualTo(transfers[i].getSourceTransactionHash());
        assertThat(topics.get(2)).isEqualTo(transfers[i].getRecipient());
        assertThat(topics.get(3)).isEqualTo(PrecompiledUtilities.pad(transfers[i].getTransferValueByteArray(), 32));
    }
    // for the last element
    {
        List<byte[]> topics = logs.get(511).copyOfTopics();
        assertThat(topics.get(0)).isEqualTo(BridgeEventSig.PROCESSED_BUNDLE.getHashed());
        assertThat(topics.get(1)).isEqualTo(blockHash);
        assertThat(topics.get(2)).isEqualTo(tuple.bundleHash);
    }
}
Also used : AionAddress(org.aion.types.AionAddress) Log(org.aion.types.Log) BigInteger(java.math.BigInteger) SecureRandom(java.security.SecureRandom) List(java.util.List) Test(org.junit.Test)

Aggregations

Log (org.aion.types.Log)31 AionAddress (org.aion.types.AionAddress)21 Test (org.junit.Test)18 BigInteger (java.math.BigInteger)14 AionTransaction (org.aion.base.AionTransaction)11 AionTxReceipt (org.aion.base.AionTxReceipt)8 InternalTransaction (org.aion.types.InternalTransaction)8 ArrayList (java.util.ArrayList)6 AionTxExecSummary (org.aion.base.AionTxExecSummary)5 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)5 PrecompiledTransactionContext (org.aion.precompiled.type.PrecompiledTransactionContext)5 BlockContext (org.aion.zero.impl.types.BlockContext)5 RepositoryCache (org.aion.base.db.RepositoryCache)4 BridgeTransfer (org.aion.precompiled.contracts.ATB.BridgeTransfer)4 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 JSONArray (org.json.JSONArray)4 List (java.util.List)3 ECKey (org.aion.crypto.ECKey)3 DataWord (org.aion.util.types.DataWord)3