forked from Manuel1234477/Stellar-Micro-Donation-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-wallet-transactions.js
More file actions
87 lines (74 loc) · 2.77 KB
/
test-wallet-transactions.js
File metadata and controls
87 lines (74 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const Database = require('./src/utils/database');
async function testWalletTransactions() {
console.log('Testing Wallet Transactions Endpoint Logic\n');
try {
// Test 1: Get transactions for user 1 (has sent transactions)
console.log('Test 1: User with transactions (sender)');
const publicKey1 = 'GBRPYHIL2CI3WHZDTOOQFC6EB4KJJGUJMUC5XNODMZTQYBB5XYZXYUU';
const user1 = await Database.get(
'SELECT id, publicKey, createdAt FROM users WHERE publicKey = ?',
[publicKey1]
);
console.log('User found:', user1);
const transactions1 = await Database.query(
`SELECT
t.id,
t.senderId,
t.receiverId,
t.amount,
t.memo,
t.timestamp,
sender.publicKey as senderPublicKey,
receiver.publicKey as receiverPublicKey
FROM transactions t
LEFT JOIN users sender ON t.senderId = sender.id
LEFT JOIN users receiver ON t.receiverId = receiver.id
WHERE t.senderId = ? OR t.receiverId = ?
ORDER BY t.timestamp DESC`,
[user1.id, user1.id]
);
console.log('Transactions:', JSON.stringify(transactions1, null, 2));
console.log(`Count: ${transactions1.length}\n`);
// Test 2: Get transactions for user 3 (receiver)
console.log('Test 2: User with transactions (receiver)');
const publicKey3 = 'GCZST3XVCDTUJ76ZAV2HA72KYQM4YQQ5DUJTHIGQ5ESE3JNEZUAEUA7X';
const user3 = await Database.get(
'SELECT id, publicKey, createdAt FROM users WHERE publicKey = ?',
[publicKey3]
);
console.log('User found:', user3);
const transactions3 = await Database.query(
`SELECT
t.id,
t.senderId,
t.receiverId,
t.amount,
t.memo,
t.timestamp,
sender.publicKey as senderPublicKey,
receiver.publicKey as receiverPublicKey
FROM transactions t
LEFT JOIN users sender ON t.senderId = sender.id
LEFT JOIN users receiver ON t.receiverId = receiver.id
WHERE t.senderId = ? OR t.receiverId = ?
ORDER BY t.timestamp DESC`,
[user3.id, user3.id]
);
console.log('Transactions:', JSON.stringify(transactions3, null, 2));
console.log(`Count: ${transactions3.length}\n`);
// Test 3: Non-existent wallet
console.log('Test 3: Non-existent wallet');
const fakePublicKey = 'GFAKEWALLETADDRESSNOTINDB123456789012345678901234567890';
const userFake = await Database.get(
'SELECT id, publicKey, createdAt FROM users WHERE publicKey = ?',
[fakePublicKey]
);
console.log('User found:', userFake);
console.log('Should return empty array\n');
console.log('✓ All tests completed successfully!');
} catch (error) {
console.error('✗ Test failed:', error.message);
process.exit(1);
}
}
testWalletTransactions();