Search in sources :

Example 1 with PushBatchRequest

use of com.quorum.tessera.recovery.resend.PushBatchRequest in project tessera by ConsenSys.

the class BatchResendManagerImplTest method testStoreResendBatchMultipleVersions.

@Test
public void testStoreResendBatchMultipleVersions() {
    try (var payloadDigestMockedStatic = mockStatic(PayloadDigest.class);
        var payloadEncoderMockedStatic = mockStatic(PayloadEncoder.class)) {
        payloadDigestMockedStatic.when(PayloadDigest::create).thenReturn((PayloadDigest) cipherText -> cipherText);
        payloadEncoderMockedStatic.when(() -> PayloadEncoder.create(any())).thenReturn(payloadEncoder);
        final EncodedPayload encodedPayload = EncodedPayload.Builder.create().withSenderKey(publicKey).withCipherText("cipherText".getBytes()).withCipherTextNonce(new Nonce("nonce".getBytes())).withRecipientBoxes(singletonList("box".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(singletonList(PublicKey.from("receiverKey".getBytes()))).withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).withAffectedContractTransactions(emptyMap()).withExecHash(new byte[0]).build();
        when(payloadEncoder.decode(any())).thenReturn(encodedPayload);
        final byte[] raw = new PayloadEncoderImpl().encode(encodedPayload);
        PushBatchRequest request = PushBatchRequest.from(List.of(raw), EncodedPayloadCodec.LEGACY);
        StagingTransaction existing = new StagingTransaction();
        when(stagingEntityDAO.retrieveByHash(any())).thenReturn(Optional.of(existing));
        when(stagingEntityDAO.update(any(StagingTransaction.class))).thenReturn(new StagingTransaction());
        manager.storeResendBatch(request);
        verify(stagingEntityDAO).save(any(StagingTransaction.class));
        verify(payloadEncoder).decode(any());
        verify(payloadEncoder).encodedPayloadCodec();
        payloadDigestMockedStatic.verify(PayloadDigest::create);
        payloadDigestMockedStatic.verifyNoMoreInteractions();
    }
}
Also used : AdditionalMatchers.lt(org.mockito.AdditionalMatchers.lt) ResendBatchRequest(com.quorum.tessera.recovery.resend.ResendBatchRequest) IntStream(java.util.stream.IntStream) PublicKey(com.quorum.tessera.encryption.PublicKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BatchWorkflowFactory(com.quorum.tessera.recovery.workflow.BatchWorkflowFactory) BatchResendManager(com.quorum.tessera.recovery.workflow.BatchResendManager) Base64Codec(com.quorum.tessera.base64.Base64Codec) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) Collections.singletonList(java.util.Collections.singletonList) PushBatchRequest(com.quorum.tessera.recovery.resend.PushBatchRequest) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) StagingEntityDAO(com.quorum.tessera.data.staging.StagingEntityDAO) EncryptedTransactionDAO(com.quorum.tessera.data.EncryptedTransactionDAO) After(org.junit.After) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) AdditionalMatchers.gt(org.mockito.AdditionalMatchers.gt) com.quorum.tessera.enclave(com.quorum.tessera.enclave) Nonce(com.quorum.tessera.encryption.Nonce) ServiceLoader(java.util.ServiceLoader) Test(org.junit.Test) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Collectors(java.util.stream.Collectors) Mockito(org.mockito.Mockito) List(java.util.List) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) Optional(java.util.Optional) Nonce(com.quorum.tessera.encryption.Nonce) PushBatchRequest(com.quorum.tessera.recovery.resend.PushBatchRequest) StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) Test(org.junit.Test)

Aggregations

Base64Codec (com.quorum.tessera.base64.Base64Codec)1 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)1 EncryptedTransactionDAO (com.quorum.tessera.data.EncryptedTransactionDAO)1 StagingEntityDAO (com.quorum.tessera.data.staging.StagingEntityDAO)1 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)1 com.quorum.tessera.enclave (com.quorum.tessera.enclave)1 Nonce (com.quorum.tessera.encryption.Nonce)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 PushBatchRequest (com.quorum.tessera.recovery.resend.PushBatchRequest)1 ResendBatchRequest (com.quorum.tessera.recovery.resend.ResendBatchRequest)1 ResendBatchResponse (com.quorum.tessera.recovery.resend.ResendBatchResponse)1 BatchResendManager (com.quorum.tessera.recovery.workflow.BatchResendManager)1 BatchWorkflow (com.quorum.tessera.recovery.workflow.BatchWorkflow)1 BatchWorkflowContext (com.quorum.tessera.recovery.workflow.BatchWorkflowContext)1 BatchWorkflowFactory (com.quorum.tessera.recovery.workflow.BatchWorkflowFactory)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Optional (java.util.Optional)1 ServiceLoader (java.util.ServiceLoader)1