Skip to content

Commit

Permalink
chore: add error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jun 15, 2024
1 parent fa935d8 commit abbe550
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/actions/public/call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,32 @@ describe('errors', () => {
`)
})
})

test('pass code and factory', async () => {
await expect(
call(client, {
code: wagmiContractConfig.bytecode,
factory: wagmiContractConfig.address,
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[ViemError: Cannot provide both \`code\` & \`factory\`/\`factoryData\` as parameters.
Version: viem@x.y.z]
`)
})

test('pass code and to', async () => {
await expect(
call(client, {
code: wagmiContractConfig.bytecode,
to: '0x0000000000000000000000000000000000000000',
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
[ViemError: Cannot provide both \`code\` & \`to\` as parameters.
Version: viem@x.y.z]
`)
})
})

describe('batch call', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ export async function call<TChain extends Chain | undefined>(
} = args
const account = account_ ? parseAccount(account_) : undefined

if (code && (factory || factoryData))
throw new BaseError(
'Cannot provide both `code` & `factory`/`factoryData` as parameters.',
)
if (code && to)
throw new BaseError('Cannot provide both `code` & `to` as parameters.')

// Check if the call is deployless via bytecode.
const deploylessCallViaBytecode = code && data_
// Check if the call is deployless via a factory.
Expand Down

0 comments on commit abbe550

Please sign in to comment.