Skip to content

Conversation

@szerintedmi
Copy link
Member

@szerintedmi szerintedmi commented May 2, 2019

  • run ganache container with --blockTime 1 (which is closer how real chains work) and adjust tests to behaviour
  • throw TransactionSendError if .send fails. .getTxHash, getTxReceipt and getConfirmedReceipt are also rejected with that error

@szerintedmi szerintedmi requested review from phraktle and rszaloki May 2, 2019 21:55
.onConfirmation(onConfirmationSpy)
.onceConfirmedReceipt(3, onceConfirmedReceiptSpy)
.onceTxRevert(onceTxRevertSpy);
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a fail within the try block to ensure an exception was thrown. Same pattern should apply to the subsequent checks (instead of isUndefined).

Copy link
Member Author

Choose a reason for hiding this comment

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

What you mean by fail within the block? .send should throw, that's what testing here. As for txHash isUndefined I'm not sure what you mean. Am I miss something? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern to properly check exceptions:

try {
  doStuff();
  assert.fail();   // we shouldn’t reach this line
} catch (e) {
  // validate the error
}

Copy link
Contributor

@phraktle phraktle May 3, 2019

Choose a reason for hiding this comment

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

Btw, you could also use fail for callbacks that shouldn’t be called. Maybe shorter/clearer than spy...

assert.equal(onceConfirmedReceiptSpy.callCount, 0);
});

/** This doesn't work with ganache --blockTime 1 : can't get error in any ways with web3 beta36 */
Copy link
Contributor

Choose a reason for hiding this comment

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

But works on rinkeby?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't try this particular yet, good point.

assert.deepEqual(error, errorCaught);
});

assert.isUndefined(txHash);
Copy link
Contributor

Choose a reason for hiding this comment

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

What I meant instead of isUndefined:

try {
  await tx.getTxHash();
  assert.fail();
} catch (error) {
  assert.deepEqual(error, errorCaught);
}	

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I suppose other styles are possible (see https://www.chaijs.com/plugins/chai-as-promised/)

Copy link
Member Author

Choose a reason for hiding this comment

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

I used chai-as-promised even in this test. I can't recall why not in this particular case, maybe it was less convenient.

@szerintedmi szerintedmi requested a review from phraktle May 6, 2019 12:24
@szerintedmi szerintedmi merged commit f198b14 into staging May 6, 2019
@phraktle phraktle deleted the ganache_blocktimeout branch May 6, 2019 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants