Skip to content

Commit cc3083f

Browse files
committed
better test logging
1 parent 1cd82b4 commit cc3083f

File tree

2 files changed

+115
-49
lines changed

2 files changed

+115
-49
lines changed

test/swapAndPlaceERC1155BuyOrder.test.ts

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -202,45 +202,64 @@ describe("SwapAndPlaceERC1155BuyOrder Integration Test", function () {
202202
recipient: deployer.address,
203203
};
204204

205-
console.log("\n=== BUY ORDER (ERC1155) INPUTS ===");
206-
console.log("TokenIn:", params.tokenIn);
207-
console.log("erc1155TokenAddress:", params.erc1155TokenAddress);
208-
console.log("erc1155TokenId:", params.erc1155TokenId.toString());
209-
console.log("category:", params.category.toString());
210-
console.log("priceInWei (GHST):", ethers.utils.formatEther(priceInWei));
211-
console.log("quantity:", quantity.toString());
212-
console.log("duration:", duration.toString());
213-
console.log("recipient:", params.recipient);
205+
console.log("\n" + "=".repeat(60));
206+
console.log("🔄 SWAP AND PLACE ERC1155 BUY ORDER TEST");
207+
console.log("=".repeat(60));
208+
209+
console.log("\n📋 ORDER PARAMETERS:");
210+
console.log("┌─ TokenIn:", params.tokenIn);
211+
console.log("├─ ERC1155 Token Address:", params.erc1155TokenAddress);
212+
console.log("├─ ERC1155 Token ID:", params.erc1155TokenId.toString());
213+
console.log("├─ Category:", params.category.toString());
214214
console.log(
215-
"swapAmount (USDC):",
215+
"├─ Price per Unit (GHST):",
216+
ethers.utils.formatEther(priceInWei)
217+
);
218+
console.log("├─ Quantity:", quantity.toString());
219+
console.log("├─ Total Cost (GHST):", ethers.utils.formatEther(totalCost));
220+
console.log("├─ Duration:", duration.toString());
221+
console.log("├─ Recipient:", params.recipient);
222+
console.log(
223+
"├─ Swap Amount (USDC):",
216224
ethers.utils.formatUnits(params.swapAmount, 6)
217225
);
218226
console.log(
219-
"minGhstOut (GHST):",
227+
"├─ Min GHST Out:",
220228
ethers.utils.formatEther(params.minGhstOut)
221229
);
222-
console.log("deadline:", params.swapDeadline);
230+
console.log("└─ Deadline:", params.swapDeadline);
231+
232+
console.log("\n💰 BALANCES (BEFORE):");
223233
console.log(
224-
"USDC balance (before):",
234+
"┌─ User USDC Balance:",
225235
ethers.utils.formatUnits(initialUsdcBalance, 6)
226236
);
237+
console.log(
238+
"└─ Diamond GHST Balance:",
239+
ethers.utils.formatEther(initialDiamondGhst)
240+
);
227241

228242
const tx = await buyOrderSwapFacet
229243
.connect(deployer)
230244
.swapAndPlaceERC1155BuyOrder(params);
231245
const receipt = await tx.wait();
232246

233247
const diamondGhstAfter = await ghstToken.balanceOf(ADDRESSES.DIAMOND);
248+
249+
console.log("\n🔄 TRANSACTION EXECUTED");
250+
console.log("└─ Transaction Hash:", tx.hash);
251+
252+
console.log("\n💰 BALANCES (AFTER):");
234253
console.log(
235-
"Diamond GHST before:",
254+
"┌─ Diamond GHST Before:",
236255
ethers.utils.formatEther(initialDiamondGhst)
237256
);
238257
console.log(
239-
"Diamond GHST after:",
258+
"├─ Diamond GHST After:",
240259
ethers.utils.formatEther(diamondGhstAfter)
241260
);
242261
console.log(
243-
"Diamond GHST delta (order funded):",
262+
"└─ Diamond GHST Delta (Order Funded):",
244263
ethers.utils.formatEther(diamondGhstAfter.sub(initialDiamondGhst))
245264
);
246265

@@ -255,14 +274,12 @@ describe("SwapAndPlaceERC1155BuyOrder Integration Test", function () {
255274
swapEvt.data,
256275
swapEvt.topics
257276
);
277+
console.log("\n🔄 SWAP RESULTS:");
258278
console.log(
259-
"GHST received from swap:",
279+
"┌─ GHST Received from Swap:",
260280
ethers.utils.formatEther(decodedSwap.ghstReceived)
261281
);
262-
console.log(
263-
"BuyOrderId (from swap evt):",
264-
decodedSwap.buyOrderId.toString()
265-
);
282+
console.log("└─ Buy Order ID:", decodedSwap.buyOrderId.toString());
266283

267284
// Parse last GHST Transfer (refund) from receipt logs
268285
const erc20Iface = new ethers.utils.Interface([
@@ -282,8 +299,9 @@ describe("SwapAndPlaceERC1155BuyOrder Integration Test", function () {
282299
lastGhstLog.topics
283300
);
284301
const refundAmount = parsed.value as BigNumber;
302+
console.log("\n💸 REFUND DETAILS:");
285303
console.log(
286-
"Refunded GHST (from diamond to recipient):",
304+
"└─ Refunded GHST (Diamond → Recipient):",
287305
ethers.utils.formatEther(refundAmount)
288306
);
289307
// refund should equal ghstReceived - totalCost
@@ -312,13 +330,29 @@ describe("SwapAndPlaceERC1155BuyOrder Integration Test", function () {
312330
expect(decoded.priceInWei).to.equal(priceInWei);
313331
expect(decoded.quantity).to.equal(quantity);
314332

315-
//diamond retains GHST for the order
316-
317333
const finalDiamondGhst = await ghstToken.balanceOf(ADDRESSES.DIAMOND);
334+
const finalUsdcBalance = await usdcToken.balanceOf(deployer.address);
335+
336+
console.log("\n✅ FINAL VERIFICATION:");
337+
console.log(
338+
"┌─ Final Diamond GHST:",
339+
ethers.utils.formatEther(finalDiamondGhst)
340+
);
341+
console.log(
342+
"├─ Final User USDC:",
343+
ethers.utils.formatUnits(finalUsdcBalance, 6)
344+
);
345+
console.log(
346+
"├─ Diamond GHST Retained:",
347+
ethers.utils.formatEther(finalDiamondGhst.sub(initialDiamondGhst))
348+
);
349+
console.log(
350+
"└─ USDC Spent:",
351+
ethers.utils.formatUnits(initialUsdcBalance.sub(finalUsdcBalance), 6)
352+
);
353+
318354
// diamond retains GHST equal to order total cost
319355
expect(finalDiamondGhst.sub(initialDiamondGhst)).to.equal(totalCost);
320-
321-
const finalUsdcBalance = await usdcToken.balanceOf(deployer.address);
322356
expect(finalUsdcBalance).to.be.lt(initialUsdcBalance);
323357

324358
// Validate the swap event emitted by BuyOrderSwapFacet

test/swapAndPlaceERC721BuyOrder.test.ts

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,44 +214,59 @@ describe("SwapAndPlaceERC721BuyOrder Integration Test", function () {
214214

215215
const validationOptions = [false, false, false];
216216

217-
console.log("\n=== BUY ORDER (ERC721) INPUTS ===");
218-
console.log("TokenIn:", params.tokenIn);
219-
console.log("erc721TokenAddress:", params.erc721TokenAddress);
220-
console.log("erc721TokenId:", params.erc721TokenId.toString());
221-
console.log("category:", params.category.toString());
222-
console.log("priceInWei (GHST):", ethers.utils.formatEther(priceInWei));
223-
console.log("duration:", duration.toString());
224-
console.log("recipient:", params.recipient);
217+
console.log("\n" + "=".repeat(60));
218+
console.log("🔄 SWAP AND PLACE ERC721 BUY ORDER TEST");
219+
console.log("=".repeat(60));
220+
221+
console.log("\n📋 ORDER PARAMETERS:");
222+
console.log("┌─ TokenIn:", params.tokenIn);
223+
console.log("├─ ERC721 Token Address:", params.erc721TokenAddress);
224+
console.log("├─ ERC721 Token ID:", params.erc721TokenId.toString());
225+
console.log("├─ Category:", params.category.toString());
226+
console.log("├─ Price (GHST):", ethers.utils.formatEther(priceInWei));
227+
console.log("├─ Duration:", duration.toString());
228+
console.log("├─ Recipient:", params.recipient);
225229
console.log(
226-
"swapAmount (USDC):",
230+
"├─ Swap Amount (USDC):",
227231
ethers.utils.formatUnits(params.swapAmount, 6)
228232
);
229233
console.log(
230-
"minGhstOut (GHST):",
234+
"├─ Min GHST Out:",
231235
ethers.utils.formatEther(params.minGhstOut)
232236
);
233-
console.log("deadline:", params.swapDeadline);
237+
console.log("└─ Deadline:", params.swapDeadline);
238+
239+
console.log("\n💰 BALANCES (BEFORE):");
234240
console.log(
235-
"USDC balance (before):",
241+
"┌─ User USDC Balance:",
236242
ethers.utils.formatUnits(initialUsdcBalance, 6)
237243
);
244+
console.log(
245+
"└─ Diamond GHST Balance:",
246+
ethers.utils.formatEther(initialDiamondGhst)
247+
);
238248

239249
const tx = await buyOrderSwapFacet
240250
.connect(deployer)
241251
.swapAndPlaceERC721BuyOrder(params, validationOptions);
242252
const receipt = await tx.wait();
243253

244254
const diamondGhstAfter = await ghstToken.balanceOf(ADDRESSES.DIAMOND);
255+
256+
console.log("\n🔄 TRANSACTION EXECUTED");
257+
console.log("└─ Transaction Hash:", tx.hash);
258+
259+
console.log("\n💰 BALANCES (AFTER):");
245260
console.log(
246-
"Diamond GHST before:",
261+
"┌─ Diamond GHST Before:",
247262
ethers.utils.formatEther(initialDiamondGhst)
248263
);
249264
console.log(
250-
"Diamond GHST after:",
265+
"├─ Diamond GHST After:",
251266
ethers.utils.formatEther(diamondGhstAfter)
252267
);
253268
console.log(
254-
"Diamond GHST delta (order funded):",
269+
"└─ Diamond GHST Delta (Order Funded):",
255270
ethers.utils.formatEther(diamondGhstAfter.sub(initialDiamondGhst))
256271
);
257272

@@ -266,14 +281,12 @@ describe("SwapAndPlaceERC721BuyOrder Integration Test", function () {
266281
swapEvt.data,
267282
swapEvt.topics
268283
);
284+
console.log("\n🔄 SWAP RESULTS:");
269285
console.log(
270-
"GHST received from swap:",
286+
"┌─ GHST Received from Swap:",
271287
ethers.utils.formatEther(decodedSwap.ghstReceived)
272288
);
273-
console.log(
274-
"BuyOrderId (from swap evt):",
275-
decodedSwap.buyOrderId.toString()
276-
);
289+
console.log("└─ Buy Order ID:", decodedSwap.buyOrderId.toString());
277290

278291
// Parse last GHST Transfer (refund) from receipt logs
279292
const erc20Iface = new ethers.utils.Interface([
@@ -293,8 +306,9 @@ describe("SwapAndPlaceERC721BuyOrder Integration Test", function () {
293306
lastGhstLog.topics
294307
);
295308
const refundAmount = parsed.value as BigNumber;
309+
console.log("\n💸 REFUND DETAILS:");
296310
console.log(
297-
"Refunded GHST (from diamond to recipient):",
311+
"└─ Refunded GHST (Diamond → Recipient):",
298312
ethers.utils.formatEther(refundAmount)
299313
);
300314
// refund should equal ghstReceived - order price
@@ -333,10 +347,28 @@ describe("SwapAndPlaceERC721BuyOrder Integration Test", function () {
333347
expect(statuses[0].status).to.equal("pending");
334348

335349
const finalDiamondGhst = await ghstToken.balanceOf(ADDRESSES.DIAMOND);
350+
const finalUsdcBalance = await usdcToken.balanceOf(deployer.address);
351+
352+
console.log("\n✅ FINAL VERIFICATION:");
353+
console.log(
354+
"┌─ Final Diamond GHST:",
355+
ethers.utils.formatEther(finalDiamondGhst)
356+
);
357+
console.log(
358+
"├─ Final User USDC:",
359+
ethers.utils.formatUnits(finalUsdcBalance, 6)
360+
);
361+
console.log(
362+
"├─ Diamond GHST Retained:",
363+
ethers.utils.formatEther(finalDiamondGhst.sub(initialDiamondGhst))
364+
);
365+
console.log(
366+
"└─ USDC Spent:",
367+
ethers.utils.formatUnits(initialUsdcBalance.sub(finalUsdcBalance), 6)
368+
);
369+
336370
// diamond retains GHST equal to order price
337371
expect(finalDiamondGhst.sub(initialDiamondGhst)).to.equal(priceInWei);
338-
339-
const finalUsdcBalance = await usdcToken.balanceOf(deployer.address);
340372
expect(finalUsdcBalance).to.be.lt(initialUsdcBalance);
341373

342374
// Validate the swap event emitted by BuyOrderSwapFacet

0 commit comments

Comments
 (0)