import { expectTypeOf, test } from 'vp/test' import type { AbiParameter } from 'abitype' import type { ParseAbiParameter } from './parseAbiParameter.js' import { parseAbiParameter } from './parseAbiParameter.js' test('ParseAbiParameter', () => { expectTypeOf>().toEqualTypeOf() expectTypeOf>().toEqualTypeOf() expectTypeOf< ParseAbiParameter<['struct Foo { string name; }']> >().toEqualTypeOf() // string expectTypeOf>().toEqualTypeOf<{ readonly type: 'address' readonly name: 'from' }>() expectTypeOf>().toEqualTypeOf<{ readonly type: 'address' readonly name: 'from' readonly indexed: true }>() expectTypeOf>().toEqualTypeOf<{ readonly type: 'address' readonly name: 'foo' }>() // Array expectTypeOf< ParseAbiParameter<['Foo', 'struct Foo { string name; }']> >().toEqualTypeOf<{ readonly type: 'tuple' readonly components: readonly [ { readonly name: 'name' readonly type: 'string' }, ] }>() expectTypeOf>().toEqualTypeOf<{ readonly type: 'tuple' readonly components: readonly [ { readonly type: 'string' readonly name: 'bar' }, ] readonly name: 'foo' }>() }) test('parseAbiParameter', () => { // @ts-expect-error empty array not allowed expectTypeOf(parseAbiParameter([])).toEqualTypeOf() expectTypeOf( parseAbiParameter(['struct Foo { string name; }']), ).toEqualTypeOf() expectTypeOf(parseAbiParameter('(string)')).toEqualTypeOf<{ readonly type: 'tuple' readonly components: readonly [{ readonly type: 'string' }] }>() const param: string = 'address' expectTypeOf(parseAbiParameter(param)).toEqualTypeOf() })