Skip to content

Commit

Permalink
Merge branch 'wevm:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-bozin-txfusion authored May 25, 2024
2 parents b909845 + 36da346 commit 65699e9
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .changeset/shaggy-onions-check.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/thin-mirrors-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Removed trailing slash from polygonAmoy explorer URL.
2 changes: 1 addition & 1 deletion site/pages/docs/ens/actions/getEnsText.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ensText = await publicClient.getEnsText({
name: normalize('wevm.eth'),
key: 'com.twitter',
})
// 'wagmi_sh'
// 'wevm_dev'
```

```ts [client.ts]
Expand Down
2 changes: 1 addition & 1 deletion site/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ viem supports all these features out-of-the-box:

Check out the following places for more wagmi-related content:

- Follow [@wagmi_sh](https://twitter.com/wagmi_sh), [@jakemoxey](https://twitter.com/jakemoxey), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
- Follow [@wevm_dev](https://twitter.com/wevm_dev), [@jakemoxey](https://twitter.com/jakemoxey), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
- Join the [discussions on GitHub](https://github.com/wevm/viem/discussions)
- [Share your project/organization](https://github.com/wevm/viem/discussions/104) that uses viem

Expand Down
8 changes: 8 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# viem

## 2.12.2

### Patch Changes

- [#2307](https://github.com/wevm/viem/pull/2307) [`15d40229ff4f0624f7edf11b9f37f9b0a135647f`](https://github.com/wevm/viem/commit/15d40229ff4f0624f7edf11b9f37f9b0a135647f) Thanks [@tmm](https://github.com/tmm)! - Fixed type inference for payable `value` property.

- [#2303](https://github.com/wevm/viem/pull/2303) [`271893feb0cf26a4fb1ad4a04a16e5186542fdce`](https://github.com/wevm/viem/commit/271893feb0cf26a4fb1ad4a04a16e5186542fdce) Thanks [@hbriese](https://github.com/hbriese)! - Fixed parsing SIWE message containing domain with port

## 2.12.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const blockNumber = await client.getBlockNumber();

Check out the following places for more viem-related content:

- Follow [@wagmi_sh](https://twitter.com/wagmi_sh), [@jakemoxey](https://twitter.com/jakemoxey), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
- Follow [@wevm_dev](https://twitter.com/wevm_dev), [@jakemoxey](https://twitter.com/jakemoxey), and [@awkweb](https://twitter.com/awkweb) on Twitter for project updates
- Join the [discussions on GitHub](https://github.com/wevm/viem/discussions)
- [Share your project/organization](https://github.com/wevm/viem/discussions/104) that uses viem

Expand Down
2 changes: 1 addition & 1 deletion src/actions/ens/getEnsText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type GetEnsTextErrorType =
* name: normalize('wevm.eth'),
* key: 'com.twitter',
* })
* // 'wagmi_sh'
* // 'wevm_dev'
*/
export async function getEnsText<TChain extends Chain | undefined>(
client: Client<Transport, TChain>,
Expand Down
30 changes: 29 additions & 1 deletion src/actions/public/simulateContract.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseAbi } from 'abitype'
import { assertType, expectTypeOf, test } from 'vitest'

import { wagmiContractConfig } from '~test/src/abis.js'
import { baycContractConfig, wagmiContractConfig } from '~test/src/abis.js'

import { anvilMainnet } from '../../../test/src/anvil.js'
import { celo } from '../../chains/definitions/celo.js'
Expand Down Expand Up @@ -67,6 +67,34 @@ test('args: account - with client account, with account arg', async () => {
}>()
})

test('args: value', () => {
// payable function
simulateContract(clientWithAccount, {
abi: baycContractConfig.abi,
address: '0x',
functionName: 'mintApe',
args: [69n],
value: 5n,
})

// payable function (undefined)
simulateContract(clientWithAccount, {
abi: baycContractConfig.abi,
address: '0x',
functionName: 'mintApe',
args: [69n],
})

// nonpayable function
simulateContract(clientWithAccount, {
abi: baycContractConfig.abi,
address: '0x',
functionName: 'approve',
// @ts-expect-error
value: 5n,
})
})

test('args: legacy txn', () => {
simulateContract(client, {
...args,
Expand Down
2 changes: 1 addition & 1 deletion src/chains/definitions/polygonAmoy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const polygonAmoy = /*#__PURE__*/ defineChain({
blockExplorers: {
default: {
name: 'PolygonScan',
url: 'https://amoy.polygonscan.com/',
url: 'https://amoy.polygonscan.com',
apiUrl: 'https://api-amoy.polygonscan.com/api',
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ export type PublicActions<
* name: normalize('wevm.eth'),
* key: 'com.twitter',
* })
* // 'wagmi_sh'
* // 'wevm_dev'
*/
getEnsText: (args: GetEnsTextParameters) => Promise<GetEnsTextReturnType>
/**
Expand Down
2 changes: 1 addition & 1 deletion src/errors/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '2.12.1'
export const version = '2.12.2'
2 changes: 1 addition & 1 deletion src/jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wevm/viem",
"version": "2.12.1",
"version": "2.12.2",
"exports": {
".": "./index.ts",
"./accounts": "./accounts/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "viem",
"description": "TypeScript Interface for Ethereum",
"version": "2.12.1",
"version": "2.12.2",
"type": "module",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down
11 changes: 6 additions & 5 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
IsNarrowable,
IsUnion,
MaybeRequired,
NoUndefined,
NoInfer,
Prettify,
UnionToTuple,
} from './utils.js'
Expand Down Expand Up @@ -210,6 +210,7 @@ export type ContractFunctionParameters<
| (functionName extends allFunctionNames ? functionName : never) // infer value
args?: (abi extends Abi ? UnionWiden<args> : never) | allArgs | undefined
} & (readonly [] extends allArgs ? {} : { args: Widen<args> }) &
// TODO: Remove `GetValue` from here (should be applied to top-level type as separate utility)
GetValue<abi, functionName>

export type ContractFunctionReturnType<
Expand Down Expand Up @@ -309,11 +310,11 @@ export type GetValue<
_Narrowable extends boolean = IsNarrowable<TAbi, Abi>,
> = _Narrowable extends true
? TAbiFunction['stateMutability'] extends 'payable'
? { value?: NoUndefined<TValueType> | undefined }
? { value?: NoInfer<TValueType> | undefined }
: TAbiFunction['payable'] extends true
? { value?: NoUndefined<TValueType> | undefined }
: { value?: never | undefined }
: { value?: TValueType | undefined }
? { value?: NoInfer<TValueType> | undefined }
: { value?: undefined }
: { value?: NoInfer<TValueType> | undefined }

//////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
3 changes: 3 additions & 0 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export type NeverBy<T, K extends keyof T> = {
[U in keyof T]: U extends K ? never : T[U]
}

// TODO: Remove when peer dep `typescript@>=4.5` (NoInfer is native)
export type NoInfer<type> = [type][type extends any ? 0 : never]

/**
* @description Constructs a type by excluding `undefined` from `T`.
*
Expand Down
84 changes: 84 additions & 0 deletions src/utils/signature/verifyTypedData.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { Address } from 'abitype'
import { expect, test } from 'vitest'

import { accounts, typedData } from '~test/src/constants.js'

import { anvilMainnet } from '../../../test/src/anvil.js'
import { signTypedData } from '../../actions/index.js'
import { verifyTypedData } from './verifyTypedData.js'

const client = anvilMainnet.getClient()

test('default', async () => {
expect(
await verifyTypedData({
Expand All @@ -25,3 +30,82 @@ test('default', async () => {
}),
).toBeTruthy()
})

test('https://github.com/wevm/viem/issues/2306', async () => {
const typedData = (address: Address) =>
({
types: {
WalletData: [{ name: 'address', type: 'address' }],
},
message: {
address,
},
primaryType: 'WalletData',
}) as const

const address = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
const nonChecksumAddress = address.toLowerCase() as `0x${string}`
const invalidChecksumAddress = address.replace('f', 'F') as `0x${string}`

// ✅ Successfully signs with valid checksum address.
const signature = await signTypedData(client, {
...typedData(address),
account: address,
})

// ✅ Successfully signs with non-checksum address.
const signature_2 = await signTypedData(client, {
...typedData(nonChecksumAddress),
account: nonChecksumAddress,
})
expect(signature_2).toEqual(signature)

// ❌ Throws when invalid checksum address provided.
await expect(() =>
signTypedData(client, {
...typedData(invalidChecksumAddress),
account: invalidChecksumAddress,
}),
).rejects.toMatchInlineSnapshot(`
[InvalidAddressError: Address "0xF39Fd6e51aad88F6F4ce6aB8827279cffFb92266" is invalid.
- Address must be a hex value of 20 bytes (40 hex characters).
- Address must match its checksum counterpart.
Version: [email protected]]
`)

// ✅ Successfully verifies with valid checksum address.
expect(
await verifyTypedData({
...typedData(address),
signature,
address: address,
}),
).toBeTruthy()

// ✅ Successfully verifies with non-checksum address.
expect(
await verifyTypedData({
...typedData(nonChecksumAddress),
signature,
address: nonChecksumAddress,
}),
).toBeTruthy()

// ❌ Throws when invalid checksum address provided.
await expect(() =>
verifyTypedData({
...typedData(invalidChecksumAddress),
signature,
address: invalidChecksumAddress,
}),
).rejects.toMatchInlineSnapshot(`
[InvalidAddressError: Address "0xF39Fd6e51aad88F6F4ce6aB8827279cffFb92266" is invalid.
- Address must be a hex value of 20 bytes (40 hex characters).
- Address must match its checksum counterpart.
Version: [email protected]]
`)
})
2 changes: 1 addition & 1 deletion src/utils/siwe/parseSiweMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Chain ID: 1
Nonce: foobarbaz
Issued At: 2023-02-01T00:00:00.000Z`
const parsed = parseSiweMessage(message)
expect(parsed.domain).toMatchInlineSnapshot('example.com:8080')
expect(parsed.domain).toMatchInlineSnapshot(`"example.com:8080"`)
})

test('behavior: with statement', () => {
Expand Down

0 comments on commit 65699e9

Please sign in to comment.