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

Conversation

ezienecker
Copy link
Contributor

Description of change

Mock iota client in integration test

Type of change

Choose a type of change, and delete any options that are not relevant.

  • Enhancement (a non-breaking change which adds functionality)

How the change has been tested

Running the tests.

Make sure to provide instructions for the maintainer as well as any relevant configurations.

Change checklist

Add an x to the boxes that are relevant to your changes, and delete any items that are not.

  • My code follows the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation -> not needed
  • I have added tests using ginkgo that prove my fix is effective or that my feature works -> not needed
  • New and existing unit tests pass locally with my changes

@kwek20
Copy link
Contributor

kwek20 commented Oct 11, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
+ Solved 6
- Added 56
           

Complexity increasing per file
==============================
- jota/src/test/java/org/iota/jota/IotaMultiSigTest.java  1
         

Clones added
============
- jota/src/test/java/org/iota/jota/IotaAPITest.java  2
- jota/src/test/java/org/iota/jota/IotaMultiSigTest.java  2
         

See the complete overview on Codacy

@@ -68,7 +66,7 @@ public void shouldIsArrayOfHashes() {

@Test
public void shouldIsArrayOfTrytes() {
assertEquals(InputValidator.isArrayOfTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}), true);
assertTrue(InputValidator.isArrayOfTrytes(new String[]{TEST_TRYTES, TEST_TRYTES}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


List<Transaction> transactionObjectsByAddresses = iotaAPIMock.findTransactionObjectsByAddresses(TEST_ADDRESSES);

assertNotNull(transactionObjectsByAddresses);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindTransactionResponse transactionsByApproves =
iotaAPIMock.findTransactionsByApprovees(TEST_ADDRESS_WITHOUT_CHECKSUM);

assertNotNull(transactionsByApproves.getHashes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


GetNodeInfoResponse nodeInfo = iotaAPIMock.getNodeInfo();

assertNotNull(nodeInfo.getAppVersion());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when(iotaAPIMock.findTransactions(addresses, tags, approves, bundles)).thenReturn(new FindTransactionResponse());

FindTransactionResponse transactionResponse = iotaAPIMock.findTransactions(addresses, tags, approves, approves);
assertNotNull(transactionResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when(iotaAPIMock.getAddressesUnchecked(addressRequest)).thenReturn(newAddressResponse);

GetNewAddressResponse addressResponse = iotaAPIMock.getAddressesUnchecked(addressRequest);
assertEquals(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, addressResponse.getAddresses().get(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (int i = 0; i < TEST_TRYTES_VALUE_TRANSFER.length; i++) {
assertEquals(new Transaction(localResponse.getTrytes()[i]).getValue(),
new Transaction(remoteResponse.getTrytes()[i]).getValue());
assertEquals(new Transaction.Builder().buildWithTrytes(localResponse.getTrytes()[i]).getValue(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindTransactionResponse transactionsByAddresses =
iotaAPIMock.findTransactionsByAddresses(TEST_ADDRESS_WITHOUT_CHECKSUM);

assertNotNull(transactionsByAddresses.getHashes());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when(iotaAPIMock.getAddressesUnchecked(addressRequest)).thenReturn(newAddressResponse);

GetNewAddressResponse res1 = iotaAPIMock.getAddressesUnchecked(addressRequest);
assertEquals(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3, res1.getAddresses().get(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final GetNewAddressResponse res3 = iotaAPI.getAddressesUnchecked(thirdAddressRequest);
assertEquals(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3, res3.getAddresses().get(0));
GetNewAddressResponse addressResponse = iotaAPIMock.getAddressesUnchecked(addressRequest);
assertEquals(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1, addressResponse.getAddresses().get(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} if (!transfer.getMessage().equals("")) {

}
if (!transfer.getMessage().equals("")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy found an issue: Avoid empty if statements

when(balancesResponseMock.getDuration()).thenReturn(0L);

assertThat(balancesResponse.getReferences(), IsNull.notNullValue());
assertThat(balancesResponse.getBalances(), IsNull.notNullValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(balancesResponse.getReferences(), IsNull.notNullValue());
assertThat(balancesResponse.getBalances(), IsNull.notNullValue());
assertThat(balancesResponse.getMilestoneIndex(), IsNull.notNullValue());
assertThat(balancesResponse.getDuration(), IsNull.notNullValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat("Error on getInputs should have thrown", res.getInputs(), IsNull.notNullValue());
GetBalancesAndFormatResponse inputs = iotaAPIMock.getInputs(TEST_SEED1, 2, 0, 10, 0);

assertNotNull(inputs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetNodeInfoResponse nodeInfo = iotaAPIMock.getNodeInfo();

assertNotNull(nodeInfo.getAppVersion());
assertNotNull(nodeInfo.getAppName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


GetAccountDataResponse accountData = iotaAPIMock.getAccountData(TEST_SEED3, 2, 0, true, 0, true, 0, 10, true, 0);

assertNotNull(accountData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertNotNull(nodeInfo.getAppName());
assertNotNull(nodeInfo.getJreVersion());
assertNotNull(nodeInfo.getLatestMilestone());
assertNotNull(nodeInfo.getLatestSolidSubtangleMilestone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when(balancesResponseMock.getBalances()).thenReturn(new String[]{});
when(balancesResponseMock.getDuration()).thenReturn(0L);

assertThat(balancesResponse.getReferences(), IsNull.notNullValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezienecker
Copy link
Contributor Author

I am not sure if the checks regarding the assertions are useful. On the one hand this contradicts the Clean Code concept by saying that the methods should be named in a way that they make a statement about what the method does (What is tested?). On the other hand I doubt the quality of the messages.

@kwek20
Copy link
Contributor

kwek20 commented Oct 16, 2020

Yea thanks for the Codacy fixes you did, I'm honestly just surprised it decided to work suddenly :)
Ill test and review in the weekend as I'm currently a bit busy with Streams, but this is a great help! Especially when we move forward with chrysalis 2.0. Could you solve the conflicts though? If not, ill do it later :)

@ezienecker
Copy link
Contributor Author

@kwek20 now it should be fine

@kwek20
Copy link
Contributor

kwek20 commented Oct 19, 2020

@ezienecker Thanks for the ping 🙏 On it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants