Search in sources :

Example 1 with PrivacyHelper

use of com.quorum.tessera.transaction.PrivacyHelper in project tessera by ConsenSys.

the class EncodedPayloadManagerProviderTest method provider.

@Test
public void provider() {
    try (var mockedEnclaveFactory = mockStatic(Enclave.class);
        var mockedPrivacyHelper = mockStatic(PrivacyHelper.class);
        var mockedPayloadDigest = mockStatic(PayloadDigest.class)) {
        mockedPayloadDigest.when(PayloadDigest::create).thenReturn(mock(PayloadDigest.class));
        mockedPrivacyHelper.when(PrivacyHelper::create).thenReturn(mock(PrivacyHelper.class));
        mockedEnclaveFactory.when(Enclave::create).thenReturn(mock(Enclave.class));
        EncodedPayloadManager encodedPayloadManager = EncodedPayloadManagerProvider.provider();
        assertThat(encodedPayloadManager).isNotNull();
        assertThat(encodedPayloadManager).describedAs("Subsequent invocations should return the same instance").isSameAs(EncodedPayloadManagerProvider.provider());
        mockedPrivacyHelper.verify(PrivacyHelper::create);
        mockedPrivacyHelper.verifyNoMoreInteractions();
        mockedEnclaveFactory.verify(Enclave::create);
        mockedEnclaveFactory.verifyNoMoreInteractions();
        mockedPayloadDigest.verify(PayloadDigest::create);
        mockedPayloadDigest.verifyNoMoreInteractions();
    }
}
Also used : PayloadDigest(com.quorum.tessera.enclave.PayloadDigest) Enclave(com.quorum.tessera.enclave.Enclave) EncodedPayloadManager(com.quorum.tessera.transaction.EncodedPayloadManager) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) Test(org.junit.Test)

Example 2 with PrivacyHelper

use of com.quorum.tessera.transaction.PrivacyHelper in project tessera by ConsenSys.

the class PrivacyHelperProviderTest method provider.

@Test
public void provider() {
    try (var mockedRuntimeContext = mockStatic(RuntimeContext.class);
        var mockedEncryptedTransactionDAO = mockStatic(EncryptedTransactionDAO.class)) {
        RuntimeContext runtimeContext = mock(RuntimeContext.class);
        when(runtimeContext.isEnhancedPrivacy()).thenReturn(true);
        mockedRuntimeContext.when(RuntimeContext::getInstance).thenReturn(runtimeContext);
        mockedEncryptedTransactionDAO.when(EncryptedTransactionDAO::create).thenReturn(mock(EncryptedTransactionDAO.class));
        PrivacyHelper privacyHelper = PrivacyHelperProvider.provider();
        assertThat(privacyHelper).isNotNull();
    }
}
Also used : RuntimeContext(com.quorum.tessera.context.RuntimeContext) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) Test(org.junit.Test)

Example 3 with PrivacyHelper

use of com.quorum.tessera.transaction.PrivacyHelper in project tessera by ConsenSys.

the class PrivacyHelperTest method create.

@Test
public void create() {
    try (var mockedServiceLoader = mockStatic(ServiceLoader.class)) {
        PrivacyHelper privacyHelper = mock(PrivacyHelper.class);
        ServiceLoader serviceLoader = mock(ServiceLoader.class);
        when(serviceLoader.findFirst()).thenReturn(Optional.of(privacyHelper));
        mockedServiceLoader.when(() -> ServiceLoader.load(PrivacyHelper.class)).thenReturn(serviceLoader);
        PrivacyHelper.create();
        mockedServiceLoader.verify(() -> ServiceLoader.load(PrivacyHelper.class));
        verify(serviceLoader).findFirst();
        mockedServiceLoader.verifyNoMoreInteractions();
        verifyNoMoreInteractions(serviceLoader);
        verifyNoInteractions(privacyHelper);
    }
}
Also used : PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) Test(org.junit.Test)

Example 4 with PrivacyHelper

use of com.quorum.tessera.transaction.PrivacyHelper in project tessera by ConsenSys.

the class PrivacyHelperTest method throwExceptionForPayloadWhenPrivacyNotEnabled.

@Test
public void throwExceptionForPayloadWhenPrivacyNotEnabled() {
    final PrivacyHelper anotherHelper = new PrivacyHelperImpl(encryptedTransactionDAO, false);
    EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PARTY_PROTECTION);
    assertThatExceptionOfType(EnhancedPrivacyNotSupportedException.class).isThrownBy(() -> anotherHelper.validatePayload(mock(TxHash.class), payload, emptyList()));
}
Also used : PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Example 5 with PrivacyHelper

use of com.quorum.tessera.transaction.PrivacyHelper in project tessera by ConsenSys.

the class PrivacyHelperTest method throwExceptionForSendRequestWhenPrivacyNotEnabled.

@Test
public void throwExceptionForSendRequestWhenPrivacyNotEnabled() {
    final PrivacyHelper anotherHelper = new PrivacyHelperImpl(encryptedTransactionDAO, false);
    assertThatExceptionOfType(EnhancedPrivacyNotSupportedException.class).isThrownBy(() -> anotherHelper.validateSendRequest(PrivacyMode.PRIVATE_STATE_VALIDATION, emptyList(), emptyList(), emptySet()));
}
Also used : PrivacyHelper(com.quorum.tessera.transaction.PrivacyHelper) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Aggregations

PrivacyHelper (com.quorum.tessera.transaction.PrivacyHelper)9 Test (org.junit.Test)6 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)4 Enclave (com.quorum.tessera.enclave.Enclave)4 PayloadDigest (com.quorum.tessera.enclave.PayloadDigest)4 RuntimeContext (com.quorum.tessera.context.RuntimeContext)2 EncryptedRawTransactionDAO (com.quorum.tessera.data.EncryptedRawTransactionDAO)2 EncodedPayloadManager (com.quorum.tessera.transaction.EncodedPayloadManager)2 EnhancedPrivacyNotSupportedException (com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException)2 BatchPayloadPublisher (com.quorum.tessera.transaction.publish.BatchPayloadPublisher)2 PayloadPublisher (com.quorum.tessera.transaction.publish.PayloadPublisher)2 ResendManager (com.quorum.tessera.transaction.resend.ResendManager)2 Config (com.quorum.tessera.config.Config)1 ConfigFactory (com.quorum.tessera.config.ConfigFactory)1 TransactionManager (com.quorum.tessera.transaction.TransactionManager)1