diff --git a/src/contracts/escrow_account.cairo b/src/contracts/escrow_account.cairo index 8a1b0c9..9138213 100644 --- a/src/contracts/escrow_account.cairo +++ b/src/contracts/escrow_account.cairo @@ -76,55 +76,54 @@ mod EscrowAccount { impl IAccountImpl of IAccount { fn __validate__(ref self: ContractState, calls: Array) -> felt252 { let execution_info = get_execution_info().unbox(); - assert(execution_info.caller_address.is_zero(), 'gift-acc/only-protocol'); - assert(calls.len() == 1, 'gift-acc/invalid-call-len'); + assert(execution_info.caller_address.is_zero(), 'escrow/only-protocol'); + assert(calls.len() == 1, 'escrow/invalid-call-len'); let Call { to, selector, calldata } = calls.at(0); - assert(*to == get_contract_address(), 'gift-acc/invalid-call-to'); - assert(*selector == selector!("claim_internal"), 'gift-acc/invalid-call-selector'); - let (gift, _): (GiftData, ContractAddress) = full_deserialize(*calldata) - .expect('gift-acc/invalid-calldata'); + assert(*to == get_contract_address(), 'escrow/invalid-call-to'); + assert(*selector == selector!("claim_internal"), 'escrow/invalid-call-selector'); + let (gift, _): (GiftData, ContractAddress) = full_deserialize(*calldata).expect('escrow/invalid-calldata'); assert_valid_claim(gift); let tx_info = execution_info.tx_info.unbox(); - assert(tx_info.nonce == 0, 'gift-acc/invalid-gift-nonce'); + assert(tx_info.nonce == 0, 'escrow/invalid-gift-nonce'); let execution_hash = tx_info.transaction_hash; let signature = tx_info.signature; - assert(signature.len() == 2, 'gift-acc/invalid-signature-len'); + assert(signature.len() == 2, 'escrow/invalid-signature-len'); let tx_version = tx_info.version; assert( check_ecdsa_signature(execution_hash, gift.gift_pubkey, *signature[0], *signature[1]) || tx_version == TX_V3_ESTIMATE || tx_version == TX_V1_ESTIMATE, - 'invalid-signature' + 'escrow/invalid-signature' ); if gift.fee_token == STRK_ADDRESS() { - assert(tx_version == TX_V3 || tx_version == TX_V3_ESTIMATE, 'gift-acc/invalid-tx3-version'); + assert(tx_version == TX_V3 || tx_version == TX_V3_ESTIMATE, 'escrow/invalid-tx3-version'); let tx_fee = compute_max_fee_v3(tx_info, tx_info.tip); - assert(tx_fee <= gift.fee_amount, 'gift-acc/max-fee-too-high-v3'); + assert(tx_fee <= gift.fee_amount, 'escrow/max-fee-too-high-v3'); } else if gift.fee_token == ETH_ADDRESS() { - assert(tx_version == TX_V1 || tx_version == TX_V1_ESTIMATE, 'gift-acc/invalid-tx1-version'); - assert(tx_info.max_fee <= gift.fee_amount, 'gift-acc/max-fee-too-high-v1'); + assert(tx_version == TX_V1 || tx_version == TX_V1_ESTIMATE, 'escrow/invalid-tx1-version'); + assert(tx_info.max_fee <= gift.fee_amount, 'escrow/max-fee-too-high-v1'); } else { - core::panic_with_felt252('gift-acc/invalid-token'); + core::panic_with_felt252('escrow/invalid-token-fee'); } VALIDATED } fn __execute__(ref self: ContractState, calls: Array) -> Array> { let execution_info = get_execution_info().unbox(); - assert(execution_info.caller_address.is_zero(), 'gift-acc/only-protocol'); + assert(execution_info.caller_address.is_zero(), 'escrow/only-protocol'); let tx_version = execution_info.tx_info.unbox().version; assert( tx_version == TX_V3 || tx_version == TX_V1 || tx_version == TX_V3_ESTIMATE || tx_version == TX_V1_ESTIMATE, - 'gift-acc/invalid-tx-version' + 'escrow/invalid-tx-version' ); let Call { .., calldata }: @Call = calls[0]; let (gift, receiver): (GiftData, ContractAddress) = full_deserialize(*calldata) - .expect('gift-acc/invalid-calldata'); + .expect('escrow/invalid-calldata'); // The __validate__ function already ensures the claim is valid let library_class_hash: ClassHash = IGiftFactoryDispatcher { contract_address: gift.factory } .get_escrow_lib_class_hash(gift.escrow_class_hash); @@ -133,7 +132,7 @@ mod EscrowAccount { fn is_valid_signature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { let mut signature_span = signature.span(); - let gift: GiftData = Serde::deserialize(ref signature_span).expect('gift-acc/invalid-gift'); + let gift: GiftData = Serde::deserialize(ref signature_span).expect('escrow/invalid-gift'); get_validated_lib(gift).is_valid_account_signature(gift, hash, signature_span) } @@ -148,7 +147,7 @@ mod EscrowAccount { impl GiftAccountImpl of IEscrowAccount { fn execute_action(ref self: ContractState, selector: felt252, calldata: Array) -> Span { let mut calldata_span = calldata.span(); - let gift: GiftData = Serde::deserialize(ref calldata_span).expect('gift-acc/invalid-gift'); + let gift: GiftData = Serde::deserialize(ref calldata_span).expect('escrow/invalid-gift'); let lib = get_validated_lib(gift); lib.execute_action(lib.class_hash, selector, calldata.span()) } @@ -159,7 +158,7 @@ mod EscrowAccount { fn execute_from_outside_v2( ref self: ContractState, outside_execution: OutsideExecution, mut signature: Span ) -> Array> { - let gift: GiftData = Serde::deserialize(ref signature).expect('gift-acc/invalid-gift'); + let gift: GiftData = Serde::deserialize(ref signature).expect('escrow/invalid-gift'); get_validated_lib(gift).execute_from_outside_v2(gift, outside_execution, signature) } @@ -177,7 +176,7 @@ mod EscrowAccount { fn assert_valid_claim(gift: GiftData) { let calculated_address = calculate_escrow_account_address(gift); - assert(calculated_address == get_contract_address(), 'gift-acc/invalid-escrow-address'); + assert(calculated_address == get_contract_address(), 'escrow/invalid-escrow-address'); } fn compute_max_fee_v3(tx_info: TxInfo, tip: u128) -> u128 { diff --git a/src/contracts/escrow_library.cairo b/src/contracts/escrow_library.cairo index b4c8b68..a1e6945 100644 --- a/src/contracts/escrow_library.cairo +++ b/src/contracts/escrow_library.cairo @@ -78,7 +78,7 @@ 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. - panic_with_felt252('instances-not-recommended') + panic_with_felt252('escr-lib/instance-not-recommend') } #[abi(embed_v0)] @@ -96,7 +96,7 @@ mod EscrowLibrary { let is_whitelisted = selector == selector!("claim_external") || selector == selector!("claim_dust") || selector == selector!("cancel"); - assert(is_whitelisted, 'gift/invalid-selector'); + assert(is_whitelisted, 'escr-lib/invalid-selector'); library_call_syscall(this_class_hash, selector, args).unwrap() } @@ -111,17 +111,16 @@ mod EscrowLibrary { .get_message_hash_rev_1(get_contract_address()); assert( check_ecdsa_signature(claim_external_hash, gift.gift_pubkey, signature.r, signature.s), - 'gift/invalid-ext-signature' + 'escr-lib/invalid-ext-signature' ); self.proceed_with_claim(gift, receiver, dust_receiver); } fn cancel(ref self: ContractState, gift: GiftData) { let contract_address = get_contract_address(); - assert(get_caller_address() == gift.sender, 'gift/wrong-sender'); - + assert(get_caller_address() == gift.sender, 'escr-lib/wrong-sender'); let gift_balance = balance_of(gift.gift_token, contract_address); - assert(gift_balance > 0, 'gift/already-claimed'); + assert(gift_balance > 0, 'escr-lib/already-claimed'); if gift.gift_token == gift.fee_token { // Sender also gets the dust transfer_from_account(gift.gift_token, gift.sender, gift_balance); @@ -137,9 +136,9 @@ mod EscrowLibrary { fn claim_dust(ref self: ContractState, gift: GiftData, receiver: ContractAddress) { let contract_address = get_contract_address(); let factory_owner = IOwnableDispatcher { contract_address: gift.factory }.owner(); - assert(factory_owner == get_caller_address(), 'gift/only-factory-owner'); + assert(factory_owner == get_caller_address(), 'escr-lib/only-factory-owner'); let gift_balance = balance_of(gift.gift_token, contract_address); - assert(gift_balance < gift.gift_amount, 'gift/not-yet-claimed'); + 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); } else { @@ -157,7 +156,7 @@ mod EscrowLibrary { fn execute_from_outside_v2( ref self: ContractState, gift: GiftData, outside_execution: OutsideExecution, signature: Span ) -> Array> { - panic_with_felt252('not-allowed-yet') + panic_with_felt252('escr-lib/not-allowed-yet') } } @@ -166,10 +165,10 @@ mod EscrowLibrary { fn proceed_with_claim( ref self: ContractState, gift: GiftData, receiver: ContractAddress, dust_receiver: ContractAddress ) { - assert(receiver.is_non_zero(), 'gift/zero-receiver'); + assert(receiver.is_non_zero(), 'escr-lib/zero-receiver'); let contract_address = get_contract_address(); let gift_balance = balance_of(gift.gift_token, contract_address); - assert(gift_balance >= gift.gift_amount, 'gift/already-claimed-or-cancel'); + assert(gift_balance >= gift.gift_amount, 'escr-lib/claimed-or-cancel'); // could be optimized to 1 transfer only when the receiver is also the dust receiver, // and the fee token is the same as the gift token @@ -194,7 +193,7 @@ mod EscrowLibrary { } fn transfer_from_account(token: ContractAddress, receiver: ContractAddress, amount: u256,) { - assert(IERC20Dispatcher { contract_address: token }.transfer(receiver, amount), 'gift/transfer-failed'); + assert(IERC20Dispatcher { contract_address: token }.transfer(receiver, amount), 'escr-lib/transfer-failed'); } fn balance_of(token: ContractAddress, account: ContractAddress) -> u256 { diff --git a/src/contracts/gift_factory.cairo b/src/contracts/gift_factory.cairo index 65279bd..2e5806e 100644 --- a/src/contracts/gift_factory.cairo +++ b/src/contracts/gift_factory.cairo @@ -231,7 +231,7 @@ mod GiftFactory { // This should do some sanity checks // We should check that the new implementation is a valid implementation // Execute the upgrade using replace_class_syscall(...) - panic_with_felt252('downgrade-not-allowed'); + panic_with_felt252('gift-fac/downgrade-not-allowed'); } } diff --git a/tests-integration/account.test.ts b/tests-integration/account.test.ts index 564e83a..89d78f0 100644 --- a/tests-integration/account.test.ts +++ b/tests-integration/account.test.ts @@ -17,7 +17,7 @@ describe("Escrow Account", function () { const { gift } = await defaultDepositTestSetup({ factory }); const escrowAddress = calculateEscrowAddress(gift); - await expectRevertWithErrorMessage("gift-acc/only-protocol", () => + await expectRevertWithErrorMessage("escrow/only-protocol", () => deployer.execute([{ contractAddress: escrowAddress, calldata: [0x0], entrypoint: "__validate__" }]), ); }); @@ -27,7 +27,7 @@ describe("Escrow Account", function () { const { gift } = await defaultDepositTestSetup({ factory }); const escrowAddress = calculateEscrowAddress(gift); - await expectRevertWithErrorMessage("gift-acc/only-protocol", () => + await expectRevertWithErrorMessage("escrow/only-protocol", () => deployer.execute([{ contractAddress: escrowAddress, calldata: [0x0], entrypoint: "__execute__" }]), ); }); @@ -37,7 +37,7 @@ describe("Escrow Account", function () { const { gift } = await defaultDepositTestSetup({ factory }); const minimalCallData = CallData.compile([buildGiftCallData(gift)]); - await expectRevertWithErrorMessage("gift/invalid-selector", () => + await expectRevertWithErrorMessage("escr-lib/invalid-selector", () => deployer.execute(executeActionOnAccount("claim_internal", calculateEscrowAddress(gift), minimalCallData)), ); }); @@ -47,7 +47,7 @@ describe("Escrow Account", function () { const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory }); const receiver = randomReceiver(); - await expectRevertWithErrorMessage("gift-acc/invalid-call-to", () => + await expectRevertWithErrorMessage("escrow/invalid-call-to", () => claimInternal({ gift, receiver, @@ -64,7 +64,7 @@ describe("Escrow Account", function () { const escrowAccount = getEscrowAccount(gift, giftPrivateKey); - await expectRevertWithErrorMessage("gift-acc/invalid-call-selector", () => + await expectRevertWithErrorMessage("escrow/invalid-call-selector", () => escrowAccount.execute( [{ contractAddress: escrowAccount.address, calldata: [], entrypoint: "execute_action" }], undefined, @@ -77,7 +77,7 @@ describe("Escrow Account", function () { const { factory } = await setupGiftProtocol(); const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory }); const escrowAccount = getEscrowAccount(gift, giftPrivateKey); - await expectRevertWithErrorMessage("gift-acc/invalid-call-len", () => + await expectRevertWithErrorMessage("escrow/invalid-call-len", () => escrowAccount.execute( [ { contractAddress: escrowAccount.address, calldata: [], entrypoint: "execute_action" }, @@ -96,7 +96,7 @@ describe("Escrow Account", function () { // double claim await claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey }); - await expectRevertWithErrorMessage("gift-acc/invalid-gift-nonce", () => + await expectRevertWithErrorMessage("escrow/invalid-gift-nonce", () => claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey, details: { skipValidate: false } }), ); }); diff --git a/tests-integration/cancel.test.ts b/tests-integration/cancel.test.ts index 46afe8b..54fc26b 100644 --- a/tests-integration/cancel.test.ts +++ b/tests-integration/cancel.test.ts @@ -31,7 +31,7 @@ describe("Cancel Gift", function () { // Check balance gift address address == 0 await manager.tokens.tokenBalance(escrowAddress, gift.fee_token).should.eventually.equal(0n); - await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => + await expectRevertWithErrorMessage("escr-lib/claimed-or-cancel", () => claimInternal({ gift, receiver, giftPrivateKey }), ); }); @@ -62,7 +62,7 @@ describe("Cancel Gift", function () { await manager.tokens.tokenBalance(escrowAddress, gift.gift_token).should.eventually.equal(0n); await manager.tokens.tokenBalance(escrowAddress, gift.fee_token).should.eventually.equal(0n); - await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => + await expectRevertWithErrorMessage("escr-lib/claimed-or-cancel", () => claimInternal({ gift, receiver, giftPrivateKey }), ); }); @@ -70,7 +70,9 @@ describe("Cancel Gift", function () { it(`wrong sender`, async function () { const { factory } = await setupGiftProtocol(); const { gift } = await defaultDepositTestSetup({ factory }); - await expectRevertWithErrorMessage("gift/wrong-sender", () => cancelGift({ gift, senderAccount: devnetAccount() })); + await expectRevertWithErrorMessage("escr-lib/wrong-sender", () => + cancelGift({ gift, senderAccount: devnetAccount() }), + ); }); it(`owner reclaim dust (gift_token == fee_token)`, async function () { @@ -99,7 +101,7 @@ describe("Cancel Gift", function () { await manager.tokens.tokenBalance(escrowAddress, gift.gift_token).should.eventually.equal(0n); }); - it(`gift/already-claimed (gift_token != fee_token)`, async function () { + it(`escr-lib/already-claimed (gift_token != fee_token)`, async function () { const mockERC20 = await deployMockERC20(); const { factory } = await setupGiftProtocol(); const { gift, giftPrivateKey } = await defaultDepositTestSetup({ @@ -109,6 +111,6 @@ describe("Cancel Gift", function () { const receiver = randomReceiver(); await claimInternal({ gift, receiver, giftPrivateKey }); - await expectRevertWithErrorMessage("gift/already-claimed", () => cancelGift({ gift })); + await expectRevertWithErrorMessage("escr-lib/already-claimed", () => cancelGift({ gift })); }); }); diff --git a/tests-integration/claim_external.test.ts b/tests-integration/claim_external.test.ts index b8b10ea..daf7d72 100644 --- a/tests-integration/claim_external.test.ts +++ b/tests-integration/claim_external.test.ts @@ -88,7 +88,9 @@ describe("Claim External", function () { const { gift, giftPrivateKey } = await defaultDepositTestSetup({ factory }); const receiver = "0x0"; - await expectRevertWithErrorMessage("gift/zero-receiver", () => claimExternal({ gift, receiver, giftPrivateKey })); + await expectRevertWithErrorMessage("escr-lib/zero-receiver", () => + claimExternal({ gift, receiver, giftPrivateKey }), + ); }); it(`Cannot call claim external twice`, async function () { @@ -97,7 +99,7 @@ describe("Claim External", function () { const receiver = randomReceiver(); await claimExternal({ gift, receiver, giftPrivateKey }); - await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => + await expectRevertWithErrorMessage("escr-lib/claimed-or-cancel", () => claimExternal({ gift, receiver, giftPrivateKey }), ); }); @@ -106,7 +108,7 @@ describe("Claim External", function () { const { factory } = await setupGiftProtocol(); const { gift } = await defaultDepositTestSetup({ factory }); const receiver = randomReceiver(); - await expectRevertWithErrorMessage("gift/invalid-ext-signature", () => + await expectRevertWithErrorMessage("escr-lib/invalid-ext-signature", () => claimExternal({ gift: gift, receiver, giftPrivateKey: "0x1234" }), ); }); @@ -127,7 +129,7 @@ describe("Claim External", function () { // Check balance gift address address == 0 await manager.tokens.tokenBalance(escrowAddress, gift.gift_token).should.eventually.equal(0n); - await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => + await expectRevertWithErrorMessage("escr-lib/claimed-or-cancel", () => claimExternal({ gift, receiver, giftPrivateKey }), ); }); diff --git a/tests-integration/claim_internal.test.ts b/tests-integration/claim_internal.test.ts index 3c608e4..286cc61 100644 --- a/tests-integration/claim_internal.test.ts +++ b/tests-integration/claim_internal.test.ts @@ -37,7 +37,7 @@ describe("Claim Internal", function () { overrides: { feeAmount: 0n }, }); - const errorMsg = useTxV3 ? "gift-acc/max-fee-too-high-v3" : "gift-acc/max-fee-too-high-v1"; + const errorMsg = useTxV3 ? "escrow/max-fee-too-high-v3" : "escrow/max-fee-too-high-v1"; await expectRevertWithErrorMessage(errorMsg, () => claimInternal({ gift, receiver, giftPrivateKey })); }); @@ -59,7 +59,7 @@ describe("Claim Internal", function () { max_price_per_unit: num.toHexString(gasPrice), }, }; - await expectRevertWithErrorMessage("gift-acc/max-fee-too-high-v3", () => + await expectRevertWithErrorMessage("escrow/max-fee-too-high-v3", () => claimInternal({ gift, receiver, @@ -68,7 +68,7 @@ describe("Claim Internal", function () { }), ); } else { - await expectRevertWithErrorMessage("gift-acc/max-fee-too-high-v1", () => + await expectRevertWithErrorMessage("escrow/max-fee-too-high-v1", () => claimInternal({ gift, receiver, @@ -88,7 +88,7 @@ describe("Claim Internal", function () { const receiver = randomReceiver(); await claimInternal({ gift, receiver, giftPrivateKey }); - await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => + await expectRevertWithErrorMessage("escr-lib/claimed-or-cancel", () => claimInternal({ gift, receiver, giftPrivateKey }), ); }); diff --git a/tests-integration/factory.test.ts b/tests-integration/factory.test.ts index f3900bd..0101594 100644 --- a/tests-integration/factory.test.ts +++ b/tests-integration/factory.test.ts @@ -132,7 +132,7 @@ describe("Test Core Factory Functions", function () { const { gift } = await defaultDepositTestSetup({ factory }); const dustReceiver = randomReceiver(); - await expectRevertWithErrorMessage("gift/only-factory-owner", () => + await expectRevertWithErrorMessage("escr-lib/only-factory-owner", () => claimDust({ gift, receiver: dustReceiver, factoryOwner: devnetAccount() }), ); }); diff --git a/tests-integration/upgrade.test.ts b/tests-integration/upgrade.test.ts index 6bcdd8f..537df0f 100644 --- a/tests-integration/upgrade.test.ts +++ b/tests-integration/upgrade.test.ts @@ -59,7 +59,7 @@ describe("Test Factory Upgrade", function () { await factory.propose_upgrade(oldFactoryClassHash, calldata); await manager.setTime(CURRENT_TIME + MIN_SECURITY_PERIOD + 1n); - await expectRevertWithErrorMessage("downgrade-not-allowed", () => factory.upgrade([])); + await expectRevertWithErrorMessage("gift-fac/downgrade-not-allowed", () => factory.upgrade([])); }); it("only-owner", async function () {