forked from yug49/PyPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-simple-dutch-auction.js
More file actions
134 lines (120 loc) ยท 4.6 KB
/
test-simple-dutch-auction.js
File metadata and controls
134 lines (120 loc) ยท 4.6 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
126
127
128
129
130
131
132
133
134
const axios = require("axios");
const API_BASE_URL = "http://localhost:5001/api";
async function testSimpleDutchAuctionFlow() {
console.log("๐ Testing Dutch Auction Flow");
// Step 1: Create a mock order in the backend database
console.log("\n๐ Step 1: Creating order in database...");
const orderId = `0x${Math.random()
.toString(16)
.substr(2, 64)
.padEnd(64, "0")}`;
const transactionHash = `0x${"a".repeat(64)}`; // Valid 64-char hex hash
const orderData = {
orderId: orderId,
walletAddress: "0x1234567890123456789012345678901234567890",
amount: "100.00",
tokenAddress: "0x11fE4B6AE13d2a6055C8D9cF65c55bac32B5d844", // MockUSDC
startPrice: "90.00",
endPrice: "80.00",
recipientUpiAddress: "test@paytm",
transactionHash: transactionHash,
blockNumber: 12345,
};
try {
const createResponse = await axios.post(
`${API_BASE_URL}/orders`,
orderData
);
console.log(`โ
Order created successfully: ${orderId}`);
console.log(
`๐ Start Price: โน${orderData.startPrice}, End Price: โน${orderData.endPrice}`
);
} catch (error) {
console.error(
"โ Failed to create order:",
error.response?.data || error.message
);
return;
}
// Step 2: Start the Dutch auction
console.log("\n๐ฏ Step 2: Starting Dutch auction...");
try {
const startResponse = await axios.post(
`${API_BASE_URL}/orders/${orderId}/start-auction`
);
console.log("โ
Auction started successfully");
console.log("๐ฅ Auction details:", startResponse.data);
} catch (error) {
console.error(
"โ Failed to start auction:",
error.response?.data || error.message
);
return;
}
// Step 3: Monitor auction status
console.log("\n๐ Step 3: Monitoring auction for 8 seconds...");
let auctionCompleted = false;
const maxChecks = 16; // 8 seconds with 0.5s interval
for (let i = 0; i < maxChecks && !auctionCompleted; i++) {
await new Promise((resolve) => setTimeout(resolve, 500));
try {
const statusResponse = await axios.get(
`${API_BASE_URL}/orders/${orderId}/auction-status`
);
const auction = statusResponse.data.auction;
if (auction && auction.isActive) {
console.log(
`๐ฐ Current Price: โน${auction.currentPrice.toFixed(
2
)} (${auction.progress.toFixed(1)}%)`
);
} else if (auction && !auction.isActive && auction.acceptedPrice) {
console.log(
`๐ฏ Auction accepted at โน${auction.acceptedPrice}!`
);
auctionCompleted = true;
} else if (auction && !auction.isActive) {
console.log(
`๐ Auction ended: ${auction.reason || "completed"}`
);
auctionCompleted = true;
}
} catch (error) {
console.error(
"โ Failed to get auction status:",
error.response?.data || error.message
);
}
}
// Step 4: Check final order status
console.log("\n๐ Step 4: Checking final order status...");
try {
const orderResponse = await axios.get(
`${API_BASE_URL}/orders/${orderId}`
);
const order = orderResponse.data.data;
console.log(`๐ Status: ${order.status}`);
console.log(`๐ฐ Final Price: โน${order.acceptedPrice || "N/A"}`);
console.log(`๐ค Accepted By: ${order.acceptedBy || "N/A"}`);
console.log(`โฑ๏ธ Accepted At: ${order.acceptedAt || "N/A"}`);
console.log(`๐ Auction Active: ${order.auctionActive}`);
if (order.status === "accepted") {
console.log("\n๐ SUCCESS: Dutch auction completed successfully!");
console.log(
"โ
Resolver bot successfully participated and accepted the auction"
);
} else {
console.log(
"\nโฐ Auction completed without acceptance (this is normal if resolver didn't participate)"
);
}
} catch (error) {
console.error(
"โ Failed to get order status:",
error.response?.data || error.message
);
}
console.log("\n๐ Dutch auction test completed!");
}
// Run the test
testSimpleDutchAuctionFlow().catch(console.error);