diff --git a/src/clients/createClient.test.ts b/src/clients/createClient.test.ts index 5dfcbe4c0c..274dfae2d8 100644 --- a/src/clients/createClient.test.ts +++ b/src/clients/createClient.test.ts @@ -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' @@ -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']) + }) })