Search in sources :

Example 56 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class AccountKeyLinkTransactionIntegrationTest method basicAnnounce.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void basicAnnounce(RepositoryType type) {
    Account account = config().getNemesisAccount2();
    PublicKey linkedPublicKey = PublicKey.fromHexString("F5D0AAD909CFBC810A3F888C33C57A9051AE1A59D1CDA872A8B90BCA7EF2D34A");
    AccountKeyLinkTransaction linkTransaction = AccountKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, LinkAction.LINK).maxFee(maxFee).build();
    announceAndValidate(type, account, linkTransaction);
    AccountKeyLinkTransaction unlinkTransaction = AccountKeyLinkTransactionFactory.create(getNetworkType(), getDeadline(), linkedPublicKey, LinkAction.UNLINK).maxFee(maxFee).build();
    announceAndValidate(type, account, unlinkTransaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicKey(io.nem.symbol.core.crypto.PublicKey) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class TransactionRepositoryVertxImplTest method getSignedTransaction.

private SignedTransaction getSignedTransaction() {
    String generationHash = "A94B1BE81F1D4C95D6D252AD7BA3FFFB1674991FD880B7A57DC3180AF8D69C32";
    Account account = Account.generateNewAccount(this.networkType);
    Address recipientAddress = Address.generateRandom(this.networkType);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), recipientAddress, Collections.singletonList(createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneTransferTransaction:message")).build();
    SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
    String payload = signedTransaction.getPayload();
    assertEquals(444, payload.length());
    return signedTransaction;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 58 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImplTest method shouldGetAccountInfo.

@Test
public void shouldGetAccountInfo() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    accountDTO.setVersion(1);
    accountDTO.setAccountType(AccountTypeEnum.NUMBER_1);
    accountDTO.setAddress(encodeAddress(address));
    accountDTO.setAddressHeight(BigInteger.TEN);
    accountDTO.setPublicKeyHeight(BigInteger.valueOf(20));
    accountDTO.setPublicKey(account.getPublicAccount().getPublicKey().toHex());
    accountDTO.setImportance(BigInteger.valueOf(5));
    accountDTO.setImportanceHeight(BigInteger.valueOf(10));
    List<Mosaic> mosaicDtos = new ArrayList<>();
    mosaicDtos.add(new Mosaic().id("0000000000000ABC").amount(BigInteger.TEN));
    accountDTO.setMosaics(mosaicDtos);
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    mockRemoteCall(accountInfoDTO);
    AccountInfo resolvedAccountInfo = repository.getAccountInfo(address).toFuture().get();
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(1, resolvedAccountInfo.getMosaics().size());
    Assertions.assertEquals("0000000000000ABC", resolvedAccountInfo.getMosaics().get(0).getId().getIdAsHex());
    Assertions.assertEquals(BigInteger.TEN, resolvedAccountInfo.getMosaics().get(0).getAmount());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) Mosaic(io.nem.symbol.sdk.openapi.vertx.model.Mosaic) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Example 59 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method shouldHandleStatus.

@Test
public void shouldHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
    Account account1 = Account.generateNewAccount(NETWORK_TYPE);
    AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
    simulateWebSocketStartup();
    Assertions.assertNotNull(listener.status(account1.getAddress()).subscribe(reference::set));
    Map<String, Object> message = new HashMap<>();
    message.put("hash", "1234hash");
    message.put("address", account1.getAddress().encoded());
    message.put("code", "some error");
    message.put("deadline", 5555);
    handle(message, "status/" + account1.getAddress().plain());
    Assertions.assertNotNull(reference.get());
    Assertions.assertEquals(message.get("hash"), reference.get().getHash());
    Assertions.assertEquals(message.get("code"), reference.get().getStatus());
    Assertions.assertEquals(account1.getAddress(), reference.get().getAddress());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account1.getAddress().plain())));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with Account

use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.

the class TestHelper method setMosaicAlias.

protected NamespaceId setMosaicAlias(RepositoryType type, MosaicId mosaicId, String namespaceName) {
    Account nemesisAccount = config().getNemesisAccount1();
    NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
    if (isAlias(type, mosaicId, namespaceId)) {
        System.out.println(namespaceName + " MOSAIC Alias found, reusing it.");
        return namespaceId;
    } else {
        System.out.println(namespaceName + " MOSAIC Alias not found, CREATING MOSAIC ALIAS");
    }
    System.out.println("Setting up namespace " + namespaceName);
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, nemesisAccount).getLeft().getNamespaceId();
    System.out.println("Setting mosaic alias " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
    MosaicAliasTransaction aliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
    announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
    int retry = 10;
    while (!isAlias(type, mosaicId, namespaceId)) {
        sleep(300);
        retry--;
        if (retry == 0) {
            Assertions.fail("Could not create " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
        }
    }
    return rootNamespaceId;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Aggregations

Account (io.nem.symbol.sdk.model.account.Account)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)39 EnumSource (org.junit.jupiter.params.provider.EnumSource)36 Test (org.junit.jupiter.api.Test)29 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)26 BigInteger (java.math.BigInteger)21 Address (io.nem.symbol.sdk.model.account.Address)20 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)18 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)17 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)17 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)15 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)15 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)14 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)13 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)11 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)9 Currency (io.nem.symbol.sdk.model.mosaic.Currency)9 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)9 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)7