aptos-labs / aptos-ts-sdk

An SDK for accessing the Aptos blockchain data, submitting transactions, and more!
https://aptos-labs.github.io/aptos-ts-sdk/
Apache License 2.0
67 stars 37 forks source link

bug: Fix fundAccount always waiting for Indexer #442

Closed jmintuitive closed 1 month ago

jmintuitive commented 2 months ago

Description

Funding an account using the faucet currently always triggers the logic to "waitForIndexer" since undefined !== false is true.

image

This PR updates the logic so that it only waits for the indexer if options.waitForIndexer is true.

This was found by trying to run simple_transfer.ts in the example folder, and immediately getting this error:

 [AptosApiError]: Indexer error: field 'processor_status' not found in type: 'query_root'
    at Gn (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:1:36526)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async f (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:470:383)
    at async tc (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:470:571)
    at async Hn (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:470:694)
    at async Zn (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:470:12500)
    at async gn.fundAccount (/Users/jacksonmills/aptos-ts-sdk/dist/common/index.js:470:55884)
    at async example (/Users/jacksonmills/aptos-ts-sdk/examples/typescript/simple_transfer.ts:57:24) {
  url: 'https://api.devnet.aptoslabs.com/v1/graphql',
  status: 200,
  statusText: 'OK',
  data: { errors: [ [Object] ] },
  request: {
    url: 'https://api.devnet.aptoslabs.com/v1/graphql',
    method: 'POST',
    originMethod: 'getProcessorStatuses',
    path: '',
    body: {
      query: '\n' +
        '    query getProcessorStatus($where_condition: processor_status_bool_exp) {\n' +
        '  processor_status(where: $where_condition) {\n' +
        '    last_success_version\n' +
        '    processor\n' +
        '    last_updated\n' +
        '  }\n' +
        '}\n' +
        '    '
    },
    contentType: undefined,
    acceptType: undefined,
    params: undefined,
    overrides: { WITH_CREDENTIALS: false, HEADERS: {} }
  }
}

While this fix solves the immediate issue for the tutorial, it does NOT address why processor_status was not found in the query_root for the devnet indexer. That should be investigated separately.

(I also updated the contributing guide to clearly spell out how to test code since it was very easy to miss when skimming.)

Test Plan

BEFORE:

Screenshot

AFTER:

image

Related Links

0xmaayan commented 2 months ago

ok, so tests are failing because of this change.

gregnazario commented 2 months ago

ok, so tests are failing because of this change.

We'll need to probably set the field for a lot of tests

jmintuitive commented 1 month ago

@0xmaayan Updated the logic so it's more explicit that undefined means that we wait for the indexer (this is functionally equivalent to the old default of always waiting :) )

This is ready for re-review when you have a chance :)

jmintuitive commented 1 month ago

@0xmaayan Updated to remove the unnecessary option: { waitForIndexer = true } lines :)