rkalis / truffle-assertions

πŸ›  Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
https://kalis.me/check-events-solidity-smart-contract-test-truffle/
MIT License
154 stars 20 forks source link

Different behavior when running testing against Rinkeby #21

Closed feamcor closed 5 years ago

feamcor commented 5 years ago

Describe the Bug When running truffle v5 javascript tests against Rinkeby it doesn't catch the revert. When running the tests against Ganache, behavior is as expected.

Error Message

  1) Contract: Bileto
       should not open store for non-owner:
     AssertionError: Expected to fail with by owner, but failed with: StatusError: Transaction: 0x5b4dc57076030dc52c18e15410bccaa1962db7f636204b8222469e888651320d exited with an error (status 0).
     Please check that the transaction:
     - satisfies all conditions set by Solidity `require` statements.
     - does not trigger a Solidity `revert` statement.
      at fails (node_modules/truffle-assertions/index.js:138:13)
      at process.internalTickCallback (internal/process/next_tick.js:77:7)

Test Code

  it("should not open store for non-owner", async () => {
    await truffleAssert.reverts(
      __contract.openStore({
        from: __organizer1
      }),
      "by owner");
  });

Expected Behavior It should recognize that method reverted and consider the test successful.

Environment Information

truffle-config.js

    rinkeby: {
      provider: () => new HDWallet(
        metamaskSeedPhrase,
        `https://rinkeby.infura.io/v3/${infuraProjectId}`,
        rinkebyAddressIndex,
        rinkebyNumAddresses),
      network_id: 4,
      skipDryRun: true
    },
rkalis commented 5 years ago

Hi @feamcor

Thanks for opening this issue. You're the first person I've spoken with that runs their tests on Rinkeby as well, so good job on being thorough. You can never test enough, especially with smart contracts.

I haven't looked into testing with Rinkeby, so I'll have to see how I can make it work with Rinkeby. I definitely think this should be fully supported by truffle-assertions, so I will see if I can make it work some time soon.

Just one idea I have from the top of my head looking at the error message. It could be that Infura Rinkeby doesn't return the "revert reason", since this is a very new feature. Could you try removing the reason string from your assertion, and check whether that one does pass?

Like this:

  it("should not open store for non-owner", async () => {
    await truffleAssert.reverts(
      __contract.openStore({
        from: __organizer1
      }));
  });

It's not ideal, but if the revert reason string is not supported by the Ethereum node itself then this is the only way to make it work for now.

feamcor commented 5 years ago

Hi @rkalis, thank you so much for the workaroud... it worked! I had 18 test cases failing due to that. See below the current test log after applying the changes you suggested (please ignore the failing test case, it is on purpose). Cheers.

$ truffle test --network rinkeby
Using network 'rinkeby'.

  Contract: Bileto
store address: 0xA8cd043eAD1ac774cE48Aa9b0320b8FA7c026b8d
    βœ“ should create store
    βœ“ should not open store for non-owner (15897ms)
    βœ“ should open store (11298ms)
    βœ“ should not suspend store for non-owner (10244ms)
    βœ“ should suspend store (10713ms)
    βœ“ should re-open store (9781ms)
    βœ“ should not create an event for non-owner (10339ms)
    βœ“ should not create an event when organizer is a contract (10344ms)
    βœ“ should not create an event without external ID (10298ms)
    βœ“ should not create an event without name (10136ms)
    βœ“ should not create an event with incentive greater than 100% (11196ms)
    βœ“ should not create an event with no tickets available for sale (10303ms)
    βœ“ should create an event (10968ms)
    βœ“ should store event basic info accordingly (982ms)
    βœ“ should init event sales info accordingly (1707ms)
    βœ“ should not complete purchase sales not started yet (26841ms)
    βœ“ should start ticket sales of an event (11803ms)
    βœ“ should not complete purchase when quantity is zero (8481ms)
    βœ“ should not complete purchase when there are not enough tickets (9915ms)
    βœ“ should not complete purchase without external ID (10304ms)
    βœ“ should not complete purchase without timestamp (10608ms)
    βœ“ should not complete purchase without customer ID (10458ms)
    βœ“ should not complete purchase value less than total (10352ms)
    βœ“ should not complete purchase value more than total (10429ms)
    βœ“ should complete a purchase (11465ms)
    βœ“ should store purchase info accordingly (997ms)
    βœ“ should suspend ticket sales of an event (17902ms)
    βœ“ should end ticket sales of an event (10905ms)
    βœ“ should cancel a purchase
    βœ“ should refund a purchase
    βœ“ should check-in customer
    βœ“ should complete an event (10854ms)
    βœ“ should settle an event (10898ms)
    1) should cancel an event

    Events emitted during test:
    ---------------------------

    EventSettled(_id: <indexed>, _extId: <indexed>, _by: <indexed>, _settlement: 90000000000000000)

    ---------------------------
    βœ“ should not close store for non-owner (9435ms)
    βœ“ should close store (11229ms)

  35 passing (9m)
  1 failing

  1) Contract: Bileto
       should cancel an event:
     Error: Transaction: 0xb1429a5af1b3b86326884215cac3a53126a944a408d404c32a6ed44076bde3b8 exited with an error (status 0).
     Please check that the transaction:
     - satisfies all conditions set by Solidity `require` statements.
     - does not trigger a Solidity `revert` statement.

      at StatusError.ExtendableError (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-error/index.js:10:1)
      at new StatusError (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/statuserror.js:31:1)
      at Object.receipt (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-contract/lib/handlers.js:117:1)
      at process.internalTickCallback (internal/process/next_tick.js:77:7)
rkalis commented 5 years ago

Good to hear that it worked for you @feamcor. I'll leave this issue open for a bit so I can look into testing on Rinkeby some more.

rkalis commented 5 years ago

I added a few test cases with your Rinkeby error messages to the tests for truffleAssert.reverts(). So I'll close the issue now.