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
4 changes: 4 additions & 0 deletions .github/trufflehog-ignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.*test.*
.*spec.*
tests/.*
__tests__/.*
25 changes: 25 additions & 0 deletions .github/workflows/secret-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Secret Scanning

on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]

jobs:
trufflehog:
name: TruffleHog Secret Scanner
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Scan for secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --exclude-paths=.github/trufflehog-ignore.txt
30 changes: 30 additions & 0 deletions payment_router/extract_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

lib_path = 'payment_router/src/lib.rs'
test_path = 'payment_router/src/test.rs'

with open(lib_path, 'r') as f:
lines = f.readlines()

test_start = -1
for i, line in enumerate(lines):
if line.strip() == '#[cfg(test)]' and lines[i+1].startswith('mod test {'):
test_start = i
break

if test_start != -1:
test_lines = lines[test_start+2 : -1] # extract inside mod test { ... }
# wait, we need to extract everything inside mod test { }
# actually, I can just grab from test_start+2 to the end and remove the last '}'
test_content = "".join(test_lines[:-1]) # omit the last '}'

with open(test_path, 'w') as f:
f.write(test_content)

lib_content = "".join(lines[:test_start]) + "#[cfg(test)]\nmod test;\n"
with open(lib_path, 'w') as f:
f.write(lib_content)

print("Extracted test mod to test.rs")
else:
print("Could not find test mod")
44 changes: 44 additions & 0 deletions payment_router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,4 +1108,48 @@ mod test {
assert_eq!(eurc_like_client.balance(&recipient), 990);
assert_eq!(client.get_user_volume(&sender), 3_000);
}

#[test]
fn test_benchmark_gas_costs() {
let (env, client, _) = setup_env();

let admin = Address::generate(&env);
let treasury = Address::generate(&env);
let sender = Address::generate(&env);
let recipient = Address::generate(&env);

let (token_address, _token_client, sac) = setup_token(&env);
sac.mint(&sender, &10_000);

// Reset budget before initialization
env.budget().reset_default();
client.initialize(&admin, &treasury, &100, &50, &PaymentRouter::MAX_AMOUNT);
let init_cpu = env.budget().cpu_instruction_cost();
let init_mem = env.budget().memory_bytes_cost();
std::println!("GAS REPORT: initialize");
std::println!("CPU Instructions: {}", init_cpu);
std::println!("Memory Bytes: {}", init_mem);

// Reset budget before route_payment
env.budget().reset_default();
client.route_payment(&sender, &recipient, &token_address, &5_000);
let route_cpu = env.budget().cpu_instruction_cost();
let route_mem = env.budget().memory_bytes_cost();
std::println!("GAS REPORT: route_payment");
std::println!("CPU Instructions: {}", route_cpu);
std::println!("Memory Bytes: {}", route_mem);

env.budget().print();

// Fails CI if gas costs exceed defined thresholds
// Set reasonable thresholds (e.g. 5M CPU and 2MB Mem per call)
let max_cpu = 5_000_000;
let max_mem = 2_000_000;

assert!(init_cpu <= max_cpu, "initialize CPU cost exceeded threshold! Cost: {}, Threshold: {}", init_cpu, max_cpu);
assert!(init_mem <= max_mem, "initialize Memory cost exceeded threshold! Cost: {}, Threshold: {}", init_mem, max_mem);

assert!(route_cpu <= max_cpu, "route_payment CPU cost exceeded threshold! Cost: {}, Threshold: {}", route_cpu, max_cpu);
assert!(route_mem <= max_mem, "route_payment Memory cost exceeded threshold! Cost: {}, Threshold: {}", route_mem, max_mem);
}
}
5 changes: 5 additions & 0 deletions stellar-payment-platform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
},
"dependencies": {
"@faker-js/faker": "^10.5.0",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/auto-instrumentations-node": "^0.47.1",
"@opentelemetry/exporter-zipkin": "^1.25.0",
"@opentelemetry/sdk-node": "^0.52.1",
"@prisma/client": "^6.19.3",
"@prisma/instrumentation": "^6.19.3",
"@sentry/node": "^10.68.0",
"@stellar/stellar-sdk": "^16.0.1",
"bad-words": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion stellar-payment-platform/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ datasource db {

generator client {
provider = "prisma-client-js"
previewFeatures = ["metrics"]
previewFeatures = ["metrics", "tracing"]
}

// Federation registry mapping a human-readable username (e.g. "lekan*localhost")
Expand Down
1 change: 1 addition & 0 deletions stellar-payment-platform/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./src/utils/tracing');
require('./config/envCheck');
const express = require('express');
const cors = require('cors');
Expand Down
28 changes: 28 additions & 0 deletions stellar-payment-platform/src/utils/tracing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { PrismaInstrumentation } = require('@prisma/instrumentation');

const sdk = new NodeSDK({
traceExporter: new ZipkinExporter({
url: process.env.ZIPKIN_ENDPOINT || 'http://localhost:9411/api/v2/spans',
serviceName: 'stellar-tags-api',
}),
instrumentations: [
getNodeAutoInstrumentations({
// We are tracing Express, HTTP, and Prisma out-of-the-box
'@opentelemetry/instrumentation-express': { enabled: true },
'@opentelemetry/instrumentation-http': { enabled: true },
}),
new PrismaInstrumentation()
]
});

sdk.start();

process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
});
Loading