Search in sources :

Example 51 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryVertxImplTest method shouldGetMosaicsNamesFromPublicKeys.

@Test
public void shouldGetMosaicsNamesFromPublicKeys() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("99262122238339734");
    MosaicNamesDTO dto = new MosaicNamesDTO();
    dto.setMosaicId("99262122238339734");
    dto.setNames(Collections.singletonList("accountalias"));
    MosaicsNamesDTO accountsNamesDTO = new MosaicsNamesDTO();
    accountsNamesDTO.setMosaicNames(Collections.singletonList(dto));
    mockRemoteCall(accountsNamesDTO);
    List<MosaicNames> resolvedList = repository.getMosaicsNames(Collections.singletonList(mosaicId)).toFuture().get();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicNames accountNames = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, accountNames.getMosaicId());
    Assertions.assertEquals("accountalias", accountNames.getNames().get(0).getName());
}
Also used : MosaicsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicsNamesDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) MosaicNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicNamesDTO) Test(org.junit.jupiter.api.Test)

Example 52 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicGlobalRestrictions.

@Test
public void shouldGetMosaicGlobalRestrictions() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicGlobalRestrictionDTO dto = new MosaicGlobalRestrictionDTO();
    MosaicGlobalRestrictionEntryWrapperDTO wrapperDTO = new MosaicGlobalRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicGlobalRestrictionEntryDTO entryDTO = new MosaicGlobalRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    MosaicGlobalRestrictionEntryRestrictionDTO entryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO();
    entryRestrictionDto.setRestrictionType(MosaicRestrictionTypeEnum.NUMBER_5);
    entryRestrictionDto.setReferenceMosaicId("456");
    entryRestrictionDto.setRestrictionValue(BigInteger.valueOf(3333));
    entryDTO.setRestriction(entryRestrictionDto);
    List<MosaicGlobalRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setVersion(1);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_1);
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicGlobalRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicGlobalRestrictions.size());
    MosaicGlobalRestriction mosaicGlobalRestriction = (MosaicGlobalRestriction) mosaicGlobalRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicGlobalRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.GLOBAL, mosaicGlobalRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicGlobalRestriction.getMosaicId());
    Assertions.assertEquals(1, mosaicGlobalRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(3333), mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionValue());
    Assertions.assertEquals("0000000000000456", mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getReferenceMosaicId().getIdAsHex());
    Assertions.assertEquals(MosaicRestrictionType.GT, mosaicGlobalRestriction.getRestrictions().get(BigInteger.valueOf(1111)).getRestrictionType());
}
Also used : MosaicGlobalRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryDTO) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) Test(org.junit.jupiter.api.Test)

Example 53 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class SecretLockRepositoryVertxImplTest method shouldSearch.

@Test
public void shouldSearch() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    Address recipientAddress = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
    SecretLockEntryDTO lockHashDto = new SecretLockEntryDTO();
    lockHashDto.setOwnerAddress(encodeAddress(address));
    lockHashDto.setAmount(BigInteger.ONE);
    lockHashDto.setEndHeight(BigInteger.TEN);
    lockHashDto.setCompositeHash("ABC");
    lockHashDto.setRecipientAddress(encodeAddress(recipientAddress));
    lockHashDto.setMosaicId(mosaicId.getIdAsHex());
    lockHashDto.setStatus(LockStatus.NUMBER_1);
    lockHashDto.setSecret("someSecret");
    lockHashDto.setHashAlgorithm(LockHashAlgorithmEnum.NUMBER_2);
    lockHashDto.setVersion(1);
    SecretLockInfoDTO hashLockInfoDTO = new SecretLockInfoDTO();
    hashLockInfoDTO.setLock(lockHashDto);
    hashLockInfoDTO.setId("123");
    mockRemoteCall(toPage(hashLockInfoDTO));
    List<SecretLockInfo> list = repository.search(new SecretLockSearchCriteria().address(address)).toFuture().get().getData();
    Assertions.assertEquals(1, list.size());
    SecretLockInfo resolvedSecretLockInfo = list.get(0);
    Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
    Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedSecretLockInfo.getRecordId().get());
    Assertions.assertEquals(address, resolvedSecretLockInfo.getOwnerAddress());
    Assertions.assertEquals(recipientAddress, resolvedSecretLockInfo.getRecipientAddress());
    Assertions.assertEquals(LockHashAlgorithm.HASH_256, resolvedSecretLockInfo.getHashAlgorithm());
    Assertions.assertEquals(lockHashDto.getCompositeHash(), resolvedSecretLockInfo.getCompositeHash());
    Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedSecretLockInfo.getStatus());
    Assertions.assertEquals(mosaicId, resolvedSecretLockInfo.getMosaicId());
    Assertions.assertEquals(lockHashDto.getAmount(), resolvedSecretLockInfo.getAmount());
    Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedSecretLockInfo.getEndHeight());
}
Also used : SecretLockSearchCriteria(io.nem.symbol.sdk.api.SecretLockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) SecretLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockInfoDTO) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.SecretLockEntryDTO) Test(org.junit.jupiter.api.Test)

Example 54 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class HashLockRepositoryVertxImplTest method shouldGetHashLockInfo.

@Test
public void shouldGetHashLockInfo() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
    HashLockEntryDTO lockHashDto = new HashLockEntryDTO();
    lockHashDto.setOwnerAddress(encodeAddress(address));
    lockHashDto.setVersion(1);
    lockHashDto.setAmount(BigInteger.ONE);
    lockHashDto.setEndHeight(BigInteger.TEN);
    lockHashDto.setHash("ABC");
    lockHashDto.setMosaicId(mosaicId.getIdAsHex());
    lockHashDto.setStatus(LockStatus.NUMBER_1);
    HashLockInfoDTO hashLockInfoDTO = new HashLockInfoDTO();
    hashLockInfoDTO.setLock(lockHashDto);
    hashLockInfoDTO.setId("123");
    mockRemoteCall(hashLockInfoDTO);
    HashLockInfo resolvedHashLockInfo = repository.getHashLock("abc").toFuture().get();
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(hashLockInfoDTO.getId(), resolvedHashLockInfo.getRecordId().get());
    Assertions.assertEquals(address, resolvedHashLockInfo.getOwnerAddress());
    Assertions.assertEquals(lockHashDto.getHash(), resolvedHashLockInfo.getHash());
    Assertions.assertEquals(io.nem.symbol.sdk.model.transaction.LockStatus.USED, resolvedHashLockInfo.getStatus());
    Assertions.assertEquals(mosaicId, resolvedHashLockInfo.getMosaicId());
    Assertions.assertEquals(lockHashDto.getAmount(), resolvedHashLockInfo.getAmount());
    Assertions.assertEquals(lockHashDto.getEndHeight(), resolvedHashLockInfo.getEndHeight());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) HashLockEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockEntryDTO) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) HashLockInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.HashLockInfoDTO) Test(org.junit.jupiter.api.Test)

Example 55 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicRepositoryVertxImplTest method shouldGetMosaicsFromAccount.

@Test
public void shouldGetMosaicsFromAccount() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    MosaicDTO mosaicDto = new MosaicDTO();
    mosaicDto.setOwnerAddress(address.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setVersion(1);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mockRemoteCall(toPage(new MosaicInfoDTO().mosaic(mosaicDto).id("ABC")));
    List<MosaicInfo> resolvedList = repository.search(new MosaicSearchCriteria().ownerAddress(publicAccount.getAddress())).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicInfo mosaicInfo = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(NetworkType.MIJIN_TEST));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)138 Test (org.junit.jupiter.api.Test)92 Address (io.nem.symbol.sdk.model.account.Address)53 BigInteger (java.math.BigInteger)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)23 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)19 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)18 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)17 Account (io.nem.symbol.sdk.model.account.Account)16 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)15 ArrayList (java.util.ArrayList)13 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)12 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)10 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)10 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 Currency (io.nem.symbol.sdk.model.mosaic.Currency)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)7