openzeppelin-test-helpers icon indicating copy to clipboard operation
openzeppelin-test-helpers copied to clipboard

Cannot test with expectRevert

Open herman-rogers opened this issue 3 years ago • 3 comments

So I have some contract testing code that basically has:

        it('does something', async () => {
            await expectRevert(
                contract.doSomething(
                    mockToken.address,
                    100,
                    { from: holder }),
                'Expected Error'
            );
        });

Which works fine. However, when I add tests below that:

        it('does something', async () => {
            await expectRevert(
                contract.doSomething(
                    mockToken.address,
                    100,
                    { from: holder }),
                'Expected Error'
            );
        });

        it('can get name', async () => {
            const name = await contract.name(owner);
            expect(name).toEqual('Mock Name');
        });

All tests below the expectRevert fail. If I re-order the test such as:

        it('can get name', async () => {
            const name = await contract.name(owner);
            expect(name).toEqual('Mock Name');
        });

        it('does something', async () => {
            await expectRevert(
                contract.doSomething(
                    mockToken.address,
                    100,
                    { from: holder }),
                'Expected Error'
            );
        });

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.

herman-rogers avatar Oct 17 '20 16:10 herman-rogers