From de52315d8179e7b7a55056cd35fdf81d7ec3a853 Mon Sep 17 00:00:00 2001 From: aitbc Date: Wed, 29 Apr 2026 13:35:48 +0200 Subject: [PATCH] fix: use return value from createEscrow instead of event parsing - Replace event log parsing with direct use of createEscrow return value - createEscrow function returns escrowId as uint256 - This avoids event parsing issues and provides reliable escrowId extraction - Update all beforeEach hooks and time lock test to use return value --- contracts/test/EscrowService.test.js | 31 ++++++---------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/contracts/test/EscrowService.test.js b/contracts/test/EscrowService.test.js index 7fddedae..31aa60f1 100644 --- a/contracts/test/EscrowService.test.js +++ b/contracts/test/EscrowService.test.js @@ -84,7 +84,7 @@ describe("EscrowService", function () { describe("Escrow Creation", function () { it("Should create standard escrow", async function () { - const tx = await escrowService.connect(depositor).createEscrow( + const escrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -93,10 +93,6 @@ describe("EscrowService", function () { 0, // Immediate release "Test escrow" ); - const receipt = await tx.wait(); - - const event = escrowService.interface.parseLog(receipt.logs[0]); - const escrowId = event.args[0]; expect(escrowId).to.not.be.undefined; }); @@ -147,7 +143,7 @@ describe("EscrowService", function () { let escrowId; beforeEach(async function () { - const tx = await escrowService.connect(depositor).createEscrow( + escrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -156,9 +152,6 @@ describe("EscrowService", function () { 0, "Test escrow" ); - const receipt = await tx.wait(); - const event = escrowService.interface.parseLog(receipt.logs[0]); - escrowId = event.args[0]; }); it("Should skip - fundEscrow not implemented", async function () { @@ -181,7 +174,7 @@ describe("EscrowService", function () { let escrowId; beforeEach(async function () { - const tx = await escrowService.connect(depositor).createEscrow( + escrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -190,9 +183,6 @@ describe("EscrowService", function () { 0, "Test escrow" ); - const receipt = await tx.wait(); - const event = escrowService.interface.parseLog(receipt.logs[0]); - escrowId = event.args[0]; }); it("Should release escrow to beneficiary", async function () { @@ -213,7 +203,7 @@ describe("EscrowService", function () { it("Should revert if time lock not passed", async function () { // Create new escrow const latestTime = await ethers.provider.getBlock('latest').then(b => b.timestamp); - const tx = await escrowService.connect(depositor).createEscrow( + const newEscrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -222,9 +212,6 @@ describe("EscrowService", function () { latestTime + 3600, "Test escrow" ); - const receipt = await tx.wait(); - const event = escrowService.interface.parseLog(receipt.logs[0]); - const newEscrowId = event.args[0]; await expect( escrowService.connect(depositor).releaseEscrow(newEscrowId, "Service completed") @@ -236,7 +223,7 @@ describe("EscrowService", function () { let escrowId; beforeEach(async function () { - const tx = await escrowService.connect(depositor).createEscrow( + escrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -245,9 +232,6 @@ describe("EscrowService", function () { 0, "Test escrow" ); - const receipt = await tx.wait(); - const event = escrowService.interface.parseLog(receipt.logs[0]); - escrowId = event.args[0]; }); it("Should refund escrow to depositor", async function () { @@ -304,7 +288,7 @@ describe("EscrowService", function () { let escrowId; beforeEach(async function () { - const tx = await escrowService.connect(depositor).createEscrow( + escrowId = await escrowService.connect(depositor).createEscrow( beneficiary.address, arbiter.address, ESCROW_AMOUNT, @@ -313,9 +297,6 @@ describe("EscrowService", function () { 0, "Test escrow" ); - const receipt = await tx.wait(); - const event = escrowService.interface.parseLog(receipt.logs[0]); - escrowId = event.args[0]; }); it("Should get escrow details", async function () {