Skip to content

AssetsContractController: Unit tests fail on external endpoints #1213

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
legobeat opened this issue Apr 19, 2023 · 8 comments
Closed

AssetsContractController: Unit tests fail on external endpoints #1213

legobeat opened this issue Apr 19, 2023 · 8 comments

Comments

@legobeat
Copy link
Contributor

legobeat commented Apr 19, 2023

Description

The assets-controller tests are failing when run locally. Is there some additional setup needed for proxying the requests properly..?

As can be seen in the log below, the tests fail on the requests to the metafi endpoints. However, from the same shell that the tests are run from, the same endpoint responds without issues:

$ curl -i https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x495f947276749Ce646f68AC8c248420045cb7b5e
HTTP/2 200
date: [...]
content-type: application/json
x-trace-id: [...]
vary: Accept, Origin, Accept-Encoding
allow: GET, OPTIONS
cache-control: public, max-age=300
age: 10
x-frame-options: DENY
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
referrer-policy: same-origin
cross-origin-opener-policy: same-origin
cf-cache-status: DYNAMIC
last-modified: [...]
strict-transport-security: max-age=15724800; includeSubDomains
server: cloudflare
cf-ray: [...]

Environment

Fresh checkout and node_modules from current main.

$ env | grep -i proxy

$ node --version
v18.13.0

$ yarn --version
3.3.0

Log

# inside `packages/assets-controllers`
$ yarn test

[...]

 PASS   assets-controllers  src/NftController.test.ts (46.552 s)
  ● Console

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x495f947276749Ce646f68AC8c248420045cb7b5e failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      534 |       error === TIMEOUT_ERROR)
      535 |   ) {
    > 536 |     console.error(error);
          |             ^
      537 |   } else {
      538 |     throw error;
      539 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:536:13)
      at ../controller-utils/src/util.ts:370:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x6EbeAf8e8E946F0716E6533A6f2cefc83f60e8Ab failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      534 |       error === TIMEOUT_ERROR)
      535 |   ) {
    > 536 |     console.error(error);
          |             ^
      537 |   } else {
      538 |     throw error;
      539 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:536:13)
      at ../controller-utils/src/util.ts:370:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x60F80121C31A0d46B5279700f9DF786054aa5eE5 failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      534 |       error === TIMEOUT_ERROR)
      535 |   ) {
    > 536 |     console.error(error);
          |             ^
      537 |   } else {
      538 |     throw error;
      539 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:536:13)
      at ../controller-utils/src/util.ts:370:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset/0x60F80121C31A0d46B5279700f9DF786054aa5eE5/1144858 failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      534 |       error === TIMEOUT_ERROR)
      535 |   ) {
    > 536 |     console.error(error);
          |             ^
      537 |   } else {
      538 |     throw error;
      539 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:536:13)
      at ../controller-utils/src/util.ts:370:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

 FAIL   assets-controllers  src/AssetsContractController.test.ts (56.857 s)

[...]

------------------------------------|---------|----------|---------|---------|---------------------------
File                                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------------------------|---------|----------|---------|---------|---------------------------
All files                           |   96.73 |    89.39 |    96.2 |   96.65 |
 src                                |   97.99 |    91.71 |   97.79 |   97.94 |
  AccountTrackerController.ts       |   98.25 |    83.33 |     100 |   98.15 | 186
  AssetsContractController.ts       |   97.47 |    93.55 |     100 |   97.47 | 187,371
  CurrencyRateController.ts         |     100 |      100 |     100 |     100 |
  NftController.ts                  |   98.11 |    88.52 |     100 |   98.08 | 269,395,1125,1188,1257
  NftDetectionController.ts         |   95.31 |    85.37 |   93.75 |   95.08 | 181,270,284
  TokenBalancesController.ts        |     100 |      100 |     100 |     100 |
  TokenDetectionController.ts       |   98.77 |    84.85 |     100 |   98.73 | 135
  TokenListController.ts            |   98.94 |    89.13 |     100 |   98.88 | 151
  TokenRatesController.ts           |   95.74 |    93.48 |   96.15 |   95.56 | 126,207,252,413
  TokensController.ts               |   97.18 |    94.71 |   90.91 |   97.18 | 299,534,538-541,641-651
  assetsUtil.ts                     |     100 |      100 |     100 |     100 |
  crypto-compare.ts                 |     100 |      100 |     100 |     100 |
  token-service.ts                  |     100 |       95 |     100 |     100 | 129
 src/Standards                      |   97.14 |    66.67 |     100 |   97.14 |
  ERC20Standard.ts                  |   97.14 |    66.67 |     100 |   97.14 | 82
 src/Standards/NftStandards/ERC1155 |   64.71 |    11.76 |   68.42 |      64 |
  ERC1155Standard.ts                |   64.71 |    11.76 |   68.42 |      64 | 44-45,111-126,167,172-182
 src/Standards/NftStandards/ERC721  |   98.44 |       85 |     100 |   98.36 |
  ERC721Standard.ts                 |   98.44 |       85 |     100 |   98.36 | 204
------------------------------------|---------|----------|---------|---------|---------------------------
Test Suites: 1 failed, 15 passed, 16 total
Tests:       3 failed, 294 passed, 297 total
Snapshots:   0 total
Time:        61.658 s
Ran all test suites.
@mcmire
Copy link
Contributor

mcmire commented Aug 17, 2023

With #1499 merged, is this still an issue?

@legobeat
Copy link
Contributor Author

Somehow, yes:

 PASS   assets-controllers  src/TokenRatesController.test.ts (18.324 s)
 PASS   assets-controllers  src/TokensController.test.ts (19.512 s)
 PASS   assets-controllers  src/TokenListController.test.ts (21.299 s)
 PASS   assets-controllers  src/NftDetectionController.test.ts (22.612 s)
  ● Console

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0xCE7ec4B2DfB30eB6c0BB5656D33aAd6BFb4001Fc failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      535 |       error === TIMEOUT_ERROR)
      536 |   ) {
    > 537 |     console.error(error);
          |             ^
      538 |   } else {
      539 |     throw error;
      540 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:537:13)
      at ../controller-utils/src/util.ts:374:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)

    console.error
      FetchError {
        message: 'request to https://proxy.metafi.codefi.network/opensea/v1/api/v1/asset_contract/0x0B0fa4fF58D28A88d63235bd0756EDca69e49e6d failed, reason: Failed to fetch',
        type: 'system',
        errno: undefined,
        code: undefined
      }

      535 |       error === TIMEOUT_ERROR)
      536 |   ) {
    > 537 |     console.error(error);
          |             ^
      538 |   } else {
      539 |     throw error;
      540 |   }

      at logOrRethrowError (../controller-utils/src/util.ts:537:13)
      at ../controller-utils/src/util.ts:374:5
          at Generator.throw (<anonymous>)
      at rejected (../controller-utils/src/util.ts:6:65)

@mcmire
Copy link
Contributor

mcmire commented Aug 22, 2023

Ah, right.

I think there are two things going on here:

  1. The tests are using "production" URLs, which makes it seem like the tests are actually hitting those URLs. This doesn't happen because network requests are being mocked.
  2. Some tests mock requests to intentionally fail. For instance:
    .replyWithError(new TypeError('Failed to fetch'))
    . These failures are then logged in the utility function that actually makes the request:
    logOrRethrowError(e, errorCodesToCatch);

So I think these errors are expected, if a bit noisy.

@legobeat
Copy link
Contributor Author

A couple of actual test failures, though. Full log attached.
assets-controller-test.log

@mcmire
Copy link
Contributor

mcmire commented Aug 23, 2023

Hmm, I see. Thanks for posting that. I don't have any intuitions for why this is happening at the moment but can take a look when I get a chance.

@desi
Copy link
Contributor

desi commented May 1, 2024

Further investigation is needed on this.

@desi
Copy link
Contributor

desi commented May 1, 2024

Maybe this isn't happening anymore?

@legobeat
Copy link
Contributor Author

legobeat commented May 1, 2024

Maybe this isn't happening anymore?

@desi It is not. Closing. Got any idea of when this was resolved?

@legobeat legobeat closed this as completed May 1, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants