unit tests for payload builder
@@ -100,4 +100,63 @@ public class EncodedPayloadBuilderTest {
.usingGetClass()
.verify();
}
+
+ @Test
+ public void withPrivacyGroupId() {
+ final EncodedPayload sample =
+ EncodedPayload.Builder.create()
+ .withSenderKey(senderKey)
+ .withCipherText(cipherText)
+ .withCipherTextNonce(cipherTextNonce)
+ .withRecipientBox(recipientBox)
+ .withRecipientNonce(recipientNonce)
+ .withPrivacyFlag(3)
+ .withAffectedContractTransactions(affectedContractTransactionsRaw)
+ .withExecHash(execHash)
+ .withRecipientKey(recipientKey)
+ .withPrivacyGroupId(PrivacyGroup.Id.fromBytes("PRIVACYGROUPID".getBytes()))
+ .build();
+
+ final EncodedPayload result = EncodedPayload.Builder.from(sample).build();
+ assertThat(result).isNotSameAs(sample).isEqualTo(sample);
+
+ EqualsVerifier.forClass(EncodedPayload.class)
+ .withIgnoredFields("affectedContractTransactions")
+ .usingGetClass()
+ .verify();
+
+ assertThat(result.getPrivacyGroupId()).isPresent();
+ assertThat(result.getPrivacyGroupId().get()).isEqualTo(PrivacyGroup.Id.fromBytes("PRIVACYGROUPID".getBytes()));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void nonPSVButExecHashPresent() {
+ EncodedPayload.Builder.create()
+ .withSenderKey(senderKey)
+ .withCipherText(cipherText)
+ .withCipherTextNonce(cipherTextNonce)
+ .withRecipientBox(recipientBox)
+ .withRecipientNonce(recipientNonce)
+ .withPrivacyFlag(1)
+ .withAffectedContractTransactions(affectedContractTransactionsRaw)
+ .withExecHash(execHash)
+ .withRecipientKey(recipientKey)
+ .withPrivacyGroupId(PrivacyGroup.Id.fromBytes("PRIVACYGROUPID".getBytes()))
+ .build();
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void psvTxWithoutExecHash() {
+ EncodedPayload.Builder.create()
+ .withSenderKey(senderKey)
+ .withCipherText(cipherText)
+ .withCipherTextNonce(cipherTextNonce)
+ .withRecipientBox(recipientBox)
+ .withRecipientNonce(recipientNonce)
+ .withPrivacyFlag(3)
+ .withAffectedContractTransactions(affectedContractTransactionsRaw)
+ .withRecipientKey(recipientKey)
+ .withPrivacyGroupId(PrivacyGroup.Id.fromBytes("PRIVACYGROUPID".getBytes()))
+ .build();
+ }
}
