Skip to content

Commit

Permalink
adding some tests lib acc
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 28, 2024
1 parent 277b3d2 commit ec2e32f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/contracts/escrow_library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions tests-integration/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
executeActionOnAccount,
expectRevertWithErrorMessage,
getEscrowAccount,
manager,
randomReceiver,
setupGiftProtocol,
} from "../lib";
Expand Down Expand Up @@ -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 }));
});
});
8 changes: 8 additions & 0 deletions tests-integration/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit ec2e32f

Please sign in to comment.