From 8ca6d6d0ff63ce9ca0b8e64c5c8a5fbbfdaa703d Mon Sep 17 00:00:00 2001 From: Gerson <71728860+Gerson2102@users.noreply.github.com> Date: Mon, 4 Nov 2024 08:05:59 -0600 Subject: [PATCH] Adding some tests for is_valid_signature (#121) --- .../.snfoundry_cache/.prev_tests_failed | 1 + snphone-contracts/tests/test_account.cairo | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/snphone-contracts/.snfoundry_cache/.prev_tests_failed b/snphone-contracts/.snfoundry_cache/.prev_tests_failed index e69de29b..3df04dd4 100644 --- a/snphone-contracts/.snfoundry_cache/.prev_tests_failed +++ b/snphone-contracts/.snfoundry_cache/.prev_tests_failed @@ -0,0 +1 @@ +tests::test_account::test_empty_signature diff --git a/snphone-contracts/tests/test_account.cairo b/snphone-contracts/tests/test_account.cairo index ca89e371..de069e21 100644 --- a/snphone-contracts/tests/test_account.cairo +++ b/snphone-contracts/tests/test_account.cairo @@ -104,6 +104,32 @@ fn test_other_account_cannot_change_public_key() { //fn test_is_valid_signature() { // TODO: Test is_valid_signature() works as expected (valid returns true, anything else returns false (check 0 hash and empty sigs as well)) //} +#[test] +fn test_is_not_valid_signature() { + let class_hash = declare("StarknetPhoneAccount"); + let _pub_key = 'pub_key'; + let contract_address = class_hash.deploy(@array![_pub_key]).unwrap(); + let wallet = IStarknetPhoneAccountDispatcher { contract_address }; + assert( + wallet.is_valid_signature(0x0, array!['starknet', 'phone'].span()) == 0, 'Valid signature' + ); +} +#[test] +fn test_empty_signature() { + let class_hash = declare("StarknetPhoneAccount"); + let _pub_key = 'pub_key'; + let contract_address = class_hash.deploy(@array![_pub_key]).unwrap(); + let wallet = IStarknetPhoneAccountDispatcher { contract_address }; + assert( + wallet.is_valid_signature('test', array![].span()) == 'invalid signature', 'Empty signature' + ); +} +//#[test] +//fn test_execute() { // TODO: Test __execute__() works as expected (solo and multi-calls should work as expected) +// - Might need to create a mock erc20 contract to test calls (see if the wallet is able to do a multi call (try sending eth to 2 accounts from the +// deployed wallet, both accounts' balance should update) +//} + #[test] #[should_panic(expected: ('invalid caller',))] fn test_execute_with_invalid_caller() {