Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Run tests against rinkeby #271

Merged
merged 1 commit into from
Jan 11, 2022
Merged

Conversation

sveitser
Copy link
Contributor

@sveitser sveitser commented Jan 10, 2022

  • Fix hardhat tests against rinkeby (was missing awaits for transactions). This only (?) seems to cause a problem against slower networks because our local chains mine the transactions quickly enough.
  • Run test_2user_and_submit against rinkeby

To test put RINKEBY_MNEMONIC and RINKEBY_URL in .env (see readme for instructions). Then run

hardhat --network rinkeby test
cape-test-rinkeby

The tests are quite slow.

Close #54

@sveitser sveitser changed the title Fix hardhat tests against rinkeby Run tests against rinkeby Jan 10, 2022
Copy link
Contributor

@alxiong alxiong left a comment

Choose a reason for hiding this comment

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

LGTM, one minor comment.

README.md Outdated Show resolved Hide resolved
@sveitser sveitser force-pushed the fix/t54-rinkeby-hardhat-tx-await branch from fcdfeaf to b69b7a3 Compare January 10, 2022 14:20
@NimaVaziri
Copy link
Contributor

Does this fix the issue described in #54? It seems there might be multiple issues in this case then, since the issue originally described there is relevant to tests failing with different outputs compared to expectations, and not having to do with async
/ mining mechanics?

@philippecamacho
Copy link
Collaborator

I get an error when running:

[nix-shell:~/repositories/Translucence/cape]$ hardhat test --network rinkeby
No need to generate any newer typings.


  Records Merkle Tree Benchmarks
    The Records Merkle root is updated with the frontier.
      ✓ shows how much gas is spent by updateRecordsMerkleTree (44601ms)

  Rescue benchmarks
    Gas spent for computing the Rescue function
      1) checks gas usage of TestRescue.hash
      ✓ checks gas usage of TestRescueNonOptimized.hash (60342ms)

  AccumulatingArray
    ✓ Accumulates correctly (20547ms)
    ✓ Reverts if the max length is exceeded (7472ms)

  CAPE
    Handling of nullifiers
      ✓ is possible to check for non-membership (20189ms)
      ✓ is possible to insert several elements (24653ms)

  Greeter (typescript)
    ✓ Should return the new greeting once it's changed (25891ms)

  Records Merkle Tree tests
    ✓ inserts all 27 leaves into a merkle tree of height 3 (26464ms)
    2) shows that inserting too many leaves triggers an error


  8 passing (6m)
  2 failing

  1) Rescue benchmarks
       Gas spent for computing the Rescue function
         checks gas usage of TestRescue.hash:

      AssertionError: expected 91712 to equal 90363
      + expected - actual

      -91712
      +90363
      
      at Context.<anonymous> (contracts/test/benchmarks/test-rescue.js:35:34)

  2) Records Merkle Tree tests
       shows that inserting too many leaves triggers an error:

      AssertionError: Expected transaction to be reverted
      + expected - actual

      -Transaction NOT reverted.
      +Transaction reverted.
      
` ` ` 

@sveitser
Copy link
Contributor Author

Hmm. This worked for me yesterday but now also fails.

@sveitser
Copy link
Contributor Author

I think it is also a race condition because the TX eventually fails in the block explorer:
https://rinkeby.etherscan.io/tx/0xc5f2bde2a8351edeeebcae445ae329441951989c53d11105483d5f0b947fef98

@sveitser
Copy link
Contributor Author

sveitser commented Jan 11, 2022

So it seems to me that the doing an

await expect(...).to.be.rejected...

Relies on the estimate gas call to fail but we are setting gas in the rinkeby network config in hardhat.config.ts.

If we change the code to

    await expect(recordsMerkleTree.testUpdateRecordsMerkleTree(elems, { gasLimit: 10000000 })).to.be.revertedWith(
      "The tree is full."
    );

then the test also fails against geth with (not reverted).

Removing gas from the rinkeby netowrk config makes the test pass for me. Will try all the tests a few times to see if this is consistent.

Alternatively we could avoid using estimate gas and check for actual reversion of transactions. This sounds a bit more robust.

@sveitser
Copy link
Contributor Author

@sveitser
Copy link
Contributor Author

@philippecamacho @NimaVaziri could you try again to see if this fixed the issue for you as well?

@NimaVaziri
Copy link
Contributor

Retrying

@NimaVaziri
Copy link
Contributor

Just retried rinkeby and the tests all passed. Retrying goerli now.

@NimaVaziri
Copy link
Contributor

Retried tests against goerli too and they all passed as well. I'm still confused as to why this change fixed the original issue though but it looks like it has.

@NimaVaziri
Copy link
Contributor

👍

Alternatively we could avoid using estimate gas and check for actual reversion of transactions. This sounds a bit more robust.

@NimaVaziri
Copy link
Contributor

Interestingly running hardhat test --network hardhat does reproduce the original error

  1) Rescue benchmarks
       Gas spent for computing the Rescue function
         checks gas usage of TestRescue.hash:

      AssertionError: expected 91712 to equal 90363
      + expected - actual

      -91712
      +90363
      
      at Context.<anonymous> (contracts/test/benchmarks/test-rescue.js:35:34)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at runNextTicks (internal/process/task_queues.js:66:3)
      at listOnTimeout (internal/timers.js:523:9)
      at processTimers (internal/timers.js:497:7)

@sveitser
Copy link
Contributor Author

Interestingly running hardhat test --network hardhat does reproduce the original error

I'm also getting this. Don't know why it's happening at this point though.

- Await transactions in tests. This only seems to cause a problem
  against slower networks because our local chains mine the transactions
  quickly enough.
- Run test_2user against rinkeby. Works most of the time, unfortunately
  not always.
- Remove manual gas setting from hardhat configs for rinkeby and goerli
  because it breaks tests that rely on the call to reverted due to
  estimageGas failing.
@sveitser sveitser force-pushed the fix/t54-rinkeby-hardhat-tx-await branch from 9e47dcb to c8eac5f Compare January 11, 2022 08:53
@@ -52,13 +52,11 @@ const config: HardhatUserConfig = {
rinkeby: {
url: process.env.RINKEBY_URL,
gasPrice: 2_000_000_000,
gas: 25_000_000,
Copy link
Contributor

@NimaVaziri NimaVaziri Jan 11, 2022

Choose a reason for hiding this comment

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

is the gas setting for the hardhat config above not needed as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need it but removing it did not fix the issue with --network hardhat for me.

@NimaVaziri
Copy link
Contributor

And related to this

The tests are quite slow.

if the plan is to integrate testnet-based testing into CI, is there an issue for making these tests run faster?

@sveitser
Copy link
Contributor Author

And related to this

The tests are quite slow.

if the plan is to integrate testnet-based testing into CI, is there an issue for making these tests run faster?

There is

but no ticket about speeding up tests.

I'm thinking we can just run a few integration tests with a timer trigger once a day or whatever. Then it's fine if it takes a while to run. I imagine running transactions in parallel would require quite some extra engineering with the current state of the rust test code.

@sveitser
Copy link
Contributor Author

@NimaVaziri Thanks for the review and testing.

@sveitser sveitser merged commit 1030fda into main Jan 11, 2022
@sveitser sveitser deleted the fix/t54-rinkeby-hardhat-tx-await branch January 11, 2022 09:44
sveitser added a commit that referenced this pull request Jan 12, 2022
This fixes the test

  Records Merkle Tree tests
    shows that inserting too many leaves triggers an error

Similarly to what we found in
#271

The remaining failures in `hardhat test --network arbitrum` are caused
by checking exact gas costs which differ on arbitrum and concern the
following tests.

  Records Merkle Tree Benchmarks
    The Records Merkle root is updated with the frontier.
      1) shows how much gas is spent by updateRecordsMerkleTree

  Rescue benchmarks
    Gas spent for computing the Rescue function
      2) checks gas usage of TestRescue.hash
      3) checks gas usage of TestRescueNonOptimized.hash

Part of #25.
sveitser added a commit that referenced this pull request Jan 13, 2022
This fixes the test

  Records Merkle Tree tests
    shows that inserting too many leaves triggers an error

Similarly to what we found in
#271

The remaining failures in `hardhat test --network arbitrum` are caused
by checking exact gas costs which differ on arbitrum and concern the
following tests.

  Records Merkle Tree Benchmarks
    The Records Merkle root is updated with the frontier.
      1) shows how much gas is spent by updateRecordsMerkleTree

  Rescue benchmarks
    Gas spent for computing the Rescue function
      2) checks gas usage of TestRescue.hash
      3) checks gas usage of TestRescueNonOptimized.hash

Part of #25.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests fail on Rinkeby/Goerli
4 participants