40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
// testE2E_Solana.js
|
|
import { Client } from 'pg';
|
|
import fetch from 'node-fetch';
|
|
|
|
async function testE2E() {
|
|
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
await client.connect();
|
|
|
|
// 1. Get Merchant
|
|
let res = await client.query('SELECT * FROM merchants LIMIT 1');
|
|
let merchantId = res.rows[0]?.id;
|
|
|
|
// 2. Create Transaction
|
|
const createRes = await fetch('http://localhost:3000/api/create-payment-intent', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ amount: 5, currency: 'TRY', merchant_id: merchantId })
|
|
});
|
|
const createData = await createRes.json();
|
|
console.log("Create Data ID:", createData.id);
|
|
|
|
const txId = createData.id;
|
|
const solAddress = createData.wallets.SOLANA;
|
|
console.log("Deposit Address:", solAddress);
|
|
|
|
// 3. Let's see how much it expects
|
|
// Assuming 5 TRY is ~0.001 SOL
|
|
console.log("Sending sweep request with NO FUNDS FIRST...");
|
|
const sweepRes = await fetch('http://localhost:3000/api/crypto-sweep', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ txId, network: 'SOLANA', token: 'SOL' })
|
|
});
|
|
const sweepData = await sweepRes.json();
|
|
console.log("Sweep Data:", sweepData);
|
|
|
|
await client.end();
|
|
}
|
|
testE2E().catch(console.error);
|