Search in sources :

Example 1 with EncryptedMessage

use of io.nem.symbol.sdk.model.message.EncryptedMessage in project nem2-sdk-java by nemtech.

the class TransferTransactionIntegrationTest method standaloneTransferTransactionEncryptedMessage.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void standaloneTransferTransactionEncryptedMessage(RepositoryType type) throws Exception {
    this.helper().sendMosaicFromNemesis(type, getRecipient(), false);
    String namespaceName = "standaloneTransferTransactionEncryptedMessagealias".toLowerCase();
    NamespaceId recipient = setAddressAlias(type, getRecipient(), namespaceName);
    System.out.println(recipient.getIdAsHex());
    Assertions.assertEquals("9960629109A48AFBC0000000000000000000000000000000", recipient.encoded(getNetworkType()));
    String message = "E2ETest:standaloneTransferTransaction:message 漢字";
    KeyPair senderKeyPair = KeyPair.random();
    KeyPair recipientKeyPair = KeyPair.random();
    Message encryptedMessage = EncryptedMessage.create(message, senderKeyPair.getPrivateKey(), recipientKeyPair.getPublicKey());
    Currency networkCurrency = getNetworkCurrency();
    Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(10202020));
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(encryptedMessage).maxFee(maxFee).build();
    TransferTransaction processed = announceAndValidate(type, signerAccount, transferTransaction);
    assertTransferTransactions(transferTransaction, processed);
    assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, processed);
    TransferTransaction restTransaction = (TransferTransaction) get(getRepositoryFactory(type).createTransactionRepository().getTransaction(TransactionGroup.CONFIRMED, processed.getTransactionInfo().get().getHash().get()));
    assertTransferTransactions(transferTransaction, restTransaction);
    assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, restTransaction);
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) Message(io.nem.symbol.sdk.model.message.Message) EncryptedMessage(io.nem.symbol.sdk.model.message.EncryptedMessage) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) PersistentHarvestingDelegationMessage(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage) Currency(io.nem.symbol.sdk.model.mosaic.Currency) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

KeyPair (io.nem.symbol.core.crypto.KeyPair)1 EncryptedMessage (io.nem.symbol.sdk.model.message.EncryptedMessage)1 Message (io.nem.symbol.sdk.model.message.Message)1 PersistentHarvestingDelegationMessage (io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage)1 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)1 Currency (io.nem.symbol.sdk.model.mosaic.Currency)1 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)1 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)1 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1