Skip to content

Commit

Permalink
fix: always use view overrides for statcCalls (#866)
Browse files Browse the repository at this point in the history
Co-authored-by: Paco <liaoishere@gmail.com>
  • Loading branch information
krzkaczor and paco0x authored Aug 20, 2023
1 parent 64d18f7 commit 04ebda9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-lamps-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@typechain/ethers-v6": patch
---

fix: always use view overrides for statcCalls
6 changes: 4 additions & 2 deletions examples/ethers-v6-nodenext/types/ethers-contracts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export interface TypedContractMethod<
populateTransaction(
...args: ContractMethodArgs<A, S>
): Promise<ContractTransaction>;
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>;
staticCall(
...args: ContractMethodArgs<A, "view">
): Promise<DefaultReturnType<R>>;
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>;
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>;
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>;
staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
}
6 changes: 4 additions & 2 deletions examples/ethers-v6/types/ethers-contracts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export interface TypedContractMethod<
populateTransaction(
...args: ContractMethodArgs<A, S>
): Promise<ContractTransaction>;
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>;
staticCall(
...args: ContractMethodArgs<A, "view">
): Promise<DefaultReturnType<R>>;
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>;
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>;
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>;
staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
}
6 changes: 4 additions & 2 deletions packages/hardhat-test/typechain-types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export interface TypedContractMethod<
populateTransaction(
...args: ContractMethodArgs<A, S>
): Promise<ContractTransaction>;
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>;
staticCall(
...args: ContractMethodArgs<A, "view">
): Promise<DefaultReturnType<R>>;
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>;
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>;
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>;
staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export interface TypedContractMethod<
populateTransaction(
...args: ContractMethodArgs<A, S>
): Promise<ContractTransaction>;
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>;
staticCall(
...args: ContractMethodArgs<A, "view">
): Promise<DefaultReturnType<R>>;
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>;
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>;
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>;
staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
}
21 changes: 21 additions & 0 deletions packages/target-ethers-v6-test/test/Payable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { AssertTrue, IsExact } from 'test-utils'

import type { Payable } from '../types'
import type { PostfixOverrides } from '../types/common'
import { createNewBlockchain } from './common'

describe('Payable', () => {
const chain = createNewBlockchain<Payable>('Payable')

it('generate view override parameter types for staticCall', async () => {
type InputType = Parameters<typeof chain.contract.payable_func.staticCall>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<IsExact<InputType, PostfixOverrides<[], 'view'>>>
})

it('generate view override parameter types for staticCallResult', async () => {
type InputType = Parameters<typeof chain.contract.payable_func.staticCallResult>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<IsExact<InputType, PostfixOverrides<[], 'view'>>>
})
})
6 changes: 4 additions & 2 deletions packages/target-ethers-v6-test/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ export interface TypedContractMethod<
populateTransaction(
...args: ContractMethodArgs<A, S>
): Promise<ContractTransaction>;
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>;
staticCall(
...args: ContractMethodArgs<A, "view">
): Promise<DefaultReturnType<R>>;
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>;
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>;
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>;
staticCallResult(...args: ContractMethodArgs<A, "view">): Promise<R>;
}
4 changes: 2 additions & 2 deletions packages/target-ethers-v6/static/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export interface TypedContractMethod<
getFragment(...args: ContractMethodArgs<A, S>): FunctionFragment

populateTransaction(...args: ContractMethodArgs<A, S>): Promise<ContractTransaction>
staticCall(...args: ContractMethodArgs<A, S>): Promise<DefaultReturnType<R>>
staticCall(...args: ContractMethodArgs<A, 'view'>): Promise<DefaultReturnType<R>>
send(...args: ContractMethodArgs<A, S>): Promise<ContractTransactionResponse>
estimateGas(...args: ContractMethodArgs<A, S>): Promise<bigint>
staticCallResult(...args: ContractMethodArgs<A, S>): Promise<R>
staticCallResult(...args: ContractMethodArgs<A, 'view'>): Promise<R>
}

0 comments on commit 04ebda9

Please sign in to comment.