Search in sources :

Example 1 with PrivacyGroup

use of org.web3j.protocol.besu.response.privacy.PrivacyGroup in project besu by hyperledger.

the class PrivacyGroupAcceptanceTest method nodeCanCreatePrivacyGroupWithoutName.

@Test
public void nodeCanCreatePrivacyGroupWithoutName() {
    final String privacyGroupId = alice.execute(privacyTransactions.createPrivacyGroup(null, "my group description", alice, bob));
    assertThat(privacyGroupId).isNotNull();
    final PrivacyGroup expected = new PrivacyGroup(privacyGroupId, PrivacyGroup.Type.PANTHEON, "", "my group description", Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey()));
    alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
    bob.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
}
Also used : Base64String(org.web3j.utils.Base64String) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) Test(org.junit.Test)

Example 2 with PrivacyGroup

use of org.web3j.protocol.besu.response.privacy.PrivacyGroup in project besu by hyperledger.

the class PrivacyGroupAcceptanceTest method nodeCanCreatePrivacyGroup.

@Test
public void nodeCanCreatePrivacyGroup() {
    Log4j2ConfiguratorUtil.setLevel("", Level.DEBUG);
    final String privacyGroupId = alice.execute(privacyTransactions.createPrivacyGroup("myGroupName", "my group description", alice, bob));
    assertThat(privacyGroupId).isNotNull();
    final PrivacyGroup expected = new PrivacyGroup(privacyGroupId, PrivacyGroup.Type.PANTHEON, "myGroupName", "my group description", Base64String.wrapList(alice.getEnclaveKey(), bob.getEnclaveKey()));
    alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
    bob.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
}
Also used : Base64String(org.web3j.utils.Base64String) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) Test(org.junit.Test)

Example 3 with PrivacyGroup

use of org.web3j.protocol.besu.response.privacy.PrivacyGroup in project besu by hyperledger.

the class PrivacyGroupAcceptanceTest method nodeCanCreatePrivacyGroupWithoutOptionalParams.

@Test
public void nodeCanCreatePrivacyGroupWithoutOptionalParams() {
    final String privacyGroupId = alice.execute(privacyTransactions.createPrivacyGroup(null, null, alice));
    assertThat(privacyGroupId).isNotNull();
    final PrivacyGroup expected = new PrivacyGroup(privacyGroupId, PrivacyGroup.Type.PANTHEON, "", "", Base64String.wrapList(alice.getEnclaveKey()));
    alice.verify(privateTransactionVerifier.validPrivacyGroupCreated(expected));
}
Also used : Base64String(org.web3j.utils.Base64String) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) Test(org.junit.Test)

Example 4 with PrivacyGroup

use of org.web3j.protocol.besu.response.privacy.PrivacyGroup in project web3j by web3j.

the class BesuOnChainPrivacyIntegrationTest method testCreateAddRemoveOnChainPrivacyGroup.

@Test
public void testCreateAddRemoveOnChainPrivacyGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String createTxHash = besu.privOnChainCreatePrivacyGroup(privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_BOB)).send().getTransactionHash();
    TransactionReceipt createReceipt = processor.waitForTransactionReceipt(createTxHash);
    assertTrue(createReceipt.isStatusOK());
    final String addTxHash = besu.privOnChainAddToPrivacyGroup(privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_CHARLIE)).send().getTransactionHash();
    TransactionReceipt addReceipt = processor.waitForTransactionReceipt(addTxHash);
    assertTrue(addReceipt.isStatusOK());
    List<PrivacyGroup> groups = besu.privOnChainFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB, ENCLAVE_KEY_CHARLIE)).send().getGroups();
    assertTrue(groups.stream().anyMatch(g -> g.getPrivacyGroupId().equals(privacyGroupId) && g.getMembers().size() == 3));
    final String removeTxHash = besu.privOnChainRemoveFromPrivacyGroup(privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, ENCLAVE_KEY_CHARLIE).send().getTransactionHash();
    TransactionReceipt removeReceipt = processor.waitForTransactionReceipt(removeTxHash);
    assertTrue(removeReceipt.isStatusOK());
    List<PrivacyGroup> removedGroups = besu.privOnChainFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB)).send().getGroups();
    assertTrue(removedGroups.stream().anyMatch(g -> g.getPrivacyGroupId().equals(privacyGroupId) && g.getMembers().size() == 2));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Arrays(java.util.Arrays) TransactionException(org.web3j.protocol.exceptions.TransactionException) ChainIdLong(org.web3j.tx.ChainIdLong) HttpService(org.web3j.protocol.http.HttpService) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) EVMTest(org.web3j.EVMTest) Disabled(org.junit.jupiter.api.Disabled) SecureRandom(java.security.SecureRandom) Credentials(org.web3j.crypto.Credentials) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) BesuPrivacyGasProvider(org.web3j.tx.gas.BesuPrivacyGasProvider) DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH(org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH) DEFAULT_POLLING_FREQUENCY(org.web3j.tx.TransactionManager.DEFAULT_POLLING_FREQUENCY) RESTRICTED(org.web3j.utils.Restriction.RESTRICTED) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Test(org.junit.jupiter.api.Test) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) List(java.util.List) NodeType(org.web3j.NodeType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) Collections(java.util.Collections) Base64String(org.web3j.utils.Base64String) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Base64String(org.web3j.utils.Base64String) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) Base64String(org.web3j.utils.Base64String) EVMTest(org.web3j.EVMTest) Test(org.junit.jupiter.api.Test)

Example 5 with PrivacyGroup

use of org.web3j.protocol.besu.response.privacy.PrivacyGroup in project web3j by web3j.

the class BesuOnChainPrivacyIntegrationTest method testCreateAndFindOnChainPrivacyGroup.

@Test
public void testCreateAndFindOnChainPrivacyGroup() throws Exception {
    Base64String privacyGroupId = Base64String.wrap(generateRandomBytes(32));
    final String txHash = besu.privOnChainCreatePrivacyGroup(privacyGroupId, ALICE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_BOB)).send().getTransactionHash();
    TransactionReceipt receipt = processor.waitForTransactionReceipt(txHash);
    assertTrue(receipt.isStatusOK());
    List<PrivacyGroup> groups = besu.privOnChainFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB)).send().getGroups();
    assertTrue(groups.stream().anyMatch(x -> x.getPrivacyGroupId().equals(privacyGroupId)));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Arrays(java.util.Arrays) TransactionException(org.web3j.protocol.exceptions.TransactionException) ChainIdLong(org.web3j.tx.ChainIdLong) HttpService(org.web3j.protocol.http.HttpService) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) EVMTest(org.web3j.EVMTest) Disabled(org.junit.jupiter.api.Disabled) SecureRandom(java.security.SecureRandom) Credentials(org.web3j.crypto.Credentials) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) BesuPrivacyGasProvider(org.web3j.tx.gas.BesuPrivacyGasProvider) DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH(org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH) DEFAULT_POLLING_FREQUENCY(org.web3j.tx.TransactionManager.DEFAULT_POLLING_FREQUENCY) RESTRICTED(org.web3j.utils.Restriction.RESTRICTED) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Test(org.junit.jupiter.api.Test) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) List(java.util.List) NodeType(org.web3j.NodeType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) Collections(java.util.Collections) Base64String(org.web3j.utils.Base64String) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Base64String(org.web3j.utils.Base64String) PrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivacyGroup) Base64String(org.web3j.utils.Base64String) EVMTest(org.web3j.EVMTest) Test(org.junit.jupiter.api.Test)

Aggregations

PrivacyGroup (org.web3j.protocol.besu.response.privacy.PrivacyGroup)7 Base64String (org.web3j.utils.Base64String)6 Test (org.junit.Test)4 Test (org.junit.jupiter.api.Test)3 BigInteger (java.math.BigInteger)2 SecureRandom (java.security.SecureRandom)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Disabled (org.junit.jupiter.api.Disabled)2 EVMTest (org.web3j.EVMTest)2 NodeType (org.web3j.NodeType)2 Credentials (org.web3j.crypto.Credentials)2 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)2 TransactionException (org.web3j.protocol.exceptions.TransactionException)2