-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1954 from oasisprotocol/ml/pending-transactions
Pending transactions
- Loading branch information
Showing
47 changed files
with
1,192 additions
and
155 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Pending transactions | ||
|
||
Introduces a section for pending transactions within the transaction history | ||
interface. It is designed to display transactions currently in a pending | ||
state that are made within the wallet. The section will also show up in case | ||
there is a discrepancy between transaction history nonce and wallet nonce, | ||
indicating that some transactions are currently in pending state. |
This file contains 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 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 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 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 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 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 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
3 changes: 0 additions & 3 deletions
3
...pages/AccountPage/Features/TransactionHistory/__tests__/__snapshots__/index.test.tsx.snap
This file was deleted.
Oops, something went wrong.
168 changes: 164 additions & 4 deletions
168
src/app/pages/AccountPage/Features/TransactionHistory/__tests__/index.test.tsx
This file contains 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,11 +1,171 @@ | ||
import * as React from 'react' | ||
import { render } from '@testing-library/react' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
import { TransactionHistory } from '..' | ||
import { configureAppStore } from '../../../../../../store/configureStore' | ||
import { Provider, useDispatch } from 'react-redux' | ||
import { DeepPartialRootState, RootState } from '../../../../../../types/RootState' | ||
import { Transaction, TransactionStatus, TransactionType } from 'app/state/transaction/types' | ||
|
||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useDispatch: jest.fn(), | ||
})) | ||
|
||
const renderCmp = (store: ReturnType<typeof configureAppStore>) => | ||
render( | ||
<Provider store={store}> | ||
<TransactionHistory /> | ||
</Provider>, | ||
) | ||
|
||
const getPendingTx = (hash: string): Transaction => ({ | ||
hash, | ||
type: TransactionType.StakingTransfer, | ||
from: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', | ||
amount: 1n.toString(), | ||
to: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuww', | ||
status: undefined, | ||
fee: undefined, | ||
level: undefined, | ||
round: undefined, | ||
runtimeId: undefined, | ||
runtimeName: undefined, | ||
timestamp: undefined, | ||
nonce: undefined, | ||
}) | ||
|
||
const getTx = ({ hash = '', nonce = 0n, status = TransactionStatus.Successful } = {}): Transaction => ({ | ||
...getPendingTx(hash), | ||
status, | ||
nonce: nonce.toString(), | ||
}) | ||
|
||
const getState = ({ | ||
accountNonce = 0n, | ||
pendingLocalTxs = [], | ||
accountTxs = [], | ||
}: { accountNonce?: bigint; pendingLocalTxs?: Transaction[]; accountTxs?: Transaction[] } = {}) => { | ||
const state: DeepPartialRootState = { | ||
account: { | ||
loading: false, | ||
address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', | ||
available: 100000000000n.toString(), | ||
delegations: null, | ||
debonding: null, | ||
total: null, | ||
transactions: [...accountTxs], | ||
accountError: undefined, | ||
transactionsError: undefined, | ||
pendingTransactions: { | ||
local: [...pendingLocalTxs], | ||
testnet: [], | ||
mainnet: [], | ||
}, | ||
nonce: accountNonce.toString(), | ||
}, | ||
staking: { | ||
delegations: [], | ||
debondingDelegations: [], | ||
}, | ||
wallet: { | ||
selectedWallet: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', | ||
wallets: { | ||
oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk: { | ||
address: 'oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', | ||
}, | ||
}, | ||
}, | ||
} | ||
return configureAppStore(state as Partial<RootState>) | ||
} | ||
|
||
describe('<TransactionHistory />', () => { | ||
it.skip('should match snapshot', () => { | ||
const component = render(<TransactionHistory />) | ||
expect(component.container.firstChild).toMatchSnapshot() | ||
beforeEach(() => { | ||
// Ignore dispatches to fetch account from AccountPage | ||
jest.mocked(useDispatch).mockImplementation(() => jest.fn()) | ||
}) | ||
|
||
it('should not display any pending or completed txs', async () => { | ||
renderCmp(getState()) | ||
|
||
expect(() => screen.getByTestId('pending-txs')).toThrow() | ||
expect(() => screen.getByTestId('completed-txs')).toThrow() | ||
|
||
expect(screen.queryByText('account.summary.someTxsInPendingState')).not.toBeInTheDocument() | ||
expect(await screen.findByText('account.summary.noTransactionFound')).toBeInTheDocument() | ||
}) | ||
|
||
it('should display pending txs alert and no transactions', async () => { | ||
renderCmp(getState({ accountNonce: 1n })) | ||
|
||
expect(() => screen.getByTestId('pending-txs')).toThrow() | ||
expect(() => screen.getByTestId('completed-txs')).toThrow() | ||
|
||
expect(await screen.findByText('account.summary.someTxsInPendingState')).toBeInTheDocument() | ||
expect(await screen.findByText('account.summary.noTransactionFound')).toBeInTheDocument() | ||
expect(await screen.findByRole('link')).toHaveAttribute( | ||
'href', | ||
'http://localhost:9001/data/accounts/detail/oasis1qz0k5q8vjqvu4s4nwxyj406ylnflkc4vrcjghuwk', | ||
) | ||
}) | ||
|
||
it('should display pending txs alert with single pending tx and no completed transactions', async () => { | ||
renderCmp(getState({ accountNonce: 0n, pendingLocalTxs: [getPendingTx('txHash1')] })) | ||
|
||
expect(screen.getByTestId('pending-txs').childElementCount).toBe(1) | ||
expect(() => screen.getByTestId('completed-txs')).toThrow() | ||
|
||
expect(await screen.findByText('account.summary.someTxsInPendingState')).toBeInTheDocument() | ||
expect(await screen.findByText('account.summary.noTransactionFound')).toBeInTheDocument() | ||
expect(await screen.findByText('txHash1')).toBeInTheDocument() | ||
}) | ||
|
||
it('should display single pending and completed tx', async () => { | ||
renderCmp( | ||
getState({ | ||
accountNonce: 2n, | ||
accountTxs: [getTx({ hash: 'txHash1', nonce: 0n })], | ||
pendingLocalTxs: [getPendingTx('txHash2')], | ||
}), | ||
) | ||
|
||
expect(screen.getByTestId('pending-txs').childElementCount).toBe(1) | ||
expect(screen.getByTestId('completed-txs').childElementCount).toBe(1) | ||
|
||
expect(await screen.findByText('txHash1')).toBeInTheDocument() | ||
expect(await screen.findByText('txHash2')).toBeInTheDocument() | ||
}) | ||
|
||
it('should not display pending section in case of failed tx', async () => { | ||
renderCmp( | ||
getState({ | ||
accountNonce: 1n, | ||
accountTxs: [getTx({ hash: 'txHash1', nonce: 0n, status: TransactionStatus.Failed })], | ||
}), | ||
) | ||
|
||
expect(() => screen.getByTestId('pending-txs')).toThrow() | ||
expect(screen.getByTestId('completed-txs').childElementCount).toBe(1) | ||
|
||
expect(await screen.findByText('txHash1')).toBeInTheDocument() | ||
|
||
expect(() => screen.getByText('account.summary.someTxsInPendingState')).toThrow() | ||
}) | ||
|
||
it('should not display pending section on initial load', async () => { | ||
renderCmp( | ||
getState({ | ||
accountNonce: 1n, | ||
accountTxs: [getTx({ hash: 'txHash1', nonce: 0n, status: TransactionStatus.Successful })], | ||
}), | ||
) | ||
|
||
expect(() => screen.getByTestId('pending-txs')).toThrow() | ||
expect(screen.getByTestId('completed-txs').childElementCount).toBe(1) | ||
|
||
expect(await screen.findByText('txHash1')).toBeInTheDocument() | ||
|
||
expect(() => screen.getByText('account.summary.someTxsInPendingState')).toThrow() | ||
}) | ||
}) |
Oops, something went wrong.