-
Notifications
You must be signed in to change notification settings - Fork 133
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
Cannot test with expectRevert #134
Comments
Hi @herman-rogers. This is a weird issue, and your snippets look good to me, but I don't know what are exactly your |
Hi @herman-rogers , Unfortunately I wasn't able to reproduce the issue that you were experiencing. I used the following contract and test on Windows Subsystem for Linux (WSL2)
MyContract.sol// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract MyContract {
address private _creator;
event DoneStuff();
uint256 public value;
constructor() public {
_creator = msg.sender;
value = 42;
}
function doStuff() public {
require(_creator == msg.sender, "MyContract: not creator");
emit DoneStuff();
}
} MyContract.test.js// test/MyContract.test.js
// Load dependencies
const { expect } = require('chai');
// Import utilities from Test Helpers
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
// Load compiled artifacts
const MyContract = artifacts.require('MyContract');
// Start test block
contract('MyContract', function ([ creator, other ]) {
beforeEach(async function () {
this.myContract = await MyContract.new({ from: creator });
});
it('it reverts when attempting to do stuff from other account', async function () {
// Test a transaction reverts
await expectRevert(
this.myContract.doStuff({ from: other }),
'MyContract: not creator'
);
});
it('it emits event when doing stuff from creator', async function () {
const receipt = await this.myContract.doStuff({ from: creator });
expectEvent(receipt, 'DoneStuff');
});
it('retrieve value', async function () {
// Use large integers ('big numbers')
const value = new BN('42');
// Use large integer comparisons
expect(await this.myContract.value()).to.be.bignumber.equal(value);
});
}); Test
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I have some contract testing code that basically has:
Which works fine. However, when I add tests below that:
All tests below the expectRevert fail. If I re-order the test such as:
Both tests pass fine. So it appears the order matters. If I order it "incorrectly" I get
Error: Error: read ECONNRESET
which seems irrelevant to my contracts and something to do with the underlying code.The text was updated successfully, but these errors were encountered: