Skip to content

Commit

Permalink
test: add extended client action test case (#2675)
Browse files Browse the repository at this point in the history
test: client action composition
  • Loading branch information
holic authored Aug 31, 2024
1 parent 962d369 commit b261491
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/clients/createClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { assertType, describe, expect, test, vi } from 'vitest'

import { anvilMainnet } from '../../test/src/anvil.js'
import { getChainId } from '../actions/public/getChainId.js'
import { localhost, mainnet } from '../chains/index.js'
import type { EIP1193RequestFn, EIP1474Methods } from '../types/eip1193.js'
import { getAction } from '../utils/getAction.js'
import { createClient } from './createClient.js'
import { publicActions } from './decorators/public.js'
import { createTransport } from './transports/createTransport.js'
Expand Down Expand Up @@ -573,4 +575,33 @@ describe('extends', () => {
expect(extended.chain.id).toEqual(client.chain.id)
})
})

test('action composition', async () => {
const calls: string[] = []
const extended = createClient({
chain: localhost,
transport: http(),
})
.extend((client) => ({
async getChainId() {
calls.push('first')
return getAction(client, getChainId, 'getChainId')({})
},
}))
.extend((client) => ({
async getChainId() {
calls.push('second')
return getAction(client, getChainId, 'getChainId')({})
},
}))
.extend((client) => ({
async getChainId() {
calls.push('third')
return getAction(client, getChainId, 'getChainId')({})
},
}))

expect(await extended.getChainId()).toBe(localhost.id)
expect(calls).toEqual(['third', 'second', 'first'])
})
})

0 comments on commit b261491

Please sign in to comment.