This repository was archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
Fix: use recommended nonce in the nonce warning #3530
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a3a90b9
Fix: use recommended nonce in the nonce warning
katspaugh 27fe1e1
Update tests
katspaugh eaa975c
Fix test title
katspaugh 0ce886f
Merge branch 'dev' of github.com:gnosis/safe-react into fix-nonce-war…
katspaugh dcae790
Merge branch 'dev' of github.com:gnosis/safe-react into fix-nonce-war…
katspaugh 498b639
Rephrase the warning for nonces in the past
katspaugh 66b580c
Merge branch 'dev' of github.com:gnosis/safe-react into fix-nonce-war…
katspaugh 22b4ed9
Merge branch 'dev' of github.com:gnosis/safe-react into fix-nonce-war…
katspaugh 7ad2e8a
Show the nonce warning only when creating a tx
katspaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,57 +1,64 @@ | ||
| import { useSelector } from 'react-redux' | ||
| import { EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas' | ||
| import { render, screen } from 'src/utils/test-utils' | ||
| import { ReviewInfoText } from './index' | ||
| import { history } from 'src/routes/routes' | ||
|
|
||
| const safeAddress = '0xC245cb45B044d66fbE8Fb33C26c0b28B4fc367B2' | ||
| const url = `/rin:${safeAddress}/settings/advanced` | ||
| history.location.pathname = url | ||
| jest.mock('src/logic/hooks/useRecommendedNonce', () => ({ | ||
| __esModule: true, | ||
| default: () => 9, | ||
| })) | ||
|
|
||
| describe('<ReviewInfoText>', () => { | ||
| const initialData = { | ||
| gasCostFormatted: '0', | ||
| isExecution: true, | ||
| isCreation: false, | ||
| isCreation: true, | ||
| isOffChainSignature: false, | ||
| txEstimationExecutionStatus: EstimationStatus.SUCCESS, | ||
| } | ||
| const customState = { | ||
| safes: { | ||
| safes: { | ||
| [safeAddress]: { | ||
| address: safeAddress, | ||
| nonce: 8, | ||
| modules: null, | ||
| guard: '', | ||
| currentVersion: '1.3.0', | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| const testId = 'reviewInfoText-component' | ||
| const warningCommonCopy = | ||
| 'will need to be created and executed before this transaction, are you sure you want to do this?' | ||
|
|
||
| it('Renders ReviewInfoText with safeNonce being one lastTxNonce + 1', () => { | ||
| const lastTxNonce = 10 | ||
| const safeNonce = `${lastTxNonce + 1}` | ||
| it('renders ReviewInfoText with safeNonce in order', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="9" />) | ||
|
|
||
| expect(screen.getByText(/You're about to create a transaction/)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders ReviewInfoText with safeNonce in order and not a creation', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="9" isCreation={false} />) | ||
|
|
||
| expect(screen.getByText(/You're about to execute a transaction/)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| render(<ReviewInfoText {...initialData} safeNonce={safeNonce} testId={testId} />, customState) | ||
| it('renders ReviewInfoText that is not a creation and nonce in future', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="100" isCreation={false} />) | ||
|
|
||
| expect(screen.getByTestId(testId)).toBeInTheDocument() | ||
| expect(screen.queryByText(warningCommonCopy)).not.toBeInTheDocument() | ||
| expect(screen.getByText(/You're about to execute a transaction/)).toBeInTheDocument() | ||
| expect(screen.queryByText(/will need to be created and executed before this transaction/)).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('Renders ReviewInfoText with safeNonce more than one transaction ahead of lastTxNonce', () => { | ||
| const lastTxNonce = 10 | ||
| const safeNonce = `${lastTxNonce + 4}` | ||
| const expectedCopy = 'transactions ' + warningCommonCopy | ||
| it('renders ReviewInfoText with a safeNonce 1 tx in the future', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="10" />) | ||
|
|
||
| expect(screen.getByText(/1/)).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText(/transaction will need to be created and executed before this transaction/), | ||
| ).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders ReviewInfoText with a safeNonce 2 txs the future', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="11" />) | ||
|
|
||
| expect(screen.getByText(/2/)).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText(/transactions will need to be created and executed before this transaction/), | ||
| ).toBeInTheDocument() | ||
| }) | ||
|
|
||
| render(<ReviewInfoText {...initialData} safeNonce={safeNonce} testId={testId} />, customState) | ||
| it('renders ReviewInfoText with already used safeNonce', () => { | ||
| render(<ReviewInfoText {...initialData} safeNonce="6" />) | ||
|
|
||
| expect(screen.getByTestId(testId)).toBeInTheDocument() | ||
| expect(screen.getByText('6')).toBeInTheDocument() | ||
| expect(screen.queryByText(expectedCopy)).toBeInTheDocument() | ||
| expect(screen.getByText(/6/)).toBeInTheDocument() | ||
| expect(screen.getByText(/9/)).toBeInTheDocument() | ||
| expect(screen.getByText(/is below the latest transaction's nonce./)).toBeInTheDocument() | ||
| expect(screen.getByText(/Your transaction might fail./)).toBeInTheDocument() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.