diff --git a/lib/claim.ts b/lib/claim.ts index bcce5e3..b16bf0b 100644 --- a/lib/claim.ts +++ b/lib/claim.ts @@ -146,10 +146,10 @@ export async function claimInternal(args: { gift: Gift; receiver: string; giftPrivateKey: string; - overrides?: { EscrowAccountAddress?: string; callToAddress?: string }; + overrides?: { escrowAccountAddress?: string; callToAddress?: string }; details?: UniversalDetails; }): Promise { - const escrowAddress = args.overrides?.EscrowAccountAddress || calculateEscrowAddress(args.gift); + const escrowAddress = args.overrides?.escrowAccountAddress || calculateEscrowAddress(args.gift); const escrowAccount = getEscrowAccount(args.gift, args.giftPrivateKey, escrowAddress); const response = await escrowAccount.execute( [ diff --git a/lib/signers/legacy.ts b/lib/signers/legacy.ts index d1347f7..0606b4b 100644 --- a/lib/signers/legacy.ts +++ b/lib/signers/legacy.ts @@ -46,3 +46,15 @@ export class LegacyStarknetKeyPair extends LegacyKeyPair { return [r.toString(), s.toString()]; } } + +export class LongSigner extends LegacyStarknetKeyPair { + public async signRaw(messageHash: string): Promise { + return ["", ...(await super.signRaw(messageHash))]; + } +} + +export class WrongSigner extends LegacyStarknetKeyPair { + public async signRaw(messageHash: string): Promise { + return ["0x1", "0x1"]; + } +} diff --git a/tests-integration/account.test.ts b/tests-integration/account.test.ts index 89d78f0..10e5c89 100644 --- a/tests-integration/account.test.ts +++ b/tests-integration/account.test.ts @@ -1,5 +1,7 @@ import { CallData } from "starknet"; import { + LongSigner, + WrongSigner, buildGiftCallData, calculateEscrowAddress, claimInternal, @@ -8,6 +10,7 @@ import { executeActionOnAccount, expectRevertWithErrorMessage, getEscrowAccount, + manager, randomReceiver, setupGiftProtocol, } from "../lib"; @@ -100,4 +103,46 @@ describe("Escrow Account", function () { claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey, details: { skipValidate: false } }), ); }); + + it(`Long signature shouldn't be accepted`, async function () { + const { factory } = await setupGiftProtocol(); + const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory }); + const receiver = randomReceiver(); + + const escrowAccount = getEscrowAccount(gift, giftPrivateKey); + escrowAccount.signer = new LongSigner(); + await expectRevertWithErrorMessage("escrow/invalid-signature-len", () => + escrowAccount.execute([ + { + contractAddress: escrowAccount.address, + calldata: [buildGiftCallData(gift), receiver], + entrypoint: "claim_internal", + }, + ]), + ); + }); + + it(`Wrong signature shouldn't be accepted`, async function () { + const { factory } = await setupGiftProtocol(); + const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory }); + const receiver = randomReceiver(); + + const escrowAccount = getEscrowAccount(gift, giftPrivateKey); + escrowAccount.signer = new WrongSigner(); + await expectRevertWithErrorMessage("escrow/invalid-signature", () => + escrowAccount.execute([ + { + contractAddress: escrowAccount.address, + calldata: [buildGiftCallData(gift), receiver], + entrypoint: "claim_internal", + }, + ]), + ); + }); + + 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/claim_internal.test.ts b/tests-integration/claim_internal.test.ts index 286cc61..e1c3112 100644 --- a/tests-integration/claim_internal.test.ts +++ b/tests-integration/claim_internal.test.ts @@ -3,10 +3,12 @@ import { num } from "starknet"; import { ETH_GIFT_MAX_FEE, STRK_GIFT_MAX_FEE, + buildGiftCallData, calculateEscrowAddress, claimInternal, defaultDepositTestSetup, expectRevertWithErrorMessage, + getEscrowAccount, manager, randomReceiver, setupGiftProtocol, @@ -27,6 +29,36 @@ describe("Claim Internal", function () { await manager.tokens.tokenBalance(receiver, gift.gift_token).should.eventually.equal(gift.gift_amount); }); + it(`Invalid gift data txV3: ${useTxV3}`, async function () { + const { factory } = await setupGiftProtocol(); + const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory, useTxV3 }); + const receiver = randomReceiver(); + const escrowAddress = calculateEscrowAddress(gift); + + const escrowAccountAddress = getEscrowAccount(gift, giftPrivateKey, escrowAddress).address; + gift.fee_amount = 42n; + await expectRevertWithErrorMessage("escrow/invalid-escrow-address", () => + claimInternal({ gift, receiver, giftPrivateKey, overrides: { escrowAccountAddress } }), + ); + }); + + it(`Invalid calldata using txV3: ${useTxV3}`, async function () { + const { factory } = await setupGiftProtocol(); + const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory, useTxV3 }); + const receiver = randomReceiver(); + + const escrowAccount = getEscrowAccount(gift, giftPrivateKey); + await expectRevertWithErrorMessage("escrow/invalid-calldata", () => + escrowAccount.execute([ + { + contractAddress: escrowAccount.address, + calldata: [buildGiftCallData(gift), receiver, 1], + entrypoint: "claim_internal", + }, + ]), + ); + }); + it(`Can't claim if no fee amount deposited (fee token == gift token) using txV3: ${useTxV3}`, async function () { const { factory } = await setupGiftProtocol(); const receiver = randomReceiver(); diff --git a/tests-integration/deposit.test.ts b/tests-integration/deposit.test.ts index fccff6c..6559f14 100644 --- a/tests-integration/deposit.test.ts +++ b/tests-integration/deposit.test.ts @@ -98,6 +98,20 @@ describe("Deposit", function () { return txReceipt; }); }); + + it(`Fee not ETH nor STRK`, async function () { + const { factory } = await setupGiftProtocol(); + const mockERC20 = await deployMockERC20(); + + await expectRevertWithErrorMessage("gift-fac/invalid-fee-token", async () => { + const { txReceipt } = await defaultDepositTestSetup({ + factory, + useTxV3, + overrides: { feeTokenAddress: mockERC20.address }, + }); + return txReceipt; + }); + }); } it("Deposit fails class hash passed != class hash in factory storage", async function () { 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 () {