* fixed getTransactionsToApprove (#12)

* updated GetNodeInfo

* fixed getTransactionsToApprove

* fixed getTransactionsToApprove

* updated tests (#13)

* updated tests

* Bundle: fixed addEntry

* added getLatestInclusion (#14)

* added getLatestInclusion

* added findTransactionObjects

* added documentation

* added replayTransfer, findTransaction (#15)

* added findTransactionObjects

* added documentation

* fixed NullPoointer

* added replayTransfer

* extended InputValidatorTest

* fixed merge conflict
This commit is contained in:
Gianluigi Davassi
2016-12-26 09:36:41 +01:00
committed by GitHub
parent 7537a34167
commit eedd456af2
8 changed files with 237 additions and 96 deletions
+95 -62
View File
@@ -1,48 +1,7 @@
package jota;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jota.dto.request.IotaAttachToTangleRequest;
import jota.dto.request.IotaBroadcastTransactionRequest;
import jota.dto.request.IotaCommandRequest;
import jota.dto.request.IotaFindTransactionsRequest;
import jota.dto.request.IotaGetBalancesRequest;
import jota.dto.request.IotaGetInclusionStateRequest;
import jota.dto.request.IotaGetTransactionsToApproveRequest;
import jota.dto.request.IotaGetTrytesRequest;
import jota.dto.request.IotaNeighborsRequest;
import jota.dto.request.IotaStoreTransactionsRequest;
import jota.dto.response.AddNeighborsResponse;
import jota.dto.response.BroadcastTransactionsResponse;
import jota.dto.response.FindTransactionResponse;
import jota.dto.response.GetAttachToTangleResponse;
import jota.dto.response.GetBalancesAndFormatResponse;
import jota.dto.response.GetBalancesResponse;
import jota.dto.response.GetBundleResponse;
import jota.dto.response.GetInclusionStateResponse;
import jota.dto.response.GetNeighborsResponse;
import jota.dto.response.GetNewAddressResponse;
import jota.dto.response.GetNodeInfoResponse;
import jota.dto.response.GetTipsResponse;
import jota.dto.response.GetTransactionsToApproveResponse;
import jota.dto.response.GetTrytesResponse;
import jota.dto.response.InterruptAttachingToTangleResponse;
import jota.dto.response.RemoveNeighborsResponse;
import jota.dto.response.StoreTransactionsResponse;
import jota.dto.request.*;
import jota.dto.response.*;
import jota.model.Bundle;
import jota.model.Input;
import jota.model.Transaction;
@@ -51,11 +10,20 @@ import jota.utils.Converter;
import jota.utils.InputValidator;
import jota.utils.IotaAPIUtils;
import okhttp3.OkHttpClient;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* IotaAPIProxy Builder. Usage:
*
@@ -282,15 +250,15 @@ public class IotaAPIProxy {
* sendTrytes
* prepareTransfers
* getInputs
* getLatestInclusion
getTransfers
sendTransfer
getBundle
getTransactionsObjects
findTransactionObjects
getLatestInclusion
replayBundle
broadcastBundle
getAccountData
@@ -317,14 +285,14 @@ public class IotaAPIProxy {
* @param {array} trytes
* @param {int} depth
* @param {int} minWeightMagnitude
* @return
* @return
*/
public List<Transaction> sendTrytes(final String trytes, final int minWeightMagnitude) {
final GetTransactionsToApproveResponse txs = getTransactionsToApprove(minWeightMagnitude);
// attach to tangle - do pow
final GetAttachToTangleResponse res = attachToTangle(txs.getTrunkTransaction(), txs.getBranchTransactionToApprove(), minWeightMagnitude, trytes);
final GetAttachToTangleResponse res = attachToTangle(txs.getTrunkTransaction(), txs.getBranchTransaction(), minWeightMagnitude, trytes);
try {
broadcastAndStore(res.getTrytes());
@@ -341,13 +309,7 @@ public class IotaAPIProxy {
}
return trx;
}
public List<Transaction> findAndGetTxs(final String addresses) {
final FindTransactionResponse res = findTransactionsByAddresses(addresses);
return getTransactionsObjects(res.getHashes());
}
/**
* Wrapper function for getTrytes and transactionObjects
* gets the trytes and transaction object from a list of transaction hashes
@@ -358,7 +320,7 @@ public class IotaAPIProxy {
* @returns {function} callback
* @returns {object} success
**/
public List<Transaction> getTransactionsObjects(String ... hashes) {
public List<Transaction> getTransactionsObjects(String[] hashes) {
if (!InputValidator.isArrayOfHashes(hashes)) {
throw new IllegalStateException("Not an Array of Hashes: " + Arrays.toString(hashes));
@@ -373,6 +335,26 @@ public class IotaAPIProxy {
}
return trxs;
}
/**
* Wrapper function for findTransactions, getTrytes and transactionObjects
* Returns the transactionObject of a transaction hash. The input can be a valid
* findTransactions input
*
* @param {object} input
* @method getTransactionsObjects
* @returns {function} callback
* @returns {object} success
**/
public List<Transaction> findTransactionObjects(String[] input) {
FindTransactionResponse ftr = findTransactions(input, null, null, null);
if (ftr == null || ftr.getHashes() == null)
return null;
// get the transaction objects of the transactions
return getTransactionsObjects(ftr.getHashes());
}
/**
* Prepares transfer by generating bundle, finding and signing inputs
@@ -413,7 +395,7 @@ public class IotaAPIProxy {
// Get total length, message / maxLength (2187 trytes)
signatureMessageLength += Math.floor(transfer.getMessage().length() / 2187);
String msgCopy = new String(transfer.getMessage());
String msgCopy = transfer.getMessage();
// While there is still a message, copy it
while (!msgCopy.isEmpty()) {
@@ -575,10 +557,12 @@ public class IotaAPIProxy {
// Calls getBalances and formats the output
// returns the final inputsObject then
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses,
final List<String> balances, long threshold, int start, int end) {
public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addresses, List<String> balances, long threshold, int start, int end) {
GetBalancesResponse bres = getBalances(100, addresses);
if (balances == null || balances.isEmpty()) {
GetBalancesResponse getBalancesResponse = getBalances(100, addresses);
balances = Arrays.asList(getBalancesResponse.getBalances());
}
// If threshold defined, keep track of whether reached or not
// else set default to true
@@ -598,7 +582,7 @@ public class IotaAPIProxy {
// Increase totalBalance of all aggregated inputs
totalBalance += balance;
if (thresholdReached == false && totalBalance >= threshold) {
if (!thresholdReached && totalBalance >= threshold) {
thresholdReached = true;
break;
}
@@ -610,11 +594,60 @@ public class IotaAPIProxy {
}
throw new IllegalStateException("Not enough balance");
}
/**
* Gets the associated bundle transactions of a single transaction
* Does validation of signatures, total sum as well as bundle order
*
* @method getBundle
* @param {string} transaction Hash of a tail transaction
* @returns {list} bundle Transaction objects
**/
public GetBundleResponse getBundle(String transaction) {
return null; //IotaAPIUtils.getBundle(transaction);
}
/**
* Replays a transfer by doing Proof of Work again
*
* @method replayBundle
* @param {string} tail
* @param {int} depth
* @param {int} minWeightMagnitude
* @param {function} callback
* @returns {object} analyzed Transaction objects
**/
public List<Transaction> replayTransfer(String transaction, int depth, int minWeightMagnitude) {
List<String> bundleTrytes = new ArrayList<>();
GetBundleResponse bundle = getBundle(transaction);
for (Transaction element : bundle.getTransactions()) {
bundleTrytes.add(IotaAPIUtils.transactionTrytes(element));
}
return sendTrytes(bundleTrytes, minWeightMagnitude);
}
/**
* Wrapper function for getNodeInfo and getInclusionStates
*
* @method getLatestInclusion
* @param {array} hashes
* @returns {function} callback
* @returns {array} state
**/
public GetInclusionStateResponse getLatestInclusion(String[] hashes) {
GetNodeInfoResponse getNodeInfoResponse = getNodeInfo();
if (getNodeInfoResponse == null) return null;
String[] latestMilestone = {getNodeInfoResponse.getLatestSolidSubtangleMilestone()};
return getInclusionStates(hashes, latestMilestone);
}
public static class Builder {
String protocol, host, port;
@@ -4,6 +4,7 @@ public class GetNodeInfoResponse extends AbstractResponse {
private String appName;
private String appVersion;
private String jreVersion;
private int jreAvailableProcessors;
private long jreFreeMemory;
private long jreMaxMemory;
@@ -26,6 +27,10 @@ public class GetNodeInfoResponse extends AbstractResponse {
return appVersion;
}
public String getJreVersion() {
return jreVersion;
}
public Integer getJreAvailableProcessors() {
return jreAvailableProcessors;
}
@@ -3,13 +3,13 @@ package jota.dto.response;
public class GetTransactionsToApproveResponse extends AbstractResponse {
private String trunkTransaction;
private String branchTransactionToApprove;
public String getBranchTransactionToApprove() {
return branchTransactionToApprove;
}
private String branchTransaction;
public String getTrunkTransaction() {
return trunkTransaction;
}
}
public String getBranchTransaction() {
return branchTransaction;
}
}
+6 -10
View File
@@ -1,7 +1,6 @@
package jota.model;
import jota.pow.Curl;
import jota.utils.Constants;
import jota.utils.Converter;
import java.util.ArrayList;
@@ -43,18 +42,14 @@ public class Bundle {
this.length = length;
}
public void addEntry(int signatureMessageLength, String slice, long value, String tag, long timestamp) {
public void addEntry(int signatureMessageLength, String address, long value, String tag, long timestamp) {
for (int i = 0; i < signatureMessageLength; i++) {
//TODO
/* var transactionObject = new Object();
transactionObject.address = address;
transactionObject.value = i == 0 ? value : 0;
transactionObject.tag = tag;
transactionObject.timestamp = timestamp;
List<Transaction> transactions = new ArrayList<>(getTransactions());
transactions.add(new Transaction(address, String.valueOf(i == 0 ? value : 0), tag, String.valueOf(timestamp)));
setTransactions(transactions);
this.bundle[this.bundle.length] = transactionObject;
*/
}
}
@@ -84,6 +79,7 @@ public class Bundle {
while (lastIndexTrits.length < 27) {
lastIndexTrits[lastIndexTrits.length] = 0;
}
int[] t = Converter.trits(this.getTransactions().get(i).getAddress() + Converter.trytes(valueTrits) + this.getTransactions().get(i).getTag() + Converter.trytes(timestampTrits) + Converter.trytes(currentIndexTrits) + Converter.trytes(lastIndexTrits));
curl.absorb(t, 0, t.length);
}
@@ -41,6 +41,14 @@ public class Transaction {
this.nonce = nonce;
}
public Transaction(String address, String value, String tag, String timestamp) {
this.address = address;
this.value = value;
this.tag = tag;
this.timestamp = timestamp;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
+33 -8
View File
@@ -2,14 +2,12 @@ package jota.utils;
import jota.model.Transaction;
import jota.pow.Curl;
import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class Converter {
private static final Logger log = LoggerFactory.getLogger(Converter.class);
@@ -69,12 +67,39 @@ public class Converter {
}
public static int[] trits(final String trytes) {
final int[] trits = new int[trytes.length() * NUMBER_OF_TRITS_IN_A_TRYTE];
for (int i = 0; i < trytes.length(); i++) {
System.arraycopy(TRYTE_TO_TRITS_MAPPINGS[Constants.TRYTE_ALPHABET.indexOf(trytes.charAt(i))], 0, trits, i * NUMBER_OF_TRITS_IN_A_TRYTE, NUMBER_OF_TRITS_IN_A_TRYTE);
}
if (InputValidator.isValue(trytes)) {
int value = Integer.parseInt(trytes);
long absoluteValue = value < 0 ? -value : value;
while (absoluteValue > 0) {
int remainder = (int) (absoluteValue % RADIX);
absoluteValue /= RADIX;
if (remainder > MAX_TRIT_VALUE) {
remainder = MIN_TRIT_VALUE;
absoluteValue++;
}
trits[trits.length] = remainder;
}
if (value < 0) {
for (int i = 0; i < trits.length; i++) {
trits[i] = -trits[i];
}
}
} else {
for (int i = 0; i < trytes.length(); i++) {
System.arraycopy(TRYTE_TO_TRITS_MAPPINGS[Constants.TRYTE_ALPHABET.indexOf(trytes.charAt(i))], 0, trits, i * NUMBER_OF_TRITS_IN_A_TRYTE, NUMBER_OF_TRITS_IN_A_TRYTE);
}
}
return trits;
}
+27 -2
View File
@@ -1,8 +1,12 @@
package jota;
import jota.model.Transfer;
import jota.utils.InputValidator;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
@@ -11,8 +15,11 @@ import static org.junit.Assert.assertEquals;
public class InputValidatorTest {
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM = "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
private static final String TEST_ADDRESS_WITH_CHECKSUM = "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
private static final String TEST_TRYTES = "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJX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TUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
private static final String TEST_HASH = "OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999";
private static final String TEST_MESSAGE = "JOTA";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
@Test
public void shouldIsAddress() {
assertEquals(InputValidator.isAddress(TEST_ADDRESS_WITHOUT_CHECKSUM), true);
@@ -27,4 +34,22 @@ public class InputValidatorTest {
public void shouldIsTrytes() {
assertEquals(InputValidator.isTrytes(TEST_TRYTES, TEST_TRYTES.length()), true);
}
}
@Test
public void shouldIsValue() {
assertEquals(InputValidator.isValue("1234"), true);
}
@Test
public void shouldIsArrayOfHashes() {
assertEquals(InputValidator.isArrayOfHashes(new String[]{TEST_HASH, TEST_HASH}), true);
}
@Test
public void shouldIsTransfersCollectionCorrect() {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
assertEquals(InputValidator.isTransfersCollectionCorrect(transfers), true);
}
}
+57 -8
View File
@@ -3,12 +3,15 @@ package jota;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jota.dto.response.*;
import jota.model.Transfer;
import org.hamcrest.core.Is;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertThat;
@@ -28,6 +31,9 @@ public class IotaAPIProxyTest {
private static final String TEST_TRYTES = "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQXCDAXOUDMLVYRMRLUDBETOLRJQAEDDLNVIRQJUBZBO9CCFDHIX9MSQCWYAXJVWHCUPTRSXJDESISQPRKZAFKFRULCGVRSBLVFOPEYLEE99JD9SEBALQINPDAZHFAB9RNBH9AZWIJOTLBZVIEJIAYGMC9AZGNFWGRSWAXTYSXVROVNKCOQQIWGPNQZKHUNODGYADPYLZZZUQRTJRTODOUKAOITNOMWNGHJBBA99QUMBHRENGBHTH9KHUAOXBVIVDVYYZMSEYSJWIOGGXZVRGN999EEGQMCOYVJQRIRROMPCQBLDYIGQO9AMORPYFSSUGACOJXGAQSPDY9YWRRPESNXXBDQ9OZOXVIOMLGTSWAMKMTDRSPGJKGBXQIVNRJRFRYEZ9VJDLHIKPS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GBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
private static final String TEST_MILESTONE = "SMYMAKKPSUKCKDRUEYCGZJTYCZ9HHDMDUWBAPXARGURPQRHTAJDASRWMIDTPTBNDKDEFBUTBGGAFX9999";
private static final Integer TEST_MILESTONE_INDEX = 8059;
private static final String TEST_MESSAGE = "JOTA";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
private IotaAPIProxy proxy;
@@ -40,6 +46,21 @@ public class IotaAPIProxyTest {
public void shouldGetNodeInfo() {
GetNodeInfoResponse nodeInfo = proxy.getNodeInfo();
assertThat(nodeInfo.getAppVersion(), IsNull.notNullValue());
assertThat(nodeInfo.getAppName(), IsNull.notNullValue());
//assertThat(nodeInfo.getJreVersion(), IsNull.notNullValue());
assertThat(nodeInfo.getJreAvailableProcessors(), IsNull.notNullValue());
assertThat(nodeInfo.getJreFreeMemory(), IsNull.notNullValue());
assertThat(nodeInfo.getJreMaxMemory(), IsNull.notNullValue());
assertThat(nodeInfo.getJreTotalMemory(), IsNull.notNullValue());
assertThat(nodeInfo.getLatestMilestone(), IsNull.notNullValue());
assertThat(nodeInfo.getLatestMilestoneIndex(), IsNull.notNullValue());
assertThat(nodeInfo.getLatestSolidSubtangleMilestone(), IsNull.notNullValue());
assertThat(nodeInfo.getLatestSolidSubtangleMilestoneIndex(), IsNull.notNullValue());
assertThat(nodeInfo.getNeighbors(), IsNull.notNullValue());
assertThat(nodeInfo.getPacketsQueueSize(), IsNull.notNullValue());
assertThat(nodeInfo.getTime(), IsNull.notNullValue());
assertThat(nodeInfo.getTips(), IsNull.notNullValue());
assertThat(nodeInfo.getTransactionsToRequest(), IsNull.notNullValue());
}
@Test
@@ -70,25 +91,25 @@ public class IotaAPIProxyTest {
public void shouldFindTransactionsByAddresses() {
FindTransactionResponse trans = proxy.findTransactionsByAddresses(TEST_ADDRESS_WITH_CHECKSUM);
System.err.println(gson.toJson(trans));
assertThat(trans, IsNull.notNullValue());
assertThat(trans.getHashes(), IsNull.notNullValue());
}
@Test
public void shouldFindTransactionsByApprovees() {
FindTransactionResponse trans = proxy.findTransactionsByApprovees(new String[]{TEST_HASH});
assertThat(trans, IsNull.notNullValue());
assertThat(trans.getHashes(), IsNull.notNullValue());
}
@Test
public void shouldFindTransactionsByBundles() {
FindTransactionResponse trans = proxy.findTransactionsByBundles(TEST_HASH);
assertThat(trans, IsNull.notNullValue());
assertThat(trans.getHashes(), IsNull.notNullValue());
}
@Test
public void shouldFindTransactionsByDigests() {
FindTransactionResponse trans = proxy.findTransactionsByDigests(TEST_HASH);
assertThat(trans, IsNull.notNullValue());
assertThat(trans.getHashes(), IsNull.notNullValue());
}
@@ -97,27 +118,32 @@ public class IotaAPIProxyTest {
@Test
public void shouldGetTrytes() {
GetTrytesResponse res = proxy.getTrytes(TEST_HASH);
assertThat(res, IsNull.notNullValue());
assertThat(res.getTrytes(), IsNull.notNullValue());
}
@Test
public void shouldGetInclusionStates() {
GetInclusionStateResponse res = proxy.getInclusionStates(new String[]{TEST_ADDRESS_WITH_CHECKSUM}, new String[]{"DNSBRJWNOVUCQPILOQIFDKBFJMVOTGHLIMLLRXOHFTJZGRHJUEDAOWXQRYGDI9KHYFGYDWQJZKX999999"});
assertThat(res, IsNull.notNullValue());
assertThat(res.getStates(), IsNull.notNullValue());
}
@Test // very long execution
public void shouldGetTransactionsToApprove() {
GetTransactionsToApproveResponse res = proxy.getTransactionsToApprove(27);
assertThat(res, IsNull.notNullValue());
assertThat(res.getTrunkTransaction(), IsNull.notNullValue());
assertThat(res.getBranchTransaction(), IsNull.notNullValue());
}
@Test
public void shouldGetBalances() {
GetBalancesResponse res = proxy.getBalances(100, new String[]{TEST_ADDRESS_WITH_CHECKSUM});
System.err.println(res);
assertThat(res, IsNull.notNullValue());
assertThat(res.getBalances(), IsNull.notNullValue());
assertThat(res.getMilestone(), IsNull.notNullValue());
assertThat(res.getMilestoneIndex(), IsNull.notNullValue());
}
@Test
@@ -131,4 +157,27 @@ public class IotaAPIProxyTest {
final GetNewAddressResponse res = proxy.getNewAddress(TEST_SEED, 0, false, 1, false);
assertThat(res.getAddresses(), Is.is(Collections.singletonList(TEST_ADDRESS_WITHOUT_CHECKSUM)));
}
@Test
public void shouldPrepareTransfer() {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
proxy.prepareTransfers(TEST_SEED, transfers, null, null);
}
@Test
public void shouldSendTrytes() {
proxy.sendTrytes(TEST_TRYTES, 18);
}
@Test
public void shouldGetLastInclusionState() {
GetInclusionStateResponse res = proxy.getLatestInclusion(new String[]{TEST_HASH});
assertThat(res.getStates(), IsNull.notNullValue());
}
@Test
public void shouldFindTransactionObjects() {
assertThat(proxy.findTransactionObjects(new String[]{TEST_ADDRESS_WITH_CHECKSUM}), IsNull.notNullValue());
}
}