From ec2e32f64f3919635bf04c41b3c6efe01845086e Mon Sep 17 00:00:00 2001 From: gaetbout Date: Fri, 28 Jun 2024 12:36:35 +0200 Subject: [PATCH] adding some tests lib acc --- src/contracts/escrow_library.cairo | 2 -- tests-integration/account.test.ts | 7 +++++++ tests-integration/factory.test.ts | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/contracts/escrow_library.cairo b/src/contracts/escrow_library.cairo index cab9a86..137fc6e 100644 --- a/src/contracts/escrow_library.cairo +++ b/src/contracts/escrow_library.cairo @@ -78,7 +78,6 @@ mod EscrowLibrary { // This prevents creating instances of this classhash by mistake, as it's not needed. // While it is technically possible to create instances by replacing classhashes, this practice is not recommended. // This contract is intended to be used exclusively through library calls. - // Not tested panic_with_felt252('escr-lib/instance-not-recommend') } @@ -139,7 +138,6 @@ mod EscrowLibrary { let factory_owner = IOwnableDispatcher { contract_address: gift.factory }.owner(); assert(factory_owner == get_caller_address(), 'escr-lib/only-factory-owner'); let gift_balance = balance_of(gift.gift_token, contract_address); - // Not tested assert(gift_balance < gift.gift_amount, 'escr-lib/not-yet-claimed'); if gift.gift_token == gift.fee_token { transfer_from_account(gift.gift_token, receiver, gift_balance); diff --git a/tests-integration/account.test.ts b/tests-integration/account.test.ts index 89d78f0..eb98967 100644 --- a/tests-integration/account.test.ts +++ b/tests-integration/account.test.ts @@ -8,6 +8,7 @@ import { executeActionOnAccount, expectRevertWithErrorMessage, getEscrowAccount, + manager, randomReceiver, setupGiftProtocol, } from "../lib"; @@ -100,4 +101,10 @@ describe("Escrow Account", function () { claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey, details: { skipValidate: false } }), ); }); + + it(`Shouldn't be possible to instantiate the library account`, async function () { + const classHash = await manager.declareLocalContract("EscrowLibrary"); + + await expectRevertWithErrorMessage("escr-lib/instance-not-recommend", () => deployer.deployContract({ classHash })); + }); }); diff --git a/tests-integration/factory.test.ts b/tests-integration/factory.test.ts index 0101594..9b8c66e 100644 --- a/tests-integration/factory.test.ts +++ b/tests-integration/factory.test.ts @@ -63,6 +63,14 @@ describe("Test Core Factory Functions", function () { await manager.tokens.tokenBalance(escrowAddress, gift.gift_token).should.eventually.equal(0n); await manager.tokens.tokenBalance(dustReceiver, gift.gift_token).should.eventually.equal(dustBalance); }); + + it(`Shouldn't be possible to claim_dust for an unclaimed gift: ${useTxV3}`, async function () { + const { factory } = await setupGiftProtocol(); + const { gift } = await defaultDepositTestSetup({ factory, useTxV3 }); + const dustReceiver = randomReceiver(); + + await expectRevertWithErrorMessage("escr-lib/not-yet-claimed", () => claimDust({ gift, receiver: dustReceiver })); + }); } it(`Pausable`, async function () {