Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: fix and optimise fetching the recovery state #2807

Merged
merged 3 commits into from
Nov 14, 2023

Conversation

schmanu
Copy link
Member

@schmanu schmanu commented Nov 14, 2023

What it solves

Querying the recovery state does not work.

How this PR fixes it

  • Uses blockNumber instead of blockHash
  • Fixes the endpoint of our tx service
  • filters the queueNonces while querying and not afterwards

How to test it

  • Load a Safe that has a recovery tx queued
  • Observe the redux state

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

github-actions bot commented Nov 14, 2023

Branch preview

⏳ Deploying a preview site...

Copy link

github-actions bot commented Nov 14, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Nov 14, 2023

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟡 Statements
75.21% (+0.02% 🔼)
10220/13589
🔴 Branches
49.93% (+0.05% 🔼)
2086/4178
🔴 Functions
57.79% (+0.02% 🔼)
1520/2630
🟡 Lines
76.74% (+0.02% 🔼)
9243/12044

Test suite run failed

Failed tests: 1/1139. Failed suites: 1/159.
  ● useLoadRecovery › should return the recovery state

    expect(received).toStrictEqual(expected) // deep equality

    - Expected  -  0
    + Received  + 15

    @@ -7,10 +7,25 @@
            ],
            "queue": Array [
              Object {
                "args": Object {
                  "queueNonce": Object {
    +               "hex": "0x01",
    +               "type": "BigNumber",
    +             },
    +           },
    +           "expiresAt": null,
    +           "getBlock": [Function getBlock],
    +           "timestamp": 69,
    +           "validFrom": Object {
    +             "hex": "0x010f71",
    +             "type": "BigNumber",
    +           },
    +         },
    +         Object {
    +           "args": Object {
    +             "queueNonce": Object {
                    "hex": "0x02",
                    "type": "BigNumber",
                  },
                },
                "expiresAt": null,

    Ignored nodes: comments, script, style
    <html>
      <head />
      <body>
        <div />
      </body>
    </html>

      118 |     // Loaded
      119 |     await waitFor(() => {
    > 120 |       expect(result.current).toStrictEqual([
          |                              ^
      121 |         [
      122 |           {
      123 |             address: delayModifier.address,

      at toStrictEqual (src/hooks/__tests__/useLoadRecovery.test.ts:120:30)
      at runWithExpensiveErrorDiagnosticsDisabled (node_modules/@testing-library/dom/dist/config.js:47:12)
      at checkCallback (node_modules/@testing-library/dom/dist/wait-for.js:127:77)
      at checkRealTimersCallback (node_modules/@testing-library/dom/dist/wait-for.js:121:16)
      at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

Report generated by 🧪jest coverage report action from 3d5e88f

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

Looks great so far! I'm sure you're aware but there are some breaking tests.


const MAX_PAGE_SIZE = 100

export const _getQueuedTransactionsAdded = (
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove the unit test for this.

@@ -48,7 +41,7 @@ export const _getSafeCreationReceipt = memoize(
safeAddress: string
provider: JsonRpcProvider
}): Promise<TransactionReceipt> => {
const url = `${transactionService}/v1/${safeAddress}/creation/`
const url = `${transactionService}api/v1/safes/${safeAddress}/creation/`
Copy link
Member

Choose a reason for hiding this comment

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

It seems as though there can be a forward slash on some networks. Perhaps we should check if one is required and/or fix the configs.

@@ -63,6 +56,28 @@ export const _getSafeCreationReceipt = memoize(
({ transactionService, safeAddress }) => transactionService + safeAddress,
)

const queryAddedTransactions = async (
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a unit test for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added more tests for it's outside function effectively also testing this logic.


const transactionAddedFilter = delayModifier.filters.TransactionAdded()

const diff = queueNonce.sub(txNonce).toNumber()
Copy link
Member

Choose a reason for hiding this comment

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

We can move this into the if below.


const diff = queueNonce.sub(txNonce).toNumber()
if (transactionAddedFilter.topics) {
const queueNonceFilter = Array.from({ length: diff }, (_, idx) => hexZeroPad(txNonce.add(idx).toHexString(), 32))
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment explaining this?

const { blockHash } = await _getSafeCreationReceipt(rest)

const transactionAddedFilter = delayModifier.filters.TransactionAdded()
const { blockNumber } = await _getSafeCreationReceipt(rest)
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this into queryAddedTransactions so it doesn't call _getSafeCreationReceipt when no queued transactions exist.

// Only queued transactions with queueNonce >= current txNonce
return transactionsAdded.filter(({ args }) => args.queueNonce.gte(txNonce))
}
export const normalizeTxServiceUrl = (url: string): string => (url.endsWith('/') ? url : `${url}/`)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: there is a trimTrailingSlash function in @/utils/url.ts that we could export and use instead of this. We would then have to append the / within _getSafeCreationReceipt.

@iamacook iamacook merged commit 3ee9b08 into recovery-epic Nov 14, 2023
8 of 11 checks passed
@iamacook iamacook deleted the optimise-query branch November 14, 2023 17:28
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2023
@iamacook iamacook linked an issue Nov 14, 2023 that may be closed by this pull request
2 tasks
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.

[Recovery] Improve TransactionAdded querying
2 participants