Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated tests #13

Merged
merged 2 commits into from
Dec 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 13 additions & 45 deletions src/main/java/jota/IotaAPIProxy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -51,11 +10,20 @@
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:
*
Expand Down Expand Up @@ -413,7 +381,7 @@ public List<String> prepareTransfers(final String seed, final List<Transfer> tra
// 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()) {
Expand Down Expand Up @@ -598,7 +566,7 @@ public GetBalancesAndFormatResponse getBalanceAndFormat(final List<String> addre
// Increase totalBalance of all aggregated inputs
totalBalance += balance;

if (thresholdReached == false && totalBalance >= threshold) {
if (!thresholdReached && totalBalance >= threshold) {
thresholdReached = true;
break;
}
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/jota/model/Bundle.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jota.model;

import jota.pow.Curl;
import jota.utils.Constants;
import jota.utils.Converter;

import java.util.ArrayList;
Expand Down Expand Up @@ -43,18 +42,14 @@ public void setLength(int length) {
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;
*/
}
}

Expand Down Expand Up @@ -84,6 +79,7 @@ public void finalize() {
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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/jota/model/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public Transaction(String signatureFragments, String currentIndex, String lastIn
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);
Expand Down
54 changes: 46 additions & 8 deletions src/test/java/jota/IotaAPIProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
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;

Expand All @@ -28,6 +31,9 @@ public class IotaAPIProxyTest {
private static final String TEST_TRYTES = "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLG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XKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
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;

Expand All @@ -40,6 +46,21 @@ public void createProxyInstance() {
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
Expand Down Expand Up @@ -70,25 +91,25 @@ public void shouldGetTips() {
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());
}


Expand All @@ -97,27 +118,32 @@ public void shouldFindTransactionsByDigests() {
@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
Expand All @@ -131,4 +157,16 @@ public void shouldCreateANewAddress() {
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);
}
}