Search in sources :

Example 36 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory in project nem2-sdk-java by nemtech.

the class AccountMetadataServiceIntegrationTest method setAndUpdateAccountMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateAccountMetadata(RepositoryType type) {
    BigInteger key = BigInteger.valueOf(RandomUtils.generateRandomInt(100000));
    String originalMessage = "The original message";
    String newMessage = "The new Message";
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();
    MetadataTransactionService service = new MetadataTransactionServiceImpl(repositoryFactory);
    AccountMetadataTransaction originalTransaction = get(service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress())).maxFee(maxFee).build();
    announceAggregateAndValidate(type, originalTransaction, signerAccount);
    sleep(1000);
    assertMetadata(key, originalMessage, metadataRepository);
    AccountMetadataTransaction updateTransaction = get(service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress())).maxFee(maxFee).build();
    announceAggregateAndValidate(type, updateTransaction, signerAccount);
    sleep(1000);
    assertMetadata(key, newMessage, metadataRepository);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) BigInteger(java.math.BigInteger) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 37 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory in project nem2-sdk-java by nemtech.

the class RepositoryFactoryVertxImplTest method shouldCreateRepositories.

@Test
public void shouldCreateRepositories() {
    String baseUrl = "https://nem.com:3000/path";
    RepositoryFactory factory = new RepositoryFactoryVertxImpl(baseUrl);
    Assertions.assertNotNull(factory.createAccountRepository());
    Assertions.assertNotNull(factory.createBlockRepository());
    Assertions.assertNotNull(factory.createReceiptRepository());
    Assertions.assertNotNull(factory.createChainRepository());
    Assertions.assertNotNull(factory.createListener());
    Assertions.assertNotNull(factory.createMosaicRepository());
    Assertions.assertNotNull(factory.createNamespaceRepository());
    Assertions.assertNotNull(factory.createNetworkRepository());
    Assertions.assertNotNull(factory.createNodeRepository());
    Assertions.assertNotNull(factory.createTransactionRepository());
    Assertions.assertNotNull(factory.createTransactionStatusRepository());
    Assertions.assertNotNull(factory.createMetadataRepository());
    Assertions.assertNotNull(factory.createRestrictionAccountRepository());
    Assertions.assertNotNull(factory.createRestrictionMosaicRepository());
    Assertions.assertNotNull(factory.createHashLockRepository());
    Assertions.assertNotNull(factory.createSecretLockRepository());
    Assertions.assertNotNull(factory.createMultisigRepository());
    Assertions.assertNotNull(factory.createFinalizationRepository());
    Assertions.assertNotNull(factory.createJsonSerialization());
    factory.close();
    factory.close();
    factory.close();
}
Also used : RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Test(org.junit.jupiter.api.Test)

Example 38 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory in project nem2-sdk-java by nemtech.

the class RepositoryFactoryVertxImplTest method getRestProvidedNetworkCurrencies.

@Test
public void getRestProvidedNetworkCurrencies() throws Exception {
    String baseUrl = "https://localhost:1934/path";
    RepositoryFactoryConfiguration configuration = new RepositoryFactoryConfiguration(baseUrl);
    configuration.withGenerationHash("abc");
    configuration.withNetworkType(NetworkType.MAIN_NET);
    RepositoryFactory factory = new RepositoryFactoryVertxImpl(configuration) {

        @Override
        protected Observable<NetworkCurrencies> loadNetworkCurrencies() {
            return Observable.just(new NetworkCurrencies(Currency.CAT_CURRENCY, Currency.CAT_HARVEST));
        }
    };
    Assertions.assertEquals(configuration.getNetworkType(), factory.getNetworkType().toFuture().get());
    Assertions.assertEquals(configuration.getGenerationHash(), factory.getGenerationHash().toFuture().get());
    Assertions.assertEquals(Currency.CAT_HARVEST, factory.getHarvestCurrency().toFuture().get());
    Assertions.assertEquals(Currency.CAT_CURRENCY, factory.getNetworkCurrency().toFuture().get());
}
Also used : NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) RepositoryFactoryConfiguration(io.nem.symbol.sdk.api.RepositoryFactoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 39 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory in project nem2-sdk-java by nemtech.

the class MosaicMetadataServiceIntegrationTest method setAndUpdateMosaicMetadata.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void setAndUpdateMosaicMetadata(RepositoryType type) {
    // TODO FIX THIS ONE when target != signerAccount
    Account signerAccount = config().getDefaultAccount();
    Account targetAccount = config().getDefaultAccount();
    Assertions.assertFalse(helper().isMultisig(type, signerAccount));
    Assertions.assertFalse(helper().isMultisig(type, targetAccount));
    MosaicId targetMosaicId = super.createMosaic(signerAccount, type, BigInteger.ZERO, null);
    BigInteger key = BigInteger.valueOf(RandomUtils.generateRandomInt(100000));
    String originalMessage = "The original message";
    String newMessage = "The new Message";
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();
    MetadataTransactionService service = new MetadataTransactionServiceImpl(repositoryFactory);
    MosaicMetadataTransaction originalTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, originalMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
    Assertions.assertEquals(targetAccount.getAddress(), originalTransaction.getTargetAddress());
    Assertions.assertEquals(targetMosaicId, originalTransaction.getTargetMosaicId());
    Assertions.assertEquals(key, originalTransaction.getScopedMetadataKey());
    Assertions.assertEquals(originalMessage, originalTransaction.getValue());
    helper().announceAggregateAndValidate(type, originalTransaction, signerAccount);
    assertMetadata(targetMosaicId, key, originalMessage, metadataRepository, signerAccount, targetAccount);
    MosaicMetadataTransaction updateTransaction = get(service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), key, newMessage, signerAccount.getAddress(), targetMosaicId)).maxFee(maxFee).build();
    Assertions.assertEquals(targetAccount.getAddress(), updateTransaction.getTargetAddress());
    Assertions.assertEquals(targetMosaicId, updateTransaction.getTargetMosaicId());
    Assertions.assertEquals(key, updateTransaction.getScopedMetadataKey());
    Pair<String, Integer> xorAndDelta = ConvertUtils.xorValues(originalMessage, newMessage);
    Assertions.assertEquals(xorAndDelta.getLeft(), updateTransaction.getValue());
    Assertions.assertEquals(xorAndDelta.getRight(), updateTransaction.getValueSizeDelta());
    helper().announceAggregateAndValidate(type, updateTransaction, signerAccount);
    assertMetadata(targetMosaicId, key, newMessage, metadataRepository, signerAccount, targetAccount);
}
Also used : MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) BigInteger(java.math.BigInteger) Account(io.nem.symbol.sdk.model.account.Account) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) BigInteger(java.math.BigInteger) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with RepositoryFactory

use of io.nem.symbol.sdk.api.RepositoryFactory 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)

Aggregations

RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)44 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Test (org.junit.jupiter.api.Test)11 BeforeEach (org.junit.jupiter.api.BeforeEach)7 RepositoryFactoryConfiguration (io.nem.symbol.sdk.api.RepositoryFactoryConfiguration)6 Account (io.nem.symbol.sdk.model.account.Account)6 BigInteger (java.math.BigInteger)6 Listener (io.nem.symbol.sdk.api.Listener)5 MetadataRepository (io.nem.symbol.sdk.api.MetadataRepository)5 NamespaceRepository (io.nem.symbol.sdk.api.NamespaceRepository)5 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)5 NetworkCurrencies (io.nem.symbol.sdk.model.mosaic.NetworkCurrencies)5 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)4 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)4 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)4 CurrencyService (io.nem.symbol.sdk.api.CurrencyService)3 MetadataTransactionService (io.nem.symbol.sdk.api.MetadataTransactionService)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3 TransactionService (io.nem.symbol.sdk.api.TransactionService)3