Files

78 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

#!/usr/bin/env node
/**
* Minimal integration test for multi-chain execution API.
* Creates intent 138 -> 651940, executes, and verifies execution.
* Assumes deterministic contract addresses: same address on 138 and 651940 (CREATE2).
* Run with: BASE_URL=http://localhost:3001 node scripts/integration-test.mjs
* Prerequisite: npm run build && npm start (in another terminal).
*/
const BASE = process.env.BASE_URL || 'http://localhost:3001';
async function request(method, path, body = null) {
const opts = { method, headers: {} };
if (body) {
opts.headers['Content-Type'] = 'application/json';
opts.body = JSON.stringify(body);
}
const res = await fetch(`${BASE}${path}`, opts);
const text = await res.text();
if (!res.ok) throw new Error(`${res.status} ${path}: ${text}`);
return text ? JSON.parse(text) : {};
}
async function main() {
console.log('Integration test (138 -> 651940, deterministic addresses assumed)\n');
const health = await request('GET', '/v1/health');
console.log('Health:', health.status, health.circuit_breaker);
if (health.status !== 'ok' && health.status !== 'degraded') {
throw new Error('Health check failed');
}
const intentPayload = {
type: 'cross_chain',
chain_from: 138,
chain_to: 651940,
asset_in: 'native',
asset_out: 'native',
amount: '1000000',
idempotency_key: `integration-${Date.now()}`,
};
const intent = await request('POST', '/v1/intents', intentPayload);
if (!intent.intent_id) throw new Error('No intent_id');
console.log('Intent created:', intent.intent_id);
const exec = await request('POST', `/v1/intents/${intent.intent_id}/execute`);
if (!exec.execution_id) throw new Error('No execution_id');
console.log('Execution started:', exec.execution_id);
const execution = await request('GET', `/v1/executions/${exec.execution_id}`);
console.log('Execution status:', execution.status || execution);
const commitPayload = {
chain_id: 138,
leaves: [{
chainId: 138,
txHash: '0x' + '0'.repeat(64),
blockNumber: '100',
receiptRootOrLogsBloom: '0x00',
normalizedEventPayloadHash: '0x00',
salJournalEntryHash: null,
}],
uri: 'https://example.com/leaves',
};
const commit = await request('POST', '/v1/mirror/commit', commitPayload);
if (commit.commit_id) {
const got = await request('GET', `/v1/mirror/commits/${commit.commit_id}`);
console.log('Mirror commit verified:', got.commit_id === commit.commit_id);
}
console.log('\nIntegration test OK (deterministic addresses assumed for 138 and 651940).');
}
main().catch((err) => {
console.error(err);
process.exit(1);
});