Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

contract-tests: fix detectNetwork test and its implementation #4744

Merged
merged 2 commits into from
Feb 17, 2022

Conversation

cds-amal
Copy link
Member

@cds-amal cds-amal commented Feb 16, 2022

This PR is necessary to fix an error hidden behind a bad test. assert.rejects is a promise that should be awaited. Upon fixing this test, it exposed an error in detectNetwork() that didn't guard use of this.interfaceAdapter.

  • await assert.reject tests as per documentation. Note: I updated all of them in the current file. Will make another PR to address this issue in other packages.
  • remove 3rd positional parameter, message, to so expected and got comparison is shown on failures
  • guard this.interfactAdapter in implementation

@cds-amal cds-amal changed the title contract-tests: fix detetNetwork test contract-tests: fix detetNetwork test and its implementation Feb 16, 2022
- guard this.interfactAdapter in  implementation
- await  in tests as per documentation
- remove 3rd positional parameter, message, to  so expected and got comparison is shown on failures
@cds-amal cds-amal changed the title contract-tests: fix detetNetwork test and its implementation contract-tests: fix detectNetwork test and its implementation Feb 16, 2022
Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Seems basically good, but I'm a bit confused about the reasoning for removing the messages... how would you get error messages if the tests pass on an error? Since the failure case is when there's no error, there won't be any pre-existing error message to pass on, right?

Also one really minor style nitpick. :P

@@ -119,6 +119,10 @@ module.exports = Contract => ({
},

async detectNetwork() {
// guard interfaceAdapter!
if (!Boolean(this.interfaceAdapter)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just a longer way of saying if (!this.interfaceAdapter) that, IMO, doesn't really add any clarity to it. I would suggest either the shorter way or the more explicit if (this.interfaceAdapter == null).

Copy link
Member Author

@cds-amal cds-amal Feb 17, 2022

Choose a reason for hiding this comment

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

Interesting, in this case I thought the !Boolean(...) is clearer than the two alternatives. I'll change it to == null here.

@cds-amal
Copy link
Member Author

cds-amal commented Feb 17, 2022

.. how would you get error messages if the tests pass on an error? Since the failure case is when there's no error, there won't be any pre-existing error message to pass on, right?

Correct, no pre-existing error message to pass on, however there's still an indication that an expected failure didn't happen, like below where I simulated a failure in a test. I think this is acceptable, but will defer to you whether it's acceptable.

  1. TruffleContract.deployed()
    throws if called before setting a provider:
    AssertionError [ERR_ASSERTION]: Missing expected rejection (Error).
    at async Context. (test/contract/constructorMethods.js:72:5)

Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Oh, I see, so the message is redundant because it wasn't saying anything not in the default message. Cool. Approved.

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.

2 participants