Skip to content

Commit 210fa9f

Browse files
committed
fix: run formatter
1 parent d8051de commit 210fa9f

13 files changed

Lines changed: 112 additions & 106 deletions

src/__tests__/contract-state.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { describe, it, expect } from 'vitest'
2-
import {
3-
decodeContractStateToBase64,
4-
parseStateNumber,
5-
parseStateString
6-
} from '../contract-state'
2+
import { decodeContractStateToBase64, parseStateNumber, parseStateString } from '../contract-state'
73
import { encode } from '../serialization'
84

95
describe('Contract State Utilities', () => {

src/__tests__/contract.test.ts

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ describe('createContract', () => {
151151
expect(unsignedTx).toHaveProperty('hash')
152152
expect(unsignedTx.tx.action.contract).toBe('LockupPrime')
153153
expect(unsignedTx.tx.action.function).toBe('lock')
154-
expect(unsignedTx.tx.action.args).toEqual([
155-
toAtomicAma(50).toString(),
156-
'7d'
157-
])
154+
expect(unsignedTx.tx.action.args).toEqual([toAtomicAma(50).toString(), '7d'])
158155
})
159156

160157
it('buildAndSignCall builds and signs from ContractCall', () => {
@@ -339,9 +336,9 @@ describe('createContract', () => {
339336
// Both produce valid output (nonces differ due to timestamp, but structure is same)
340337
expect(viaSignCall.txHash).toBeTypeOf('string')
341338
expect(viaSigned.txHash).toBeTypeOf('string')
342-
expect(
343-
Math.abs(viaSignCall.txPacked.length - viaSigned.txPacked.length)
344-
).toBeLessThan(5)
339+
expect(Math.abs(viaSignCall.txPacked.length - viaSigned.txPacked.length)).toBeLessThan(
340+
5
341+
)
345342
})
346343

347344
it('builder.contract(ABI).lock() produces same size as builder.lockupPrimeLock()', () => {
@@ -355,9 +352,9 @@ describe('createContract', () => {
355352

356353
expect(viaContract.txHash).toBeTypeOf('string')
357354
expect(viaBuiltIn.txHash).toBeTypeOf('string')
358-
expect(
359-
Math.abs(viaContract.txPacked.length - viaBuiltIn.txPacked.length)
360-
).toBeLessThan(5)
355+
expect(Math.abs(viaContract.txPacked.length - viaBuiltIn.txPacked.length)).toBeLessThan(
356+
5
357+
)
361358
})
362359
})
363360

@@ -387,7 +384,9 @@ describe('createContract', () => {
387384

388385
it('throws on empty contractName', () => {
389386
// @ts-expect-error — testing runtime validation
390-
expect(() => createContract({ contractName: '', abi: [] })).toThrow(/missing or empty "contractName"/)
387+
expect(() => createContract({ contractName: '', abi: [] })).toThrow(
388+
/missing or empty "contractName"/
389+
)
391390
})
392391

393392
it('throws on missing abi array', () => {
@@ -397,44 +396,64 @@ describe('createContract', () => {
397396

398397
it('throws on non-array abi', () => {
399398
// @ts-expect-error — testing runtime validation
400-
expect(() => createContract({ contractName: 'Test', abi: 'bad' })).toThrow(/"abi" must be an array/)
399+
expect(() => createContract({ contractName: 'Test', abi: 'bad' })).toThrow(
400+
/"abi" must be an array/
401+
)
401402
})
402403

403404
it('throws on function entry with wrong type', () => {
404-
expect(() => createContract({
405-
contractName: 'Test',
406-
abi: [
407-
// @ts-expect-error — testing runtime validation
408-
{ type: 'event', name: 'foo', inputs: [], outputs: [], stateMutability: 'view' }
409-
]
410-
})).toThrow(/has type "event", expected "function"/)
405+
expect(() =>
406+
createContract({
407+
contractName: 'Test',
408+
abi: [
409+
// @ts-expect-error — testing runtime validation
410+
{
411+
type: 'event',
412+
name: 'foo',
413+
inputs: [],
414+
outputs: [],
415+
stateMutability: 'view'
416+
}
417+
]
418+
})
419+
).toThrow(/has type "event", expected "function"/)
411420
})
412421

413422
it('throws on function entry missing name', () => {
414-
expect(() => createContract({
415-
contractName: 'Test',
416-
abi: [
417-
// @ts-expect-error — testing runtime validation
418-
{ type: 'function', inputs: [], outputs: [], stateMutability: 'view' }
419-
]
420-
})).toThrow(/missing "name"/)
423+
expect(() =>
424+
createContract({
425+
contractName: 'Test',
426+
abi: [
427+
// @ts-expect-error — testing runtime validation
428+
{ type: 'function', inputs: [], outputs: [], stateMutability: 'view' }
429+
]
430+
})
431+
).toThrow(/missing "name"/)
421432
})
422433

423434
it('throws on function entry missing inputs', () => {
424-
expect(() => createContract({
425-
contractName: 'Test',
426-
abi: [
427-
// @ts-expect-error — testing runtime validation
428-
{ type: 'function', name: 'foo', outputs: [], stateMutability: 'view' }
429-
]
430-
})).toThrow(/missing "inputs" array/)
435+
expect(() =>
436+
createContract({
437+
contractName: 'Test',
438+
abi: [
439+
// @ts-expect-error — testing runtime validation
440+
{ type: 'function', name: 'foo', outputs: [], stateMutability: 'view' }
441+
]
442+
})
443+
).toThrow(/missing "inputs" array/)
431444
})
432445

433446
it('accepts valid minimal ABI', () => {
434447
const contract = createContract({
435448
contractName: 'Minimal',
436449
abi: [
437-
{ type: 'function', name: 'ping', inputs: [], outputs: [], stateMutability: 'nonpayable' }
450+
{
451+
type: 'function',
452+
name: 'ping',
453+
inputs: [],
454+
outputs: [],
455+
stateMutability: 'nonpayable'
456+
}
438457
]
439458
} as const)
440459

src/__tests__/lockup.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ describe('Lockup Contract', () => {
4545
})
4646

4747
it('buildArgs throws for missing parameter', () => {
48-
expect(() => Lockup.buildArgs('unlock', {})).toThrow(
49-
'Missing parameter: vaultIndex'
50-
)
48+
expect(() => Lockup.buildArgs('unlock', {})).toThrow('Missing parameter: vaultIndex')
5149
})
5250

5351
it('getContractName returns correct name', () => {

src/__tests__/serialization.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ describe('Serialization (VecPack)', () => {
216216
const txKey = new TextEncoder().encode('tx')
217217
let txMap: Map<DecodedValue, DecodedValue> | undefined
218218
for (const [k, v] of decoded.entries()) {
219-
if (k instanceof Uint8Array && k.length === txKey.length && k.every((b, i) => b === txKey[i])) {
219+
if (
220+
k instanceof Uint8Array &&
221+
k.length === txKey.length &&
222+
k.every((b, i) => b === txKey[i])
223+
) {
220224
txMap = v as Map<DecodedValue, DecodedValue>
221225
break
222226
}
@@ -226,7 +230,11 @@ describe('Serialization (VecPack)', () => {
226230
const nonceKey = new TextEncoder().encode('nonce')
227231
let decodedNonce: bigint | undefined
228232
for (const [k, v] of txMap!.entries()) {
229-
if (k instanceof Uint8Array && k.length === nonceKey.length && k.every((b, i) => b === nonceKey[i])) {
233+
if (
234+
k instanceof Uint8Array &&
235+
k.length === nonceKey.length &&
236+
k.every((b, i) => b === nonceKey[i])
237+
) {
230238
decodedNonce = v as bigint
231239
break
232240
}
@@ -289,9 +297,7 @@ describe('Serialization (VecPack)', () => {
289297

290298
it('throws for non-binary map values', () => {
291299
// Integer values decode to bigint, not Uint8Array
292-
const map = new Map<SerializableValue, SerializableValue>([
293-
[new Uint8Array([1]), 42]
294-
])
300+
const map = new Map<SerializableValue, SerializableValue>([[new Uint8Array([1]), 42]])
295301
const encoded = encode(map)
296302
expect(() => decodeContractState(encoded)).toThrow('Expected Uint8Array')
297303
})

src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,3 @@ export const NODE_API_URL = 'https://mainnet-rpc.ama.one/api'
5353
* Default request timeout in milliseconds
5454
*/
5555
export const DEFAULT_TIMEOUT = 30000
56-

src/contract-state.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ export function decodeContractStateToBase64(
5454
* parseStateNumber(null) // 0
5555
* ```
5656
*/
57-
export function parseStateNumber(
58-
value: string | number | Uint8Array | null | undefined
59-
): number {
57+
export function parseStateNumber(value: string | number | Uint8Array | null | undefined): number {
6058
if (value === null || value === undefined) return 0
6159
if (typeof value === 'number') return Number.isInteger(value) && value >= 0 ? value : 0
6260
if (typeof value === 'string') {

src/contracts/abi-types.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ export type ExtractFunctionNames<T extends AbiDefinition> = T['abi'][number]['na
7070
/**
7171
* Find a specific function entry in the ABI by name
7272
*/
73-
type FindFunction<
74-
TAbi extends AbiDefinition,
75-
TFn extends string
76-
> = Extract<TAbi['abi'][number], { readonly name: TFn }>
73+
type FindFunction<TAbi extends AbiDefinition, TFn extends string> = Extract<
74+
TAbi['abi'][number],
75+
{ readonly name: TFn }
76+
>
7777

7878
/**
7979
* Extract the inputs array for a specific function
8080
*/
81-
type FunctionInputs<
82-
TAbi extends AbiDefinition,
83-
TFn extends string
84-
> = FindFunction<TAbi, TFn>['inputs']
81+
type FunctionInputs<TAbi extends AbiDefinition, TFn extends string> = FindFunction<
82+
TAbi,
83+
TFn
84+
>['inputs']
8585

8686
/**
8787
* Map an inputs tuple to a params object `{ inputName: string }`
@@ -92,9 +92,6 @@ type FunctionInputs<
9292
* // => { amount: string; tier: string }
9393
* ```
9494
*/
95-
export type FunctionParams<
96-
TAbi extends AbiDefinition,
97-
TFn extends string
98-
> = {
95+
export type FunctionParams<TAbi extends AbiDefinition, TFn extends string> = {
9996
[K in FunctionInputs<TAbi, TFn>[number] as K['name']]: string
10097
}

src/contracts/coin.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ export function buildCoinTransfer(params: CoinTransferParams): ContractCall {
4747
return {
4848
contract: 'Coin',
4949
method: 'transfer',
50-
args: [
51-
fromBase58(params.recipient),
52-
toAtomicAma(params.amount).toString(),
53-
params.symbol
54-
]
50+
args: [fromBase58(params.recipient), toAtomicAma(params.amount).toString(), params.symbol]
5551
}
5652
}

src/contracts/contract-call.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
*/
77

88
import type { SerializableValue } from '../types'
9-
import type { AbiDefinition, ExtractContractName, ExtractFunctionNames, FunctionParams } from './abi-types'
9+
import type {
10+
AbiDefinition,
11+
ExtractContractName,
12+
ExtractFunctionNames,
13+
FunctionParams
14+
} from './abi-types'
1015

1116
/**
1217
* A fully-resolved contract call ready for TransactionBuilder.
@@ -61,9 +66,7 @@ export function buildContractCall<
6166
): ContractCall<TAbi, TFn & string> {
6267
const fn = abi.abi.find((f) => f.name === functionName)
6368
if (!fn) {
64-
throw new Error(
65-
`Function "${String(functionName)}" not found in ${abi.contractName} ABI`
66-
)
69+
throw new Error(`Function "${String(functionName)}" not found in ${abi.contractName} ABI`)
6770
}
6871

6972
const args: SerializableValue[] = []
@@ -79,7 +82,7 @@ export function buildContractCall<
7982
if (!input.enum.includes(value)) {
8083
throw new Error(
8184
`Invalid value "${value}" for parameter "${input.name}". ` +
82-
`Expected one of: ${input.enum.join(', ')}`
85+
`Expected one of: ${input.enum.join(', ')}`
8386
)
8487
}
8588
}

src/contracts/contract.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ export function createContract<TAbi extends AbiDefinition>(abi: TAbi): TypedCont
163163

164164
for (const fn of abi.abi) {
165165
contract[fn.name] = (params?: Record<string, string>) => {
166-
return buildContractCall(
167-
abi,
168-
fn.name as never,
169-
(params ?? {}) as never
170-
)
166+
return buildContractCall(abi, fn.name as never, (params ?? {}) as never)
171167
}
172168
}
173169

@@ -188,11 +184,7 @@ function createSignedContract<TAbi extends AbiDefinition>(
188184

189185
for (const fn of abi.abi) {
190186
contract[fn.name] = (params?: Record<string, string>) => {
191-
const call = buildContractCall(
192-
abi,
193-
fn.name as never,
194-
(params ?? {}) as never
195-
)
187+
const call = buildContractCall(abi, fn.name as never, (params ?? {}) as never)
196188
return signContractCall(privateKey, call)
197189
}
198190
}

0 commit comments

Comments
 (0)