Search in sources :

Example 71 with Account

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

the class MultisigRepositoryIntegrationTest method getMultisigAccountGraphInfo.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMultisigAccountGraphInfo(RepositoryType type) {
    Account multisigAccount = helper().getMultisigAccount(type).getLeft();
    MultisigAccountGraphInfo multisigAccountGraphInfos = get(this.getRepositoryFactory(type).createMultisigRepository().getMultisigAccountGraphInfo(multisigAccount.getAddress()));
    assertEquals(2, multisigAccountGraphInfos.getLevelsNumber().size());
    assertEquals(2, multisigAccountGraphInfos.getMultisigEntries().size());
    assertEquals(1, multisigAccountGraphInfos.getMultisigEntries().get(0).size());
    assertEquals(1, multisigAccountGraphInfos.getMultisigEntries().get(0).size());
    assertEquals(2, multisigAccountGraphInfos.getMultisigEntries().get(1).size());
    assertEquals(multisigAccount.getAddress(), multisigAccountGraphInfos.getMultisigEntries().get(0).get(0).getAccountAddress());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) MultisigAccountGraphInfo(io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with Account

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

the class SecretLockIntegrationTest method secretLockAndProofTransaction.

@ParameterizedTest
@MethodSource("provider")
void secretLockAndProofTransaction(RepositoryType type, LockHashAlgorithm lockHashAlgorithm) {
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    byte[] secretSeed = RandomUtils.generateRandomBytes(20);
    String secret = ConvertUtils.toHex(lockHashAlgorithm.hash(secretSeed));
    String storedSecret = ConvertUtils.padHex(secret, LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE);
    if (lockHashAlgorithm == LockHashAlgorithm.HASH_160) {
        Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
        Assertions.assertEquals(40, secret.length());
    } else {
        Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
        Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, secret.length());
    }
    String proof = ConvertUtils.toHex(secretSeed);
    Account account = config().getNemesisAccount1();
    Account account2 = config().getNemesisAccount2();
    Currency currency = get(repositoryFactory.getNetworkCurrency());
    Mosaic mosaic = currency.createAbsolute(BigInteger.valueOf(1));
    BigInteger amount = mosaic.getAmount();
    BigInteger duration = BigInteger.valueOf(10000);
    SecretLockTransaction secretLockTransaction = SecretLockTransactionFactory.create(getNetworkType(), getDeadline(), mosaic, duration, lockHashAlgorithm, secret, account2.getAddress()).maxFee(maxFee).build();
    announceAndValidate(type, account, secretLockTransaction);
    SecretProofTransaction secretProofTransaction = SecretProofTransactionFactory.create(getNetworkType(), getDeadline(), lockHashAlgorithm, account2.getAddress(), secret, proof).maxFee(maxFee).build();
    SecretProofTransaction secretProofTransactionAnnounced = announceAndValidate(type, account, secretProofTransaction);
    sleep(500);
    Assertions.assertEquals(lockHashAlgorithm, secretProofTransactionAnnounced.getHashType());
    Assertions.assertEquals(account2.getAddress(), secretProofTransactionAnnounced.getRecipient());
    Assertions.assertEquals(storedSecret, secretProofTransactionAnnounced.getSecret());
    Assertions.assertEquals(proof, secretProofTransactionAnnounced.getProof());
    SecretLockRepository hashLockRepository = getRepositoryFactory(type).createSecretLockRepository();
    SecretLockInfo info = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).secret(storedSecret))).getData().get(0);
    Assertions.assertNotNull(info);
    Assertions.assertEquals(account.getAddress(), info.getOwnerAddress());
    Assertions.assertEquals(account2.getAddress(), info.getRecipientAddress());
    Assertions.assertEquals(amount, info.getAmount());
    Assertions.assertEquals(storedSecret, info.getSecret());
    Assertions.assertEquals(lockHashAlgorithm, info.getHashAlgorithm());
    Assertions.assertEquals(LockStatus.USED, info.getStatus());
    Page<SecretLockInfo> page = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).order(OrderBy.DESC)));
    Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getSecret().equals(storedSecret)));
    Assertions.assertEquals(20, page.getPageSize());
    SecretLockInfo infoSearch = page.getData().stream().filter(m -> m.getSecret().equals(storedSecret)).findFirst().get();
    Assertions.assertNotNull(infoSearch);
    Assertions.assertEquals(account.getAddress(), infoSearch.getOwnerAddress());
    Assertions.assertEquals(account2.getAddress(), infoSearch.getRecipientAddress());
    Assertions.assertEquals(amount, infoSearch.getAmount());
    Assertions.assertEquals(lockHashAlgorithm, infoSearch.getHashAlgorithm());
    Assertions.assertEquals(LockStatus.USED, infoSearch.getStatus());
    Assertions.assertEquals(storedSecret, infoSearch.getSecret());
}
Also used : SecretLockTransactionFactory(io.nem.symbol.sdk.model.transaction.SecretLockTransactionFactory) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) LockHashAlgorithm(io.nem.symbol.sdk.model.transaction.LockHashAlgorithm) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Account(io.nem.symbol.sdk.model.account.Account) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) LockStatus(io.nem.symbol.sdk.model.transaction.LockStatus) Arguments(org.junit.jupiter.params.provider.Arguments) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Currency(io.nem.symbol.sdk.model.mosaic.Currency) ArrayList(java.util.ArrayList) SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) OrderBy(io.nem.symbol.sdk.api.OrderBy) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestInstance(org.junit.jupiter.api.TestInstance) Assertions(org.junit.jupiter.api.Assertions) BigInteger(java.math.BigInteger) SecretLockRepository(io.nem.symbol.sdk.api.SecretLockRepository) Page(io.nem.symbol.sdk.api.Page) SecretProofTransactionFactory(io.nem.symbol.sdk.model.transaction.SecretProofTransactionFactory) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) MethodSource(org.junit.jupiter.params.provider.MethodSource) Account(io.nem.symbol.sdk.model.account.Account) SecretLockRepository(io.nem.symbol.sdk.api.SecretLockRepository) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) Currency(io.nem.symbol.sdk.model.mosaic.Currency) BigInteger(java.math.BigInteger) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 73 with Account

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

the class TestHelper method getTestAccount.

public Pair<Account, NamespaceId> getTestAccount(RepositoryType type) {
    Account testAccount = config().getTestAccount();
    NamespaceId namespaceId = setAddressAlias(type, testAccount.getAddress(), "testaccount");
    sendMosaicFromNemesis(type, testAccount.getAddress(), false);
    return Pair.of(testAccount, namespaceId);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 74 with Account

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

the class TestnetTester method sendVotingKey2.

private static void sendVotingKey2(RepositoryFactory repositoryFactory) throws Exception {
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account account = Account.createFromPrivateKey(PRIVATE_KEY, networkType);
    System.out.println(account.getAddress().plain());
    Duration duration = repositoryFactory.getEpochAdjustment().toFuture().get();
    Deadline deadline = Deadline.create(duration);
    PublicKey votingKey = PublicKey.fromHexString("463CCC639B5306DD06E56A273E13EF08CAB8D46A8ACA1D3919F19AF89DE116C5");
    VotingKeyLinkTransaction transaction = VotingKeyLinkTransactionFactory.create(networkType, deadline, votingKey, (1), (26280), LinkAction.LINK).maxFee(MAX_FEE).build();
    announceTransaction(repositoryFactory, account, transaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicKey(io.nem.symbol.core.crypto.PublicKey) VotingKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.VotingKeyLinkTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Duration(java.time.Duration)

Example 75 with Account

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

the class RepositoryFactoryConfigurationExamplesIntegrationTest method appDoSomeStuff.

public void appDoSomeStuff(RepositoryFactory repositoryFactory) throws ExecutionException, InterruptedException {
    // The application logic is exactly the same regardless of how the repository
    // factory was
    // set
    // Note: if rest is used, these values are cached form rest
    Currency currency = repositoryFactory.getNetworkCurrency().toFuture().get();
    String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account sender = Account.generateNewAccount(networkType);
    Account recipient = Account.generateNewAccount(networkType);
    Duration epochAdjustment = repositoryFactory.getEpochAdjustment().toFuture().get();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, Deadline.create(epochAdjustment), recipient.getAddress(), Collections.singletonList(currency.createRelative(BigInteger.TEN))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(sender, generationHash);
// Announce or store somewhere....
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Currency(io.nem.symbol.sdk.model.mosaic.Currency) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

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