genius-intents 0.1.4
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/CHANGELOG.md +45 -0
- package/LICENSE +21 -0
- package/README.md +376 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +62 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/intents-protocols.d.ts +69 -0
- package/dist/src/intents-protocols.d.ts.map +1 -0
- package/dist/src/intents-protocols.js +371 -0
- package/dist/src/intents-protocols.js.map +1 -0
- package/dist/src/interfaces/intent-protocol.d.ts +21 -0
- package/dist/src/interfaces/intent-protocol.d.ts.map +1 -0
- package/dist/src/interfaces/intent-protocol.js +3 -0
- package/dist/src/interfaces/intent-protocol.js.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.service.d.ts +28 -0
- package/dist/src/protocols/aftermath/aftermath.service.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.service.js +162 -0
- package/dist/src/protocols/aftermath/aftermath.service.js.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.types.d.ts +100 -0
- package/dist/src/protocols/aftermath/aftermath.types.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/aftermath.types.js +3 -0
- package/dist/src/protocols/aftermath/aftermath.types.js.map +1 -0
- package/dist/src/protocols/aftermath/index.d.ts +3 -0
- package/dist/src/protocols/aftermath/index.d.ts.map +1 -0
- package/dist/src/protocols/aftermath/index.js +7 -0
- package/dist/src/protocols/aftermath/index.js.map +1 -0
- package/dist/src/protocols/debridge/debridge.service.d.ts +157 -0
- package/dist/src/protocols/debridge/debridge.service.d.ts.map +1 -0
- package/dist/src/protocols/debridge/debridge.service.js +462 -0
- package/dist/src/protocols/debridge/debridge.service.js.map +1 -0
- package/dist/src/protocols/debridge/debridge.types.d.ts +82 -0
- package/dist/src/protocols/debridge/debridge.types.d.ts.map +1 -0
- package/dist/src/protocols/debridge/debridge.types.js +3 -0
- package/dist/src/protocols/debridge/debridge.types.js.map +1 -0
- package/dist/src/protocols/debridge/index.d.ts +3 -0
- package/dist/src/protocols/debridge/index.d.ts.map +1 -0
- package/dist/src/protocols/debridge/index.js +7 -0
- package/dist/src/protocols/debridge/index.js.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.d.ts +36 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.js +312 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.service.js.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.d.ts +100 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.js +3 -0
- package/dist/src/protocols/genius-bridge/genius-bridge.types.js.map +1 -0
- package/dist/src/protocols/genius-bridge/index.d.ts +3 -0
- package/dist/src/protocols/genius-bridge/index.d.ts.map +1 -0
- package/dist/src/protocols/genius-bridge/index.js +7 -0
- package/dist/src/protocols/genius-bridge/index.js.map +1 -0
- package/dist/src/protocols/jupiter/index.d.ts +3 -0
- package/dist/src/protocols/jupiter/index.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/index.js +7 -0
- package/dist/src/protocols/jupiter/index.js.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.service.d.ts +37 -0
- package/dist/src/protocols/jupiter/jupiter.service.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.service.js +188 -0
- package/dist/src/protocols/jupiter/jupiter.service.js.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.types.d.ts +272 -0
- package/dist/src/protocols/jupiter/jupiter.types.d.ts.map +1 -0
- package/dist/src/protocols/jupiter/jupiter.types.js +3 -0
- package/dist/src/protocols/jupiter/jupiter.types.js.map +1 -0
- package/dist/src/protocols/kyberswap/index.d.ts +3 -0
- package/dist/src/protocols/kyberswap/index.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/index.js +7 -0
- package/dist/src/protocols/kyberswap/index.js.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.d.ts +34 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.js +218 -0
- package/dist/src/protocols/kyberswap/kyberswap.service.js.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.d.ts +114 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.d.ts.map +1 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.js +3 -0
- package/dist/src/protocols/kyberswap/kyberswap.types.js.map +1 -0
- package/dist/src/protocols/odos/index.d.ts +3 -0
- package/dist/src/protocols/odos/index.d.ts.map +1 -0
- package/dist/src/protocols/odos/index.js +7 -0
- package/dist/src/protocols/odos/index.js.map +1 -0
- package/dist/src/protocols/odos/odos.service.d.ts +39 -0
- package/dist/src/protocols/odos/odos.service.d.ts.map +1 -0
- package/dist/src/protocols/odos/odos.service.js +207 -0
- package/dist/src/protocols/odos/odos.service.js.map +1 -0
- package/dist/src/protocols/odos/odos.types.d.ts +114 -0
- package/dist/src/protocols/odos/odos.types.d.ts.map +1 -0
- package/dist/src/protocols/odos/odos.types.js +3 -0
- package/dist/src/protocols/odos/odos.types.js.map +1 -0
- package/dist/src/protocols/okx/index.d.ts +3 -0
- package/dist/src/protocols/okx/index.d.ts.map +1 -0
- package/dist/src/protocols/okx/index.js +7 -0
- package/dist/src/protocols/okx/index.js.map +1 -0
- package/dist/src/protocols/okx/okx.service.d.ts +36 -0
- package/dist/src/protocols/okx/okx.service.d.ts.map +1 -0
- package/dist/src/protocols/okx/okx.service.js +281 -0
- package/dist/src/protocols/okx/okx.service.js.map +1 -0
- package/dist/src/protocols/okx/okx.types.d.ts +119 -0
- package/dist/src/protocols/okx/okx.types.d.ts.map +1 -0
- package/dist/src/protocols/okx/okx.types.js +4 -0
- package/dist/src/protocols/okx/okx.types.js.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.d.ts +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.d.ts.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.js +2 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.service.js.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.d.ts +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.d.ts.map +1 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.js +2 -0
- package/dist/src/protocols/okx-bridge/okx-bridge.types.js.map +1 -0
- package/dist/src/protocols/openocean/index.d.ts +3 -0
- package/dist/src/protocols/openocean/index.d.ts.map +1 -0
- package/dist/src/protocols/openocean/index.js +7 -0
- package/dist/src/protocols/openocean/index.js.map +1 -0
- package/dist/src/protocols/openocean/openocean.service.d.ts +29 -0
- package/dist/src/protocols/openocean/openocean.service.d.ts.map +1 -0
- package/dist/src/protocols/openocean/openocean.service.js +181 -0
- package/dist/src/protocols/openocean/openocean.service.js.map +1 -0
- package/dist/src/protocols/openocean/openocean.types.d.ts +68 -0
- package/dist/src/protocols/openocean/openocean.types.d.ts.map +1 -0
- package/dist/src/protocols/openocean/openocean.types.js +3 -0
- package/dist/src/protocols/openocean/openocean.types.js.map +1 -0
- package/dist/src/protocols/pumpfun/index.d.ts +3 -0
- package/dist/src/protocols/pumpfun/index.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/index.js +7 -0
- package/dist/src/protocols/pumpfun/index.js.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.d.ts +45 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.js +217 -0
- package/dist/src/protocols/pumpfun/pumpfun.service.js.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.d.ts +14 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.d.ts.map +1 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.js +3 -0
- package/dist/src/protocols/pumpfun/pumpfun.types.js.map +1 -0
- package/dist/src/protocols/raydium/index.d.ts +3 -0
- package/dist/src/protocols/raydium/index.d.ts.map +1 -0
- package/dist/src/protocols/raydium/index.js +7 -0
- package/dist/src/protocols/raydium/index.js.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.service.d.ts +35 -0
- package/dist/src/protocols/raydium/raydium-v2.service.d.ts.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.service.js +301 -0
- package/dist/src/protocols/raydium/raydium-v2.service.js.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.types.d.ts +96 -0
- package/dist/src/protocols/raydium/raydium-v2.types.d.ts.map +1 -0
- package/dist/src/protocols/raydium/raydium-v2.types.js +3 -0
- package/dist/src/protocols/raydium/raydium-v2.types.js.map +1 -0
- package/dist/src/protocols/zeroX/index.d.ts +3 -0
- package/dist/src/protocols/zeroX/index.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/index.js +7 -0
- package/dist/src/protocols/zeroX/index.js.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.service.d.ts +37 -0
- package/dist/src/protocols/zeroX/zeroX.service.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.service.js +209 -0
- package/dist/src/protocols/zeroX/zeroX.service.js.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.types.d.ts +120 -0
- package/dist/src/protocols/zeroX/zeroX.types.d.ts.map +1 -0
- package/dist/src/protocols/zeroX/zeroX.types.js +3 -0
- package/dist/src/protocols/zeroX/zeroX.types.js.map +1 -0
- package/dist/src/types/enums.d.ts +42 -0
- package/dist/src/types/enums.d.ts.map +1 -0
- package/dist/src/types/enums.js +49 -0
- package/dist/src/types/enums.js.map +1 -0
- package/dist/src/types/intents-protocols.d.ts +89 -0
- package/dist/src/types/intents-protocols.d.ts.map +1 -0
- package/dist/src/types/intents-protocols.js +3 -0
- package/dist/src/types/intents-protocols.js.map +1 -0
- package/dist/src/types/price-response.d.ts +26 -0
- package/dist/src/types/price-response.d.ts.map +1 -0
- package/dist/src/types/price-response.js +3 -0
- package/dist/src/types/price-response.js.map +1 -0
- package/dist/src/types/quote-response.d.ts +31 -0
- package/dist/src/types/quote-response.d.ts.map +1 -0
- package/dist/src/types/quote-response.js +3 -0
- package/dist/src/types/quote-response.js.map +1 -0
- package/dist/src/utils/address-validation.d.ts +9 -0
- package/dist/src/utils/address-validation.d.ts.map +1 -0
- package/dist/src/utils/address-validation.js +42 -0
- package/dist/src/utils/address-validation.js.map +1 -0
- package/dist/src/utils/address.d.ts +9 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +74 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/base64-to-base58.d.ts +2 -0
- package/dist/src/utils/base64-to-base58.d.ts.map +1 -0
- package/dist/src/utils/base64-to-base58.js +22 -0
- package/dist/src/utils/base64-to-base58.js.map +1 -0
- package/dist/src/utils/chain-id-name.d.ts +3 -0
- package/dist/src/utils/chain-id-name.d.ts.map +1 -0
- package/dist/src/utils/chain-id-name.js +23 -0
- package/dist/src/utils/chain-id-name.js.map +1 -0
- package/dist/src/utils/check-vm.d.ts +8 -0
- package/dist/src/utils/check-vm.d.ts.map +1 -0
- package/dist/src/utils/check-vm.js +39 -0
- package/dist/src/utils/check-vm.js.map +1 -0
- package/dist/src/utils/constants.d.ts +7 -0
- package/dist/src/utils/constants.d.ts.map +1 -0
- package/dist/src/utils/constants.js +10 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/create-error-message.d.ts +5 -0
- package/dist/src/utils/create-error-message.d.ts.map +1 -0
- package/dist/src/utils/create-error-message.js +42 -0
- package/dist/src/utils/create-error-message.js.map +1 -0
- package/dist/src/utils/fetch-spl-metadata.d.ts +4 -0
- package/dist/src/utils/fetch-spl-metadata.d.ts.map +1 -0
- package/dist/src/utils/fetch-spl-metadata.js +108 -0
- package/dist/src/utils/fetch-spl-metadata.js.map +1 -0
- package/dist/src/utils/is-native.d.ts +2 -0
- package/dist/src/utils/is-native.d.ts.map +1 -0
- package/dist/src/utils/is-native.js +23 -0
- package/dist/src/utils/is-native.js.map +1 -0
- package/dist/src/utils/logger.d.ts +56 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +108 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/throw-error.d.ts +3 -0
- package/dist/src/utils/throw-error.d.ts.map +1 -0
- package/dist/src/utils/throw-error.js +8 -0
- package/dist/src/utils/throw-error.js.map +1 -0
- package/dist/tests/core/intent-protocol-suite.test.d.ts +2 -0
- package/dist/tests/core/intent-protocol-suite.test.d.ts.map +1 -0
- package/dist/tests/core/intent-protocol-suite.test.js +485 -0
- package/dist/tests/core/intent-protocol-suite.test.js.map +1 -0
- package/dist/tests/core/intents-protocols.test.d.ts +2 -0
- package/dist/tests/core/intents-protocols.test.d.ts.map +1 -0
- package/dist/tests/core/intents-protocols.test.js +307 -0
- package/dist/tests/core/intents-protocols.test.js.map +1 -0
- package/dist/tests/core/protocol-test-runner.d.ts +62 -0
- package/dist/tests/core/protocol-test-runner.d.ts.map +1 -0
- package/dist/tests/core/protocol-test-runner.js +260 -0
- package/dist/tests/core/protocol-test-runner.js.map +1 -0
- package/dist/tests/core/setup.test.d.ts +1 -0
- package/dist/tests/core/setup.test.d.ts.map +1 -0
- package/dist/tests/core/setup.test.js +13 -0
- package/dist/tests/core/setup.test.js.map +1 -0
- package/dist/tests/fixtures/test-data.d.ts +84 -0
- package/dist/tests/fixtures/test-data.d.ts.map +1 -0
- package/dist/tests/fixtures/test-data.js +142 -0
- package/dist/tests/fixtures/test-data.js.map +1 -0
- package/dist/tests/integration/cross-chain.test.d.ts +2 -0
- package/dist/tests/integration/cross-chain.test.d.ts.map +1 -0
- package/dist/tests/integration/cross-chain.test.js +44 -0
- package/dist/tests/integration/cross-chain.test.js.map +1 -0
- package/dist/tests/protocols/simple-protocol.test.d.ts +2 -0
- package/dist/tests/protocols/simple-protocol.test.d.ts.map +1 -0
- package/dist/tests/protocols/simple-protocol.test.js +77 -0
- package/dist/tests/protocols/simple-protocol.test.js.map +1 -0
- package/dist/tests/setup.d.ts +24 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +48 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/tests/utils/test-generator.d.ts +30 -0
- package/dist/tests/utils/test-generator.d.ts.map +1 -0
- package/dist/tests/utils/test-generator.js +153 -0
- package/dist/tests/utils/test-generator.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents-protocols.test.d.ts","sourceRoot":"","sources":["../../../tests/core/intents-protocols.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globals_1 = require("@jest/globals");
|
|
4
|
+
const intents_protocols_1 = require("../../src/intents-protocols");
|
|
5
|
+
const enums_1 = require("../../src/types/enums");
|
|
6
|
+
const test_data_1 = require("../fixtures/test-data");
|
|
7
|
+
// Mock all protocol services to prevent actual network calls
|
|
8
|
+
globals_1.jest.mock('../../src/protocols/odos/odos.service');
|
|
9
|
+
globals_1.jest.mock('../../src/protocols/jupiter/jupiter.service');
|
|
10
|
+
globals_1.jest.mock('../../src/protocols/raydium/raydium-v2.service');
|
|
11
|
+
globals_1.jest.mock('../../src/protocols/pumpfun/pumpfun.service');
|
|
12
|
+
globals_1.jest.mock('../../src/protocols/openocean/openocean.service');
|
|
13
|
+
globals_1.jest.mock('../../src/protocols/okx/okx.service');
|
|
14
|
+
globals_1.jest.mock('../../src/protocols/kyberswap/kyberswap.service');
|
|
15
|
+
globals_1.jest.mock('../../src/protocols/aftermath/aftermath.service');
|
|
16
|
+
globals_1.jest.mock('../../src/protocols/zeroX/zeroX.service');
|
|
17
|
+
globals_1.jest.mock('../../src/protocols/debridge/debridge.service');
|
|
18
|
+
globals_1.jest.mock('../../src/protocols/genius-bridge/genius-bridge.service');
|
|
19
|
+
describe('IntentsProtocols', () => {
|
|
20
|
+
let intentsProtocols;
|
|
21
|
+
let consoleWarnSpy;
|
|
22
|
+
let consoleInfoSpy;
|
|
23
|
+
let consoleDebugSpy;
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
globals_1.jest.clearAllMocks();
|
|
26
|
+
// Spy on console methods
|
|
27
|
+
consoleWarnSpy = globals_1.jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
28
|
+
consoleInfoSpy = globals_1.jest.spyOn(console, 'info').mockImplementation(() => { });
|
|
29
|
+
consoleDebugSpy = globals_1.jest.spyOn(console, 'debug').mockImplementation(() => { });
|
|
30
|
+
});
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
consoleWarnSpy.mockRestore();
|
|
33
|
+
consoleInfoSpy.mockRestore();
|
|
34
|
+
consoleDebugSpy.mockRestore();
|
|
35
|
+
});
|
|
36
|
+
describe('Constructor and Initialization', () => {
|
|
37
|
+
test('should initialize with default configuration', () => {
|
|
38
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
39
|
+
expect(intentsProtocols).toBeDefined();
|
|
40
|
+
expect(typeof intentsProtocols.getInitializedProtocols).toBe('function');
|
|
41
|
+
expect(typeof intentsProtocols.fetchPrice).toBe('function');
|
|
42
|
+
expect(typeof intentsProtocols.fetchQuote).toBe('function');
|
|
43
|
+
});
|
|
44
|
+
test('should initialize with custom configuration', () => {
|
|
45
|
+
const config = {
|
|
46
|
+
method: 'race',
|
|
47
|
+
timeout: 20000,
|
|
48
|
+
maxConcurrency: 5,
|
|
49
|
+
debug: true,
|
|
50
|
+
};
|
|
51
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols(config);
|
|
52
|
+
expect(intentsProtocols).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
test('should respect includeProtocols configuration', () => {
|
|
55
|
+
const config = {
|
|
56
|
+
includeProtocols: [enums_1.ProtocolEnum.JUPITER],
|
|
57
|
+
};
|
|
58
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols(config);
|
|
59
|
+
const initializedProtocols = intentsProtocols.getInitializedProtocols();
|
|
60
|
+
// Should only include Jupiter if it's available, or be empty if not
|
|
61
|
+
expect(initializedProtocols.length).toBeLessThanOrEqual(1);
|
|
62
|
+
if (initializedProtocols.length > 0) {
|
|
63
|
+
expect(initializedProtocols).toContain(enums_1.ProtocolEnum.JUPITER);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
test('should respect excludeProtocols configuration', () => {
|
|
67
|
+
const config = {
|
|
68
|
+
excludeProtocols: [enums_1.ProtocolEnum.ODOS],
|
|
69
|
+
};
|
|
70
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols(config);
|
|
71
|
+
const initializedProtocols = intentsProtocols.getInitializedProtocols();
|
|
72
|
+
expect(initializedProtocols).not.toContain(enums_1.ProtocolEnum.ODOS);
|
|
73
|
+
});
|
|
74
|
+
test('should handle protocol initialization gracefully', () => {
|
|
75
|
+
// This test verifies that the class doesn't crash when protocols fail to initialize
|
|
76
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
77
|
+
// The class should still be functional even if some protocols fail
|
|
78
|
+
expect(intentsProtocols).toBeDefined();
|
|
79
|
+
expect(typeof intentsProtocols.getInitializedProtocols).toBe('function');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('Protocol Management', () => {
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
85
|
+
});
|
|
86
|
+
test('should return list of initialized protocols', () => {
|
|
87
|
+
const protocols = intentsProtocols.getInitializedProtocols();
|
|
88
|
+
expect(Array.isArray(protocols)).toBe(true);
|
|
89
|
+
protocols.forEach(protocol => {
|
|
90
|
+
expect(Object.values(enums_1.ProtocolEnum)).toContain(protocol);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
test('should get specific protocol instance', () => {
|
|
94
|
+
const protocols = intentsProtocols.getInitializedProtocols();
|
|
95
|
+
if (protocols.length > 0) {
|
|
96
|
+
const firstProtocol = protocols[0];
|
|
97
|
+
const protocol = intentsProtocols.getProtocol(firstProtocol);
|
|
98
|
+
// Protocol might be undefined due to mocking, which is expected
|
|
99
|
+
if (protocol && protocol.protocol) {
|
|
100
|
+
expect(protocol.protocol).toBe(firstProtocol);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// Protocol exists but doesn't have the expected structure due to mocking
|
|
104
|
+
expect(protocol).toBeDefined();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// If no protocols are initialized (due to mocking), that's also valid
|
|
109
|
+
expect(protocols.length).toBe(0);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
test('should return undefined for non-existent protocol', () => {
|
|
113
|
+
const protocol = intentsProtocols.getProtocol('NON_EXISTENT');
|
|
114
|
+
expect(protocol).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('Compatible Protocol Selection', () => {
|
|
118
|
+
beforeEach(() => {
|
|
119
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
120
|
+
});
|
|
121
|
+
test('should find compatible protocols for same-chain swap', () => {
|
|
122
|
+
const params = (0, test_data_1.createPriceParams)({
|
|
123
|
+
networkIn: enums_1.ChainIdEnum.ETHEREUM,
|
|
124
|
+
networkOut: enums_1.ChainIdEnum.ETHEREUM,
|
|
125
|
+
});
|
|
126
|
+
// Access the protected method through reflection
|
|
127
|
+
try {
|
|
128
|
+
const compatibleProtocols = intentsProtocols.getCompatibleProtocols(params);
|
|
129
|
+
expect(Array.isArray(compatibleProtocols)).toBe(true);
|
|
130
|
+
compatibleProtocols.forEach((protocol) => {
|
|
131
|
+
if (protocol && protocol.chains) {
|
|
132
|
+
expect(protocol.singleChain).toBe(true);
|
|
133
|
+
expect(protocol.chains).toContain(enums_1.ChainIdEnum.ETHEREUM);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
// Expected when protocols are not properly mocked
|
|
139
|
+
expect(error).toBeDefined();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
test('should find compatible protocols for cross-chain swap', () => {
|
|
143
|
+
const params = (0, test_data_1.createPriceParams)({
|
|
144
|
+
networkIn: enums_1.ChainIdEnum.ETHEREUM,
|
|
145
|
+
networkOut: enums_1.ChainIdEnum.BSC,
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
const compatibleProtocols = intentsProtocols.getCompatibleProtocols(params);
|
|
149
|
+
expect(Array.isArray(compatibleProtocols)).toBe(true);
|
|
150
|
+
compatibleProtocols.forEach((protocol) => {
|
|
151
|
+
if (protocol && protocol.chains) {
|
|
152
|
+
expect(protocol.multiChain).toBe(true);
|
|
153
|
+
expect(protocol.chains).toContain(enums_1.ChainIdEnum.ETHEREUM);
|
|
154
|
+
expect(protocol.chains).toContain(enums_1.ChainIdEnum.BSC);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// Expected when protocols are not properly mocked
|
|
160
|
+
expect(error).toBeDefined();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
test('should return empty array when no compatible protocols found', () => {
|
|
164
|
+
const params = (0, test_data_1.createPriceParams)({
|
|
165
|
+
networkIn: 999, // Non-existent chain
|
|
166
|
+
networkOut: 998, // Non-existent chain
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
const compatibleProtocols = intentsProtocols.getCompatibleProtocols(params);
|
|
170
|
+
expect(compatibleProtocols).toHaveLength(0);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
// Expected when protocols are not properly mocked
|
|
174
|
+
expect(error).toBeDefined();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('Price Fetching', () => {
|
|
179
|
+
beforeEach(() => {
|
|
180
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols({ method: 'best' });
|
|
181
|
+
});
|
|
182
|
+
test('should handle price fetching with no compatible protocols', async () => {
|
|
183
|
+
const params = (0, test_data_1.createPriceParams)({
|
|
184
|
+
networkIn: 999,
|
|
185
|
+
networkOut: 998,
|
|
186
|
+
});
|
|
187
|
+
await expect(intentsProtocols.fetchPrice(params)).rejects.toThrow();
|
|
188
|
+
});
|
|
189
|
+
test('should handle price fetching method configuration', () => {
|
|
190
|
+
const bestModeInstance = new intents_protocols_1.IntentsProtocols({ method: 'best' });
|
|
191
|
+
const raceModeInstance = new intents_protocols_1.IntentsProtocols({ method: 'race' });
|
|
192
|
+
expect(bestModeInstance).toBeDefined();
|
|
193
|
+
expect(raceModeInstance).toBeDefined();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
describe('Quote Fetching', () => {
|
|
197
|
+
beforeEach(() => {
|
|
198
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols({ method: 'best' });
|
|
199
|
+
});
|
|
200
|
+
test('should handle quote fetching with no compatible protocols', async () => {
|
|
201
|
+
const params = (0, test_data_1.createQuoteParams)({
|
|
202
|
+
networkIn: 999,
|
|
203
|
+
networkOut: 998,
|
|
204
|
+
});
|
|
205
|
+
await expect(intentsProtocols.fetchQuote(params)).rejects.toThrow();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('Configuration Updates', () => {
|
|
209
|
+
beforeEach(() => {
|
|
210
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
211
|
+
});
|
|
212
|
+
test('should update configuration', () => {
|
|
213
|
+
const newConfig = {
|
|
214
|
+
method: 'race',
|
|
215
|
+
timeout: 15000,
|
|
216
|
+
};
|
|
217
|
+
expect(() => intentsProtocols.updateConfig(newConfig)).not.toThrow();
|
|
218
|
+
});
|
|
219
|
+
test('should reinitialize protocols when protocol configs change', () => {
|
|
220
|
+
const newConfig = {
|
|
221
|
+
includeProtocols: [enums_1.ProtocolEnum.JUPITER],
|
|
222
|
+
};
|
|
223
|
+
intentsProtocols.updateConfig(newConfig);
|
|
224
|
+
const updatedProtocols = intentsProtocols.getInitializedProtocols();
|
|
225
|
+
// The protocols should be reinitialized
|
|
226
|
+
expect(Array.isArray(updatedProtocols)).toBe(true);
|
|
227
|
+
expect(updatedProtocols).not.toContain(enums_1.ProtocolEnum.ODOS);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe('Error Handling', () => {
|
|
231
|
+
beforeEach(() => {
|
|
232
|
+
intentsProtocols = new intents_protocols_1.IntentsProtocols();
|
|
233
|
+
});
|
|
234
|
+
test('should handle protocol service creation errors', () => {
|
|
235
|
+
const createProtocolSafely = intentsProtocols.createProtocolSafely;
|
|
236
|
+
const failingFactory = () => {
|
|
237
|
+
throw new Error('Service creation failed');
|
|
238
|
+
};
|
|
239
|
+
const result = createProtocolSafely(failingFactory);
|
|
240
|
+
expect(result).toBeNull();
|
|
241
|
+
});
|
|
242
|
+
test('should handle invalid parameters gracefully', async () => {
|
|
243
|
+
const invalidParams = {
|
|
244
|
+
networkIn: null,
|
|
245
|
+
networkOut: null,
|
|
246
|
+
tokenIn: '',
|
|
247
|
+
tokenOut: '',
|
|
248
|
+
amountIn: '',
|
|
249
|
+
slippage: -1,
|
|
250
|
+
from: '',
|
|
251
|
+
};
|
|
252
|
+
await expect(intentsProtocols.fetchPrice(invalidParams)).rejects.toThrow();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
describe('Method Selection Logic', () => {
|
|
256
|
+
test('should handle best response selection logic', () => {
|
|
257
|
+
const results = [
|
|
258
|
+
{
|
|
259
|
+
protocol: enums_1.ProtocolEnum.ODOS,
|
|
260
|
+
response: { amountOut: '1800000000' },
|
|
261
|
+
duration: 100,
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
protocol: enums_1.ProtocolEnum.JUPITER,
|
|
265
|
+
response: { amountOut: '1900000000' },
|
|
266
|
+
duration: 150,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
protocol: enums_1.ProtocolEnum.OPEN_OCEAN,
|
|
270
|
+
response: { amountOut: '1750000000' },
|
|
271
|
+
duration: 120,
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
const bestResponse = intentsProtocols.selectBestPriceResponse(results);
|
|
275
|
+
expect(bestResponse).toBeDefined();
|
|
276
|
+
expect(bestResponse.amountOut).toBe('1900000000');
|
|
277
|
+
});
|
|
278
|
+
test('should return undefined when no successful responses', () => {
|
|
279
|
+
const results = [
|
|
280
|
+
{
|
|
281
|
+
protocol: enums_1.ProtocolEnum.ODOS,
|
|
282
|
+
error: new Error('Failed'),
|
|
283
|
+
duration: 100,
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
const bestResponse = intentsProtocols.selectBestPriceResponse(results);
|
|
287
|
+
expect(bestResponse).toBeUndefined();
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
describe('Timeout and Concurrency', () => {
|
|
291
|
+
test('should respect timeout configuration', () => {
|
|
292
|
+
const config = {
|
|
293
|
+
timeout: 5000,
|
|
294
|
+
};
|
|
295
|
+
const instance = new intents_protocols_1.IntentsProtocols(config);
|
|
296
|
+
expect(instance).toBeDefined();
|
|
297
|
+
});
|
|
298
|
+
test('should respect maxConcurrency configuration', () => {
|
|
299
|
+
const config = {
|
|
300
|
+
maxConcurrency: 3,
|
|
301
|
+
};
|
|
302
|
+
const instance = new intents_protocols_1.IntentsProtocols(config);
|
|
303
|
+
expect(instance).toBeDefined();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
//# sourceMappingURL=intents-protocols.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents-protocols.test.js","sourceRoot":"","sources":["../../../tests/core/intents-protocols.test.ts"],"names":[],"mappings":";;AAAA,2CAAqC;AACrC,mEAA+D;AAC/D,iDAAkE;AAElE,qDAA6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
|
|
1
|
+
import { IIntentProtocol } from '../../src/interfaces/intent-protocol';
|
|
2
|
+
import { ChainIdEnum } from '../../src/types/enums';
|
|
3
|
+
import { IntentPriceParams } from '../../src/types/price-params';
|
|
4
|
+
import { IntentQuoteParams } from '../../src/types/quote-params';
|
|
5
|
+
export interface ProtocolTestConfig {
|
|
6
|
+
protocol: IIntentProtocol;
|
|
7
|
+
expectedBehavior: {
|
|
8
|
+
supportedChains: readonly ChainIdEnum[];
|
|
9
|
+
singleChain: boolean;
|
|
10
|
+
multiChain: boolean;
|
|
11
|
+
requiresApprovals?: boolean;
|
|
12
|
+
};
|
|
13
|
+
skipTests?: {
|
|
14
|
+
price?: boolean;
|
|
15
|
+
quote?: boolean;
|
|
16
|
+
validation?: boolean;
|
|
17
|
+
errorHandling?: boolean;
|
|
18
|
+
};
|
|
19
|
+
customTestParams?: {
|
|
20
|
+
validPriceParams?: IntentPriceParams;
|
|
21
|
+
validQuoteParams?: IntentQuoteParams;
|
|
22
|
+
invalidPriceParams?: IntentPriceParams;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare class ProtocolTestRunner {
|
|
26
|
+
private config;
|
|
27
|
+
constructor(config: ProtocolTestConfig);
|
|
28
|
+
/**
|
|
29
|
+
* Runs the complete test suite for a protocol
|
|
30
|
+
*/
|
|
31
|
+
runAllTests(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Tests basic interface compliance
|
|
34
|
+
*/
|
|
35
|
+
private runBasicInterfaceTests;
|
|
36
|
+
/**
|
|
37
|
+
* Tests supported chains functionality
|
|
38
|
+
*/
|
|
39
|
+
private runChainSupportTests;
|
|
40
|
+
/**
|
|
41
|
+
* Tests price fetching functionality
|
|
42
|
+
*/
|
|
43
|
+
private runPriceTests;
|
|
44
|
+
/**
|
|
45
|
+
* Tests quote fetching functionality
|
|
46
|
+
*/
|
|
47
|
+
private runQuoteTests;
|
|
48
|
+
/**
|
|
49
|
+
* Tests parameter validation
|
|
50
|
+
*/
|
|
51
|
+
private runValidationTests;
|
|
52
|
+
/**
|
|
53
|
+
* Tests error handling
|
|
54
|
+
*/
|
|
55
|
+
private runErrorHandlingTests;
|
|
56
|
+
private getValidPriceParams;
|
|
57
|
+
private getValidQuoteParams;
|
|
58
|
+
private getUnsupportedChain;
|
|
59
|
+
private getMockPriceResponse;
|
|
60
|
+
private getMockQuoteResponse;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=protocol-test-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-test-runner.d.ts","sourceRoot":"","sources":["../../../tests/core/protocol-test-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,eAAe,CAAC;IAC1B,gBAAgB,EAAE;QAChB,eAAe,EAAE,SAAS,WAAW,EAAE,CAAC;QACxC,WAAW,EAAE,OAAO,CAAC;QACrB,UAAU,EAAE,OAAO,CAAC;QACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,CAAC;IACF,SAAS,CAAC,EAAE;QACV,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,gBAAgB,CAAC,EAAE;QACjB,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;QACrC,gBAAgB,CAAC,EAAE,iBAAiB,CAAC;QACrC,kBAAkB,CAAC,EAAE,iBAAiB,CAAC;KACxC,CAAC;CACH;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAqB;gBAEvB,MAAM,EAAE,kBAAkB;IAItC;;OAEG;IACI,WAAW,IAAI,IAAI;IAW1B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAwB9B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAsB5B;;OAEG;IACH,OAAO,CAAC,aAAa;IA2CrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAyCrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAmC1B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA8B7B,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,oBAAoB;CAuB7B"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProtocolTestRunner = void 0;
|
|
4
|
+
const enums_1 = require("../../src/types/enums");
|
|
5
|
+
const test_data_1 = require("../fixtures/test-data");
|
|
6
|
+
class ProtocolTestRunner {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Runs the complete test suite for a protocol
|
|
12
|
+
*/
|
|
13
|
+
runAllTests() {
|
|
14
|
+
describe(`Protocol: ${this.config.protocol.protocol}`, () => {
|
|
15
|
+
this.runBasicInterfaceTests();
|
|
16
|
+
this.runChainSupportTests();
|
|
17
|
+
this.runPriceTests();
|
|
18
|
+
this.runQuoteTests();
|
|
19
|
+
this.runValidationTests();
|
|
20
|
+
this.runErrorHandlingTests();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tests basic interface compliance
|
|
25
|
+
*/
|
|
26
|
+
runBasicInterfaceTests() {
|
|
27
|
+
describe('Interface Compliance', () => {
|
|
28
|
+
const protocol = this.config.protocol;
|
|
29
|
+
test('should implement IIntentProtocol interface', () => {
|
|
30
|
+
expect(protocol).toBeDefined();
|
|
31
|
+
expect(typeof protocol.fetchPrice).toBe('function');
|
|
32
|
+
expect(typeof protocol.fetchQuote).toBe('function');
|
|
33
|
+
});
|
|
34
|
+
test('should have required protocol properties', () => {
|
|
35
|
+
expect(protocol.protocol).toBeDefined();
|
|
36
|
+
expect(Array.isArray(protocol.chains)).toBe(true);
|
|
37
|
+
expect(typeof protocol.singleChain).toBe('boolean');
|
|
38
|
+
expect(typeof protocol.multiChain).toBe('boolean');
|
|
39
|
+
});
|
|
40
|
+
test('should have correct chain configuration', () => {
|
|
41
|
+
expect(protocol.singleChain).toBe(this.config.expectedBehavior.singleChain);
|
|
42
|
+
expect(protocol.multiChain).toBe(this.config.expectedBehavior.multiChain);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Tests supported chains functionality
|
|
48
|
+
*/
|
|
49
|
+
runChainSupportTests() {
|
|
50
|
+
describe('Chain Support', () => {
|
|
51
|
+
const protocol = this.config.protocol;
|
|
52
|
+
const expectedChains = this.config.expectedBehavior.supportedChains;
|
|
53
|
+
test('should support expected chains', () => {
|
|
54
|
+
expectedChains.forEach(chain => {
|
|
55
|
+
expect(protocol.chains).toContain(chain);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
test('should not support unexpected chains', () => {
|
|
59
|
+
const allChains = Object.values(enums_1.ChainIdEnum);
|
|
60
|
+
const unsupportedChains = allChains.filter(chain => !expectedChains.includes(chain));
|
|
61
|
+
unsupportedChains.forEach(chain => {
|
|
62
|
+
expect(protocol.chains).not.toContain(chain);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Tests price fetching functionality
|
|
69
|
+
*/
|
|
70
|
+
runPriceTests() {
|
|
71
|
+
if (this.config.skipTests?.price)
|
|
72
|
+
return;
|
|
73
|
+
describe('Price Fetching', () => {
|
|
74
|
+
const protocol = this.config.protocol;
|
|
75
|
+
test('should fetch price with valid parameters', async () => {
|
|
76
|
+
const params = this.getValidPriceParams();
|
|
77
|
+
// Mock the API call
|
|
78
|
+
const mockResponse = this.getMockPriceResponse();
|
|
79
|
+
jest.spyOn(protocol, 'fetchPrice').mockResolvedValue(mockResponse);
|
|
80
|
+
const result = await protocol.fetchPrice(params);
|
|
81
|
+
expect(result).toBeDefined();
|
|
82
|
+
expect(result.protocol).toBe(protocol.protocol);
|
|
83
|
+
expect(result.tokenIn).toBe(params.tokenIn);
|
|
84
|
+
expect(result.tokenOut).toBe(params.tokenOut);
|
|
85
|
+
expect(result.amountIn).toBe(params.amountIn);
|
|
86
|
+
expect(result.amountOut).toBeDefined();
|
|
87
|
+
expect(typeof result.amountOut).toBe('string');
|
|
88
|
+
});
|
|
89
|
+
test('should handle unsupported chains', async () => {
|
|
90
|
+
const unsupportedChain = this.getUnsupportedChain();
|
|
91
|
+
if (!unsupportedChain)
|
|
92
|
+
return;
|
|
93
|
+
const params = this.getValidPriceParams();
|
|
94
|
+
params.networkIn = unsupportedChain;
|
|
95
|
+
await expect(protocol.fetchPrice(params)).rejects.toThrow();
|
|
96
|
+
});
|
|
97
|
+
test('should validate required parameters', async () => {
|
|
98
|
+
const invalidParams = { ...this.getValidPriceParams() };
|
|
99
|
+
delete invalidParams.tokenIn;
|
|
100
|
+
await expect(protocol.fetchPrice(invalidParams)).rejects.toThrow();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Tests quote fetching functionality
|
|
106
|
+
*/
|
|
107
|
+
runQuoteTests() {
|
|
108
|
+
if (this.config.skipTests?.quote)
|
|
109
|
+
return;
|
|
110
|
+
describe('Quote Fetching', () => {
|
|
111
|
+
const protocol = this.config.protocol;
|
|
112
|
+
test('should fetch quote with valid parameters', async () => {
|
|
113
|
+
const params = this.getValidQuoteParams();
|
|
114
|
+
// Mock both price and quote responses
|
|
115
|
+
const mockPriceResponse = this.getMockPriceResponse();
|
|
116
|
+
const mockQuoteResponse = this.getMockQuoteResponse();
|
|
117
|
+
jest.spyOn(protocol, 'fetchPrice').mockResolvedValue(mockPriceResponse);
|
|
118
|
+
jest.spyOn(protocol, 'fetchQuote').mockResolvedValue(mockQuoteResponse);
|
|
119
|
+
const result = await protocol.fetchQuote(params);
|
|
120
|
+
expect(result).toBeDefined();
|
|
121
|
+
expect(result.protocol).toBe(protocol.protocol);
|
|
122
|
+
expect(result.from).toBe(params.from);
|
|
123
|
+
expect(result.executionPayload).toBeDefined();
|
|
124
|
+
});
|
|
125
|
+
test('should handle missing price response', async () => {
|
|
126
|
+
const params = this.getValidQuoteParams();
|
|
127
|
+
params.priceResponse = undefined;
|
|
128
|
+
// Mock price fetching to be called automatically
|
|
129
|
+
const mockPriceResponse = this.getMockPriceResponse();
|
|
130
|
+
const mockQuoteResponse = this.getMockQuoteResponse();
|
|
131
|
+
jest.spyOn(protocol, 'fetchPrice').mockResolvedValue(mockPriceResponse);
|
|
132
|
+
jest.spyOn(protocol, 'fetchQuote').mockResolvedValue(mockQuoteResponse);
|
|
133
|
+
const result = await protocol.fetchQuote(params);
|
|
134
|
+
expect(result).toBeDefined();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Tests parameter validation
|
|
140
|
+
*/
|
|
141
|
+
runValidationTests() {
|
|
142
|
+
if (this.config.skipTests?.validation)
|
|
143
|
+
return;
|
|
144
|
+
describe('Parameter Validation', () => {
|
|
145
|
+
const protocol = this.config.protocol;
|
|
146
|
+
test('should validate price parameters', async () => {
|
|
147
|
+
const testCases = [
|
|
148
|
+
{ name: 'missing tokenIn', params: { ...this.getValidPriceParams(), tokenIn: '' } },
|
|
149
|
+
{ name: 'missing tokenOut', params: { ...this.getValidPriceParams(), tokenOut: '' } },
|
|
150
|
+
{ name: 'invalid amountIn', params: { ...this.getValidPriceParams(), amountIn: '0' } },
|
|
151
|
+
{ name: 'invalid slippage', params: { ...this.getValidPriceParams(), slippage: -1 } },
|
|
152
|
+
];
|
|
153
|
+
for (const testCase of testCases) {
|
|
154
|
+
await expect(protocol.fetchPrice(testCase.params)).rejects.toThrow();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
test('should validate quote parameters', async () => {
|
|
158
|
+
const testCases = [
|
|
159
|
+
{ name: 'missing from address', params: { ...this.getValidQuoteParams(), from: '' } },
|
|
160
|
+
{
|
|
161
|
+
name: 'invalid receiver',
|
|
162
|
+
params: { ...this.getValidQuoteParams(), receiver: 'invalid' },
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
for (const testCase of testCases) {
|
|
166
|
+
await expect(protocol.fetchQuote(testCase.params)).rejects.toThrow();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Tests error handling
|
|
173
|
+
*/
|
|
174
|
+
runErrorHandlingTests() {
|
|
175
|
+
if (this.config.skipTests?.errorHandling)
|
|
176
|
+
return;
|
|
177
|
+
describe('Error Handling', () => {
|
|
178
|
+
const protocol = this.config.protocol;
|
|
179
|
+
test('should handle network errors gracefully', async () => {
|
|
180
|
+
const params = this.getValidPriceParams();
|
|
181
|
+
// Mock network error
|
|
182
|
+
jest.spyOn(protocol, 'fetchPrice').mockRejectedValue(new Error('Network error'));
|
|
183
|
+
await expect(protocol.fetchPrice(params)).rejects.toThrow('Network error');
|
|
184
|
+
});
|
|
185
|
+
test('should handle API errors gracefully', async () => {
|
|
186
|
+
const params = this.getValidPriceParams();
|
|
187
|
+
// Mock API error response
|
|
188
|
+
jest.spyOn(protocol, 'fetchPrice').mockRejectedValue({
|
|
189
|
+
response: { status: 400, data: { error: 'Invalid parameters' } },
|
|
190
|
+
});
|
|
191
|
+
await expect(protocol.fetchPrice(params)).rejects.toBeDefined();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
// Helper methods
|
|
196
|
+
getValidPriceParams() {
|
|
197
|
+
if (this.config.customTestParams?.validPriceParams) {
|
|
198
|
+
return this.config.customTestParams.validPriceParams;
|
|
199
|
+
}
|
|
200
|
+
const supportedChain = this.config.expectedBehavior.supportedChains[0];
|
|
201
|
+
return (0, test_data_1.createPriceParams)({
|
|
202
|
+
networkIn: supportedChain,
|
|
203
|
+
networkOut: supportedChain,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
getValidQuoteParams() {
|
|
207
|
+
if (this.config.customTestParams?.validQuoteParams) {
|
|
208
|
+
return this.config.customTestParams.validQuoteParams;
|
|
209
|
+
}
|
|
210
|
+
const supportedChain = this.config.expectedBehavior.supportedChains[0];
|
|
211
|
+
return (0, test_data_1.createQuoteParams)({
|
|
212
|
+
networkIn: supportedChain,
|
|
213
|
+
networkOut: supportedChain,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getUnsupportedChain() {
|
|
217
|
+
const allChains = Object.values(enums_1.ChainIdEnum);
|
|
218
|
+
const unsupportedChains = allChains.filter((chain) => !this.config.expectedBehavior.supportedChains.includes(chain));
|
|
219
|
+
return unsupportedChains.length > 0 ? unsupportedChains[0] : null;
|
|
220
|
+
}
|
|
221
|
+
getMockPriceResponse() {
|
|
222
|
+
const params = this.getValidPriceParams();
|
|
223
|
+
return {
|
|
224
|
+
protocol: this.config.protocol.protocol,
|
|
225
|
+
networkIn: params.networkIn,
|
|
226
|
+
networkOut: params.networkOut,
|
|
227
|
+
tokenIn: params.tokenIn,
|
|
228
|
+
tokenOut: params.tokenOut,
|
|
229
|
+
amountIn: params.amountIn,
|
|
230
|
+
amountOut: '1000000000',
|
|
231
|
+
slippage: params.slippage,
|
|
232
|
+
protocolResponse: { mockData: true },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
getMockQuoteResponse() {
|
|
236
|
+
const params = this.getValidQuoteParams();
|
|
237
|
+
return {
|
|
238
|
+
protocol: this.config.protocol.protocol,
|
|
239
|
+
networkIn: params.networkIn,
|
|
240
|
+
networkOut: params.networkOut,
|
|
241
|
+
tokenIn: params.tokenIn,
|
|
242
|
+
tokenOut: params.tokenOut,
|
|
243
|
+
amountIn: params.amountIn,
|
|
244
|
+
amountOut: '1000000000',
|
|
245
|
+
from: params.from,
|
|
246
|
+
receiver: params.receiver,
|
|
247
|
+
executionPayload: {
|
|
248
|
+
transactionData: {
|
|
249
|
+
data: '0x',
|
|
250
|
+
to: '0x123',
|
|
251
|
+
value: '0',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
slippage: params.slippage,
|
|
255
|
+
protocolResponse: { mockData: true },
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
exports.ProtocolTestRunner = ProtocolTestRunner;
|
|
260
|
+
//# sourceMappingURL=protocol-test-runner.js.map
|