use of org.web3j.tx.response.TransactionReceiptProcessor in project web3j by web3j.
the class BesuPrivacyQuickstartIntegrationTest method legacyContract.
@Test
public void legacyContract() throws Exception {
TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
PrivateTransactionManager tmAlice = new PrivateTransactionManager(nodeAlice, ALICE, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_ALICE, Collections.singletonList(ENCLAVE_KEY_BOB), RESTRICTED);
PrivateTransactionManager tmBob = new PrivateTransactionManager(nodeBob, BOB, transactionReceiptProcessor, ChainIdLong.NONE, ENCLAVE_KEY_BOB, Collections.singletonList(ENCLAVE_KEY_ALICE), 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);
}
use of org.web3j.tx.response.TransactionReceiptProcessor 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);
}
use of org.web3j.tx.response.TransactionReceiptProcessor in project web3j by web3j.
the class PrivateTransactionManagerTest method sendPrivCallRevertedTest.
@Test
public void sendPrivCallRevertedTest() throws IOException {
when(response.isReverted()).thenReturn(true);
when(response.getRevertReason()).thenReturn(OWNER_REVERT_MSG_STR);
when(service.send(any(), any())).thenReturn(response);
TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
PrivateTransactionManager besuTransactionManager = new PrivateTransactionManager(besu, credentials, transactionReceiptProcessor, ChainIdLong.NONE, PRIVATE_FROM, PRIVACY_GROUP_ID, RESTRICTED);
ContractCallException thrown = assertThrows(ContractCallException.class, () -> besuTransactionManager.sendCall("", "", defaultBlockParameter));
assertEquals(String.format(REVERT_ERR_STR, OWNER_REVERT_MSG_STR), thrown.getMessage());
}
use of org.web3j.tx.response.TransactionReceiptProcessor in project web3j by web3j.
the class PrivateTransactionManagerTest method sendPrivCallTest.
@Test
public void sendPrivCallTest() throws IOException {
when(response.getValue()).thenReturn("test");
when(service.send(any(), any())).thenReturn(response);
TransactionReceiptProcessor transactionReceiptProcessor = new PollingPrivateTransactionReceiptProcessor(besu, DEFAULT_POLLING_FREQUENCY, DEFAULT_POLLING_ATTEMPTS_PER_TX_HASH);
PrivateTransactionManager besuTransactionManager = new PrivateTransactionManager(besu, credentials, transactionReceiptProcessor, ChainIdLong.NONE, PRIVATE_FROM, PRIVACY_GROUP_ID, RESTRICTED);
String value = besuTransactionManager.sendCall("", "", defaultBlockParameter);
assertEquals("test", value);
}
use of org.web3j.tx.response.TransactionReceiptProcessor 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);
}
Aggregations