refactored, updated SendTransferResponse, tests

This commit is contained in:
pinpong 2017-11-07 17:11:05 +01:00
parent 8d07e0ba60
commit afd6f1152d
16 changed files with 241 additions and 186 deletions

View File

@ -1,6 +1,5 @@
package jota;
import com.google.gson.Gson;
import jota.dto.response.*;
import jota.error.*;
import jota.model.*;
@ -52,10 +51,6 @@ public class IotaAPI extends IotaAPICore {
*/
public GetNewAddressResponse getNewAddress(final String seed, int security, final int index, final boolean checksum, final int total, final boolean returnAll) throws InvalidSecurityLevelException, InvalidAddressException {
if (security < 1) {
throw new InvalidSecurityLevelException();
}
StopWatch stopWatch = new StopWatch();
List<String> allAddresses = new ArrayList<>();
@ -114,11 +109,6 @@ public class IotaAPI extends IotaAPICore {
throw new IllegalStateException("Invalid Seed");
}
if (security < 1) {
throw new InvalidSecurityLevelException();
}
if (start > end || end > (start + 500)) {
throw new ArgumentException("Invalid inputs provided");
}
@ -255,7 +245,6 @@ public class IotaAPI extends IotaAPICore {
final GetTransactionsToApproveResponse txs = getTransactionsToApprove(depth);
// attach to tangle - do pow
System.out.println(new Gson().toJson(txs));
final GetAttachToTangleResponse res = attachToTangle(txs.getTrunkTransaction(), txs.getBranchTransaction(), minWeightMagnitude, trytes);
try {
@ -330,7 +319,7 @@ public class IotaAPI extends IotaAPICore {
/**
* Prepares transfer by generating bundle, finding and signing inputs.
*
* @param seed 81-tryte encoded address of recipient.
* @param seed Tryte-encoded private key / seed.
* @param security The security level of private key / seed.
* @param transfers Array of transfer objects.
* @param remainder If defined, this address will be used for sending the remainder value (of the inputs) to.
@ -344,15 +333,6 @@ public class IotaAPI extends IotaAPICore {
*/
public List<String> prepareTransfers(String seed, int security, final List<Transfer> transfers, String remainder, List<Input> inputs, boolean validateInputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidAddressException, InvalidTransferException {
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
throw new InvalidTransferException();
}
// Input validation of transfers object
if (transfers.isEmpty()) {
throw new IllegalArgumentException("No transfer provided");
}
// validate seed
if ((!InputValidator.isValidSeed(seed))) {
throw new IllegalStateException("Invalid Seed");
@ -362,61 +342,69 @@ public class IotaAPI extends IotaAPICore {
throw new InvalidSecurityLevelException();
}
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
throw new InvalidTransferException();
}
// Create a new bundle
final Bundle bundle = new Bundle();
final List<String> signatureFragments = new ArrayList<>();
long totalValue = 0;
String tag = "";
// Iterate over all transfers, get totalValue
// and prepare the signatureFragments, message and tag
for (final Transfer transfer : transfers) {
// If address with checksum then remove checksum
if (Checksum.isAddressWithChecksum(transfer.getAddress()))
// remove the checksum of the address if provided
if (Checksum.isValidChecksum(transfer.getAddress())) {
transfer.setAddress(Checksum.removeChecksum(transfer.getAddress()));
}
int signatureMessageLength = 1;
// If message longer than 2187 trytes, increase signatureMessageLength (add 2nd transaction)
if (transfer.getMessage().length() > 2187) {
if (transfer.getMessage().length() > Constants.MESSAGE_LENGTH) {
// Get total length, message / maxLength (2187 trytes)
signatureMessageLength += Math.floor(transfer.getMessage().length() / 2187);
signatureMessageLength += Math.floor(transfer.getMessage().length() / Constants.MESSAGE_LENGTH);
String msgCopy = transfer.getMessage();
// While there is still a message, copy it
while (!msgCopy.isEmpty()) {
String fragment = StringUtils.substring(msgCopy, 0, 2187);
msgCopy = StringUtils.substring(msgCopy, 2187, msgCopy.length());
String fragment = StringUtils.substring(msgCopy, 0, Constants.MESSAGE_LENGTH);
msgCopy = StringUtils.substring(msgCopy, Constants.MESSAGE_LENGTH, msgCopy.length());
// Pad remainder of fragment
fragment = StringUtils.rightPad(fragment, 2187, '9');
fragment = StringUtils.rightPad(fragment, Constants.MESSAGE_LENGTH, '9');
signatureFragments.add(fragment);
}
} else {
// Else, get single fragment with 2187 of 9's trytes
String fragment = StringUtils.substring(transfer.getMessage(), 0, 2187);
fragment = StringUtils.rightPad(fragment, 2187, '9');
String fragment = transfer.getMessage();
if (transfer.getMessage().length() < Constants.MESSAGE_LENGTH) {
fragment = StringUtils.rightPad(fragment, Constants.MESSAGE_LENGTH, '9');
}
signatureFragments.add(fragment);
}
tag = transfer.getTag();
// pad for required 27 tryte length
if (transfer.getTag().length() < Constants.TAG_LENGTH) {
tag = StringUtils.rightPad(tag, Constants.TAG_LENGTH, '9');
}
// get current timestamp in seconds
long timestamp = (long) Math.floor(Calendar.getInstance().getTimeInMillis() / 1000);
// If no tag defined, get 27 tryte tag.
tag = transfer.getTag().isEmpty() ? "999999999999999999999999999" : transfer.getTag();
// Pad for required 27 tryte length
tag = StringUtils.rightPad(tag, 27, '9');
// Add first entry to the bundle
bundle.addEntry(signatureMessageLength, transfer.getAddress(), transfer.getValue(), tag, timestamp);
// Sum up total value
@ -430,9 +418,9 @@ public class IotaAPI extends IotaAPICore {
// Validate the inputs by calling getBalances
if (inputs != null && !inputs.isEmpty()) {
if (!validateInputs)
if (!validateInputs) {
return addRemainder(seed, security, inputs, bundle, tag, totalValue, remainder, signatureFragments);
}
// Get list if addresses of the provided inputs
List<String> inputsAddresses = new ArrayList<>();
for (final Input i : inputs) {
@ -799,7 +787,7 @@ public class IotaAPI extends IotaAPICore {
* @param inputs List of inputs used for funding the transfer.
* @param remainderAddress If defined, this remainderAddress will be used for sending the remainder value (of the inputs) to.
* @param validateInputs Whether or not to validate the balances of the provided inputs
* @return Array of Transaction objects.
* @return Array of valid Transaction objects.
* @throws InvalidAddressException is thrown when the specified remainderAddress is not an valid remainderAddress.
* @throws NotEnoughBalanceException is thrown when a transfer fails because their is not enough balance to perform the transfer.
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
@ -809,10 +797,6 @@ public class IotaAPI extends IotaAPICore {
*/
public SendTransferResponse sendTransfer(String seed, int security, int depth, int minWeightMagnitude, final List<Transfer> transfers, List<Input> inputs, String remainderAddress, boolean validateInputs) throws NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
if (security < 1) {
throw new InvalidSecurityLevelException();
}
StopWatch stopWatch = new StopWatch();
List<String> trytes = prepareTransfers(seed, security, transfers, remainderAddress, inputs, validateInputs);
@ -821,13 +805,11 @@ public class IotaAPI extends IotaAPICore {
Boolean[] successful = new Boolean[trxs.size()];
for (int i = 0; i < trxs.size(); i++) {
final FindTransactionResponse response = findTransactionsByBundles(trxs.get(i).getBundle());
successful[i] = response.getHashes().length != 0;
}
return SendTransferResponse.create(successful, stopWatch.getElapsedTimeMili());
return SendTransferResponse.create(trxs, successful, stopWatch.getElapsedTimeMili());
}
/**
@ -897,17 +879,7 @@ public class IotaAPI extends IotaAPICore {
public List<Transaction> initiateTransfer(int securitySum, final String inputAddress, String remainderAddress,
final List<Transfer> transfers, boolean testMode) throws InvalidAddressException, InvalidBundleException, InvalidTransferException {
if (transfers.isEmpty()) {
throw new IllegalArgumentException("No transfer provided");
}
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
throw new InvalidTransferException();
}
// validate input address
if (!InputValidator.isAddress(inputAddress))
throw new InvalidAddressException();
@ -916,18 +888,9 @@ public class IotaAPI extends IotaAPICore {
throw new InvalidBundleException();
}
// If message or tag is not supplied, provide it
// Also remove the checksum of the address if it's there
for (Transfer transfer : transfers) {
transfer.setMessage(transfer.getMessage().isEmpty() ? StringUtils.rightPad(transfer.getMessage(), 2187, '9') : transfer.getMessage());
transfer.setTag(transfer.getTag().isEmpty() ? StringUtils.rightPad(transfer.getTag(), 27, '9') : transfer.getTag());
if (Checksum.isValidChecksum(transfer.getAddress())) {
transfer.setAddress(Checksum.removeChecksum(transfer.getAddress()));
}
// Input validation of transfers object
if (!InputValidator.isTransfersCollectionValid(transfers)) {
throw new InvalidTransferException();
}
// Create a new bundle
@ -942,50 +905,57 @@ public class IotaAPI extends IotaAPICore {
// and prepare the signatureFragments, message and tag
for (final Transfer transfer : transfers) {
// remove the checksum of the address if provided
if (Checksum.isValidChecksum(transfer.getAddress())) {
transfer.setAddress(Checksum.removeChecksum(transfer.getAddress()));
}
int signatureMessageLength = 1;
// If message longer than 2187 trytes, increase signatureMessageLength (add 2nd transaction)
if (transfer.getMessage().length() > 2187) {
// If message longer than 2187 trytes, increase signatureMessageLength (add next transaction)
if (transfer.getMessage().length() > Constants.MESSAGE_LENGTH) {
// Get total length, message / maxLength (2187 trytes)
signatureMessageLength += Math.floor(transfer.getMessage().length() / 2187);
signatureMessageLength += Math.floor(transfer.getMessage().length() / Constants.MESSAGE_LENGTH);
String msgCopy = transfer.getMessage();
// While there is still a message, copy it
while (!msgCopy.isEmpty()) {
String fragment = StringUtils.substring(msgCopy, 0, 2187);
msgCopy = StringUtils.substring(msgCopy, 2187, msgCopy.length());
String fragment = StringUtils.substring(msgCopy, 0, Constants.MESSAGE_LENGTH);
msgCopy = StringUtils.substring(msgCopy, Constants.MESSAGE_LENGTH, msgCopy.length());
// Pad remainder of fragment
fragment = StringUtils.rightPad(fragment, 2187, '9');
fragment = StringUtils.rightPad(fragment, Constants.MESSAGE_LENGTH, '9');
signatureFragments.add(fragment);
}
} else {
// Else, get single fragment with 2187 of 9's trytes
String fragment = StringUtils.substring(transfer.getMessage(), 0, 2187);
String fragment = transfer.getMessage();
fragment = StringUtils.rightPad(fragment, 2187, '9');
if (transfer.getMessage().length() < Constants.MESSAGE_LENGTH) {
fragment = StringUtils.rightPad(fragment, Constants.MESSAGE_LENGTH, '9');
}
signatureFragments.add(fragment);
}
tag = transfer.getTag();
// pad for required 27 tryte length
if (transfer.getTag().length() < Constants.TAG_LENGTH) {
tag = StringUtils.rightPad(tag, Constants.TAG_LENGTH, '9');
}
// get current timestamp in seconds
long timestamp = (long) Math.floor(Calendar.getInstance().getTimeInMillis() / 1000);
// If no tag defined, get 27 tryte tag.
tag = transfer.getTag().isEmpty() ? StringUtils.rightPad(transfer.getTag(), 27, '9') : transfer.getTag();
// Pad for required 27 tryte length
tag = StringUtils.rightPad(tag, 27, '9');
// Add first entry to the bundle
bundle.addEntry(signatureMessageLength, transfer.getAddress(), transfer.getValue(), tag, timestamp);
// Sum up total value
@ -1049,7 +1019,7 @@ public class IotaAPI extends IotaAPICore {
}
}
/**
* @param seed Tryte-encoded seed.
* @param security The security level of private key / seed.

View File

@ -1,22 +1,47 @@
package jota.dto.response;
import jota.model.Transaction;
import java.util.ArrayList;
import java.util.List;
/**
* Response of api request 'sendTransfer'.
**/
public class SendTransferResponse extends AbstractResponse {
private List<Transaction> transactions = new ArrayList<>();
private Boolean[] successfully;
/**
* Initializes a new instance of the SendTransferResponse class.
*/
public static SendTransferResponse create(Boolean[] successfully, long duration) {
public static SendTransferResponse create(List<Transaction> transactions, Boolean[] successfully, long duration) {
SendTransferResponse res = new SendTransferResponse();
res.transactions = transactions;
res.successfully = successfully;
res.setDuration(duration);
return res;
}
/**
* Gets the transactions.
*
* @return The transactions.
*/
public List<Transaction> getTransactions() {
return transactions;
}
/**
* Sets the transactions.
*
* @param transactions The transactions.
*/
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
/**
* Gets the successfully.
*
@ -34,5 +59,4 @@ public class SendTransferResponse extends AbstractResponse {
public void setSuccessfully(Boolean[] successfully) {
this.successfully = successfully;
}
}

View File

@ -2,6 +2,7 @@ package jota.model;
import jota.pow.ICurl;
import jota.pow.SpongeFactory;
import jota.utils.Constants;
import jota.utils.Converter;
import org.apache.commons.lang3.StringUtils;
@ -150,7 +151,7 @@ public class Bundle implements Comparable<Bundle> {
String emptyHash = EMPTY_HASH;
long emptyTimestamp = 999999999L;
emptySignatureFragment = StringUtils.rightPad(emptySignatureFragment, 2187, '9');
emptySignatureFragment = StringUtils.rightPad(emptySignatureFragment, Constants.MESSAGE_LENGTH, '9');
for (int i = 0; i < this.getTransactions().size(); i++) {

View File

@ -29,7 +29,16 @@ public class Transfer {
this.value = value;
this.message = message;
this.tag = tag;
}
/**
* Initializes a new instance of the Transfer class.
*/
public Transfer(String address, long value) {
this.address = address;
this.value = value;
this.message = "";
this.tag = "";
}
/**
@ -118,7 +127,7 @@ public class Transfer {
/**
* Set the timestamp.
*
* @param timestamp The timestamp.
* @param timestamp The timestamp in seconds.
*/
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
@ -154,7 +163,7 @@ public class Transfer {
/**
* Set the message.
*
* @param message The message.
* @param message The message trytes encoded.
*/
public void setMessage(String message) {
this.message = message;
@ -172,7 +181,7 @@ public class Transfer {
/**
* Set the tag.
*
* @param tag The tag.
* @param tag The tag max 27 trytes encoded.
*/
public void setTag(String tag) {
this.tag = tag;

View File

@ -59,25 +59,23 @@ public class Checksum {
return addressWithRecalculateChecksum.equals(addressWithChecksum);
}
/**
* Check if specified address is a address with checksum.
*
* @param address The address to check.
* @return <code>true</code> if the specified address is with checksum ; otherwise, <code>false</code>.
* @throws InvalidAddressException is thrown when the specified address is not an valid address
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
**/
public static boolean isAddressWithChecksum(String address) throws InvalidAddressException {
return InputValidator.checkAddress(address) && address.length() == Constants.ADDRESS_LENGTH_WITH_CHECKSUM;
}
/**
* check if specified address is a address
* Check if specified address is a address without checksum.
*
* @param address address
* @return boolean
* @throws InvalidAddressException is thrown when the specified address is not an valid address
* @param address The address to check.
* @return <code>true</code> if the specified address is without checksum ; otherwise, <code>false</code>.
* @throws InvalidAddressException is thrown when the specified address is not an valid address.
**/
public static boolean isAddressWithoutChecksum(String address) throws InvalidAddressException {
return InputValidator.checkAddress(address) && address.length() == Constants.ADDRESS_LENGTH_WITHOUT_CHECKSUM;

View File

@ -26,4 +26,14 @@ public class Constants {
* The length of an address with checksum
*/
public static int ADDRESS_LENGTH_WITH_CHECKSUM = 90;
/**
* The length of an message
*/
public static int MESSAGE_LENGTH = 2187;
/**
* The length of an tag
*/
public static int TAG_LENGTH = 27;
}

View File

@ -24,6 +24,21 @@ public class InputValidator {
address.length() == Constants.ADDRESS_LENGTH_WITH_CHECKSUM) && isTrytes(address, address.length());
}
/**
* Determines whether the specified addresses are valid.
*
* @param addresses The address list to validate.
* @return <code>true</code> if the specified addresses are valid; otherwise, <code>false</code>.
**/
public static boolean isAddressesCollectionValid(final List<String> addresses) throws InvalidAddressException {
for (final String address : addresses) {
if (!checkAddress(address)) {
return false;
}
}
return true;
}
/**
* Checks whether the specified address is an address and throws and exception if the address is invalid.
*
@ -119,6 +134,11 @@ public class InputValidator {
**/
public static boolean isTransfersCollectionValid(final List<Transfer> transfers) {
// Input validation of transfers object
if (transfers == null || transfers.isEmpty()) {
throw new IllegalArgumentException("No transfer provided");
}
for (final Transfer transfer : transfers) {
if (!isValidTransfer(transfer)) {
return false;
@ -127,6 +147,7 @@ public class InputValidator {
return true;
}
/**
* Determines whether the specified transfer is valid.
*
@ -135,21 +156,25 @@ public class InputValidator {
**/
public static boolean isValidTransfer(final Transfer transfer) {
if (transfer == null) {
return false;
}
if (!isAddress(transfer.getAddress())) {
return false;
}
// Check if message is correct trytes of any length
if (!isTrytes(transfer.getMessage(), 0)) {
// Check if message is correct trytes encoded of any length
if (transfer.getMessage() == null || !isTrytes(transfer.getMessage(), transfer.getMessage().length())) {
return false;
}
if (null == transfer.getTag() || transfer.getTag().isEmpty()) {
return true;
} else {
// Check if tag is correct trytes of {0,27} trytes
return isTrytes(transfer.getTag(), 27);
// Check if tag is correct trytes encoded and not longer than 27 trytes
if (transfer.getTag() == null || !isTrytes(transfer.getTag(), transfer.getTag().length()) || transfer.getTag().length() > Constants.TAG_LENGTH) {
return false;
}
return true;
}
/**

View File

@ -32,6 +32,11 @@ public class IotaAPIUtils {
* @throws InvalidSecurityLevelException is thrown when the specified security level is not valid.
*/
public static String newAddress(String seed, int security, int index, boolean checksum, ICurl curl) throws InvalidAddressException, InvalidSecurityLevelException {
if (security < 1) {
throw new InvalidSecurityLevelException();
}
Signing signing = new Signing(curl);
final int[] key = signing.key(Converter.trits(seed), index, security);
final int[] digests = signing.digests(key);

View File

@ -140,7 +140,7 @@ public class Multisig {
// Get the security used for the private key
// 1 security level = 2187 trytes
int security = (keyTrytes.length() / 2187);
int security = (keyTrytes.length() / Constants.MESSAGE_LENGTH);
// convert private key trytes into trits
int[] key = Converter.trits(keyTrytes);

View File

@ -11,23 +11,21 @@ import static org.junit.Assert.assertEquals;
*/
public class ChecksumTest {
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM = "EUHMAFIYBYZOXAVQQYRQ9RCNMTYX9KNEZFWXYMQIYPSRZRVDOLXDPUEARYPTWSZCAXJLXRYUUQKSHIJYZ";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM2 = "P9UDUZMN9DEXCRQEKLJYSBSBZFCHOBPJSDKMLCCVJDOVOFDWMNBZRIRRZJGINOUMPJBMYYZEGRTIDUABD";
private static final String TEST_ADDRESS_WITH_CHECKSUM = "EUHMAFIYBYZOXAVQQYRQ9RCNMTYX9KNEZFWXYMQIYPSRZRVDOLXDPUEARYPTWSZCAXJLXRYUUQKSHIJYZICCXCXUHX";
private static final String TEST_ADDRESS_WITH_CHECKSUM2 = "P9UDUZMN9DEXCRQEKLJYSBSBZFCHOBPJSDKMLCCVJDOVOFDWMNBZRIRRZJGINOUMPJBMYYZEGRTIDUABDODCNSCYJD";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
private static final String TEST_ADDRESS_WITH_CHECKSUM = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
@Test
public void shouldAddChecksum() throws InvalidAddressException {
assertEquals(Checksum.addChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM2), TEST_ADDRESS_WITH_CHECKSUM2);
assertEquals(Checksum.addChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM), TEST_ADDRESS_WITH_CHECKSUM);
}
@Test
public void shouldRemoveChecksum() throws InvalidAddressException {
assertEquals(Checksum.removeChecksum(TEST_ADDRESS_WITH_CHECKSUM2), TEST_ADDRESS_WITHOUT_CHECKSUM2);
assertEquals(Checksum.removeChecksum(TEST_ADDRESS_WITH_CHECKSUM), TEST_ADDRESS_WITHOUT_CHECKSUM);
}
@Test
public void shouldIsValidChecksum() throws InvalidAddressException {
assertEquals(Checksum.isValidChecksum(TEST_ADDRESS_WITH_CHECKSUM2), true);
assertEquals(Checksum.isValidChecksum(TEST_ADDRESS_WITH_CHECKSUM), true);
}
}

View File

@ -50,10 +50,9 @@ public class InputValidatorTest {
@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));
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, null));
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, ""));
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, "", ""));
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0));
assertEquals(InputValidator.isTransfersCollectionValid(transfers), true);
}
}

View File

@ -28,14 +28,14 @@ import static org.junit.Assert.assertThat;
*/
public class IotaAPITest {
private static final String TEST_SEED1 = "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
private static final String TEST_SEED2 = "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
private static final String TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1 = "MALAZGDVZIAQQRTNYJDSZMY9VE9LAHQKTVCUOAGZUCX9IBUMODFFTMGUIUAXGLWZQ9CYRSLYBM9QBIBYAEIAOPKXEA";
private static final String TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2 = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
private static final String TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3 = "ASCZZOBQDMNHLELQKWJBMRETMHBTF9V9TNKYDIFW9PDXPUHPVVGHMSWPVMNJHSJF99QFCMNTPCPGS9DT9XAFKJVO9X";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_1 = "MALAZGDVZIAQQRTNYJDSZMY9VE9LAHQKTVCUOAGZUCX9IBUMODFFTMGUIUAXGLWZQ9CYRSLYBM9QBIBYA";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2 = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2 = "RXTLHYQWBSJUZQXUS9LMLBE9RLAQFNDWBMZUGYJRJRHYRQQKVXBXJKEZOJDCVKFXM9GXYNMKTESEEILAYFCTLW9DQD";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_3 = "ASCZZOBQDMNHLELQKWJBMRETMHBTF9V9TNKYDIFW9PDXPUHPVVGHMSWPVMNJHSJF99QFCMNTPCPGS9DT9";
private static final String TEST_HASH = "EVCNKLXUTEKHSQKYKBSBACP9SCPTCBLLYLB9IDBMNQ9HAYANSUBZOCAAIPSGIMDAYLICTGWJAFFAA9999";
private static final String TEST_HASH = "BKBALUPMEECOGEYQU9OHXTFTHV9OKEVUGHAUNNQCNETAQWIRJIKDGWSWXY9RSIMZJBPIPEIQEFEIA9999";
private static final String TEST_INVALID_T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TTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
private static final String TEST_TRYTES = "9RYSLXACOTYQZAQIAMCULCVKMBIPMKINPFJCZFIZOOZMTCTKIXQHQTUTVGZMVHGKLRZGWOT9UGYQFNCGNRJWDETRKWUFIAFA9M9ZPZKVJWKOJENHFWMFBDVOLEVCGQTKCTOPNGRYQURVQPFJAZFUKCXAOORIYCVDKDINDXRFAFRSFVRXCTPETGIJULBYGXUHQMBGHAKGJLMNZUQE9EVOGTFVJ9EVSDNUYPGQLZBAJNWG9XXXDHETVT9XBBCQZEWJXFLVHEXHEQARCOSRKQQVEQKK9APNBRBJHHUWRGAWUIMLY9AFCULX9ITRJBYU9BNQPZBJKJDNHDAKIGDMNUOFCWAEDSBDRUTORPZQCHCSQRVIERZNGPYBPEOQXGFAKANGXPE9MA9ZZCLKDQANOKIAV9QDDUZILVMEIHXDSHDISEJMLQGVEUJWMCKCMIQTRRGJKJFSVMZWYNQJCFCPOEGOTJULGPFTM9GQGEONOXSYXYPQZHVFYHKYREHQMYWHYUTZE999HRWIQTOENSRFPB9NXDVFSUA9NLAKOELYAAH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HVTHEQUMHO999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999DNVEZXD99A99999999A99999999BULMKQXROXEBHPBYGKQINYJTHPTL9OGKUFBFAVRHPZSNXBUDMNRJFYIIGWOFVCXSVFQRZMPGCZMZUNKCDDRWDLKTKCZXZFMIZ9CZBWNOJGSXHBKEXCFQPBNFAE9QAVRX9SWGEZQRSYAYNW9TPWVWCJXAUPQHYZ9999NBDPASDXMXDCHLMZJIBHAZREUBOTZZAYGKCWTBSBKKETULAPABDTY9AMPBSXO9KJOLCWJMJSZFKU999999999999999999999999999999999999999999999999999999999999CWJQRPBIJGTWQTCMDUVOCBUAMH";
private static final String TEST_MESSAGE = "JUSTANOTHERJOTATEST";
@ -65,76 +65,89 @@ public class IotaAPITest {
, "XCCPS9GMTSUB9DXPVKLTBDHOFX9PJMBYZQYQEXMRQDPGQPLWRGZGXODYJKGVFOHHYUJRCSXAIDGYSAWRB"
, "KVEBCGMEOPDPRCQBPIEMZTTXYBURGZVNH9PLHKPMM9D9FUKWIGLKZROGNSYIFHULLWQWXCNAW9HKKVIDC"};
private IotaAPI iotaClient;
private IotaAPI iotaAPI;
@Before
public void createApiClientInstance() {
iotaClient = new IotaAPI.Builder().build();
iotaAPI = new IotaAPI.Builder().build();
}
@Test
public void shouldCreateIotaApiProxyInstanceWithDefaultValues() {
IotaAPI proxy = new IotaAPI.Builder().build();
assertThat(proxy, IsNull.notNullValue());
assertThat(proxy.getHost(), Is.is("localhost"));
assertThat(proxy.getPort(), Is.is("14265"));
assertThat(proxy.getProtocol(), Is.is("http"));
iotaAPI = new IotaAPI.Builder().build();
assertThat(iotaAPI, IsNull.notNullValue());
assertThat(iotaAPI.getHost(), Is.is("node.iotawallet.info"));
assertThat(iotaAPI.getPort(), Is.is("14265"));
assertThat(iotaAPI.getProtocol(), Is.is("http"));
}
@Test
public void shouldRetainValuesFromBuilder() {
IotaAPI proxy = new IotaAPI.Builder().host("somewhere_over_the_rainbow").build();
assertThat(proxy.getHost(), Is.is("somewhere_over_the_rainbow"));
iotaAPI = new IotaAPI.Builder().host("somewhere_over_the_rainbow").build();
assertThat(iotaAPI.getHost(), Is.is("somewhere_over_the_rainbow"));
proxy = new IotaAPI.Builder().port("15515").build();
assertThat(proxy.getPort(), Is.is("15515"));
iotaAPI = new IotaAPI.Builder().port("15515").build();
assertThat(iotaAPI.getPort(), Is.is("15515"));
proxy = new IotaAPI.Builder().protocol("https").build();
assertThat(proxy.getProtocol(), Is.is("https"));
iotaAPI = new IotaAPI.Builder().protocol("https").build();
assertThat(iotaAPI.getProtocol(), Is.is("https"));
}
@Test
public void shouldGetValuesFromProperties() {
Properties properties = new Properties();
properties.put("iota.node.host", "somewhere_over_the_rainbow");
IotaAPI proxy = new IotaAPI.Builder().config(properties).build();
assertThat(proxy.getHost(), Is.is("somewhere_over_the_rainbow"));
iotaAPI = new IotaAPI.Builder().config(properties).build();
assertThat(iotaAPI.getHost(), Is.is("somewhere_over_the_rainbow"));
properties = new Properties();
properties.put("iota.node.port", "15515");
proxy = new IotaAPI.Builder().config(properties).build();
assertThat(proxy.getPort(), Is.is("15515"));
iotaAPI = new IotaAPI.Builder().config(properties).build();
assertThat(iotaAPI.getPort(), Is.is("15515"));
properties = new Properties();
properties.put("iota.node.protocol", "https");
proxy = new IotaAPI.Builder().config(properties).build();
assertThat(proxy.getProtocol(), Is.is("https"));
iotaAPI = new IotaAPI.Builder().config(properties).build();
assertThat(iotaAPI.getProtocol(), Is.is("https"));
}
@Test
public void shouldGetInputs() throws InvalidSecurityLevelException, InvalidAddressException {
GetBalancesAndFormatResponse res = iotaClient.getInputs(TEST_SEED1, 2, 0, 0, 0);
GetBalancesAndFormatResponse res = iotaAPI.getInputs(TEST_SEED1, 2, 0, 0, 0);
System.out.println(res);
assertThat(res, IsNull.notNullValue());
assertThat(res.getTotalBalance(), IsNull.notNullValue());
assertThat(res.getInputs(), IsNull.notNullValue());
}
@Test
public void shouldCreateANewAddressWithChecksum() throws InvalidSecurityLevelException, InvalidAddressException {
final GetNewAddressResponse res1 = iotaAPI.getNewAddress(TEST_SEED1, 1, 0, true, 5, false);
assertThat(res1.getAddresses().get(0), Is.is(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1));
final GetNewAddressResponse res2 = iotaAPI.getNewAddress(TEST_SEED1, 2, 0, true, 5, false);
assertThat(res2.getAddresses().get(0), Is.is(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2));
final GetNewAddressResponse res3 = iotaAPI.getNewAddress(TEST_SEED1, 3, 0, true, 5, false);
assertThat(res3.getAddresses().get(0), Is.is(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3));
}
@Test
public void shouldCreateANewAddressWithoutChecksum() throws InvalidSecurityLevelException, InvalidAddressException {
final GetNewAddressResponse res1 = iotaClient.getNewAddress(TEST_SEED1, 1, 0, false, 5, false);
final GetNewAddressResponse res1 = iotaAPI.getNewAddress(TEST_SEED1, 1, 0, false, 5, false);
assertThat(res1.getAddresses().get(0), Is.is(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_1));
final GetNewAddressResponse res2 = iotaClient.getNewAddress(TEST_SEED1, 2, 0, false, 5, false);
final GetNewAddressResponse res2 = iotaAPI.getNewAddress(TEST_SEED1, 2, 0, false, 5, false);
assertThat(res2.getAddresses().get(0), Is.is(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2));
final GetNewAddressResponse res3 = iotaClient.getNewAddress(TEST_SEED1, 3, 0, false, 5, false);
final GetNewAddressResponse res3 = iotaAPI.getNewAddress(TEST_SEED1, 3, 0, false, 5, false);
assertThat(res3.getAddresses().get(0), Is.is(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_3));
}
@Test
public void shouldCreate100Addresses() throws InvalidSecurityLevelException, InvalidAddressException {
GetNewAddressResponse res = iotaClient.getNewAddress(TEST_SEED1, 2, 0, false, 100, false);
GetNewAddressResponse res = iotaAPI.getNewAddress(TEST_SEED1, 2, 0, false, 100, false);
assertEquals(res.getAddresses().size(), 100);
}
@ -143,15 +156,15 @@ public class IotaAPITest {
List<Input> inputlist = new ArrayList<>();
List<Transfer> transfers = new ArrayList<>();
GetBalancesAndFormatResponse rsp = iotaClient.getInputs(TEST_SEED1, 2, 0, 0, 100);
GetBalancesAndFormatResponse rsp = iotaAPI.getInputs(TEST_SEED1, 2, 0, 0, 100);
for (Input input : rsp.getInputs()) {
inputlist.add(input);
}
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG));
List<String> trytes1 = iotaClient.prepareTransfers(TEST_SEED1, 2, transfers, null, null, false);
List<String> trytes2 = iotaClient.prepareTransfers(TEST_SEED1, 2, transfers, null, inputlist, true);
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 0));
List<String> trytes1 = iotaAPI.prepareTransfers(TEST_SEED1, 2, transfers, null, null, false);
List<String> trytes2 = iotaAPI.prepareTransfers(TEST_SEED1, 2, transfers, null, inputlist, true);
Assert.assertNotNull(trytes1);
assertThat(trytes1.isEmpty(), Is.is(false));
@ -161,39 +174,39 @@ public class IotaAPITest {
@Test
public void shouldGetLastInclusionState() throws NoNodeInfoException {
GetInclusionStateResponse res = iotaClient.getLatestInclusion(new String[]{TEST_HASH});
GetInclusionStateResponse res = iotaAPI.getLatestInclusion(new String[]{TEST_HASH});
assertThat(res.getStates(), IsNull.notNullValue());
}
@Test
public void shouldFindTransactionObjects() {
List<Transaction> ftr = iotaClient.findTransactionObjects(TEST_ADDRESSES);
List<Transaction> ftr = iotaAPI.findTransactionObjects(TEST_ADDRESSES);
System.out.println(ftr);
assertThat(ftr, IsNull.notNullValue());
}
@Test
public void shouldGetAccountData() throws NoInclusionStatesException, InvalidTrytesException, NoNodeInfoException, ArgumentException, InvalidBundleException, InvalidSecurityLevelException, InvalidAddressException, InvalidSignatureException {
GetAccountDataResponse gad = iotaClient.getAccountData(TEST_SEED1, 2, 0, true, 0, true, 0, 0, true, 0);
GetAccountDataResponse gad = iotaAPI.getAccountData(TEST_SEED1, 2, 0, true, 0, true, 0, 0, true, 0);
assertThat(gad, IsNull.notNullValue());
}
@Test(expected = IllegalAccessError.class)
public void shouldNotGetBundle() throws InvalidBundleException, ArgumentException, InvalidSignatureException {
GetBundleResponse gbr = iotaClient.getBundle("SADASD");
GetBundleResponse gbr = iotaAPI.getBundle("SADASD");
assertThat(gbr, IsNull.notNullValue());
}
@Test
public void shouldGetBundle() throws InvalidBundleException, ArgumentException, InvalidSignatureException {
GetBundleResponse gbr = iotaClient.getBundle(TEST_HASH);
GetBundleResponse gbr = iotaAPI.getBundle(TEST_HASH);
System.out.println(gbr);
assertThat(gbr, IsNull.notNullValue());
}
@Test
public void shouldGetTransfers() throws InvalidBundleException, ArgumentException, InvalidSignatureException, NoInclusionStatesException, NoNodeInfoException, InvalidSecurityLevelException, InvalidAddressException {
GetTransferResponse gtr = iotaClient.getTransfers(TEST_SEED1, 2, 0, 0, false);
GetTransferResponse gtr = iotaAPI.getTransfers(TEST_SEED1, 2, 0, 0, false);
assertThat(gtr.getTransfers(), IsNull.notNullValue());
System.out.println(gtr);
@ -207,34 +220,35 @@ public class IotaAPITest {
@Ignore
@Test
public void shouldReplayBundle() throws InvalidTrytesException, InvalidBundleException, InvalidSignatureException, ArgumentException {
ReplayBundleResponse rbr = iotaClient.replayBundle(TEST_HASH, DEPTH, MIN_WEIGHT_MAGNITUDE);
ReplayBundleResponse rbr = iotaAPI.replayBundle(TEST_HASH, DEPTH, MIN_WEIGHT_MAGNITUDE);
assertThat(rbr, IsNull.notNullValue());
}
@Ignore
@Test(expected = InvalidTrytesException.class)
public void shouldNotSendTrytes() throws InvalidTrytesException {
iotaClient.sendTrytes(new String[]{TEST_INVALID_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
iotaAPI.sendTrytes(new String[]{TEST_INVALID_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
}
@Test()
public void shouldGetTrytes() throws InvalidTrytesException {
System.out.println(iotaClient.getTrytes(TEST_HASH));
System.out.println(iotaAPI.getTrytes(TEST_HASH));
}
@Ignore
@Test
public void shouldSendTrytes() throws InvalidTrytesException {
iotaClient.sendTrytes(new String[]{TEST_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
iotaAPI.sendTrytes(new String[]{TEST_TRYTES}, DEPTH, MIN_WEIGHT_MAGNITUDE);
}
@Ignore
@Test(expected = IllegalStateException.class)
public void shouldNotSendTransfer() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaClient.sendTransfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
assertThat(str.getTransactions(), IsNull.notNullValue());
assertThat(str.getSuccessfully(), IsNull.notNullValue());
}
@ -242,8 +256,9 @@ public class IotaAPITest {
@Test
public void shouldSendTransferWithoutInputs() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2, 100, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaClient.sendTransfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 1, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
assertThat(str.getTransactions(), IsNull.notNullValue());
assertThat(str.getSuccessfully(), IsNull.notNullValue());
}
@ -253,15 +268,16 @@ public class IotaAPITest {
List<Input> inputlist = new ArrayList<>();
List<Transfer> transfers = new ArrayList<>();
GetBalancesAndFormatResponse rsp = iotaClient.getInputs(TEST_SEED1, 2, 0, 0, 100);
GetBalancesAndFormatResponse rsp = iotaAPI.getInputs(TEST_SEED1, 2, 0, 0, 1);
for (Input input : rsp.getInputs()) {
inputlist.add(input);
}
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2, 100, TEST_MESSAGE, TEST_TAG));
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 1, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, inputlist, null, true);
SendTransferResponse str = iotaAPI.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, inputlist, null, true);
assertThat(str.getTransactions(), IsNull.notNullValue());
assertThat(str.getSuccessfully(), IsNull.notNullValue());
}
}

View File

@ -20,7 +20,7 @@ import static org.junit.Assert.assertThat;
public class IotaLocalPoWTest {
private static final String TEST_SEED1 = "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2 = "RXTLHYQWBSJUZQXUS9LMLBE9RLAQFNDWBMZUGYJRJRHYRQQKVXBXJKEZOJDCVKFXM9GXYNMKTESEEILAYFCTLW9DQD";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2 = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
private static final String TEST_MESSAGE = "JUSTANOTHERJOTATEST";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
private static final int MIN_WEIGHT_MAGNITUDE = 14;
@ -37,7 +37,7 @@ public class IotaLocalPoWTest {
@Test
public void shouldSendTransfer() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2, 0, TEST_MESSAGE, TEST_TAG));
transfers.add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG));
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
assertThat(str.getSuccessfully(), IsNull.notNullValue());
}

View File

@ -1,7 +1,5 @@
package jota;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jota.error.InvalidAddressException;
import jota.error.InvalidBundleException;
import jota.error.InvalidSecurityLevelException;
@ -30,8 +28,8 @@ public class IotaMultisigTest {
private static final String TEST_SEED2 = "FDSAG";
private static final String REMAINDER_ADDRESS = "NZRALDYNVGJWUVLKDWFKJVNYLWQGCWYCURJIIZRLJIKSAIVZSGEYKTZRDBGJLOA9AWYJQB9IPWRAKUC9FBDRZJZXZG";
private static final String RECEIVE_ADDRESS = "ZGHXPZYDKXPEOSQTAQOIXEEI9K9YKFKCWKYYTYAUWXK9QZAVMJXWAIZABOXHHNNBJIEBEUQRTBWGLYMTX";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
private static Gson gson = new GsonBuilder().create();
private IotaAPI iotaClient;
@Before
@ -66,9 +64,8 @@ public class IotaMultisigTest {
System.out.println("Is a valid multisig address " + isValidMultisigAddress);
assertTrue("Address is not a valid multisigAddress", isValidMultisigAddress);
Transfer transfer = new Transfer(RECEIVE_ADDRESS, 999, "", "");
List<Transfer> transfers = new ArrayList<>();
transfers.add(transfer);
transfers.add(new Transfer(RECEIVE_ADDRESS, 999, "", TEST_TAG));
List<Transaction> trxs = iotaClient.initiateTransfer(6, multiSigAddress, REMAINDER_ADDRESS, transfers, true);

View File

@ -1,7 +1,10 @@
package jota;
import jota.dto.response.SendTransferResponse;
import jota.error.*;
import jota.model.Transfer;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -9,14 +12,15 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertThat;
public class SendMessageTest {
private static final String TEST_SEED1 = "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
private static final String TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2 = "RXTLHYQWBSJUZQXUS9LMLBE9RLAQFNDWBMZUGYJRJRHYRQQKVXBXJKEZOJDCVKFXM9GXYNMKTESEEILAYFCTLW9DQD";
private static final String TEST_MESSAGE = "JUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATESTJUSTANOTHERJOTATEST";
private static final String TEST_TAG = "TESTER999999999999999999999";
private static final String TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2 = "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
private static final String TEST_MESSAGE = "JUSTANOTHERJOTATEST";
private static final String TEST_TAG = "JOTASPAM9999999999999999999";
private static final int MIN_WEIGHT_MAGNITUDE = 14;
private static final int DEPTH = 9;
@ -31,12 +35,13 @@ public class SendMessageTest {
@Test
public void shouldSendMessage() throws ArgumentException, InvalidSignatureException, InvalidBundleException, NotEnoughBalanceException, InvalidSecurityLevelException, InvalidTrytesException, InvalidAddressException, InvalidTransferException {
List<Transfer> transfers = new ArrayList<>();
transfers.add(new jota.model.Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2_2, 0, TEST_MESSAGE, TEST_TAG));
// for each 2187 trytes in a message a new transfer is necessary
List<String> trytes = iotaClient.prepareTransfers(TEST_SEED1, 2, transfers, null, null, false);
assertEquals(trytes.size(), 2);
// for each 2187 trytes in a message one transfer is necessary
transfers.add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 0, StringUtils.rightPad(TEST_MESSAGE, 2188, '9'), TEST_TAG));
iotaClient.sendTrytes(trytes.toArray(new String[trytes.size()]), DEPTH, MIN_WEIGHT_MAGNITUDE);
SendTransferResponse str = iotaClient.sendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null, false);
assertEquals(str.getTransactions().size(), 2);
assertThat(str.getTransactions(), IsNull.notNullValue());
assertThat(str.getSuccessfully(), IsNull.notNullValue());
}
}

View File

@ -27,9 +27,7 @@ public class TrytesConverterTest {
@Test
public void shouldConvertBackAndForth() {
String str = RandomStringUtils.randomAlphabetic(1000).toUpperCase();
System.err.println(str);
String back = TrytesConverter.toString(TrytesConverter.toTrytes(str));
assertTrue(str.equals(back));
}
}