Skip to content

Commit

Permalink
fix cairo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 6, 2024
1 parent 4f55eab commit 573332c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/contracts/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait IGiftFactory<TContractState> {
fn cancel(ref self: TContractState, claim: ClaimData);
fn get_dust(ref self: TContractState, claim: ClaimData, receiver: ContractAddress);

fn get_claim_class_hash(self: @TContractState) -> ClassHash;
fn get_latest_claim_class_hash(self: @TContractState) -> ClassHash;
fn get_claim_address(
self: @TContractState,
class_hash: ClassHash,
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe("Gifting", function () {

// wrong selector
factory.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/invalid-call-selector", () => factory.get_claim_class_hash());
await expectRevertWithErrorMessage("gift-acc/invalid-call-selector", () => factory.get_latest_claim_class_hash());

// multicall
await expectRevertWithErrorMessage("gift-acc/invalid-call-len", () =>
Expand Down
4 changes: 2 additions & 2 deletions tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn deploy_gifting_broken_erc20() -> GiftingSetup {
];
let (factory_contract_address, _) = factory_contract.deploy(@factory_calldata).expect('Failed to deploy factory');
let gift_factory = IGiftFactoryDispatcher { contract_address: factory_contract_address };
assert(gift_factory.get_claim_class_hash() == claim_contract.class_hash, 'Incorrect factory setup');
assert(gift_factory.get_latest_claim_class_hash() == claim_contract.class_hash, 'Incorrect factory setup');

GiftingSetup {
mock_eth: broken_erc20, mock_strk: broken_erc20, gift_factory, claim_class_hash: claim_contract.class_hash
Expand Down Expand Up @@ -83,7 +83,7 @@ fn deploy_gifting_normal() -> GiftingSetup {
];
let (factory_contract_address, _) = factory_contract.deploy(@factory_calldata).expect('Failed to deploy factory');
let gift_factory = IGiftFactoryDispatcher { contract_address: factory_contract_address };
assert(gift_factory.get_claim_class_hash() == claim_contract.class_hash, 'Incorrect factory setup');
assert(gift_factory.get_latest_claim_class_hash() == claim_contract.class_hash, 'Incorrect factory setup');

start_cheat_caller_address(mock_eth_address, OWNER());
start_cheat_caller_address(mock_strk.contract_address, OWNER());
Expand Down
9 changes: 7 additions & 2 deletions tests/test_gift_factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ fn test_claim_account_deployed() {
// un-deployed claim account should return 0
let fetched_claim_class_hash = get_class_hash(calculated_claim_address);
assert(claim_class_hash == fetched_claim_class_hash, 'Claim account not deployed');
assert(claim_class_hash == gift_factory.get_claim_class_hash(), 'Incorrect claim class hash');
assert(claim_class_hash == gift_factory.get_latest_claim_class_hash(), 'Incorrect claim class hash');

// Check that factory calculates claim address correctly
let get_claim_address = gift_factory
.get_claim_address(
claim_data.sender, claim_data.amount, claim_data.max_fee, claim_data.token, claim_data.claim_pubkey
claim_data.class_hash,
claim_data.sender,
claim_data.amount,
claim_data.max_fee,
claim_data.token,
claim_data.claim_pubkey
);
assert!(calculated_claim_address == get_claim_address, "Claim address not calculated correctly");
}
Expand Down

0 comments on commit 573332c

Please sign in to comment.