Search in sources :

Example 1 with EventEmitter

use of org.hyperledger.besu.tests.web3j.generated.EventEmitter in project besu by hyperledger.

the class FlexibleMultiTenancyAcceptanceTest method removedMemberCannotGetFilterChanges.

@Test
public void removedMemberCannotGetFilterChanges() {
    final MultiTenancyPrivacyGroup allTenantsFromAlice = new MultiTenancyPrivacyGroup();
    final List<String> tenants = aliceMultiTenancyPrivacyNode.getTenants();
    allTenantsFromAlice.addNodeWithTenants(aliceMultiTenancyPrivacyNode, tenants);
    final String privacyGroupId = createFlexiblePrivacyGroup(allTenantsFromAlice);
    final MultiTenancyPrivacyNode multiTenancyPrivacyNode = allTenantsFromAlice.getPrivacyNodes().get(0);
    final String groupCreatingTenant = allTenantsFromAlice.getGroupCreatingTenant();
    final String tenantToBeRemoved = tenants.stream().filter(t -> !t.equals(groupCreatingTenant)).findFirst().orElseThrow();
    final PrivacyNode groupCreatingPrivacyNode = allTenantsFromAlice.getGroupCreatingPrivacyNode();
    final BesuNode groupCreatingPrivacyNodeBesu = groupCreatingPrivacyNode.getBesu();
    groupCreatingPrivacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(groupCreatingTenant));
    final EventEmitter eventEmitter = groupCreatingPrivacyNode.execute(privateContractTransactions.createSmartContractWithPrivacyGroupId(EventEmitter.class, groupCreatingPrivacyNode.getTransactionSigningKey(), groupCreatingTenant, privacyGroupId));
    final LogFilterJsonParameter filterParameter = new LogFilterJsonParameter("earliest", "latest", List.of(eventEmitter.getContractAddress()), Collections.emptyList(), null);
    final String filterId = groupCreatingPrivacyNode.execute(privacyTransactions.newFilter(privacyGroupId, filterParameter));
    final CallPrivateSmartContractFunction storeTransaction = privateContractTransactions.callSmartContractWithPrivacyGroupId(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.valueOf(VALUE_SET)).encodeFunctionCall(), groupCreatingPrivacyNode.getTransactionSigningKey(), Restriction.RESTRICTED, groupCreatingTenant, privacyGroupId);
    final String storeTransactionHash = groupCreatingPrivacyNode.execute(storeTransaction);
    groupCreatingPrivacyNode.execute(privacyTransactions.getPrivateTransactionReceipt(storeTransactionHash));
    // check that getting the filter changes works for a member
    groupCreatingPrivacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenantToBeRemoved));
    assertThat(groupCreatingPrivacyNode.execute(privacyTransactions.getFilterChanges(privacyGroupId, filterId))).hasSize(1);
    groupCreatingPrivacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(groupCreatingTenant));
    final CallPrivateSmartContractFunction store2Transaction = privateContractTransactions.callSmartContractWithPrivacyGroupId(eventEmitter.getContractAddress(), eventEmitter.store(BigInteger.valueOf(VALUE_SET)).encodeFunctionCall(), groupCreatingPrivacyNode.getTransactionSigningKey(), Restriction.RESTRICTED, groupCreatingTenant, privacyGroupId);
    final String store2TransactionHash = groupCreatingPrivacyNode.execute(store2Transaction);
    groupCreatingPrivacyNode.execute(privacyTransactions.getPrivateTransactionReceipt(store2TransactionHash));
    // now remove from privacy group
    final String removeTransactionHash = removeFromPrivacyGroup(privacyGroupId, groupCreatingPrivacyNode, groupCreatingTenant, Credentials.create(groupCreatingPrivacyNode.getTransactionSigningKey()), tenantToBeRemoved);
    groupCreatingPrivacyNode.execute(privacyTransactions.getPrivateTransactionReceipt(removeTransactionHash));
    // check that it does not work anymore when member has been removed
    groupCreatingPrivacyNodeBesu.useAuthenticationTokenInHeaderForJsonRpc(multiTenancyPrivacyNode.getTokenForTenant(tenantToBeRemoved));
    assertThatThrownBy(() -> groupCreatingPrivacyNode.execute(privacyTransactions.getFilterChanges(privacyGroupId, filterId))).hasMessageContaining("Unauthorized");
}
Also used : BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) PrivacyNode(org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode) LogFilterJsonParameter(org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter) CallPrivateSmartContractFunction(org.hyperledger.besu.tests.acceptance.dsl.privacy.contract.CallPrivateSmartContractFunction) Base64String(org.web3j.utils.Base64String) Test(org.junit.Test)

Example 2 with EventEmitter

use of org.hyperledger.besu.tests.web3j.generated.EventEmitter 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
}
Also used : PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) PrivacyNode(org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode) PrivacyRequestFactory(org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyRequestFactory) Base64String(org.web3j.utils.Base64String) EthCall(org.web3j.protocol.core.methods.response.EthCall) Base64String(org.web3j.utils.Base64String) BesuNode(org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode) EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) LogFilterJsonParameter(org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter) CallPrivateSmartContractFunction(org.hyperledger.besu.tests.acceptance.dsl.privacy.contract.CallPrivateSmartContractFunction) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 3 with EventEmitter

use of org.hyperledger.besu.tests.web3j.generated.EventEmitter in project besu by hyperledger.

the class BftPrivacyClusterAcceptanceTest method aliceCanDeployMultipleTimesInSingleGroup.

@Test
public void aliceCanDeployMultipleTimesInSingleGroup() {
    final String firstDeployedAddress = "0xebf56429e6500e84442467292183d4d621359838";
    privacyCluster.stopNode(charlie);
    final EventEmitter firstEventEmitter = alice.execute(privateContractTransactions.createSmartContract(EventEmitter.class, alice.getTransactionSigningKey(), alice.getEnclaveKey(), bob.getEnclaveKey()));
    privateContractVerifier.validPrivateContractDeployed(firstDeployedAddress, alice.getAddress().toString()).verify(firstEventEmitter);
    final String secondDeployedAddress = "0x10f807f8a905da5bd319196da7523c6bd768690f";
    final EventEmitter secondEventEmitter = alice.execute(privateContractTransactions.createSmartContract(EventEmitter.class, alice.getTransactionSigningKey(), alice.getEnclaveKey(), bob.getEnclaveKey()));
    privateContractVerifier.validPrivateContractDeployed(secondDeployedAddress, alice.getAddress().toString()).verify(secondEventEmitter);
}
Also used : EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) Test(org.junit.Test)

Example 4 with EventEmitter

use of org.hyperledger.besu.tests.web3j.generated.EventEmitter 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));
    }
}
Also used : EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) Test(org.junit.Test)

Example 5 with EventEmitter

use of org.hyperledger.besu.tests.web3j.generated.EventEmitter 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));
}
Also used : EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) Test(org.junit.Test)

Aggregations

EventEmitter (org.hyperledger.besu.tests.web3j.generated.EventEmitter)35 Test (org.junit.Test)32 PrivateTransactionReceipt (org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt)13 BigInteger (java.math.BigInteger)9 LogFilterJsonParameter (org.hyperledger.besu.tests.acceptance.dsl.privacy.util.LogFilterJsonParameter)7 EthCall (org.web3j.protocol.core.methods.response.EthCall)6 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)6 Base64String (org.web3j.utils.Base64String)6 LogResult (org.web3j.protocol.core.methods.response.EthLog.LogResult)3 BesuNode (org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode)2 PrivacyNode (org.hyperledger.besu.tests.acceptance.dsl.privacy.PrivacyNode)2 CallPrivateSmartContractFunction (org.hyperledger.besu.tests.acceptance.dsl.privacy.contract.CallPrivateSmartContractFunction)2 CrossContractReader (org.hyperledger.besu.tests.web3j.generated.CrossContractReader)2 Credentials (org.web3j.crypto.Credentials)2 Disposable (io.reactivex.disposables.Disposable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 PrivacyRequestFactory (org.hyperledger.besu.tests.acceptance.dsl.transaction.privacy.PrivacyRequestFactory)1 StoredEventResponse (org.hyperledger.besu.tests.web3j.generated.EventEmitter.StoredEventResponse)1