Skip to content

Commit

Permalink
AKI-556: Added a test that logs produced during deployment can be found
Browse files Browse the repository at this point in the history
-this just attempts to log data during deployment and verifies that this shows up in the receipt and the "eth_getLogs" result
-note that this depends on kernel commit efb0de4614dca56f49b8064b47a2a8d1871b743c and will fail on line 344 (checking the "eth_getLogs" result), prior to that
  • Loading branch information
jeff-aion committed Nov 18, 2019
1 parent 7590fe1 commit 7fdf562
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tests/src/org/aion/harness/tests/contracts/avm/LogTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class LogTarget {
topic2 = new byte[]{ 8, 8, 0, 1, 4, 2, 0, 1, 2, 6, 8, 3, 4, 6, 8, 8, 0, 1, 4, 2, 0, 1, 2, 6, 8, 3, 4, 6, 8, 8, 0, 1, 4, 2, 0, 1, 2, 6, 8, 3, 4, 6, 8, 8, 0, 1, 4, 2, 0, 1, 2, 6, 8, 3, 4, 6, 8, 8, 0, 1, 4, 2, 0, 1, 2, 6, 8, 3, 4, 6 };
topic3 = new byte[]{ 0xf };
topic4 = new byte[0];

// We also want to write a log entry and check for it on the other side (we will use all the topics, just to make more filtering an option).
writeDataLogWithFourTopics();
}

public static byte[] main() {
Expand Down
26 changes: 26 additions & 0 deletions Tests/test/org/aion/harness/tests/integ/AvmReceiptLogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,32 @@ public void testContractWritesMultipleLogsAndAlsoLogsInternalCall() throws Excep
assertArrayEquals(receipt.getBlockHash(), logs.get(0).copyOfBlockHash());
}

@Test
public void testFourLogsAndDataOnDeployment() throws Exception {
// We inline the deployment logic here since we need the receipt.
SignedTransaction transaction = SignedTransaction.newAvmCreateTransaction(
this.preminedAccount.getPrivateKey(),
this.preminedAccount.getAndIncrementNonce(),
getAvmContractBytes(),
ENERGY_LIMIT,
ENERGY_PRICE,
BigInteger.ZERO, null);

TransactionReceipt receipt = sendTransaction(transaction);
assertTrue(receipt.getAddressOfDeployedContract().isPresent());
Address contractAddress = receipt.getAddressOfDeployedContract().get();
List<TransactionLog> logs = receipt.getLogs();

assertEquals(1, logs.size());
assertIsLogWithFourTopics(contractAddress, logs.get(0));

long blockNumber = receipt.getBlockNumber().longValue();
logs = rpc.getLatestFilteredLogs(blockNumber, Collections.singleton(new byte[]{ 9, 5, 5, 2, 3, 8, 1 }), contractAddress).getResult();
assertEquals(1, logs.size());
assertIsLogWithFourTopics(contractAddress, logs.get(0));
}


private TransactionReceipt callMethodWriteLogsFromInternalCallAlso(Address caller, Address callee, byte[] data)
throws InterruptedException, TimeoutException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException {
SignedTransaction transaction = makeCallTransaction(caller, "writeLogsFromInternalCallAlso", callee.getAddressBytes(), data);
Expand Down

0 comments on commit 7fdf562

Please sign in to comment.