Skip to content

Integration tests: utxo-filter, utxo-consolidation, create-nft #164

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

Merged
merged 35 commits into from
Apr 14, 2022

Conversation

tuliomir
Copy link
Contributor

@tuliomir tuliomir commented Mar 22, 2022

This pull request is the third phase of the implementation of Integration Tests on the Hathor Wallet Headless, and expands the scope of #149 and #152.

Acceptance Criteria

  • Run the integration tests on the following routes:
    • /wallet/utxo-filter
    • /wallet/utxo-consolidation
    • /wallet/create-nft

Other changes

  • Improves JSDocs for existing helpers
  • Improves error handling
    • Improves the helpers' error handling
    • GitHub workflow log output with better error description
  • Improves logging
    • Adds monitoring on wallet init
    • Logs for the dockerized private network added on the run artifacts
  • Centralizes the code for waiting on Websocket update on the helper methods
    • A few tests that call a URL directly to make a transaction still have the delay explicitly
    • Cleaner code
    • More stable runs on GitHub CI

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@tuliomir tuliomir added the tests label Mar 22, 2022
@tuliomir tuliomir self-assigned this Mar 22, 2022
@codecov
Copy link

codecov bot commented Mar 22, 2022

Codecov Report

Merging #164 (a9225bb) into dev (4fc71df) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##              dev     #164   +/-   ##
=======================================
  Coverage   85.78%   85.78%           
=======================================
  Files          19       19           
  Lines         647      647           
  Branches      132      132           
=======================================
  Hits          555      555           
  Misses         83       83           
  Partials        9        9           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fc71df...a9225bb. Read the comment docs.

@tuliomir tuliomir requested a review from r4mmer March 23, 2022 21:03
@tuliomir tuliomir marked this pull request as ready for review March 23, 2022 21:03
@tuliomir tuliomir marked this pull request as draft March 25, 2022 23:18
@tuliomir tuliomir force-pushed the test/integration-3 branch from 5d9ed6b to c6dd570 Compare March 30, 2022 22:33
@tuliomir tuliomir marked this pull request as ready for review March 30, 2022 22:53

- name: Collect docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v1
Copy link
Member

Choose a reason for hiding this comment

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

I like this action to make an artifact with the logs on failure but isn't there any official action for this? Could we fork it as to not depend on this external action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a quick search I found no official action for this purpose.

The fact that this one is announced on the GitHub Action Marketplace gives me some confidence that this code will be running safely in the future, but I agree that a fork would be a safe solution as well.

Maybe we could open an issue dedicated to make this?

@@ -14,5 +14,5 @@ module.exports = {
wsUpdateDelay: process.env.TEST_WS_UPDATE_DELAY || 1000,

// Defines for how long the startMultipleWalletsForTest can run
walletStartTimeout: process.env.TEST_WALLET_START_TIMEOUT || 60000,
walletStartTimeout: process.env.TEST_WALLET_START_TIMEOUT || 180000,
Copy link
Member

Choose a reason for hiding this comment

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

I know this is the default, but I think we should add this variable on the github config when running the CI.
This way we can change the value when we want (or for a batch of tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The environment variable was added to GitHub on f8d62f2.

expect(nftErr).toBeInstanceOf(Error);
expect(nftErr.response.text).toContain(field);
}
done();
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just not use the done when we don't need it.

it('should etc', async () => {
    // test body
});

ref

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests on the 3 suites within the scope of this PR were rewritten without the done() call

expect(nftTx.hash).toBeDefined();

// Validating authority tokens
const authorityOutputs = nftTx.outputs.filter(o => o.token_data === TOKEN_DATA.AUTHORITY_TOKEN);
Copy link
Member

Choose a reason for hiding this comment

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

I saw that TOKEN_DATA.AUTHORITY_TOKEN is 129, which works because we only have 1 custom token on this tx but I don't think we should do it like this.
Instead, use the authority mask (128) and filter with the & operator this will make sure this works even if we include multiple tokens on a transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point! This would give a headache for a future test developer.
Fixed this on a1431c7

export const TOKEN_DATA = {
HTR: 0,
TOKEN: 1,
AUTHORITY_TOKEN: 129
Copy link
Member

Choose a reason for hiding this comment

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

We should use authority mask instead of assuming we only have 1 token on the tx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied the wallet-lib constants mask on 7ada0f6

TestUtils.logError(errMsg);
startBenchmark.failureAt = timestamp;
startBenchmark.failureDiff = failureDiff;
TestUtils.logTx(`Wallet init failure`, startBenchmark);
Copy link
Member

Choose a reason for hiding this comment

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

Should we change logTx to just log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 765442b

Comment on lines 2 to 4
const mainTestMatch = process.env.SPECIFIC_INTEGRATION_TEST_FILE
? `<rootDir>/__tests__/integration/**/${process.env.SPECIFIC_INTEGRATION_TEST_FILE}.test.js`
: '<rootDir>/__tests__/integration/**/*.test.js'
Copy link
Member

Choose a reason for hiding this comment

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

Sugestion: take this from command line arguments so we can run specific tests with npm run test_network_integration -- start for instance

Suggested change
const mainTestMatch = process.env.SPECIFIC_INTEGRATION_TEST_FILE
? `<rootDir>/__tests__/integration/**/${process.env.SPECIFIC_INTEGRATION_TEST_FILE}.test.js`
: '<rootDir>/__tests__/integration/**/*.test.js'
const args = process.argv.slice(6);
const testMatch = args.length == 0 ? ['<rootDir>/__tests__/integration/**/*.test.js'] : args.map(arg => `<rootDir>/__tests__/integration/**/${arg}.test.js`);

Obs: the slice(6) is because we have "node", the filename and 4 other arguments we pass to jest on package.json

Edit: actually, we can already fillter tests with the command line wihtout this.
Running npm run test test_network_integration -- address will match all tests on __tests__/integration/ but will filter with the pattern /address/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can confirm it already has this behavior. You can even inform an environment variable and the command line - the later filters the first.

Screenshot from 2022-03-31 15-15-51

I prefer keeping it that way, so that I can use not only the test_network_integration script but also the test_integration that derives from it.

@r4mmer
Copy link
Member

r4mmer commented Mar 31, 2022

During my review I found it somewhat confusing when using helper methods to test the endpoints.
I think we should refactor these tests to make the call to the endpoint being tested directly from the test and use the helpers only to build the test scenario (and cleanup if necessary)

@tuliomir
Copy link
Contributor Author

I think we should refactor these tests to make the call to the endpoint being tested directly from the test and use the helpers only to build the test scenario (and cleanup if necessary)

A refactor was made to implement this on the three test suites that are in the scope of this PR.

The test code is more straightforward now and doubles as documentation, as expected from tests. The only issue being that we have to remember to manually put pauses for websocket update where needed.

@tuliomir tuliomir mentioned this pull request Apr 11, 2022
3 tasks
@pedroferreira1 pedroferreira1 self-requested a review April 14, 2022 22:38
@tuliomir tuliomir merged commit 7a29078 into dev Apr 14, 2022
@tuliomir tuliomir deleted the test/integration-3 branch April 14, 2022 22:53
This was referenced Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants