Search in sources :

Example 1 with RESTRICTED

use of org.web3j.utils.Restriction.RESTRICTED in project web3j by web3j.

the class BesuPrivacyQuickstartIntegrationTest method privacyGroupContract.

@Test
public void privacyGroupContract() throws Exception {
    // Build new privacy group using the create API
    final Base64String aliceBobGroup = nodeAlice.privCreatePrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB), "AliceBob", "AliceBob group").send().getPrivacyGroupId();
    // Find the privacy group that was built by Alice from Bob's node
    final Base64String aliceBobGroupFromBobNode = nodeBob.privFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB)).send().getGroups().stream().filter(g -> g.getName().equals("AliceBob") && g.getDescription().equals("AliceBob group") && g.getPrivacyGroupId().equals(aliceBobGroup)).findFirst().orElseThrow(RuntimeException::new).getPrivacyGroupId();
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager tmBob = new PrivateTransactionManager(nodeBob, BOB, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_BOB, aliceBobGroupFromBobNode, RESTRICTED);
    PrivateTransactionManager tmAlice = new PrivateTransactionManager(nodeAlice, ALICE, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_ALICE, aliceBobGroupFromBobNode, RESTRICTED);
    final HumanStandardToken tokenAlice = HumanStandardToken.deploy(nodeAlice, tmAlice, ZERO_GAS_PROVIDER, BigInteger.TEN, "eea_token", BigInteger.TEN, "EEATKN").send();
    final HumanStandardToken tokenBob = HumanStandardToken.load(tokenAlice.getContractAddress(), nodeBob, tmBob, ZERO_GAS_PROVIDER);
    tokenAlice.transfer(BOB.getAddress(), BigInteger.TEN).send();
    testBalances(tokenAlice, tokenBob, BigInteger.ZERO, BigInteger.TEN);
}
Also used : PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ChainIdLong(org.web3j.tx.ChainIdLong) HttpService(org.web3j.protocol.http.HttpService) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Disabled(org.junit.jupiter.api.Disabled) Credentials(org.web3j.crypto.Credentials) BeforeAll(org.junit.jupiter.api.BeforeAll) BigInteger(java.math.BigInteger) PrivateTransactionEncoder(org.web3j.protocol.eea.crypto.PrivateTransactionEncoder) 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) IOException(java.io.IOException) PrivateTransactionWithPrivacyGroup(org.web3j.protocol.besu.response.privacy.PrivateTransactionWithPrivacyGroup) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) TransactionEncoder(org.web3j.crypto.TransactionEncoder) Sign(org.web3j.crypto.Sign) Test(org.junit.jupiter.api.Test) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) Numeric(org.web3j.utils.Numeric) RawPrivateTransaction(org.web3j.protocol.eea.crypto.RawPrivateTransaction) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) Collections(java.util.Collections) Base64String(org.web3j.utils.Base64String) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Base64String(org.web3j.utils.Base64String) Test(org.junit.jupiter.api.Test)

Example 2 with RESTRICTED

use of org.web3j.utils.Restriction.RESTRICTED in project web3j by web3j.

the class BesuOnChainPrivacyIntegrationTest method testCanExecuteSmartContractsInOnChainPrivacyGroup.

@Test
public void testCanExecuteSmartContractsInOnChainPrivacyGroup() throws Exception {
    Base64String aliceBobGroup = Base64String.wrap(generateRandomBytes(32));
    final String createTxHash = besu.privOnChainCreatePrivacyGroup(aliceBobGroup, ALICE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_BOB)).send().getTransactionHash();
    TransactionReceipt createReceipt = processor.waitForTransactionReceipt(createTxHash);
    assertTrue(createReceipt.isStatusOK());
    // Find the privacy group that was built by Alice from Bob's node
    final Base64String aliceBobGroupFromBobNode = besu.privOnChainFindPrivacyGroup(Arrays.asList(ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB)).send().getGroups().stream().filter(g -> g.getPrivacyGroupId().equals(aliceBobGroup)).findFirst().orElseThrow(RuntimeException::new).getPrivacyGroupId();
    TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
    PrivateTransactionManager tmAlice = new PrivateTransactionManager(besu, ALICE, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_ALICE, aliceBobGroupFromBobNode, RESTRICTED);
    PrivateTransactionManager tmBob = new PrivateTransactionManager(besu, BOB, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_BOB, aliceBobGroupFromBobNode, RESTRICTED);
    final HumanStandardToken tokenAlice = HumanStandardToken.deploy(besu, tmAlice, ZERO_GAS_PROVIDER, BigInteger.TEN, "eea_token", BigInteger.TEN, "EEATKN").send();
    final HumanStandardToken tokenBob = HumanStandardToken.load(tokenAlice.getContractAddress(), besu, tmBob, ZERO_GAS_PROVIDER);
    tokenAlice.transfer(BOB.getAddress(), BigInteger.TEN).send();
    testBalances(tokenAlice, tokenBob, BigInteger.ZERO, BigInteger.TEN);
}
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) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) PrivateTransactionManager(org.web3j.tx.PrivateTransactionManager) PollingPrivateTransactionReceiptProcessor(org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor) TransactionReceiptProcessor(org.web3j.tx.response.TransactionReceiptProcessor) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Base64String(org.web3j.utils.Base64String) HumanStandardToken(org.web3j.test.contract.HumanStandardToken) Base64String(org.web3j.utils.Base64String) EVMTest(org.web3j.EVMTest) Test(org.junit.jupiter.api.Test)

Aggregations

BigInteger (java.math.BigInteger)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2 Credentials (org.web3j.crypto.Credentials)2 HttpService (org.web3j.protocol.http.HttpService)2 HumanStandardToken (org.web3j.test.contract.HumanStandardToken)2 ChainIdLong (org.web3j.tx.ChainIdLong)2 PrivateTransactionManager (org.web3j.tx.PrivateTransactionManager)2 DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH (org.web3j.tx.TransactionManager.DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH)2 DEFAULT_POLLING_FREQUENCY (org.web3j.tx.TransactionManager.DEFAULT_POLLING_FREQUENCY)2 BesuPrivacyGasProvider (org.web3j.tx.gas.BesuPrivacyGasProvider)2 PollingPrivateTransactionReceiptProcessor (org.web3j.tx.response.PollingPrivateTransactionReceiptProcessor)2 TransactionReceiptProcessor (org.web3j.tx.response.TransactionReceiptProcessor)2 Base64String (org.web3j.utils.Base64String)2 RESTRICTED (org.web3j.utils.Restriction.RESTRICTED)2 IOException (java.io.IOException)1