use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method aggregateBondedAddedHash.
@Test
public void aggregateBondedAddedHash() throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
String channelName = ListenerChannel.AGGREGATE_BONDED_ADDED.toString();
List<Transaction> transactions = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
listener.aggregateBondedAddedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
String topic = channelName + "/" + address.plain();
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, topic)));
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
handle(transactionInfoDtoJsonObject, topic);
Assertions.assertEquals(1, transactions.size());
Assertions.assertEquals(0, exceptions.size());
Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
}
use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method confirmedUsingHashUsingAlias.
@Test
public void confirmedUsingHashUsingAlias() throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
NamespaceId alias = NamespaceId.createFromId(BigInteger.TEN);
String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
List<Transaction> transactions = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
listener.confirmedOrError(alias, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, channelName + "/" + alias.plain());
Assertions.assertEquals(1, transactions.size());
Assertions.assertEquals(0, exceptions.size());
Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + alias.plain())));
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + alias.plain())));
}
use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.
the class ListenerOkHttpTest method confirmedUsingHashRaiseError.
@Test
public void confirmedUsingHashRaiseError() throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
Map<String, Object> transactionStatusError = new HashMap<>();
transactionStatusError.put("address", address.encoded());
transactionStatusError.put("code", "Fail 666");
transactionStatusError.put("hash", getHash(transactionInfo));
transactionStatusError.put("deadline", 123);
List<Transaction> transactions = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
listener.confirmedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
handle(transactionStatusError, "status/" + address.plain());
Assertions.assertEquals(0, transactions.size());
Assertions.assertEquals(1, exceptions.size());
Assertions.assertEquals(TransactionStatusException.class, exceptions.get(0).getClass());
Assertions.assertEquals("Fail 666 processing transaction " + getHash(transactionInfo), exceptions.get(0).getMessage());
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.
the class MetadataRepositoryOkHttpImplTest method createMetadataDto.
private MetadataInfoDTO createMetadataDto(String name, MetadataTypeEnum type, String targetId) {
MetadataInfoDTO dto = new MetadataInfoDTO();
dto.setId(name);
Address sourceAddress = Account.generateNewAccount(networkType).getAddress();
Address targetAddress = Account.generateNewAccount(networkType).getAddress();
MetadataEntryDTO metadataEntry = new MetadataEntryDTO();
metadataEntry.setVersion(1);
metadataEntry.setCompositeHash("ompositeHash " + name);
metadataEntry.setMetadataType(type);
metadataEntry.setScopedMetadataKey("10");
metadataEntry.sourceAddress(sourceAddress.encoded());
metadataEntry.setTargetId(targetId);
metadataEntry.setTargetAddress(targetAddress.encoded());
metadataEntry.setValue(ConvertUtils.fromStringToHex(name + " message"));
dto.setMetadataEntry(metadataEntry);
return dto;
}
use of io.nem.symbol.sdk.model.account.Address 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());
}
Aggregations