Initial project setup: Add contracts, API definitions, tests, and documentation
- Add Foundry project configuration (foundry.toml, foundry.lock) - Add Solidity contracts (TokenFactory138, BridgeVault138, ComplianceRegistry, etc.) - Add API definitions (OpenAPI, GraphQL, gRPC, AsyncAPI) - Add comprehensive test suite (unit, integration, fuzz, invariants) - Add API services (REST, GraphQL, orchestrator, packet service) - Add documentation (ISO20022 mapping, runbooks, adapter guides) - Add development tools (RBC tool, Swagger UI, mock server) - Update OpenZeppelin submodules to v5.0.0
This commit is contained in:
74
api/tools/mock-server/src/graphql-mock.ts
Normal file
74
api/tools/mock-server/src/graphql-mock.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* GraphQL Mock Server
|
||||
* Mocks GraphQL schema for testing
|
||||
*/
|
||||
|
||||
import { createYoga } from 'graphql-yoga';
|
||||
import { createServer } from 'http';
|
||||
import { addMocksToSchema } from '@graphql-tools/mock';
|
||||
import { makeExecutableSchema } from '@graphql-tools/schema';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
const SCHEMA_PATH = join(__dirname, '../../packages/graphql/schema.graphql');
|
||||
|
||||
function startGraphQLMockServer() {
|
||||
const typeDefs = readFileSync(SCHEMA_PATH, 'utf-8');
|
||||
|
||||
const schema = makeExecutableSchema({
|
||||
typeDefs,
|
||||
});
|
||||
|
||||
// Add mocks
|
||||
const mockedSchema = addMocksToSchema({
|
||||
schema,
|
||||
mocks: {
|
||||
Token: () => ({
|
||||
code: 'USDW',
|
||||
address: '0x1234567890123456789012345678901234567890',
|
||||
name: 'USD Wrapped',
|
||||
symbol: 'USDW',
|
||||
decimals: 18,
|
||||
issuer: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
|
||||
policy: {
|
||||
paused: false,
|
||||
bridgeOnly: false,
|
||||
lienMode: 'ENCUMBERED',
|
||||
forceTransferMode: false,
|
||||
routes: ['FEDWIRE', 'SWIFT'],
|
||||
},
|
||||
}),
|
||||
Lien: () => ({
|
||||
lienId: '123',
|
||||
debtor: '0xabcd...',
|
||||
amount: '1000000000000000000',
|
||||
active: true,
|
||||
priority: 1,
|
||||
reasonCode: 'DEBT_ENFORCEMENT',
|
||||
}),
|
||||
Trigger: () => ({
|
||||
triggerId: 'abc123',
|
||||
rail: 'FEDWIRE',
|
||||
msgType: 'pacs.008',
|
||||
state: 'PENDING',
|
||||
instructionId: '0x1234...',
|
||||
amount: '1000000000000000000',
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const yoga = createYoga({
|
||||
schema: mockedSchema,
|
||||
graphqlEndpoint: '/graphql',
|
||||
});
|
||||
|
||||
const server = createServer(yoga);
|
||||
const PORT = process.env.MOCK_GRAPHQL_PORT || 4020;
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`GraphQL Mock Server running on http://localhost:${PORT}/graphql`);
|
||||
});
|
||||
}
|
||||
|
||||
startGraphQLMockServer();
|
||||
|
||||
26
api/tools/mock-server/src/index.ts
Normal file
26
api/tools/mock-server/src/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Start all mock servers
|
||||
*/
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
import { join } from 'path';
|
||||
|
||||
const servers = [
|
||||
{ name: 'REST Mock', script: 'rest-mock.js' },
|
||||
{ name: 'GraphQL Mock', script: 'graphql-mock.js' },
|
||||
{ name: 'Rail Simulator', script: 'rail-simulator.js' },
|
||||
{ name: 'Packet Simulator', script: 'packet-simulator.js' },
|
||||
];
|
||||
|
||||
console.log('Starting all mock servers...');
|
||||
|
||||
servers.forEach(({ name, script }) => {
|
||||
const proc = spawn('node', [join(__dirname, script)], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
proc.on('error', (error) => {
|
||||
console.error(`Failed to start ${name}:`, error);
|
||||
});
|
||||
});
|
||||
|
||||
57
api/tools/mock-server/src/packet-simulator.ts
Normal file
57
api/tools/mock-server/src/packet-simulator.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Packet Simulator
|
||||
* Simulates AS4 receipts and email acknowledgements for testing
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const PORT = process.env.PACKET_SIMULATOR_PORT || 4040;
|
||||
|
||||
// Simulate AS4 receipt
|
||||
app.post('/simulate/as4/receipt', (req, res) => {
|
||||
const { packetId, messageRef } = req.body;
|
||||
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
packetId,
|
||||
messageRef,
|
||||
ackId: `AS4-ACK-${Date.now()}`,
|
||||
status: 'RECEIVED',
|
||||
receivedAt: new Date().toISOString(),
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// Simulate email acknowledgement
|
||||
app.post('/simulate/email/ack', (req, res) => {
|
||||
const { packetId, recipient } = req.body;
|
||||
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
packetId,
|
||||
recipient,
|
||||
ackId: `EMAIL-ACK-${Date.now()}`,
|
||||
status: 'ACCEPTED',
|
||||
receivedAt: new Date().toISOString(),
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// Simulate packet delivery failure
|
||||
app.post('/simulate/failure', (req, res) => {
|
||||
const { packetId, reason } = req.body;
|
||||
|
||||
res.status(400).json({
|
||||
packetId,
|
||||
error: reason || 'Delivery failed',
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Packet Simulator running on http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
73
api/tools/mock-server/src/rail-simulator.ts
Normal file
73
api/tools/mock-server/src/rail-simulator.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Rail Simulator
|
||||
* Simulates Fedwire/SWIFT/SEPA/RTGS responses for testing
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
const PORT = process.env.RAIL_SIMULATOR_PORT || 4030;
|
||||
|
||||
// Simulate Fedwire response
|
||||
app.post('/simulate/fedwire', (req, res) => {
|
||||
const { instructionId, amount } = req.body;
|
||||
|
||||
// Simulate processing delay
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
railTxRef: `FED-${Date.now()}`,
|
||||
status: 'ACCEPTED',
|
||||
settlementDate: new Date().toISOString(),
|
||||
instructionId,
|
||||
amount,
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// Simulate SWIFT response
|
||||
app.post('/simulate/swift', (req, res) => {
|
||||
const { instructionId, amount } = req.body;
|
||||
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
railTxRef: `SWIFT-${Date.now()}`,
|
||||
status: 'ACCEPTED',
|
||||
settlementDate: new Date().toISOString(),
|
||||
instructionId,
|
||||
amount,
|
||||
});
|
||||
}, 1500);
|
||||
});
|
||||
|
||||
// Simulate SEPA response
|
||||
app.post('/simulate/sepa', (req, res) => {
|
||||
const { instructionId, amount } = req.body;
|
||||
|
||||
setTimeout(() => {
|
||||
res.json({
|
||||
railTxRef: `SEPA-${Date.now()}`,
|
||||
status: 'ACCEPTED',
|
||||
settlementDate: new Date().toISOString(),
|
||||
instructionId,
|
||||
amount,
|
||||
});
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
// Simulate status update (pacs.002)
|
||||
app.post('/simulate/status', (req, res) => {
|
||||
const { railTxRef, status } = req.body;
|
||||
|
||||
res.json({
|
||||
railTxRef,
|
||||
status: status || 'ACSC', // ACSC = AcceptedSettlementCompleted
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Rail Simulator running on http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
37
api/tools/mock-server/src/rest-mock.ts
Normal file
37
api/tools/mock-server/src/rest-mock.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* REST API Mock Server using Prism
|
||||
* Mocks OpenAPI specification for testing
|
||||
*/
|
||||
|
||||
import { createServer } from '@stoplight/prism-http';
|
||||
import { createHttpServer } from '@stoplight/prism-http-server';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
const OPENAPI_SPEC = join(__dirname, '../../packages/openapi/v1/openapi.yaml');
|
||||
|
||||
async function startMockServer() {
|
||||
const spec = readFileSync(OPENAPI_SPEC, 'utf-8');
|
||||
|
||||
const server = createHttpServer({
|
||||
document: spec,
|
||||
config: {
|
||||
mock: {
|
||||
dynamic: true,
|
||||
exampleKey: 'default',
|
||||
},
|
||||
cors: true,
|
||||
errors: false,
|
||||
},
|
||||
});
|
||||
|
||||
const PORT = process.env.MOCK_PORT || 4010;
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`REST API Mock Server running on http://localhost:${PORT}`);
|
||||
console.log(`OpenAPI spec: ${OPENAPI_SPEC}`);
|
||||
});
|
||||
}
|
||||
|
||||
startMockServer().catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user