Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Issue-174: Mock iota client in integration tests #235

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e69c2ed
ISSUE-229: Remove check consistency code, test and related docs
ezienecker Oct 2, 2020
42f590b
ISSUE-174: Start migrate integration test to use mock instead of real…
ezienecker Oct 3, 2020
6f94c40
ISSUE-174: Refactor transaction class and fix some minor code smells
ezienecker Oct 9, 2020
f7146d3
ISSUE-174: Mock iota client for IotaLocalPoWTest
ezienecker Oct 9, 2020
3131cff
ISSUE-174: Mock iota client for IotaLocalPoWTest
ezienecker Oct 11, 2020
dce52b5
ISSUE-174: Fix some minor smells
ezienecker Oct 11, 2020
592985a
ISSUE-174: Mock iota client for IotaCoreApiTest
ezienecker Oct 11, 2020
f12cc97
ISSUE-229: Implement review remarks
ezienecker Oct 11, 2020
a047fa4
Merge pull request #234 from ezienecker/feature/ISSUE-229-removal-of-…
Oct 11, 2020
0210476
ISSUE-174: Add documentation to transaction builder methods
ezienecker Oct 16, 2020
33d8c4c
ISSUE-174: Add messages for assertions in test
ezienecker Oct 16, 2020
d4594ee
ISSUE-174: Add more method documentation
ezienecker Oct 16, 2020
1743aa4
ISSUE-174: Codacy happiness
ezienecker Oct 16, 2020
4db4236
ISSUE-174: Document assertions in IotaCoreApiTest
ezienecker Oct 16, 2020
60db27e
ISSUE-174: Start migrate integration test to use mock instead of real…
ezienecker Oct 3, 2020
de25d79
ISSUE-174: Refactor transaction class and fix some minor code smells
ezienecker Oct 9, 2020
a140e63
ISSUE-174: Mock iota client for IotaLocalPoWTest
ezienecker Oct 9, 2020
bf48a59
ISSUE-174: Mock iota client for IotaLocalPoWTest
ezienecker Oct 11, 2020
f77e029
ISSUE-174: Fix some minor smells
ezienecker Oct 11, 2020
94137d0
ISSUE-174: Mock iota client for IotaCoreApiTest
ezienecker Oct 11, 2020
17eebcb
ISSUE-174: Add documentation to transaction builder methods
ezienecker Oct 16, 2020
902d027
ISSUE-174: Add messages for assertions in test
ezienecker Oct 16, 2020
bac1bd6
ISSUE-174: Add more method documentation
ezienecker Oct 16, 2020
4ad4e20
ISSUE-174: Codacy happiness
ezienecker Oct 16, 2020
a783b16
ISSUE-174: Document assertions in IotaCoreApiTest
ezienecker Oct 16, 2020
ae04ef1
Resolve conflicts
ezienecker Oct 19, 2020
a8738a3
Merge branch 'feature/ISSUE-174-mock-integration-tests' of github.com…
ezienecker Oct 19, 2020
27d6ba0
Removed checkconsistency
Oct 19, 2020
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
503 changes: 265 additions & 238 deletions jota/src/main/java/org/iota/jota/IotaAPI.java

Large diffs are not rendered by default.

91 changes: 62 additions & 29 deletions jota/src/main/java/org/iota/jota/IotaAPICore.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,69 @@
package org.iota.jota;

import static org.iota.jota.utils.Constants.INVALID_ADDRESSES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_APPROVE_DEPTH_ERROR;
import static org.iota.jota.utils.Constants.INVALID_ATTACHED_TRYTES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_BUNDLE_HASH_ERROR;
import static org.iota.jota.utils.Constants.INVALID_HASHES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_TAG_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_THRESHOLD_ERROR;
import static org.iota.jota.utils.Constants.INVALID_TRYTES_INPUT_ERROR;

import org.apache.commons.lang3.ArrayUtils;
import org.iota.jota.connection.Connection;
import org.iota.jota.dto.request.*;
import org.iota.jota.dto.response.*;
import org.iota.jota.dto.request.IotaAttachToTangleRequest;
import org.iota.jota.dto.request.IotaBroadcastTransactionRequest;
import org.iota.jota.dto.request.IotaCheckConsistencyRequest;
import org.iota.jota.dto.request.IotaCommandRequest;
import org.iota.jota.dto.request.IotaCustomRequest;
import org.iota.jota.dto.request.IotaFindTransactionsRequest;
import org.iota.jota.dto.request.IotaGetBalancesRequest;
import org.iota.jota.dto.request.IotaGetInclusionStateRequest;
import org.iota.jota.dto.request.IotaGetTransactionsToApproveRequest;
import org.iota.jota.dto.request.IotaGetTrytesRequest;
import org.iota.jota.dto.request.IotaNeighborsRequest;
import org.iota.jota.dto.request.IotaStoreTransactionsRequest;
import org.iota.jota.dto.request.IotaWereAddressesSpentFromRequest;
import org.iota.jota.dto.response.AddNeighborsResponse;
import org.iota.jota.dto.response.BroadcastTransactionsResponse;
import org.iota.jota.dto.response.CheckConsistencyResponse;
import org.iota.jota.dto.response.FindTransactionResponse;
import org.iota.jota.dto.response.GetAttachToTangleResponse;
import org.iota.jota.dto.response.GetBalancesResponse;
import org.iota.jota.dto.response.GetInclusionStateResponse;
import org.iota.jota.dto.response.GetNeighborsResponse;
import org.iota.jota.dto.response.GetNodeAPIConfigurationResponse;
import org.iota.jota.dto.response.GetNodeInfoResponse;
import org.iota.jota.dto.response.GetTipsResponse;
import org.iota.jota.dto.response.GetTransactionsToApproveResponse;
import org.iota.jota.dto.response.GetTrytesResponse;
import org.iota.jota.dto.response.InterruptAttachingToTangleResponse;
import org.iota.jota.dto.response.IotaCustomResponse;
import org.iota.jota.dto.response.RemoveNeighborsResponse;
import org.iota.jota.dto.response.StoreTransactionsResponse;
import org.iota.jota.dto.response.WereAddressesSpentFromResponse;
import org.iota.jota.error.ArgumentException;
import org.iota.jota.model.Transaction;
import org.iota.jota.pow.ICurl;
import org.iota.jota.pow.SpongeFactory;
import org.iota.jota.utils.Checksum;
import org.iota.jota.utils.InputValidator;
import org.iota.mddoclet.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;

import static org.iota.jota.utils.Constants.INVALID_ADDRESSES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_APPROVE_DEPTH_ERROR;
import static org.iota.jota.utils.Constants.INVALID_ATTACHED_TRYTES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_BUNDLE_HASH_ERROR;
import static org.iota.jota.utils.Constants.INVALID_HASHES_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_TAG_INPUT_ERROR;
import static org.iota.jota.utils.Constants.INVALID_THRESHOLD_ERROR;
import static org.iota.jota.utils.Constants.INVALID_TRYTES_INPUT_ERROR;

/**
* This class provides access to the Iota core API
* Handles direct methods with the connected node(s), and does basic verification
*/
public class IotaAPICore {
private static final Logger log = LoggerFactory.getLogger(IotaAPICore.class);
private static final Logger LOGGER = LoggerFactory.getLogger(IotaAPICore.class);

private ApiOptions options;

Expand Down Expand Up @@ -70,21 +103,21 @@ public boolean addNode(Connection n) {
synchronized (nodes) {
for (Connection c : nodes) {
if (c.equals(n)) {
log.warn("Tried to add a node we allready have: " + n);
LOGGER.warn("Tried to add a node we allready have: " + n);
return true;
}
}

boolean started = n.start();
if (started) {
nodes.add(n);
log.debug("Added node: " + n.toString());
LOGGER.debug("Added node: " + n.toString());
}

return started;
}
} catch (Exception e) {
log.warn("Failed to add node connection to pool due to \"" + e.getMessage() + "\"");
LOGGER.warn("Failed to add node connection to pool due to \"" + e.getMessage() + "\"");
return false;
}
}
Expand Down Expand Up @@ -386,7 +419,7 @@ public GetInclusionStateResponse getInclusionStates(String... transactions) thro
/**
* Returns the raw transaction data (trytes) of a specific transaction.
* These trytes can then be easily converted into the actual transaction object.
* You can use {@link Transaction#Transaction(String)} for conversion to an object.
* You can use {@link Transaction.Builder#buildWithTrytes(String)} for conversion to an object.
*
* @param hashes The transaction hashes you want to get trytes from.
* @return {@link GetTrytesResponse}
Expand Down Expand Up @@ -733,7 +766,7 @@ public GetAttachToTangleResponse attachToTangle(String trunkTransaction, String
public GetAttachToTangleResponse attachToTangleLocalPow(String trunkTransaction, String branchTransaction,
Integer minWeightMagnitude, IotaPoW pow, String... trytes) {
if (pow == null) {
log.warn("Called local POW without POW defined, switching to remote POW");
LOGGER.warn("Called local POW without POW defined, switching to remote POW");
return attachToTangle(trunkTransaction, branchTransaction, minWeightMagnitude, trytes);
}

Expand All @@ -754,20 +787,20 @@ public GetAttachToTangleResponse attachToTangleLocalPow(String trunkTransaction,

try {
for (int i = 0; i < resultTrytes.length; i++) {
Transaction txn = new Transaction(trytes[i]);
txn.setTrunkTransaction(previousTransaction == null ? trunkTransaction : previousTransaction);
txn.setBranchTransaction(previousTransaction == null ? branchTransaction : trunkTransaction);
Transaction transaction = new Transaction.Builder().buildWithTrytes(trytes[i]);
transaction.setTrunkTransaction(previousTransaction == null ? trunkTransaction : previousTransaction);
transaction.setBranchTransaction(previousTransaction == null ? branchTransaction : trunkTransaction);

if (txn.getTag().isEmpty() || txn.getTag().matches("9*")) {
txn.setTag(txn.getObsoleteTag());
if (transaction.getTag().isEmpty() || transaction.getTag().matches("9*")) {
transaction.setTag(transaction.getObsoleteTag());
}

txn.setAttachmentTimestamp(System.currentTimeMillis());
txn.setAttachmentTimestampLowerBound(0);
txn.setAttachmentTimestampUpperBound(3_812_798_742_493L);
transaction.setAttachmentTimestamp(System.currentTimeMillis());
transaction.setAttachmentTimestampLowerBound(0);
transaction.setAttachmentTimestampUpperBound(3_812_798_742_493L);

resultTrytes[i] = pow.performPoW(txn.toTrytes(), minWeightMagnitude);
previousTransaction = new Transaction(resultTrytes[i], SpongeFactory.create(SpongeFactory.Mode.CURL_P81)).getHash();
resultTrytes[i] = pow.performPoW(transaction.toTrytes(), minWeightMagnitude);
previousTransaction = new Transaction.Builder().buildWithTrytes(resultTrytes[i]).getHash();
}
Collections.reverse(Arrays.asList(resultTrytes));
} catch (Exception e) {
Expand Down
Loading