use of org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt in project besu by hyperledger.
the class FlexibleMultiTenancyAcceptanceTest method createFlexiblePrivacyGroup.
private String createFlexiblePrivacyGroup(final MultiTenancyPrivacyGroup group) {
final List<MultiTenancyPrivacyNode> multiTenancyPrivacyNodes = group.getPrivacyNodes();
final MultiTenancyPrivacyNode groupCreatorMultiTenancyPrivacyNode = multiTenancyPrivacyNodes.get(0);
final PrivacyNode groupCreatorNode = group.getGroupCreatingPrivacyNode();
final String groupCreatorTenant = group.getGroupCreatingTenant();
final List<String> members = group.getTenants();
final String token = groupCreatorMultiTenancyPrivacyNode.getTokenForTenant(groupCreatorTenant);
final CreateFlexiblePrivacyGroupTransaction createTx = privacyTransactions.createFlexiblePrivacyGroup(groupCreatorNode, groupCreatorTenant, members, token);
final PrivacyRequestFactory.PrivxCreatePrivacyGroupResponse createResponse = groupCreatorNode.execute(createTx);
final String privacyGroupId = createResponse.getPrivacyGroupId();
final List<Base64String> base64StringList = members.stream().map(Base64String::wrap).collect(Collectors.toList());
for (final MultiTenancyPrivacyNode mtpn : multiTenancyPrivacyNodes) {
final PrivacyNode privacyNode = mtpn.getPrivacyNode();
for (final String tenant : mtpn.getTenants()) {
if (members.contains(tenant)) {
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(mtpn.getTokenForTenant(tenant));
privacyNode.verify(flexiblePrivacyGroupExists(privacyGroupId, base64StringList));
}
}
}
groupCreatorNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(token);
final String commitmentHash = callGetParticipantsMethodAndReturnCommitmentHash(privacyGroupId, groupCreatorNode, groupCreatorTenant);
final PrivateTransactionReceipt expectedReceipt = buildExpectedAddMemberTransactionReceipt(privacyGroupId, groupCreatorNode, groupCreatorTenant, members.toArray(new String[] {}));
for (final MultiTenancyPrivacyNode mtpn : multiTenancyPrivacyNodes) {
final PrivacyNode privacyNode = mtpn.getPrivacyNode();
for (final String tenant : mtpn.getTenants()) {
if (members.contains(tenant)) {
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(mtpn.getTokenForTenant(tenant));
privacyNode.verify(privateTransactionVerifier.validPrivateTransactionReceipt(commitmentHash, expectedReceipt));
}
}
}
return privacyGroupId;
}
use of org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt in project besu by hyperledger.
the class FlexibleMultiTenancyAcceptanceTest method noAccessWhenNotAMember.
@Test
public void noAccessWhenNotAMember() {
final MultiTenancyPrivacyGroup twoTenantsFromAlice = new MultiTenancyPrivacyGroup();
final List<String> tenants = aliceMultiTenancyPrivacyNode.getTenants();
final String removedTenant = tenants.remove(tenants.size() - 1);
twoTenantsFromAlice.addNodeWithTenants(aliceMultiTenancyPrivacyNode, tenants);
final String privacyGroupId = createFlexiblePrivacyGroup(twoTenantsFromAlice);
final MultiTenancyPrivacyNode multiTenancyPrivacyNode = twoTenantsFromAlice.getPrivacyNodes().get(0);
final String tenant = tenants.get(0);
final PrivacyNode privacyNode = multiTenancyPrivacyNode.getPrivacyNode();
final BesuNode privacyNodeBesu = privacyNode.getBesu();
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final EventEmitter eventEmitter = privacyNode.execute(privateContractTransactions.createSmartContractWithPrivacyGroupId(EventEmitter.class, privacyNode.getTransactionSigningKey(), tenant, privacyGroupId));
final String transactionHash = getContractDeploymentCommitmentHash(eventEmitter);
// check that a member can get the transaction receipt
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
privacyNode.verify(privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, (PrivateTransactionReceipt) eventEmitter.getTransactionReceipt().get()));
final String actual = privacyNode.execute(privacyTransactions.privGetCode(privacyGroupId, Address.fromHexString(eventEmitter.getContractAddress()), "latest")).toHexString();
assertThat(EventEmitter.BINARY).contains(actual.substring(2));
// check that getting the transaction receipt does not work if you are not a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
privacyNode.verify(privateTransactionVerifier.noPrivateTransactionReceipt(// returning null because the RPC is using the enclave key
transactionHash));
// check that getting the code of the event emitter does not work when you are not a member
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.privGetCode(privacyGroupId, Address.fromHexString(eventEmitter.getContractAddress()), "latest"))).hasMessageContaining("Unauthorized");
final LogFilterJsonParameter filterParameter = new LogFilterJsonParameter("earliest", "latest", List.of(eventEmitter.getContractAddress()), Collections.emptyList(), null);
// create a valid filter
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final String filterId = privacyNode.execute(privacyTransactions.newFilter(privacyGroupId, filterParameter));
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final CallPrivateSmartContractFunction storeTransaction = privateContractTransactions.callSmartContractWithPrivacyGroupId(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.valueOf(VALUE_SET)).encodeFunctionCall(), privacyNode.getTransactionSigningKey(), Restriction.RESTRICTED, tenant, privacyGroupId);
final String storeTransactionHash = privacyNode.execute(storeTransaction);
privacyNode.execute(privacyTransactions.getPrivateTransactionReceipt(storeTransactionHash));
// check that getting the filter changes works for a member
assertThat(privacyNode.execute(privacyTransactions.getFilterChanges(privacyGroupId, filterId))).hasSize(1);
// check that getting the filter changes does not work if you are not a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.getFilterChanges(privacyGroupId, filterId))).hasMessageContaining("Unauthorized");
// check that getting the filter logs works for a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
assertThat(privacyNode.execute(privacyTransactions.getFilterLogs(privacyGroupId, filterId))).hasSize(// create privacy group, deploy event emitter, store on event emitter
3);
// check that getting the filter logs does not work if you are not a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.getFilterLogs(privacyGroupId, filterId))).hasMessageContaining("Unauthorized");
// check that getting the logs works for a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
assertThat(privacyNode.execute(privacyTransactions.privGetLogs(privacyGroupId, filterParameter))).hasSize(// create privacy group, deploy event emitter, store on event emitter
3);
// check that getting the logs does not work if you are not a member
privacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.privGetLogs(privacyGroupId, filterParameter))).hasMessageContaining("Unauthorized");
final List<Base64String> base64StringList = tenants.stream().map(Base64String::wrap).collect(Collectors.toList());
// check that a member can find the on-chain privacy group
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final List<PrivacyRequestFactory.FlexiblePrivacyGroup> group = privacyNode.execute(privacyTransactions.findFlexiblePrivacyGroup(Base64String.unwrapList(base64StringList)));
assertThat(group.size()).isEqualTo(1);
assertThat(group.get(0).getMembers()).containsAll(base64StringList).hasSize(2);
// check that when you are not a member you cannot find the privacy group
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.findFlexiblePrivacyGroup(Base64String.unwrapList(base64StringList)))).hasMessageContaining("Error finding flexible privacy group");
// check that a member can do a priv_call
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final EthCall readValue = privacyNode.execute(privacyTransactions.privCall(privacyGroupId, eventEmitter, eventEmitter.value().encodeFunctionCall()));
assertThat(new BigInteger(readValue.getValue().substring(2), 16)).isEqualByComparingTo(BigInteger.valueOf(VALUE_SET));
// check that when you are not a member you cannot do a priv_call
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.privCall(privacyGroupId, eventEmitter, eventEmitter.value().encodeFunctionCall()))).hasMessageContaining("Unauthorized");
// check that a member can do a priv_getTransaction
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenant));
final PrivacyRequestFactory.GetPrivateTransactionResponse privTransaction = privacyNode.execute(privacyTransactions.privGetTransaction(storeTransactionHash));
assertThat(privTransaction.getResult().getPrivacyGroupId()).isEqualTo(privacyGroupId);
// check that when you are not a member you cannot do a priv_getTransaction
privacyNode.getBesu().useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(removedTenant));
assertThatThrownBy(() -> privacyNode.execute(privacyTransactions.privGetTransaction(storeTransactionHash))).hasMessageContaining(// TODO: returning null because the RPC is using the
"Expecting actual not to be null");
// enclave key
}
use of org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt in project besu by hyperledger.
the class BftPrivacyClusterAcceptanceTest method onlyAliceAndBobCanExecuteContract.
@Test
public void onlyAliceAndBobCanExecuteContract() {
// Contract address is generated from sender address and transaction nonce
final String contractAddress = "0xebf56429e6500e84442467292183d4d621359838";
final EventEmitter eventEmitter = alice.execute(privateContractTransactions.createSmartContract(EventEmitter.class, alice.getTransactionSigningKey(), alice.getEnclaveKey(), bob.getEnclaveKey()));
privateContractVerifier.validPrivateContractDeployed(contractAddress, alice.getAddress().toString()).verify(eventEmitter);
final String transactionHash = alice.execute(privateContractTransactions.callSmartContract(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.ONE).encodeFunctionCall(), alice.getTransactionSigningKey(), bftPrivacyType.restriction, alice.getEnclaveKey(), bob.getEnclaveKey()));
final PrivateTransactionReceipt expectedReceipt = alice.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash));
bob.verify(privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, expectedReceipt));
if (bftPrivacyType.restriction != Restriction.UNRESTRICTED) {
charlie.verify(privateTransactionVerifier.noPrivateTransactionReceipt(transactionHash));
}
}
use of org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt in project besu by hyperledger.
the class EnclaveErrorAcceptanceTest method whenEnclaveIsDisconnectedGetReceiptReturnsInternalError.
@Test
public void whenEnclaveIsDisconnectedGetReceiptReturnsInternalError() {
final EventEmitter eventEmitter = alice.execute(privateContractTransactions.createSmartContract(EventEmitter.class, alice.getTransactionSigningKey(), alice.getEnclaveKey(), bob.getEnclaveKey()));
privateContractVerifier.validPrivateContractDeployed(eventEmitter.getContractAddress(), alice.getAddress().toString()).verify(eventEmitter);
final String transactionHash = alice.execute(privateContractTransactions.callSmartContract(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.ONE).encodeFunctionCall(), alice.getTransactionSigningKey(), Restriction.RESTRICTED, alice.getEnclaveKey(), bob.getEnclaveKey()));
final PrivateTransactionReceipt receiptBeforeEnclaveLosesConnection = alice.execute(privacyTransactions.getPrivateTransactionReceipt(transactionHash));
alice.verify(privateTransactionVerifier.validPrivateTransactionReceipt(transactionHash, receiptBeforeEnclaveLosesConnection));
alice.getEnclave().stop();
alice.verify(privateTransactionVerifier.internalErrorPrivateTransactionReceipt(transactionHash));
}
use of org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt in project besu by hyperledger.
the class FlexiblePrivacyAcceptanceTest method setEventEmitterValue.
private PrivateTransactionReceipt setEventEmitterValue(final List<PrivacyNode> nodes, final String privacyGroupId, final EventEmitter eventEmitter, final int value) {
final PrivacyNode firstNode = nodes.get(0);
final String txHash = firstNode.execute(privateContractTransactions.callOnchainPermissioningSmartContract(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.valueOf(value)).encodeFunctionCall(), firstNode.getTransactionSigningKey(), firstNode.getEnclaveKey(), privacyGroupId));
PrivateTransactionReceipt receipt = null;
for (final PrivacyNode node : nodes) {
receipt = node.execute(privacyTransactions.getPrivateTransactionReceipt(txHash));
assertThat(receipt.getStatus()).isEqualTo("0x1");
}
return receipt;
}
Aggregations