import { expect, test } from 'vitest' import * as Signer from './Signer.js' const intent = { boostRewards: true, domain: { chainId: 4217, earnShare: '0x0000000000000000000000000000000000000002', earnVault: '0x0000000000000000000000000000000000000001', factory: '0x0000000000000000000000000000000000000003', treasury: '0x0000000000000000000000000000000000000004', }, operation: 'deploy', targetYield: false, treasury: '0x0000000000000000000000000000000000000004', } as const test('id deterministically binds the complete typed intent', () => { expect(Signer.id(intent)).toBe(Signer.id({ ...intent })) expect(Signer.id({ ...intent, boostRewards: false })).not.toBe(Signer.id(intent)) }) test('id normalizes address casing before hashing', () => { const mixedCase = { ...intent, domain: { ...intent.domain, earnVault: '0xD730394F3Bb85A4828E35fc5e361DCC9F894fa4F', }, } as const const normalized = Signer.schema.Intent.parse(mixedCase) expect(Signer.id(mixedCase)).toBe(Signer.id(normalized)) }) test('uses the deployed single-funder controller path', () => { expect([Signer.targetYieldFunction(1), Signer.targetYieldFunction(2)]).toStrictEqual([ 'fund', 'fundBatchExact', ]) expect(() => Signer.targetYieldFunction(0)).toThrow('at least one funder') }) test('schema accepts at most two gas-bounded payout calls per transaction', () => { const payout = { batches: [ { cumulativeAmounts: ['1'], multiproof: [], proofFlags: [], recipients: [intent.domain.earnVault], }, { cumulativeAmounts: ['2'], multiproof: [], proofFlags: [], recipients: [intent.domain.earnShare], }, ], distributor: intent.domain.earnShare, domain: intent.domain, operation: 'push', rootVersion: '1', statementHash: `0x${'11'.repeat(32)}`, } const request = { attemptId: 'rat_000000000000000000000000', id: `0x${'22'.repeat(32)}`, intent: payout, } expect([ Signer.schema.Request.safeParse(request).success, Signer.schema.Request.safeParse({ ...request, intent: { ...payout, batches: [...payout.batches, payout.batches[0]!] }, }).success, ]).toStrictEqual([true, false]) })