use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class MosaicAddressRestrictionIntegrationTest method createMultiAddressRestrictions.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMultiAddressRestrictions(RepositoryType type) {
Account testAccount = helper().createTestAccount(type);
Account testAccount2 = config().getTestAccount2();
Account testAccount3 = config().getTestAccount3();
// 1) Create a mosaic
MosaicId mosaicId = createMosaic(type, testAccount);
BigInteger restrictionKey1 = BigInteger.valueOf(11);
BigInteger restrictionKey2 = BigInteger.valueOf(22);
// 2) Create a global restriction on the mosaic
MosaicGlobalRestrictionTransaction mosaicGlobalRestrictionTransaction1 = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, BigInteger.valueOf(20), MosaicRestrictionType.GE).maxFee(maxFee).build();
// 2) Create a global restriction on the mosaic
MosaicGlobalRestrictionTransaction mosaicGlobalRestrictionTransaction2 = MosaicGlobalRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey2, BigInteger.valueOf(10), MosaicRestrictionType.GT).maxFee(maxFee).build();
announceAndValidate(type, testAccount, mosaicGlobalRestrictionTransaction1);
announceAndValidate(type, testAccount, mosaicGlobalRestrictionTransaction2);
sleep(1000);
// 3)Create a new MosaicAddressRestrictionTransaction
MosaicAddressRestrictionTransaction createTransaction1 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, testAccount2.getAddress(), BigInteger.valueOf(30)).maxFee(maxFee).build();
MosaicAddressRestrictionTransaction createTransaction2 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey1, testAccount3.getAddress(), BigInteger.valueOf(20)).maxFee(maxFee).build();
MosaicAddressRestrictionTransaction createTransaction3 = MosaicAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), mosaicId, restrictionKey2, testAccount3.getAddress(), BigInteger.valueOf(70)).maxFee(maxFee).build();
announceAndValidate(type, testAccount, createTransaction1);
announceAndValidate(type, testAccount, createTransaction2);
announceAndValidate(type, testAccount, createTransaction3);
sleep(1000);
RestrictionMosaicRepository restrictionRepository = getRepositoryFactory(type).createRestrictionMosaicRepository();
PaginationStreamer<MosaicRestriction<?>, MosaicRestrictionSearchCriteria> streamer = restrictionRepository.streamer();
List<MosaicRestriction<?>> restrictions = get(streamer.search(new MosaicRestrictionSearchCriteria().targetAddress(testAccount.getAddress())).toList().toObservable());
Assertions.assertEquals(1, restrictions.size());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class MultisigRepositoryIntegrationTest method getMultisigAccountInfo.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMultisigAccountInfo(RepositoryType type) {
Account multisigAccount = helper().getMultisigAccount(type).getLeft();
Account cosignatoryAccount = config().getCosignatoryAccount();
Account cosignatory2Account = config().getCosignatory2Account();
System.out.println(multisigAccount.getAddress().plain());
MultisigAccountInfo multisigAccountInfo = get(getRepositoryFactory(type).createMultisigRepository().getMultisigAccountInfo(multisigAccount.getAddress()));
Set<UnresolvedAddress> cosignatoriesSet = new HashSet<>(multisigAccountInfo.getCosignatoryAddresses());
Assertions.assertEquals(Sets.newSet(cosignatoryAccount.getAddress(), cosignatory2Account.getAddress()), cosignatoriesSet);
Assertions.assertTrue(multisigAccountInfo.isMultisig());
assertEquals(multisigAccount.getAddress(), multisigAccountInfo.getAccountAddress());
Assertions.assertEquals(1, multisigAccountInfo.getMinApproval());
Assertions.assertEquals(1, multisigAccountInfo.getMinRemoval());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method shouldFilterOutHandleStatus.
@Test
public void shouldFilterOutHandleStatus() throws InterruptedException, ExecutionException, TimeoutException {
Account account1 = Account.generateNewAccount(networkType);
Account account2 = Account.generateNewAccount(networkType);
AtomicReference<TransactionStatusError> reference = new AtomicReference<>();
simulateWebSocketStartup();
Assertions.assertNotNull(listener.status(account2.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.assertNull(reference.get());
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + account2.getAddress().plain())));
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
Assertions.assertEquals(2, deserialized.getCosignatures().size());
Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method getMultipleTransactions.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMultipleTransactions(RepositoryType type) {
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
Account account = config().getDefaultAccount();
List<TransactionType> transactionTypes = Arrays.asList(TransactionType.TRANSFER, TransactionType.AGGREGATE_COMPLETE, TransactionType.NAMESPACE_METADATA);
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).transactionTypes(transactionTypes))).getData();
Assertions.assertFalse(transactions.isEmpty());
transactions.forEach(t -> Assertions.assertTrue(transactionTypes.contains(t.getType())));
}
Aggregations