trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

ExpectRevert not working when using HDWalletProvider #5131

Open cipaterson opened 2 years ago

cipaterson commented 2 years ago

Issue

When using HDWalletProvider in the truffle-config.js file, the tests are not working as expected. When a call reverts, the promise doesn't fail as expected but is resolved with the reverted transaction As soon as the development network is not user HDWalletProvider the tests will be successful

Steps to Reproduce

git clone https://github.com/cipaterson/HDWalletProviderIssue cd HDWalletProviderIssue npm install ganache -m "ahead nasty leopard trick demise trap ten spoil festival comic unlock shallow" truffle test # Will fail truffle test --network dev # will succeed

Expected Behavior

~/HDWalletProviderIssue master !1 ?1 > truffle test --network dev 7s 18:38:07 Using network 'dev'.

Compiling your contracts...

Compiling ./contracts/Test.sol Compiling @openzeppelin/contracts/access/Ownable.sol Compiling @openzeppelin/contracts/utils/Context.sol Artifacts written to /var/folders/b2/_77sbqqj34d1h8f91dz9229h0000gn/T/test--80927-jlutVldRrnS6 Compiled successfully using:

  • solc: 0.8.13+commit.abaa5c0e.Emscripten.clang

Contract: Stacking Test Suite Owner: Test to attach tokens owner 0x64729B74061b020Adfd7Bbc5148C4f3CD516044E user1 0x842d479e85a854A74a736Ba6E2cC888b9C68b887 catch ✔ should reject for not owner caller

1 passing (69ms)

Actual Results

~/HDWalletProviderIssue master !1 ?1 > truffle test 57s 18:37:52 Using network 'development'.

Compiling your contracts...

Compiling ./contracts/Test.sol Compiling @openzeppelin/contracts/access/Ownable.sol Compiling @openzeppelin/contracts/utils/Context.sol Artifacts written to /var/folders/b2/_77sbqqj34d1h8f91dz9229h0000gn/T/test--80629-XGUzFlNdOGPY Compiled successfully using:

  • solc: 0.8.13+commit.abaa5c0e.Emscripten.clang

Contract: Stacking Test Suite Owner: Test to attach tokens owner 0x64729B74061b020Adfd7Bbc5148C4f3CD516044E user1 0x842d479e85a854A74a736Ba6E2cC888b9C68b887 resolve 1) should reject for not owner caller

No events were emitted

0 passing (99ms) 1 failing

1) Contract: Stacking Test Suite Owner: Test to attach tokens should reject for not owner caller: AssertionError: Expected an exception but none was received at expectException (node_modules/@openzeppelin/test-helpers/src/expectRevert.js:25:10) at runNextTicks (node:internal/process/task_queues:61:5) at listOnTimeout (node:internal/timers:528:9) at processTimers (node:internal/timers:502:7) at expectRevert (node_modules/@openzeppelin/test-helpers/src/expectRevert.js:75:3) at Context. (test/test.js:27:13)

Environment

eggplantzzz commented 2 years ago

Thanks @cipaterson for opening this! On investigation it seems like this might have something to do with the difference in how web3 handles when gas estimation fails versus how hdwallet-provider does? web3 might allow it to fail and try to run the tx anyways - some relevant code can be found here in contract. There will need to be some more investigation.