Skip to content

Commit 6ce955b

Browse files
authored
test(cairo): add should_panic coverage to the contract gate (#731)
1 parent b12be9a commit 6ce955b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

packages/snfoundry/contracts/tests/test_contract.cairo

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,33 @@ fn test_transfer() {
6060
); // we transfer 500 wei
6161
assert(your_contract_dispatcher.greeting() == new_greeting, 'Should allow set new message');
6262
}
63+
64+
#[test]
65+
#[fork("SEPOLIA_LATEST")]
66+
#[should_panic(
67+
expected: ('ERC20: insufficient allowance', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'),
68+
)]
69+
fn test_set_greeting_no_allowance() {
70+
let user = OWNER;
71+
let your_contract_address = deploy_contract("YourContract");
72+
73+
let your_contract_dispatcher = IYourContractDispatcher {
74+
contract_address: your_contract_address,
75+
};
76+
77+
let new_greeting: ByteArray = "Learn Scaffold-Stark 2! :)";
78+
79+
cheat_caller_address(your_contract_address, user, CheatSpan::TargetCalls(1));
80+
your_contract_dispatcher.set_greeting(new_greeting.clone(), Option::Some(500));
81+
}
82+
83+
#[test]
84+
#[should_panic(expected: ('Caller is not the owner', 'ENTRYPOINT_FAILED'))]
85+
fn test_withdraw_not_owner() {
86+
let contract_address = deploy_contract("YourContract");
87+
let dispatcher = IYourContractDispatcher { contract_address };
88+
89+
let not_owner: ContractAddress = 0x123.try_into().unwrap();
90+
cheat_caller_address(contract_address, not_owner, CheatSpan::TargetCalls(1));
91+
dispatcher.withdraw();
92+
}

0 commit comments

Comments
 (0)