Skip to content

Commit

Permalink
test: cov
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Sep 30, 2024
1 parent d6860c5 commit 5013b04
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/actions/waitForTransactionReceipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ test('default', async () => {

await disconnect(config, { connector })
})

test('behavior: transaction reverted', async () => {
await expect(
waitForTransactionReceipt(config, {
hash: '0x745367f76807d411b7fa4c3a552a62e3e45303ef40145fff04d84b867c2575d3',
}),
).rejects.toThrowErrorMatchingInlineSnapshot('[Error: unknown reason]')
})
75 changes: 75 additions & 0 deletions packages/core/src/connectors/mock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,78 @@ test('setup', () => {
const connector = config._internal.connectors.setup(connectorFn)
expect(connector.name).toEqual('Mock Connector')
})

test('behavior: features.connectError', () => {
const connectorFn = mock({ accounts, features: { connectError: true } })
const connector = config._internal.connectors.setup(connectorFn)
expect(() => connector.connect()).rejects.toThrowErrorMatchingInlineSnapshot(`
[UserRejectedRequestError: User rejected the request.
Details: Failed to connect.
Version: viem@2.17.0]
`)
})

test('behavior: connector.getProvider request errors', async () => {
const connectorFn = mock({
accounts,
features: {
signMessageError: true,
signTypedDataError: true,
switchChainError: true,
watchAssetError: true,
},
})
const connector = config._internal.connectors.setup(
connectorFn,
) as ReturnType<typeof connectorFn>
const provider = await connector.getProvider()

expect(
provider.request({
method: 'eth_signTypedData_v4',
params: [] as any,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[UserRejectedRequestError: User rejected the request.
Details: Failed to sign typed data.
Version: viem@2.17.0]
`)

expect(
provider.request({
method: 'wallet_switchEthereumChain',
params: [] as any,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[UserRejectedRequestError: User rejected the request.
Details: Failed to switch chain.
Version: viem@2.17.0]
`)

expect(
provider.request({
method: 'wallet_watchAsset',
params: [] as any,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[UserRejectedRequestError: User rejected the request.
Details: Failed to switch chain.
Version: viem@2.17.0]
`)

expect(
provider.request({
method: 'personal_sign',
params: [] as any,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[UserRejectedRequestError: User rejected the request.
Details: Failed to sign message.
Version: viem@2.17.0]
`)
})
18 changes: 9 additions & 9 deletions packages/core/src/experimental/actions/getCallsStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { sendCalls } from './sendCalls.js'

const connector = config.connectors[0]!

test.skip('default', async () => {
test('default', async () => {
await connect(config, { connector })
const id = await sendCalls(config, {
calls: [
Expand Down Expand Up @@ -41,27 +41,27 @@ test.skip('default', async () => {
[
{
"blockHash": undefined,
"blockNumber": 19258222n,
"blockNumber": 19258214n,
"gasUsed": 21064n,
"logs": [],
"status": "success",
"transactionHash": "0xe170f3830536bf30afc3db8e387fc5b2c32c04775cb7ec0fa144ec398d464c7c",
"transactionHash": "0x13c53b2d4d9da424835525349cd66e553330f323d6fb19458b801ae1f7989a41",
},
{
"blockHash": undefined,
"blockNumber": 19258222n,
"gasUsed": 42064n,
"blockNumber": 19258214n,
"gasUsed": 21000n,
"logs": [],
"status": "success",
"transactionHash": "0xf1ea1c5422b1c2fc42fa8e5b50cc1023696de2a10cdefd311c9b2e4d30bb8a6a",
"transactionHash": "0xd8397b3e82b061c26a0c2093f1ceca0c3662a512614f7d6370349e89d0eea007",
},
{
"blockHash": undefined,
"blockNumber": 19258222n,
"gasUsed": 63064n,
"blockNumber": 19258214n,
"gasUsed": 21000n,
"logs": [],
"status": "success",
"transactionHash": "0xd6bee0fa50e87adf00d0d3d0727aa27914aa3ca13765a108d04794f960b39289",
"transactionHash": "0x4d26e346593d9ea265bb164b115e89aa92df43b0b8778ac75d4ad28e2a22b101",
},
]
`,
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/query/getFeeHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,29 @@ test('parameters: blockTag', async () => {
}
`)
})

test('behavior: blockCount is required', async () => {
const options = getFeeHistoryQueryOptions(config, {})
expect(
options.queryFn({
queryKey: options.queryKey,
signal: new AbortSignal(),
meta: undefined,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
'[Error: blockCount is required]',
)
})

test('behavior: rewardPercentiles is required', async () => {
const options = getFeeHistoryQueryOptions(config, { blockCount: 4 })
expect(
options.queryFn({
queryKey: options.queryKey,
signal: new AbortSignal(),
meta: undefined,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
'[Error: rewardPercentiles is required]'
)
})

0 comments on commit 5013b04

Please sign in to comment.