use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class RestrictionMosaicRepositoryOkHttpImplTest method shouldGetMosaicAddressRestrictions.
@Test
public void shouldGetMosaicAddressRestrictions() throws Exception {
Address address = Address.generateRandom(this.networkType);
MosaicId mosaicId = MapperUtils.toMosaicId("123");
MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
dto.setMosaicRestrictionEntry(wrapperDTO);
MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
entryDTO.setValue("2222");
List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
restrictions.add(entryDTO);
wrapperDTO.setCompositeHash("compositeHash");
wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
wrapperDTO.setRestrictions(restrictions);
wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
wrapperDTO.setTargetAddress(address.encoded());
wrapperDTO.setVersion(1);
mockRemoteCall(toPage(dto));
List<MosaicRestriction<?>> mosaicAddressRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
Assertions.assertEquals(1, mosaicAddressRestrictions.size());
MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) mosaicAddressRestrictions.get(0);
Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get(BigInteger.valueOf(1111)));
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class HashLockRepositoryOkHttpImplTest 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.setAmount(BigInteger.ONE);
lockHashDto.setEndHeight(BigInteger.TEN);
lockHashDto.setVersion(1);
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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class HashLockRepositoryOkHttpImplTest method shouldSearch.
@Test
public void shouldSearch() throws Exception {
Address address = Address.generateRandom(this.networkType);
MosaicId mosaicId = MosaicId.createFromNonce(MosaicNonce.createRandom(), address);
HashLockEntryDTO lockHashDto = new HashLockEntryDTO();
lockHashDto.setOwnerAddress(encodeAddress(address));
lockHashDto.setAmount(BigInteger.ONE);
lockHashDto.setEndHeight(BigInteger.TEN);
lockHashDto.setVersion(1);
lockHashDto.setHash("ABC");
lockHashDto.setMosaicId(mosaicId.getIdAsHex());
lockHashDto.setStatus(LockStatus.NUMBER_1);
HashLockInfoDTO hashLockInfoDTO = new HashLockInfoDTO();
hashLockInfoDTO.setLock(lockHashDto);
hashLockInfoDTO.setId("123");
mockRemoteCall(toPage(hashLockInfoDTO));
List<HashLockInfo> list = repository.search(new HashLockSearchCriteria().address(address)).toFuture().get().getData();
Assertions.assertEquals(1, list.size());
HashLockInfo resolvedHashLockInfo = list.get(0);
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());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class AccountSearchRepositoryIntegrationTest method searchMosaicIdProvided.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchMosaicIdProvided(RepositoryType type) {
AccountPaginationStreamer streamer = new AccountPaginationStreamer(this.getAccountRepository(type));
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
NamespaceId networkCurrencyId = get(repositoryFactory.getNetworkCurrency()).getNamespaceId().get();
Assertions.assertTrue(networkCurrencyId.getFullName().isPresent());
MosaicId mosaicId = get(repositoryFactory.createNamespaceRepository().getLinkedMosaicId(networkCurrencyId));
AccountSearchCriteria criteria = new AccountSearchCriteria().mosaicId(mosaicId);
List<AccountInfo> accounts = get(streamer.search(criteria).toList().toObservable());
Assertions.assertFalse(accounts.isEmpty());
System.out.println(toJson(accounts));
accounts.forEach(a -> {
Assertions.assertTrue(a.getMosaics().stream().filter(m -> m.getId().equals(mosaicId)).findFirst().get().getAmount().longValue() > 0);
});
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class NamespaceRepositoryVertxImplTest method shouldGetLinkedMosaicId.
@Test
public void shouldGetLinkedMosaicId() throws Exception {
NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
Address ownerAddress = Account.generateNewAccount(networkType).getAddress();
NamespaceInfoDTO dto = new NamespaceInfoDTO();
NamespaceMetaDTO meta = new NamespaceMetaDTO();
meta.setActive(true);
dto.setId("SomeId");
meta.setIndex(123);
dto.setMeta(meta);
NamespaceDTO namespace = new NamespaceDTO();
namespace.setDepth(111);
namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_0);
namespace.setOwnerAddress(ownerAddress.encoded());
AliasDTO alias = new AliasDTO();
alias.setType(AliasTypeEnum.NUMBER_1);
alias.setMosaicId("528280977531");
namespace.setAlias(alias);
dto.setNamespace(namespace);
mockRemoteCall(dto);
MosaicId linkedMosaicId = repository.getLinkedMosaicId(namespaceId).toFuture().get();
Assertions.assertNotNull(linkedMosaicId);
Assertions.assertEquals("0000528280977531", linkedMosaicId.getIdAsHex());
}
Aggregations