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();
}
}
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();
}
}
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);
}
}
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()));
}
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()));
}
Aggregations