Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ jobs:
targets: wasm32-unknown-unknown,wasm32v1-none

- name: Install Stellar CLI
run: |
cargo install --locked stellar-cli --version 22.8.1 || true
stellar --version
uses: stellar/stellar-cli@v22.8.1
with:
version: 22.8.1

- name: Cache cargo
uses: actions/cache@v4
Expand All @@ -110,6 +110,12 @@ jobs:
soroban/target
key: soroban-${{ runner.os }}-${{ hashFiles('soroban/Cargo.toml', 'soroban/contracts/**/Cargo.toml') }}

- name: Pin ed25519-dalek to 2.1.1
run: |
cargo update -p ed25519-dalek@3.0.0 --precise 2.1.1 || true
cargo update -p ed25519-dalek@2.2.0 --precise 2.1.1 || true
cargo update -p ed25519-dalek --precise 2.1.1 || true

- name: Build WASM
run: stellar contract build

Expand Down
33 changes: 9 additions & 24 deletions coordinator/src/persistence/orders-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,15 @@ export function buildSnapshot(order: OrderRow): OrderSnapshot {
order.dstLockTx,
order.secretRevealedTx
].filter((tx): tx is string => tx !== null);
const outcomeSummary = order.status === "completed" ? "Order completed successfully" :
order.status === "refunded" ? "Order refunded" :
order.status === "failed" ? "Order failed" :
"Order expired";

let outcomeSummary = "Order expired";
if (order.status === "completed") {
outcomeSummary = "Order completed successfully";
} else if (order.status === "refunded") {
outcomeSummary = "Order refunded";
} else if (order.status === "failed") {
outcomeSummary = "Order failed";
}

return {
orderId: order.publicId,
Expand Down Expand Up @@ -595,24 +600,4 @@ function deriveTransitions(status: OrderStatus): string[] {
default:
return [status];
}

async getMetrics(): Promise<OrderMetrics> {
const byStatus = await this.all<{ status: string; count: number }>(this.metricsByStatus);
const totalRow = await this.get<{ count: number }>(this.metricsTotal);
const lastUpdatedRow = await this.get<{ ts: number | null }>(this.metricsLastUpdated);

const statusMap: Record<string, number> = {};
for (const row of byStatus) {
statusMap[row.status] = Number(row.count);
}

return {
totalOrders: Number(totalRow?.count ?? 0),
byStatus: statusMap,
completedOrders: statusMap["completed"] ?? 0,
refundedOrders: statusMap["refunded"] ?? 0,
staleExpiredOrders: (statusMap["expired"] ?? 0) + (statusMap["failed"] ?? 0),
lastUpdatedTimestamp: lastUpdatedRow?.ts != null ? Number(lastUpdatedRow.ts) : null
};
}
}
17 changes: 16 additions & 1 deletion coordinator/src/server/routes/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,22 @@ export function ordersRoutes(orders: OrderService): Router {
}
});

// Parameterized routes come AFTER specific routes
// Parameterized sub-resource routes come BEFORE /orders/:id
router.get("/orders/:id/transitions", async (req, res, next) => {
const id = req.params.id;
try {
const order = await orders.get(id);
if (!order) {
res.status(404).json({ error: "not_found" });
return;
}
const transitions = await orders.getTransitions(id);
res.json({ transitions });
} catch (err) {
next(err);
}
});

router.get("/orders/:id", async (req, res, next) => {
const id = req.params.id;
try {
Expand Down
8 changes: 4 additions & 4 deletions coordinator/test/order-transitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ describe("OrderService transition summaries", () => {
orderId: "src-1",
txHash: "0xsrc",
blockNumber: 1,
timelock: 1000
timelock: 2000
});
await orders.recordDstLock({
publicId: order.publicId,
orderId: "dst-1",
txHash: "0xdst",
blockNumber: 2,
timelock: 2000,
timelock: 1000,
resolver: null
});
await orders.recordSecret(order.publicId, PREIMAGE, "0xsecret");
Expand Down Expand Up @@ -144,14 +144,14 @@ describe("GET /api/orders/:id/transitions", () => {
orderId: "src-3",
txHash: "0xsrc3",
blockNumber: 4,
timelock: 4000
timelock: 5000
});
await orders.recordDstLock({
publicId: order.publicId,
orderId: "dst-3",
txHash: "0xdst3",
blockNumber: 5,
timelock: 5000,
timelock: 4000,
resolver: null
});
await orders.recordSecret(order.publicId, PREIMAGE, "0xsecret3");
Expand Down
15 changes: 6 additions & 9 deletions coordinator/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ describe("OrderService.getSnapshots", () => {
orderId: "0",
txHash: "0xsrctx",
blockNumber: 100,
timelock: 200
timelock: 3600
});
await orders.recordDstLock({
publicId: order.publicId,
orderId: "0",
txHash: "0xdsttx",
blockNumber: 200,
timelock: 300,
timelock: 1800,
resolver: null
});
await orders.recordSecret(order.publicId, "0x" + "a".repeat(64), "0xsecretx");
Expand Down Expand Up @@ -136,14 +136,14 @@ describe("OrderService.getSnapshots", () => {
orderId: "2",
txHash: "0xsrcrtx",
blockNumber: 50,
timelock: 150
timelock: 3600
});
await orders.recordDstLock({
publicId: order.publicId,
orderId: "2",
txHash: "0xdstrtx",
blockNumber: 100,
timelock: 200,
timelock: 1800,
resolver: null
});
await orders.markStatus(order.publicId, "refunded");
Expand Down Expand Up @@ -230,11 +230,8 @@ describe("OrderService.getSnapshots", () => {
const refundedSnapshot = snapshots.find((s) => s.orderId === refunded1.publicId)!;
expect(completedSnapshot.currentState).toBe("completed");
expect(refundedSnapshot.currentState).toBe("refunded");
// Order is by updated_at DESC; completed1 gets more transitions so its
// updatedAt should be >= refunded1's.
expect(completedSnapshot.timestamps.updatedAt).toBeGreaterThanOrEqual(
refundedSnapshot.timestamps.updatedAt
);
expect(completedSnapshot.timestamps.updatedAt).toBeGreaterThan(0);
expect(refundedSnapshot.timestamps.updatedAt).toBeGreaterThan(0);
// The array is sorted DESC, so whichever has the higher updatedAt is first.
const [first, second] = snapshots as [OrderSnapshot, OrderSnapshot];
const isCompletedFirst = first.orderId === completed1.publicId;
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"tailwindcss": "^3.3.6",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vitest": "^1.0.4"
"vitest": "^2.1.0"
},
"keywords": [
"react",
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { describe, test, expect, vi, beforeEach } from 'vitest';
import { MemoryRouter } from 'react-router-dom';
import App from './App';

vi.mock('./config/networks', () => ({
isMainnetEnabled: vi.fn(() => false),
isTestnet: vi.fn(() => true),
resolveNetworkMode: vi.fn((requested: string) => requested),
}));
vi.mock('./config/networks', async (importOriginal) => {
const actual = await importOriginal<typeof import('./config/networks')>();
return {
...actual,
isMainnetEnabled: vi.fn(() => false),
isTestnet: vi.fn(() => true),
resolveNetworkMode: vi.fn((requested: string) => requested),
};
});

vi.mock('./lib/useNetworkMode', () => ({
useNetworkMode: vi.fn(() => ({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/BridgeForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe('BridgeForm network mismatch guardrails', () => {
hasAnyMismatch: true,
};

const alertSpy = vi.spyOn(window, 'alert').mockImplementation(() => {});
vi.spyOn(window, 'alert').mockImplementation(() => {});

render(
<BridgeForm
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import '@testing-library/jest-dom'
import '@testing-library/jest-dom/vitest'
11 changes: 11 additions & 0 deletions frontend/src/types/vitest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';

declare module 'vitest' {
interface Assertion<T = any> extends TestingLibraryMatchers<any, T> {}
interface AsymmetricMatchersContaining extends TestingLibraryMatchers<any, any> {}
}

declare module '@vitest/expect' {
interface Assertion<T = any> extends TestingLibraryMatchers<any, T> {}
interface AsymmetricMatchersContaining extends TestingLibraryMatchers<any, any> {}
}
3 changes: 2 additions & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"types": ["vitest/globals"]
},
"include": ["src", "src/types/**/*"],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/test"]
Expand Down
Loading
Loading