forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-simple-auction.js
More file actions
125 lines (111 loc) · 4.01 KB
/
test-simple-auction.js
File metadata and controls
125 lines (111 loc) · 4.01 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
const http = require("http");
const url = require("url");
const BACKEND_URL = "http://localhost:5001";
function makeRequest(urlPath, method = "GET", data = null) {
return new Promise((resolve, reject) => {
const urlObj = new URL(urlPath, BACKEND_URL);
const options = {
hostname: urlObj.hostname,
port: urlObj.port,
path: urlObj.pathname + urlObj.search,
method: method,
headers: {
"Content-Type": "application/json",
},
};
const req = http.request(options, (res) => {
let body = "";
res.on("data", (chunk) => (body += chunk));
res.on("end", () => {
try {
const result = JSON.parse(body);
resolve({ status: res.statusCode, data: result });
} catch (e) {
resolve({ status: res.statusCode, data: body });
}
});
});
req.on("error", reject);
if (data) {
req.write(JSON.stringify(data));
}
req.end();
});
}
async function testDutchAuctionAPI() {
console.log("🧪 Testing Dutch Auction API Implementation\n");
// Test 1: Health check
console.log("1️⃣ Testing backend health...");
try {
const response = await makeRequest("/health");
if (response.status === 200) {
console.log("✅ Backend is healthy:", response.data);
} else {
console.log("❌ Backend health check failed:", response.status);
return;
}
} catch (error) {
console.log("❌ Backend health check failed:", error.message);
return;
}
// Test 2: Test auction status API with mock order
const TEST_ORDER_ID = "0x" + "1".repeat(64);
console.log("\n2️⃣ Testing auction status API...");
try {
const response = await makeRequest(
`/api/orders/${TEST_ORDER_ID}/auction-status`
);
if (response.status === 200) {
console.log("✅ Auction status API working:", response.data);
} else {
console.log(
"⚠️ Auction status response:",
response.status,
response.data
);
}
} catch (error) {
console.log("❌ Auction status test failed:", error.message);
}
// Test 3: Test auction start API (will fail without valid order, but tests endpoint)
console.log("\n3️⃣ Testing auction start API...");
try {
const response = await makeRequest(
`/api/orders/${TEST_ORDER_ID}/start-auction`,
"POST",
{
duration: 5000,
}
);
if (response.status === 404) {
console.log(
"✅ Auction start API endpoint working (order not found as expected)"
);
} else if (response.data.success) {
console.log("✅ Auction started successfully:", response.data);
} else {
console.log(
"⚠️ Auction start response:",
response.status,
response.data
);
}
} catch (error) {
console.log("❌ Auction start test failed:", error.message);
}
console.log("\n🎉 Dutch auction API testing completed!");
console.log("\n📋 Summary:");
console.log("- Backend server: ✅ Running on http://localhost:5001");
console.log("- Health endpoint: ✅ Working");
console.log("- Auction APIs: ✅ Endpoints configured");
console.log("\n🚀 Ready for full testing!");
console.log("\n📝 Next steps:");
console.log("1. Start frontend: cd frontend && npm run dev");
console.log("2. Open: http://localhost:3000/maker-dashboard");
console.log("3. Connect wallet and create an order");
console.log("4. Enable Dutch auction toggle");
console.log("5. Watch real-time price updates!");
}
// Run the test
testDutchAuctionAPI().catch(console.error);