@mimicprotocol/test-ts 0.0.1-rc.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ <h1 align="center">
2
+ <a href="https://mimic.fi"><img src="https://www.mimic.fi/logo.png" alt="Mimic Protocol" width="200"></a>
3
+ </h1>
4
+
5
+ <h4 align="center">Blockchain automation protocol</h4>
6
+
7
+ <p align="center">
8
+ <a href="https://github.com/mimic-protocol/tooling/actions/workflows/ci.yml">
9
+ <img src="https://github.com/mimic-protocol/tooling/actions/workflows/ci.yml/badge.svg" alt="Build">
10
+ </a>
11
+ <a href="https://discord.mimic.fi">
12
+ <img alt="Discord" src="https://img.shields.io/discord/989984112397922325">
13
+ </a>
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="#content">Content</a> •
18
+ <a href="#setup">Setup</a> •
19
+ <a href="#usage">Usage</a> •
20
+ <a href="#security">Security</a> •
21
+ <a href="#license">License</a>
22
+ </p>
23
+
24
+ ---
25
+
26
+ ## Content
27
+
28
+ This package provides tooling and helpers to write and run tests for Mimic Protocol tasks using TypeScript. It includes:
29
+
30
+ - Mocking of inputs, balances, prices, contract calls responses, and context variables
31
+ - Simulated task execution with mocked environment
32
+ - Structured task outputs to assert emitted intents using frameworks like Mocha and Chai
33
+
34
+ ## Setup
35
+
36
+ To set up this project you'll need [git](https://git-scm.com) and [yarn](https://classic.yarnpkg.com) installed.
37
+
38
+ Install the library from the root of the monorepo:
39
+
40
+ ```bash
41
+ # Clone this repository
42
+ $ git clone https://github.com/mimic-protocol/tooling
43
+
44
+ # Go into the repository
45
+ $ cd tooling
46
+
47
+ # Install dependencies
48
+ $ yarn
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ Here’s an example of how to test a Mimic task:
54
+
55
+ ```ts
56
+ import { runTask } from '@mimicprotocol/test-ts'
57
+ import { expect } from 'chai'
58
+
59
+ const taskDir = './my-task'
60
+ const context = { user: '0x...', settler: '0x...', timestamp: Date.now() }
61
+ const inputs = { token: '0x...', amount: '10000000' }
62
+
63
+ const intents = await runTask(taskDir, context, { inputs })
64
+
65
+ expect(intents).to.be.an('array').that.is.not.empty
66
+ expect(intents).to.have.lengthOf(1)
67
+
68
+ expect(intents[0].type).to.be.equal('transfer')
69
+ expect(intents[0].settler).to.be.equal(context.settler)
70
+
71
+ expect(intents[0].transfers).to.have.lengthOf(1)
72
+ expect(intents[0].transfers[0].token).to.be.equal(inputs.token)
73
+ expect(intents[0].transfers[0].amount).to.be.equal(inputs.amount)
74
+ ```
75
+
76
+ For full task testing guide and examples please visit [docs.mimic.fi](https://docs.mimic.fi/)
77
+
78
+ ## Security
79
+
80
+ To read more about our auditing and related security processes please refer to the [security section](https://docs.mimic.fi/miscellaneous/security) of our docs site.
81
+
82
+ However, if you found any potential issue in any of our smart contracts or in any piece of code you consider critical
83
+ for the safety of the protocol, please contact us through <a href="mailto:security@mimic.fi">security@mimic.fi</a>.
84
+
85
+ ## License
86
+
87
+ This project is licensed under the GNU General Public License v3.0.
88
+ See the [LICENSE](../../LICENSE) file for details.
89
+
90
+
91
+ ---
92
+
93
+ > Website [mimic.fi](https://mimic.fi) &nbsp;&middot;&nbsp;
94
+ > Docs [docs.mimic.fi](https://docs.mimic.fi) &nbsp;&middot;&nbsp;
95
+ > GitHub [@mimic-fi](https://github.com/mimic-fi) &nbsp;&middot;&nbsp;
96
+ > Twitter [@mimicfi](https://twitter.com/mimicfi) &nbsp;&middot;&nbsp;
97
+ > Discord [mimic](https://discord.mimic.fi)
@@ -0,0 +1,19 @@
1
+ export default class RunnerMock {
2
+ private instance;
3
+ private mockFolder;
4
+ private ENV_IMPORTS;
5
+ constructor(taskFolder: string, mockFolder: string);
6
+ private initializeWasmInstance;
7
+ private readJsonFile;
8
+ run(fnName?: string): void;
9
+ private createLogFn;
10
+ private logToFile;
11
+ private generateImports;
12
+ private patchStringInputs;
13
+ private createMockFunction;
14
+ private isParameterizedResponse;
15
+ private createConstantFunction;
16
+ private createParameterizedFunction;
17
+ private getStringFromMemory;
18
+ private writeStringToMemory;
19
+ }
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const path_1 = require("path");
28
+ const validators_1 = require("./validators");
29
+ const LITTLE_ENDIAN = true;
30
+ class RunnerMock {
31
+ constructor(taskFolder, mockFolder) {
32
+ this.ENV_IMPORTS = {
33
+ abort: (msgPtr, filePtr, line, col) => {
34
+ const msg = this.getStringFromMemory(msgPtr);
35
+ const file = this.getStringFromMemory(filePtr);
36
+ throw Error(`${msg} in ${file} (line ${line}, column ${col})`);
37
+ },
38
+ 'console.log': (ptr) => {
39
+ const text = this.getStringFromMemory(ptr);
40
+ console.log('[LOG]:', text);
41
+ },
42
+ };
43
+ this.mockFolder = mockFolder;
44
+ this.instance = this.initializeWasmInstance(taskFolder, mockFolder);
45
+ }
46
+ initializeWasmInstance(taskFolder, mockFolder) {
47
+ try {
48
+ const taskPath = (0, path_1.join)(taskFolder, 'task.wasm');
49
+ let { inputs, ...mock } = this.readJsonFile((0, path_1.join)(mockFolder, 'mock.json'), validators_1.MockConfigValidator);
50
+ inputs = inputs || {};
51
+ const imports = this.generateImports(mock, inputs);
52
+ const wasmBuffer = fs.readFileSync(taskPath);
53
+ const wasmModule = new WebAssembly.Module(wasmBuffer);
54
+ const instance = new WebAssembly.Instance(wasmModule, imports);
55
+ this.patchStringInputs(inputs, imports, instance);
56
+ return instance;
57
+ }
58
+ catch (error) {
59
+ throw new Error(`Failed to initialize task runner instance - ${error}`);
60
+ }
61
+ }
62
+ readJsonFile(filePath, validator) {
63
+ try {
64
+ const rawData = fs.readFileSync(filePath, 'utf8');
65
+ const parsedData = JSON.parse(rawData);
66
+ if (validator) {
67
+ const result = validator.safeParse(parsedData);
68
+ if (!result.success) {
69
+ const formattedError = result.error.format();
70
+ throw new Error(`Invalid JSON data in ${filePath}: ${JSON.stringify(formattedError, null, 2)}`);
71
+ }
72
+ return result.data;
73
+ }
74
+ return parsedData;
75
+ }
76
+ catch (error) {
77
+ if (error instanceof SyntaxError) {
78
+ throw new Error(`Invalid JSON in file ${filePath}: ${error.message}`);
79
+ }
80
+ throw new Error(`Failed to read or validate JSON file ${filePath}: ${error}`);
81
+ }
82
+ }
83
+ run(fnName = 'main') {
84
+ try {
85
+ const fn = this.instance.exports[fnName];
86
+ if (typeof fn === 'function') {
87
+ fn();
88
+ }
89
+ else {
90
+ const availableExports = Object.keys(this.instance.exports).join(', ');
91
+ throw Error(`No "${fnName}" found in exports. Available exports: ${availableExports}`);
92
+ }
93
+ }
94
+ catch (error) {
95
+ throw Error(`Task Execution Error - ${error}`);
96
+ }
97
+ }
98
+ createLogFn(call) {
99
+ return (ptr) => {
100
+ const params = this.getStringFromMemory(ptr);
101
+ this.logToFile(call, params);
102
+ };
103
+ }
104
+ logToFile(call, params) {
105
+ const logFile = (0, path_1.join)(this.mockFolder, 'test.log');
106
+ fs.appendFileSync(logFile, `${call}: ${params}\n`);
107
+ }
108
+ generateImports(mock, inputs) {
109
+ const importModules = {};
110
+ const variableImports = {};
111
+ for (const moduleName of ['environment', 'evm']) {
112
+ const moduleMocks = mock[moduleName] ?? {};
113
+ const moduleImports = {};
114
+ for (const [functionName, mockValue] of Object.entries(moduleMocks)) {
115
+ moduleImports[functionName] = this.createMockFunction(functionName, mockValue);
116
+ }
117
+ importModules[moduleName] = moduleImports;
118
+ }
119
+ for (const [key, value] of Object.entries(inputs)) {
120
+ variableImports[`input.${key}`] =
121
+ typeof value === 'string' ? new WebAssembly.Global({ value: 'i32', mutable: true }, 0) : value;
122
+ }
123
+ return {
124
+ ...importModules,
125
+ env: this.ENV_IMPORTS,
126
+ index: variableImports,
127
+ };
128
+ }
129
+ patchStringInputs(inputs, imports, instance) {
130
+ for (const [key, value] of Object.entries(inputs)) {
131
+ if (typeof value === 'string') {
132
+ const ptr = this.writeStringToMemory(value, instance);
133
+ imports.index[`input.${key}`].value = ptr;
134
+ }
135
+ }
136
+ }
137
+ createMockFunction(functionName, mockValue) {
138
+ if (mockValue === 'log') {
139
+ return this.createLogFn(functionName);
140
+ }
141
+ else if (this.isParameterizedResponse(mockValue)) {
142
+ return this.createParameterizedFunction(functionName, mockValue);
143
+ }
144
+ else {
145
+ return this.createConstantFunction(String(mockValue));
146
+ }
147
+ }
148
+ isParameterizedResponse(value) {
149
+ const result = validators_1.ParameterizedResponseValidator.safeParse(value);
150
+ return result.success;
151
+ }
152
+ createConstantFunction(value) {
153
+ return () => this.writeStringToMemory(value);
154
+ }
155
+ createParameterizedFunction(functionName, config) {
156
+ return (ptr) => {
157
+ const param = this.getStringFromMemory(ptr);
158
+ let result;
159
+ if (config.paramResponse && param in config.paramResponse) {
160
+ result = this.writeStringToMemory(config.paramResponse[param]);
161
+ }
162
+ else if ('default' in config && config.default !== undefined) {
163
+ result = this.writeStringToMemory(config.default);
164
+ }
165
+ else {
166
+ throw new Error(`No response defined for parameter "${param}" in function "${functionName}" and no default value provided`);
167
+ }
168
+ if (config.log === true) {
169
+ this.logToFile(functionName, param);
170
+ }
171
+ return result;
172
+ };
173
+ }
174
+ getStringFromMemory(ptr) {
175
+ const memory = this.instance.exports.memory;
176
+ const memoryBuffer = new Uint8Array(memory.buffer);
177
+ const view = new DataView(memory.buffer);
178
+ const length = view.getInt32(ptr - 4, LITTLE_ENDIAN);
179
+ const bytes = memoryBuffer.subarray(ptr, ptr + length);
180
+ return new TextDecoder('utf-16le').decode(bytes);
181
+ }
182
+ writeStringToMemory(str, instance = this.instance) {
183
+ const memory = instance.exports.memory;
184
+ const malloc = instance.exports.__new;
185
+ if (!malloc)
186
+ throw new Error('__new function not found in WebAssembly exports');
187
+ const ptr = malloc(str.length * 2, 2);
188
+ const uint16View = new Uint16Array(memory.buffer, ptr, str.length);
189
+ uint16View.set(Array.from(str, (char) => char.charCodeAt(0)));
190
+ return ptr;
191
+ }
192
+ }
193
+ exports.default = RunnerMock;
194
+ //# sourceMappingURL=RunnerMock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RunnerMock.js","sourceRoot":"","sources":["../src/RunnerMock.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,+BAA2B;AAI3B,6CAAkF;AAElF,MAAM,aAAa,GAAG,IAAI,CAAA;AAE1B,MAAqB,UAAU;IAe7B,YAAY,UAAkB,EAAE,UAAkB;QAZ1C,gBAAW,GAAG;YACpB,KAAK,EAAE,CAAC,MAAc,EAAE,OAAe,EAAE,IAAY,EAAE,GAAW,EAAE,EAAE;gBACpE,MAAM,GAAG,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAA;gBAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;gBAC9C,MAAM,KAAK,CAAC,GAAG,GAAG,OAAO,IAAI,UAAU,IAAI,YAAY,GAAG,GA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,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAClD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,EAAE,aAAa,CAAC,CAAA;QACpD,MAAM,KAAK,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC,CAAA;QACtD,OAAO,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAClD,CAAC;IAEO,mBAAmB,CAAC,GAAW,EAAE,QAAQ,GAAG,IAAI,CAAC,QAAQ;QAC/D,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAA4B,CAAA;QAC5D,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAyB,CAAA;QAEzD,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;QAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAW,CAAA;QAC/C,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QAClE,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAE7D,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAlMD,6BAkMC"}
@@ -0,0 +1,3 @@
1
+ export * from './run-task';
2
+ export { default as RunnerMock } from './RunnerMock';
3
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.RunnerMock = void 0;
21
+ __exportStar(require("./run-task"), exports);
22
+ var RunnerMock_1 = require("./RunnerMock");
23
+ Object.defineProperty(exports, "RunnerMock", { enumerable: true, get: function () { return __importDefault(RunnerMock_1).default; } });
24
+ __exportStar(require("./types"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,2CAAoD;AAA3C,yHAAA,OAAO,OAAc;AAC9B,0CAAuB"}
@@ -0,0 +1,2 @@
1
+ import { Context, Output, RunTaskOptionalParams } from './types';
2
+ export declare function runTask(taskDir: string, context: Context, optional?: RunTaskOptionalParams): Promise<Output[]>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.runTask = runTask;
30
+ const fs = __importStar(require("fs"));
31
+ const path = __importStar(require("path"));
32
+ const RunnerMock_1 = __importDefault(require("./RunnerMock"));
33
+ async function runTask(taskDir, context, optional = {}) {
34
+ const { prices = [], balances = [], calls = [], inputs = {} } = optional;
35
+ const taskPath = path.join(taskDir, 'build');
36
+ const testDir = path.join(taskDir, 'tests');
37
+ const logPath = path.join(testDir, 'test.log');
38
+ const mockPath = path.join(testDir, 'mock.json');
39
+ const mock = generateMock({ context, prices, balances, calls, inputs });
40
+ fs.mkdirSync(testDir, { recursive: true });
41
+ fs.writeFileSync(mockPath, JSON.stringify(mock, null, 2));
42
+ if (fs.existsSync(logPath))
43
+ fs.unlinkSync(logPath);
44
+ try {
45
+ const runner = new RunnerMock_1.default(taskPath, testDir);
46
+ runner.run();
47
+ if (!fs.existsSync(logPath))
48
+ return [];
49
+ const logLines = fs.readFileSync(logPath, 'utf-8').trim().split('\n');
50
+ return parseLogs(logLines);
51
+ }
52
+ finally {
53
+ if (fs.existsSync(logPath))
54
+ fs.unlinkSync(logPath);
55
+ if (fs.existsSync(mockPath))
56
+ fs.unlinkSync(mockPath);
57
+ }
58
+ }
59
+ function generateMock(params) {
60
+ const { context, prices, balances, inputs, calls } = params;
61
+ let _getRelevantTokens = '';
62
+ if (balances.length > 0) {
63
+ const tokenAmounts = balances.map((b) => `TokenAmount(Token(${b.token},${b.chainId}),BigInt(${b.balance}))`);
64
+ _getRelevantTokens = tokenAmounts.join(',');
65
+ }
66
+ const priceResponse = {};
67
+ if (prices.length > 0) {
68
+ for (const { token, chainId, timestamp, usdPrice } of prices) {
69
+ const key = `${token},${chainId},${timestamp || ''}`;
70
+ priceResponse[key] = usdPrice;
71
+ }
72
+ }
73
+ const _getPrice = { paramResponse: priceResponse, default: '0' };
74
+ const callResponse = {};
75
+ const decodeResponse = {};
76
+ if (calls.length > 0) {
77
+ for (const { to, chainId, timestamp, data, output, outputType } of calls) {
78
+ const key = JSON.stringify({ to, chainId, timestamp: timestamp || null, data });
79
+ callResponse[key] = output;
80
+ const decodeKey = `EvmDecodeParam(${outputType},${output})`;
81
+ decodeResponse[decodeKey] = output;
82
+ }
83
+ }
84
+ const _contractCall = { paramResponse: callResponse, default: '0' };
85
+ const _decode = { paramResponse: decodeResponse, default: '0' };
86
+ const environment = {
87
+ _getContext: JSON.stringify({ ...context, configId: 'config-id' }),
88
+ _getRelevantTokens,
89
+ _getPrice,
90
+ _contractCall,
91
+ _transfer: { log: true, default: '' },
92
+ _swap: { log: true, default: '' },
93
+ _call: { log: true, default: '' },
94
+ };
95
+ const evm = { _keccak: '', _encode: { default: '' }, _decode };
96
+ return { environment, evm, inputs };
97
+ }
98
+ function parseLogs(logLines) {
99
+ return logLines.map((line) => {
100
+ const [rawType, json] = line.split(/:(.+)/);
101
+ const type = rawType.trim().replace('_', '');
102
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
103
+ const { op, ...data } = JSON.parse(json.trim());
104
+ return { type, ...data };
105
+ });
106
+ }
107
+ //# sourceMappingURL=run-task.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AE,OAAO,EAAE,EAAE,EAAE;KAClC,CAAA;IAED,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAA;IAE9D,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,CAAA;AACrC,CAAC;AAED,SAAS,SAAS,CAAC,QAAkB;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC5C,6DAA6D;QAC7D,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/C,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAA;IAC1B,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ import { InputsValidator, MockConfigValidator, MockFunctionResponseValidator, ParameterizedResponseValidator } from './validators';
3
+ export type MockResponseValue = z.infer<typeof MockFunctionResponseValidator>;
4
+ export type ParameterizedResponse = z.infer<typeof ParameterizedResponseValidator>;
5
+ export type MockConfig = z.output<typeof MockConfigValidator>;
6
+ export type Inputs = z.infer<typeof InputsValidator>;
7
+ export type Context = {
8
+ user: string;
9
+ settler: string;
10
+ timestamp: string;
11
+ };
12
+ export type TokenPrice = {
13
+ token: string;
14
+ chainId: number;
15
+ usdPrice: string;
16
+ timestamp?: string;
17
+ };
18
+ export type TokenBalance = {
19
+ token: string;
20
+ chainId: number;
21
+ user: string;
22
+ balance: string;
23
+ };
24
+ export type ContractCall = {
25
+ to: string;
26
+ chainId: number;
27
+ timestamp?: string;
28
+ data: string;
29
+ output: string;
30
+ outputType: string;
31
+ };
32
+ export type GenerateMockParams = {
33
+ context: Context;
34
+ inputs: Inputs;
35
+ prices: TokenPrice[];
36
+ balances: TokenBalance[];
37
+ calls: ContractCall[];
38
+ };
39
+ export type RunTaskOptionalParams = Partial<Omit<GenerateMockParams, 'context'>>;
40
+ export type Intent = {
41
+ op: number;
42
+ settler: string;
43
+ user: string;
44
+ deadline: string;
45
+ nonce: string;
46
+ };
47
+ export type Transfer = Intent & {
48
+ type: 'transfer';
49
+ chainId: number;
50
+ transfers: {
51
+ token: string;
52
+ amount: string;
53
+ recipient: string;
54
+ }[];
55
+ feeToken: string;
56
+ feeAmount: string;
57
+ };
58
+ export type Swap = Intent & {
59
+ type: 'swap';
60
+ sourceChain: number;
61
+ destinationChain: number;
62
+ tokensIn: {
63
+ token: string;
64
+ amount: string;
65
+ }[];
66
+ tokensOut: {
67
+ token: string;
68
+ minAmount: string;
69
+ recipient: string;
70
+ }[];
71
+ };
72
+ export type Call = Intent & {
73
+ type: 'call';
74
+ chainId: number;
75
+ calls: {
76
+ target: string;
77
+ data: string;
78
+ value: string;
79
+ }[];
80
+ feeToken: string;
81
+ feeAmount: string;
82
+ };
83
+ export type Output = Transfer | Swap | Call;
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,86 @@
1
+ import { z } from 'zod';
2
+ export declare const ParameterizedResponseValidator: z.ZodEffects<z.ZodObject<{
3
+ paramResponse: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
4
+ default: z.ZodOptional<z.ZodString>;
5
+ log: z.ZodOptional<z.ZodBoolean>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ paramResponse?: Record<string, string> | undefined;
8
+ default?: string | undefined;
9
+ log?: boolean | undefined;
10
+ }, {
11
+ paramResponse?: Record<string, string> | undefined;
12
+ default?: string | undefined;
13
+ log?: boolean | undefined;
14
+ }>, {
15
+ paramResponse?: Record<string, string> | undefined;
16
+ default?: string | undefined;
17
+ log?: boolean | undefined;
18
+ }, {
19
+ paramResponse?: Record<string, string> | undefined;
20
+ default?: string | undefined;
21
+ log?: boolean | undefined;
22
+ }>;
23
+ export declare const InputsValidator: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodString]>>;
24
+ export declare const MockFunctionResponseValidator: z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodObject<{
25
+ paramResponse: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
26
+ default: z.ZodOptional<z.ZodString>;
27
+ log: z.ZodOptional<z.ZodBoolean>;
28
+ }, "strip", z.ZodTypeAny, {
29
+ paramResponse?: Record<string, string> | undefined;
30
+ default?: string | undefined;
31
+ log?: boolean | undefined;
32
+ }, {
33
+ paramResponse?: Record<string, string> | undefined;
34
+ default?: string | undefined;
35
+ log?: boolean | undefined;
36
+ }>, {
37
+ paramResponse?: Record<string, string> | undefined;
38
+ default?: string | undefined;
39
+ log?: boolean | undefined;
40
+ }, {
41
+ paramResponse?: Record<string, string> | undefined;
42
+ default?: string | undefined;
43
+ log?: boolean | undefined;
44
+ }>, z.ZodLiteral<"log">]>;
45
+ export declare const MockSectionValidator: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodObject<{
46
+ paramResponse: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
47
+ default: z.ZodOptional<z.ZodString>;
48
+ log: z.ZodOptional<z.ZodBoolean>;
49
+ }, "strip", z.ZodTypeAny, {
50
+ paramResponse?: Record<string, string> | undefined;
51
+ default?: string | undefined;
52
+ log?: boolean | undefined;
53
+ }, {
54
+ paramResponse?: Record<string, string> | undefined;
55
+ default?: string | undefined;
56
+ log?: boolean | undefined;
57
+ }>, {
58
+ paramResponse?: Record<string, string> | undefined;
59
+ default?: string | undefined;
60
+ log?: boolean | undefined;
61
+ }, {
62
+ paramResponse?: Record<string, string> | undefined;
63
+ default?: string | undefined;
64
+ log?: boolean | undefined;
65
+ }>, z.ZodLiteral<"log">]>>;
66
+ export declare const MockConfigValidator: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodObject<{
67
+ paramResponse: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
68
+ default: z.ZodOptional<z.ZodString>;
69
+ log: z.ZodOptional<z.ZodBoolean>;
70
+ }, "strip", z.ZodTypeAny, {
71
+ paramResponse?: Record<string, string> | undefined;
72
+ default?: string | undefined;
73
+ log?: boolean | undefined;
74
+ }, {
75
+ paramResponse?: Record<string, string> | undefined;
76
+ default?: string | undefined;
77
+ log?: boolean | undefined;
78
+ }>, {
79
+ paramResponse?: Record<string, string> | undefined;
80
+ default?: string | undefined;
81
+ log?: boolean | undefined;
82
+ }, {
83
+ paramResponse?: Record<string, string> | undefined;
84
+ default?: string | undefined;
85
+ log?: boolean | undefined;
86
+ }>, z.ZodLiteral<"log">]>>, z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodNumber, z.ZodString]>>]>>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockConfigValidator = exports.MockSectionValidator = exports.MockFunctionResponseValidator = exports.InputsValidator = exports.ParameterizedResponseValidator = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.ParameterizedResponseValidator = zod_1.z
6
+ .object({
7
+ paramResponse: zod_1.z.record(zod_1.z.string()).optional(),
8
+ default: zod_1.z.string().optional(),
9
+ log: zod_1.z.boolean().optional(),
10
+ })
11
+ .refine((data) => !!data.paramResponse || data.default !== undefined, {
12
+ message: "At least one of 'paramResponse' or 'default' must be defined",
13
+ });
14
+ exports.InputsValidator = zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.number(), zod_1.z.string()]));
15
+ exports.MockFunctionResponseValidator = zod_1.z.union([zod_1.z.string(), exports.ParameterizedResponseValidator, zod_1.z.literal('log')]);
16
+ exports.MockSectionValidator = zod_1.z.record(exports.MockFunctionResponseValidator);
17
+ exports.MockConfigValidator = zod_1.z.record(zod_1.z.union([exports.MockSectionValidator, exports.InputsValidator]));
18
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAEV,QAAA,8BAA8B,GAAG,OAAC;KAC5C,MAAM,CAAC;IACN,aAAa,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IAC9C,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,GAAG,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC;KACD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;IACpE,OAAO,EAAE,8DAA8D;CACxE,CAAC,CAAA;AAES,QAAA,eAAe,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;AAEzE,QAAA,6BAA6B,GAAG,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,sCAA8B,EAAE,OAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEvG,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC,qCAA6B,CAAC,CAAA;AAE9D,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,KAAK,CAAC,CAAC,4BAAoB,EAAE,uBAAe,CAAC,CAAC,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@mimicprotocol/test-ts",
3
+ "version": "0.0.1-rc.9",
4
+ "license": "GPL-3.0",
5
+ "private": false,
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "prepare": "yarn build",
9
+ "build": "rm -rf dist && tsc",
10
+ "test": "echo 'no tests for now'",
11
+ "lint": "eslint ."
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "dependencies": {
17
+ "zod": "^3.24.1"
18
+ },
19
+ "devDependencies": {
20
+ "@types/chai": "^4.3.5",
21
+ "@types/mocha": "^10.0.1",
22
+ "chai": "^4.3.7",
23
+ "eslint-config-mimic": "^0.0.3",
24
+ "mocha": "^10.2.0",
25
+ "nodemon": "^2.0.22",
26
+ "ts-mocha": "^10.0.0",
27
+ "typescript": "5.5.4"
28
+ }
29
+ }