Skip to content

Commit ca3ef24

Browse files
committed
extract intention from validator test
1 parent c4cfebe commit ca3ef24

File tree

2 files changed

+59
-50
lines changed

2 files changed

+59
-50
lines changed

test/helpers/testFixtures.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Shared test data and constants used across test suites.
88
*/
99

10+
import type { Intention } from '../../src/types/core.js'
11+
1012
/**
1113
* Sample vault ID for testing (valid 32-byte hex string with 0x prefix).
1214
*/
@@ -97,3 +99,58 @@ export const TOKEN = '0x1111111111111111111111111111111111111111'
9799
* Zero address (ETH address).
98100
*/
99101
export const ZERO = '0x0000000000000000000000000000000000000000'
102+
103+
/**
104+
* Creates a mock valid intention object for testing.
105+
* Returns a new intention object each time it's called with a fresh expiry timestamp.
106+
*/
107+
export const createMockValidIntention = (): Intention => ({
108+
action: 'Swap 1,000 USDC for 0.3 WETH with .016 WETH in fees',
109+
nonce: 1,
110+
expiry: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour
111+
inputs: [
112+
{
113+
asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
114+
amount: '1000.0',
115+
chain_id: 1,
116+
},
117+
],
118+
outputs: [
119+
{
120+
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
121+
amount: '0.3',
122+
to_external: '0xDB473D9716ac61dc4D4aeA6e4d691239DB84C77D',
123+
chain_id: 1,
124+
},
125+
],
126+
totalFee: [
127+
{
128+
asset: ['WETH'],
129+
amount: '0.016',
130+
},
131+
],
132+
proposerTip: [
133+
{
134+
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
135+
amount: '0.01',
136+
to: 123, // Some vault ID
137+
chain_id: 1,
138+
},
139+
],
140+
agentTip: [
141+
{
142+
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
143+
amount: '0.005',
144+
to: 456, // Some other vault ID
145+
chain_id: 1,
146+
},
147+
],
148+
protocolFee: [
149+
{
150+
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
151+
amount: '0.001',
152+
to: 0, // Oya vault ID
153+
chain_id: 1,
154+
},
155+
],
156+
})

test/validator.test.ts

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,11 @@ import {
2020
ValidationError,
2121
} from '../src/utils/validator.js'
2222
import type { Intention } from '../src/types/core.js'
23+
import { createMockValidIntention } from './helpers/testFixtures.js'
2324

2425
// --- MOCK DATA FOR TESTS ---
2526

26-
const mockValidIntention: Intention = {
27-
action: 'Swap 1,000 USDC for 0.3 WETH with .016 WETH in fees',
28-
nonce: 1,
29-
expiry: Math.floor(Date.now() / 1000) + 3600, // Expires in 1 hour
30-
inputs: [
31-
{
32-
asset: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
33-
amount: '1000.0',
34-
chain_id: 1,
35-
},
36-
],
37-
outputs: [
38-
{
39-
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
40-
amount: '0.3',
41-
to_external: '0xDB473D9716ac61dc4D4aeA6e4d691239DB84C77D',
42-
chain_id: 1,
43-
},
44-
],
45-
totalFee: [
46-
{
47-
asset: ['WETH'],
48-
amount: '0.016',
49-
},
50-
],
51-
proposerTip: [
52-
{
53-
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
54-
amount: '0.01',
55-
to: 123, // Some vault ID
56-
chain_id: 1,
57-
},
58-
],
59-
agentTip: [
60-
{
61-
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
62-
amount: '0.005',
63-
to: 456, // Some other vault ID
64-
chain_id: 1,
65-
},
66-
],
67-
protocolFee: [
68-
{
69-
asset: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
70-
amount: '0.001',
71-
to: 0, // Oya vault ID
72-
chain_id: 1,
73-
},
74-
],
75-
}
27+
const mockValidIntention: Intention = createMockValidIntention()
7628

7729
// --- TEST SUITES ---
7830

0 commit comments

Comments
 (0)