updated tests (#13)

* updated tests

* Bundle: fixed addEntry
This commit is contained in:
Oliver Nitzschke
2016-12-22 14:55:13 +01:00
committed by Gianluigi Davassi
parent bee2aa3302
commit 9af3d2d027
4 changed files with 73 additions and 63 deletions
+13 -45
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:
*
@@ -413,7 +381,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()) {
@@ -598,7 +566,7 @@ public class IotaAPIProxy {
// Increase totalBalance of all aggregated inputs
totalBalance += balance;
if (thresholdReached == false && totalBalance >= threshold) {
if (!thresholdReached && totalBalance >= threshold) {
thresholdReached = true;
break;
}
+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);
+46 -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 = "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQXCDAXOUDMLVYRMRLUDBETOLRJQAEDDLNVIRQJUBZBO9CCFDHIX9MSQCWYAXJVWHCUPTRSXJDESISQPRKZAFKFRULCGVRSBLVFOPEYLEE99JD9SEBALQINPDAZHFAB9RNBH9AZWIJOTLBZVI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QQRXTPACOWCPRLYRYSJARRKSQPR9TCFXDVIXLP9XVL99ERRDSOHBFJDJQQGGGCZNDQ9NYCTQJWVZIAELCRBJJFDMCNZU9FIZRPGNURTXOCDSQGXTQHKHUECGWFUUYS9J9NYQ9U9P9UUP9YMZHWWWCIASCFLCMSKTELZWUGCDE9YOKVOVKTAYPHDF9ZCCQAYPJIJNGSHUIHHCOSSOOBUDOKE9CJZGYSSGNCQJVBEFTZFJ9SQUHOASKRRGBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
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,16 @@ 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);
}
}