From 872c3a0bc99c8fe51e94c51b20d3208e8782933a Mon Sep 17 00:00:00 2001 From: Damian Kuthoore Date: Mon, 3 Nov 2025 15:43:25 -0500 Subject: [PATCH 1/3] extract constants from deposits test into fixtures file --- test/helpers/testFixtures.ts | 25 +++++++++++++++++++++++++ test/integration/deposits.db.test.ts | 7 +------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/test/helpers/testFixtures.ts b/test/helpers/testFixtures.ts index f811bd6..04ec9ba 100644 --- a/test/helpers/testFixtures.ts +++ b/test/helpers/testFixtures.ts @@ -72,3 +72,28 @@ export const SAMPLE_INTENTION = { vaultId: TEST_VAULT_ID, signature: '0x' + '0'.repeat(130), // Dummy signature } + +/** + * Test transaction hash for deposits tests. + */ +export const TEST_TX = '0xtest-deposit-tx' + +/** + * Generate test UID for deposits tests. + */ +export const TEST_UID = (n: number) => `${TEST_TX}:${n}` + +/** + * Controller address for deposits tests. + */ +export const CTRL = '0xCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCc' + +/** + * Token address for deposits tests. + */ +export const TOKEN = '0x1111111111111111111111111111111111111111' + +/** + * Zero address (ETH address). + */ +export const ZERO = '0x0000000000000000000000000000000000000000' diff --git a/test/integration/deposits.db.test.ts b/test/integration/deposits.db.test.ts index d7789e9..dc48a49 100644 --- a/test/integration/deposits.db.test.ts +++ b/test/integration/deposits.db.test.ts @@ -17,12 +17,7 @@ import { findDepositWithSufficientRemaining, createAssignmentEventTransactional, } from '../../src/utils/deposits.js' - -const TEST_TX = '0xtest-deposit-tx' -const TEST_UID = (n: number) => `${TEST_TX}:${n}` -const CTRL = '0xCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCcCc' -const TOKEN = '0x1111111111111111111111111111111111111111' -const ZERO = '0x0000000000000000000000000000000000000000' +import { TEST_TX, TEST_UID, CTRL, TOKEN, ZERO } from '../helpers/testFixtures.js' beforeAll(async () => { await pool.query('DELETE FROM deposits WHERE tx_hash = $1', [TEST_TX]) From c4cfebe9dac401aadb60428fcbec370ef82c1cf7 Mon Sep 17 00:00:00 2001 From: Damian Kuthoore Date: Mon, 3 Nov 2025 15:44:35 -0500 Subject: [PATCH 2/3] format fix --- test/integration/deposits.db.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integration/deposits.db.test.ts b/test/integration/deposits.db.test.ts index dc48a49..8f2db84 100644 --- a/test/integration/deposits.db.test.ts +++ b/test/integration/deposits.db.test.ts @@ -17,7 +17,13 @@ import { findDepositWithSufficientRemaining, createAssignmentEventTransactional, } from '../../src/utils/deposits.js' -import { TEST_TX, TEST_UID, CTRL, TOKEN, ZERO } from '../helpers/testFixtures.js' +import { + TEST_TX, + TEST_UID, + CTRL, + TOKEN, + ZERO, +} from '../helpers/testFixtures.js' beforeAll(async () => { await pool.query('DELETE FROM deposits WHERE tx_hash = $1', [TEST_TX]) From ca3ef24a5156605700c27cbacb21fa5e1279f16a Mon Sep 17 00:00:00 2001 From: Damian Kuthoore Date: Mon, 3 Nov 2025 15:48:10 -0500 Subject: [PATCH 3/3] extract intention from validator test --- test/helpers/testFixtures.ts | 57 ++++++++++++++++++++++++++++++++++++ test/validator.test.ts | 52 ++------------------------------ 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/test/helpers/testFixtures.ts b/test/helpers/testFixtures.ts index 04ec9ba..41f67bb 100644 --- a/test/helpers/testFixtures.ts +++ b/test/helpers/testFixtures.ts @@ -7,6 +7,8 @@ * Shared test data and constants used across test suites. */ +import type { Intention } from '../../src/types/core.js' + /** * Sample vault ID for testing (valid 32-byte hex string with 0x prefix). */ @@ -97,3 +99,58 @@ export const TOKEN = '0x1111111111111111111111111111111111111111' * Zero address (ETH address). */ export const ZERO = '0x0000000000000000000000000000000000000000' + +/** + * Creates a mock valid intention object for testing. + * Returns a new intention object each time it's called with a fresh expiry timestamp. + */ +export const createMockValidIntention = (): Intention => ({ + action: 'Swap 1,000 USDC for 0.3 WETH with .016 WETH in fees', + nonce: 1, + expiry: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour + inputs: [ + { + asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC + amount: '1000.0', + chain_id: 1, + }, + ], + outputs: [ + { + asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH + amount: '0.3', + to_external: '0xDB473D9716ac61dc4D4aeA6e4d691239DB84C77D', + chain_id: 1, + }, + ], + totalFee: [ + { + asset: ['WETH'], + amount: '0.016', + }, + ], + proposerTip: [ + { + asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH + amount: '0.01', + to: 123, // Some vault ID + chain_id: 1, + }, + ], + agentTip: [ + { + asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH + amount: '0.005', + to: 456, // Some other vault ID + chain_id: 1, + }, + ], + protocolFee: [ + { + asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH + amount: '0.001', + to: 0, // Oya vault ID + chain_id: 1, + }, + ], +}) diff --git a/test/validator.test.ts b/test/validator.test.ts index 3c65fb0..c661591 100644 --- a/test/validator.test.ts +++ b/test/validator.test.ts @@ -20,59 +20,11 @@ import { ValidationError, } from '../src/utils/validator.js' import type { Intention } from '../src/types/core.js' +import { createMockValidIntention } from './helpers/testFixtures.js' // --- MOCK DATA FOR TESTS --- -const mockValidIntention: Intention = { - action: 'Swap 1,000 USDC for 0.3 WETH with .016 WETH in fees', - nonce: 1, - expiry: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour - inputs: [ - { - asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC - amount: '1000.0', - chain_id: 1, - }, - ], - outputs: [ - { - asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH - amount: '0.3', - to_external: '0xDB473D9716ac61dc4D4aeA6e4d691239DB84C77D', - chain_id: 1, - }, - ], - totalFee: [ - { - asset: ['WETH'], - amount: '0.016', - }, - ], - proposerTip: [ - { - asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH - amount: '0.01', - to: 123, // Some vault ID - chain_id: 1, - }, - ], - agentTip: [ - { - asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH - amount: '0.005', - to: 456, // Some other vault ID - chain_id: 1, - }, - ], - protocolFee: [ - { - asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH - amount: '0.001', - to: 0, // Oya vault ID - chain_id: 1, - }, - ], -} +const mockValidIntention: Intention = createMockValidIntention() // --- TEST SUITES ---