From 7fdf5628753e4a3b25b064a5f4df9fea85158407 Mon Sep 17 00:00:00 2001 From: Jeff Disher Date: Mon, 18 Nov 2019 16:29:04 -0500 Subject: [PATCH] AKI-556: Added a test that logs produced during deployment can be found -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 --- .../tests/contracts/avm/LogTarget.java | 3 +++ .../tests/integ/AvmReceiptLogTest.java | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Tests/src/org/aion/harness/tests/contracts/avm/LogTarget.java b/Tests/src/org/aion/harness/tests/contracts/avm/LogTarget.java index 959e2770..633bc36f 100644 --- a/Tests/src/org/aion/harness/tests/contracts/avm/LogTarget.java +++ b/Tests/src/org/aion/harness/tests/contracts/avm/LogTarget.java @@ -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() { diff --git a/Tests/test/org/aion/harness/tests/integ/AvmReceiptLogTest.java b/Tests/test/org/aion/harness/tests/integ/AvmReceiptLogTest.java index 216e8523..0751d413 100644 --- a/Tests/test/org/aion/harness/tests/integ/AvmReceiptLogTest.java +++ b/Tests/test/org/aion/harness/tests/integ/AvmReceiptLogTest.java @@ -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 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);