Search in sources :

Example 1 with CrossContractReader

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

the class PrivateContractPublicStateAcceptanceTest method privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract.

@Test
public void privateContractMustNotBeAbleToCallPublicContractWhichInstantiatesContract() throws Exception {
    final CrossContractReader privateReader = transactionNode.execute(privateContractTransactions.createSmartContract(CrossContractReader.class, transactionNode.getTransactionSigningKey(), transactionNode.getEnclaveKey()));
    final CrossContractReader publicReader = transactionNode.execute(contractTransactions.createSmartContract(CrossContractReader.class));
    assertThatExceptionOfType(TransactionException.class).isThrownBy(() -> privateReader.deployRemote(publicReader.getContractAddress()).send()).returns(0, e -> e.getTransactionReceipt().get().getLogs().size());
}
Also used : CrossContractReader(org.hyperledger.besu.tests.web3j.generated.CrossContractReader) Test(org.junit.Test)

Example 2 with CrossContractReader

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

the class PrivateContractPublicStateAcceptanceTest method privateContractMustNotBeAbleToCallPublicContractWhichChangesState.

@Test
public void privateContractMustNotBeAbleToCallPublicContractWhichChangesState() throws Exception {
    final CrossContractReader privateReader = transactionNode.execute(privateContractTransactions.createSmartContract(CrossContractReader.class, transactionNode.getTransactionSigningKey(), transactionNode.getEnclaveKey()));
    final CrossContractReader publicReader = transactionNode.execute(contractTransactions.createSmartContract(CrossContractReader.class));
    assertThatExceptionOfType(TransactionException.class).isThrownBy(() -> privateReader.incrementRemote(publicReader.getContractAddress()).send()).returns("0x", e -> ((PrivateTransactionReceipt) e.getTransactionReceipt().get()).getOutput());
}
Also used : CrossContractReader(org.hyperledger.besu.tests.web3j.generated.CrossContractReader) Test(org.junit.Test)

Example 3 with CrossContractReader

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

the class PrivateContractPublicStateAcceptanceTest method mustNotAllowAccessToPrivateStateFromPublicTx.

@Test
public void mustNotAllowAccessToPrivateStateFromPublicTx() throws Exception {
    final EventEmitter privateEventEmitter = transactionNode.execute((privateContractTransactions.createSmartContract(EventEmitter.class, transactionNode.getTransactionSigningKey(), transactionNode.getEnclaveKey())));
    final TransactionReceipt receipt = privateEventEmitter.store(BigInteger.valueOf(12)).send();
    assertThat(receipt).isNotNull();
    final CrossContractReader publicReader = transactionNode.execute(contractTransactions.createSmartContract(CrossContractReader.class));
    final RemoteFunctionCall<BigInteger> functionCall = publicReader.read(privateEventEmitter.getContractAddress());
    assertThatThrownBy(functionCall::send).isInstanceOf(ContractCallException.class);
}
Also used : EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) CrossContractReader(org.hyperledger.besu.tests.web3j.generated.CrossContractReader) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 4 with CrossContractReader

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

the class PrivateContractPublicStateAcceptanceTest method privateContractMustNotBeAbleToCallSelfDestructOnPublicContract.

@Test
public void privateContractMustNotBeAbleToCallSelfDestructOnPublicContract() throws Exception {
    final CrossContractReader privateReader = transactionNode.execute(privateContractTransactions.createSmartContract(CrossContractReader.class, transactionNode.getTransactionSigningKey(), transactionNode.getEnclaveKey()));
    final CrossContractReader publicReader = transactionNode.getBesu().execute(contractTransactions.createSmartContract(CrossContractReader.class));
    assertThatExceptionOfType(TransactionException.class).isThrownBy(() -> privateReader.remoteDestroy(publicReader.getContractAddress()).send()).withMessage("Transaction null has failed with status: 0x0. Gas used: unknown. Revert reason: '0x'.").returns("0x", e -> ((PrivateTransactionReceipt) e.getTransactionReceipt().get()).getOutput());
}
Also used : TransactionException(org.web3j.protocol.exceptions.TransactionException) CrossContractReader(org.hyperledger.besu.tests.web3j.generated.CrossContractReader) Test(org.junit.Test)

Example 5 with CrossContractReader

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

the class PrivateContractPublicStateAcceptanceTest method mustAllowAccessToPublicStateFromPrivateTx.

@Test
public void mustAllowAccessToPublicStateFromPrivateTx() throws Exception {
    final EventEmitter publicEventEmitter = transactionNode.execute(contractTransactions.createSmartContract(EventEmitter.class));
    final TransactionReceipt receipt = publicEventEmitter.store(BigInteger.valueOf(12)).send();
    assertThat(receipt).isNotNull();
    final CrossContractReader reader = transactionNode.execute(privateContractTransactions.createSmartContract(CrossContractReader.class, transactionNode.getTransactionSigningKey(), transactionNode.getEnclaveKey()));
    final RemoteFunctionCall<BigInteger> remoteFunctionCall = reader.read(publicEventEmitter.getContractAddress());
    final BigInteger result = remoteFunctionCall.send();
    assertThat(result).isEqualTo(BigInteger.valueOf(12));
}
Also used : EventEmitter(org.hyperledger.besu.tests.web3j.generated.EventEmitter) CrossContractReader(org.hyperledger.besu.tests.web3j.generated.CrossContractReader) PrivateTransactionReceipt(org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Aggregations

CrossContractReader (org.hyperledger.besu.tests.web3j.generated.CrossContractReader)5 Test (org.junit.Test)5 BigInteger (java.math.BigInteger)2 EventEmitter (org.hyperledger.besu.tests.web3j.generated.EventEmitter)2 PrivateTransactionReceipt (org.web3j.protocol.besu.response.privacy.PrivateTransactionReceipt)2 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)2 TransactionException (org.web3j.protocol.exceptions.TransactionException)1