neonevm / neon-compatibility

GNU General Public License v3.0
4 stars 3 forks source link

Introduce a feature to avoid "Invalid Ethereum transaction nonce" in the OZ tests #189

Open vasiliy-zaznobin opened 2 years ago

vasiliy-zaznobin commented 2 years ago

It needs to add a feature: A test should use the right nonce for a transaction by sending getTransactionCount.

For example: test/utils/escrow/RefundEscrow.test.js

  2) Contract: RefundEscrow
       once deployed
         closed state
           "before each" hook for "rejects deposits":
     Error: Returned error: {"err": {"InstructionError": [1, "InvalidArgument"]}, "fee": 10000, "innerInstructions": [], "logMessages": ["Program 53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io invoke [1]", "Program log: program/src/entrypoint.rs:1256 : Invalid Ethereum transaction nonce: acc 13, trx 12", "Program 53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io consumed 31859 of 500000 compute units", "Program 53DfF883gyixYNXnM7s5xhdeyV8mVk9T4i2hGV9vG9io failed: invalid program argument"], "postBalances": [4975963116800, 925880, 2039280, 2039280, 2672640, 2039280, 64456560, 2672640, 1, 0, 1, 1141440, 1461600, 1130582400, 1169280], "postTokenBalances": [{"accountIndex": 2, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "99951000003212714", "decimals": 9, "uiAmount": 99951000.00321272, "uiAmountString": "99951000.003212714"}}, {"accountIndex": 3, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "783998504074", "decimals": 9, "uiAmount": 783.998504074, "uiAmountString": "783.998504074"}}, {"accountIndex": 5, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "1054000000000", "decimals": 9, "uiAmount": 1054.0, "uiAmountString": "1054"}}], "preBalances": [4975963126800, 925880, 2039280, 2039280, 2672640, 2039280, 64456560, 2672640, 1, 0, 1, 1141440, 1461600, 1130582400, 1169280], "preTokenBalances": [{"accountIndex": 2, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "99951000003212714", "decimals": 9, "uiAmount": 99951000.00321272, "uiAmountString": "99951000.003212714"}}, {"accountIndex": 3, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "783998504074", "decimals": 9, "uiAmount": 783.998504074, "uiAmountString": "783.998504074"}}, {"accountIndex": 5, "mint": "HPsV9Deocecw3GeZv1FkAPNCBRfuVyfw9MMwjwRe1xaU", "uiTokenAmount": {"amount": "1054000000000", "decimals": 9, "uiAmount": 1054.0, "uiAmountString": "1054"}}], "rewards": [], "status": {"Err": {"InstructionError": [1, "InvalidArgument"]}}}
      at /home/vzaznobin/neon/neon-compatibility/openzeppelin-contracts/test/utils/escrow/RefundEscrow.test.js:63:65
      at Array.map (<anonymous>)
      at Context.<anonymous> (test/utils/escrow/RefundEscrow.test.js:63:37)
      at processImmediate (node:internal/timers:464:21)

Additional Info: https://github.com/neonlabsorg/proxy-model.py/blob/7841b07f33d9d45b68b621c711ff4c7e67b7f3f6/proxy/testing/test_eth_sendRawTransaction.py#L172

ivandzen commented 2 years ago

During investigation it was found that this issue is caused by parallel execution of eth_sendRawTransaction with the same nonces. The behaviour is next:

  1. beforeEach hook maps async lambda on array with eth accounts (line 63 in RefundEscrow.test.js)
  2. lambdas simultaneously calls RefundEscrow.deposit() contract method using the same nonce - this is approved by proxy's logs.
  3. evm loader fails transaction that was received later.

After talk with @otselnik we concluded that this behaviour is expected. The solution to this issue could be forcing tests to execute functions in sequential manner - this approach was tested by me on local environment with this particular test case and approved to solve issue