diff --git a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivTraceTransactionAcceptanceTest.java b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivTraceTransactionAcceptanceTest.java index ffc41f6acab..af3ebedbe74 100644 --- a/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivTraceTransactionAcceptanceTest.java +++ b/acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivTraceTransactionAcceptanceTest.java @@ -29,6 +29,8 @@ import java.math.BigInteger; import java.util.Optional; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Test; import org.web3j.utils.Restriction; @@ -36,6 +38,8 @@ public class PrivTraceTransactionAcceptanceTest extends ParameterizedEnclaveTest private final PrivacyNode node; + private final PrivacyNode wrongNode; + public PrivTraceTransactionAcceptanceTest( final Restriction restriction, final EnclaveType enclaveType, @@ -54,7 +58,18 @@ public PrivTraceTransactionAcceptanceTest( false, restriction == UNRESTRICTED); + wrongNode = + privacyBesu.createPrivateTransactionEnabledMinerNode( + restriction + "-node", + PrivacyAccountResolver.BOB.resolve(enclaveEncryptorType), + enclaveType, + Optional.empty(), + false, + false, + restriction == UNRESTRICTED); + privacyCluster.start(node); + privacyCluster.start(wrongNode); } @Test @@ -66,19 +81,81 @@ public void getTransactionTrace() { Updating the contract value */ Hash transactionHash = - Hash.fromHexString(doTransaction(privacyGroupId, simpleStorageContract, 1)); + Hash.fromHexString(doTransaction(privacyGroupId, simpleStorageContract, 0)); final String result = node.execute(privacyTransactions.privTraceTransaction(privacyGroupId, transactionHash)); - System.out.println("privTransactionTrace = " + result); assertThat(result).isNotNull(); + ObjectMapper mapper = new ObjectMapper(); + try { + JsonNode rootNode = mapper.readTree(result); + JsonNode resultNode = rootNode.get("result"); + + assertThat(resultNode).isNotNull(); + assertThat(resultNode.isArray()).isTrue(); + assertThat(resultNode.size()).isGreaterThan(0); + + JsonNode trace = resultNode.get(0); + assertThat(trace.get("action").get("callType").asText()).isEqualTo("call"); + assertThat(trace.get("action").get("from").asText()).isEqualTo(node.getAddress().toString()); + assertThat(trace.get("action").get("input").asText()).startsWith("0x60fe47b1"); + assertThat(trace.get("action").get("to").asText()) + .isEqualTo(simpleStorageContract.getContractAddress()); + assertThat(trace.get("action").get("value").asText()).isEqualTo("0x0"); + assertThat(trace.get("blockHash").asText()).isNotEmpty(); + assertThat(trace.get("blockNumber").asInt()).isGreaterThan(0); + assertThat(trace.get("transactionHash").asText()).isEqualTo(transactionHash.toString()); + assertThat(trace.get("type").asText()).isEqualTo("call"); + + } catch (Exception e) { + e.printStackTrace(); + } + + final String wrongPrivacyGroupId = createWrongPrivacyGroup(); + + final String resultEmpty = + wrongNode.execute( + privacyTransactions.privTraceTransaction(wrongPrivacyGroupId, transactionHash)); + + ObjectMapper mapperEmpty = new ObjectMapper(); + try { + JsonNode rootNode = mapperEmpty.readTree(resultEmpty); + JsonNode resultNode = rootNode.get("result"); + + assertThat(resultNode).isNotNull(); + assertThat(resultNode.isArray()).isTrue(); + assertThat(resultNode.isEmpty()).isTrue(); + + } catch (Exception e) { + e.printStackTrace(); + } + + final String resultWrongHash = + wrongNode.execute(privacyTransactions.privTraceTransaction(privacyGroupId, Hash.EMPTY)); + + ObjectMapper mapperWrongHash = new ObjectMapper(); + try { + JsonNode rootNode = mapperWrongHash.readTree(resultWrongHash); + JsonNode resultNode = rootNode.get("result"); + + assertThat(resultNode).isNotNull(); + assertThat(resultNode.isArray()).isTrue(); + assertThat(resultNode.isEmpty()).isTrue(); + + } catch (Exception e) { + e.printStackTrace(); + } } private String createPrivacyGroup() { return node.execute(createPrivacyGroup("myGroupName", "my group description", node)); } + private String createWrongPrivacyGroup() { + return wrongNode.execute(createPrivacyGroup("myGroupName", "my group description", wrongNode)); + } + private SimpleStorage deploySimpleStorageContract(final String privacyGroupId) { final SimpleStorage simpleStorage = node.execute( diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index e2e135d40e2..586a0fadb18 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'zns89fore/VSEiEk1mmdfIO/pX0ktMJ8Ks4j1Z6Ecoo=' + knownHash = '53dRJ5mnFaM86Wslf2y/UE33DHPsJJV6kbH8vhUsY2o=' } check.dependsOn('checkAPIChanges')