diff --git a/src/openzeppelin/account.cairo b/src/openzeppelin/account.cairo index d995b6329..47e57df8a 100644 --- a/src/openzeppelin/account.cairo +++ b/src/openzeppelin/account.cairo @@ -1,7 +1,7 @@ mod account; use account::{ - Account, AccountABIDispatcher, AccountABIDispatcherTrait, AccountABICamelDispatcher, - AccountABICamelDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION + Account, AccountCamelABIDispatcher, AccountCamelABIDispatcherTrait, AccountABIDispatcher, + AccountABIDispatcherTrait, TRANSACTION_VERSION, QUERY_VERSION }; mod dual_account; diff --git a/src/openzeppelin/account/account.cairo b/src/openzeppelin/account/account.cairo index 3c7a860ea..714f1f89f 100644 --- a/src/openzeppelin/account/account.cairo +++ b/src/openzeppelin/account/account.cairo @@ -2,96 +2,92 @@ use array::ArrayTrait; use array::SpanTrait; use option::OptionTrait; use serde::Serde; +use starknet::account::Call; use starknet::ContractAddress; -use openzeppelin::account::interface::Call; -use openzeppelin::utils::serde::SpanSerde; const TRANSACTION_VERSION: felt252 = 1; + // 2**128 + TRANSACTION_VERSION const QUERY_VERSION: felt252 = 340282366920938463463374607431768211457; -#[abi] -trait AccountABI { - #[external] - fn __execute__(calls: Array) -> Array>; - #[external] - fn __validate__(calls: Array) -> felt252; - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252; - #[external] +#[starknet::interface] +trait AccountABI { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252; fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + self: @TState, class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 ) -> felt252; - #[external] - fn set_public_key(new_public_key: felt252); - #[view] - fn get_public_key() -> felt252; - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252; - #[view] - fn supports_interface(interface_id: felt252) -> bool; + fn set_public_key(ref self: TState, new_public_key: felt252); + fn get_public_key(self: @TState) -> felt252; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> felt252; + fn supports_interface(self: @TState, interface_id: felt252) -> bool; } // Entry points case-convention is enforced by the protocol -#[abi] -trait AccountABICamel { - #[external] - fn __execute__(calls: Array) -> Array>; - #[external] - fn __validate__(calls: Array) -> felt252; - #[external] - fn __validate_declare__(classHash: felt252) -> felt252; - #[external] +#[starknet::interface] +trait AccountCamelABI { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn __validate_declare__(self: @TState, classHash: felt252) -> felt252; fn __validate_deploy__( - classHash: felt252, contractAddressSalt: felt252, _publicKey: felt252 + self: @TState, classHash: felt252, contractAddressSalt: felt252, _publicKey: felt252 ) -> felt252; - #[external] - fn setPublicKey(newPublicKey: felt252); - #[view] - fn getPublicKey() -> felt252; - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252; - #[view] - fn supportsInterface(interfaceId: felt252) -> bool; + fn setPublicKey(ref self: TState, newPublicKey: felt252); + fn getPublicKey(self: @TState) -> felt252; + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> felt252; + fn supportsInterface(self: @TState, interfaceId: felt252) -> bool; +} + +trait PublicKeyTrait { + fn set_public_key(ref self: TState, new_public_key: felt252); + fn get_public_key(self: @TState) -> felt252; } -#[account_contract] +trait PublicKeyCamelTrait { + fn setPublicKey(ref self: TState, newPublicKey: felt252); + fn getPublicKey(self: @TState) -> felt252; +} + +#[starknet::contract] mod Account { use array::SpanTrait; use array::ArrayTrait; use box::BoxTrait; use ecdsa::check_ecdsa_signature; use option::OptionTrait; - use serde::ArraySerde; use starknet::get_tx_info; use starknet::get_caller_address; use starknet::get_contract_address; use zeroable::Zeroable; - use openzeppelin::account::interface::IDeclarer; - use openzeppelin::account::interface::ISRC6; - use openzeppelin::account::interface::ISRC6Camel; - use openzeppelin::account::interface::ISRC6_ID; - use openzeppelin::introspection::src5::ISRC5; + use openzeppelin::account::interface; + use openzeppelin::introspection::interface::ISRC5; + use openzeppelin::introspection::interface::ISRC5Camel; use openzeppelin::introspection::src5::SRC5; use super::Call; use super::QUERY_VERSION; - use super::SpanSerde; use super::TRANSACTION_VERSION; + #[storage] struct Storage { public_key: felt252 } #[constructor] - fn constructor(_public_key: felt252) { - initializer(_public_key); + fn constructor(ref self: ContractState, _public_key: felt252) { + self.initializer(_public_key); } - impl SRC6Impl of ISRC6 { - fn __execute__(mut calls: Array) -> Array> { + // + // External + // + + #[external(v0)] + impl SRC6Impl of interface::ISRC6 { + fn __execute__(self: @ContractState, mut calls: Array) -> Array> { // Avoid calls from other contracts // https://github.com/OpenZeppelin/cairo-contracts/issues/344 let sender = get_caller_address(); @@ -107,12 +103,14 @@ mod Account { _execute_calls(calls) } - fn __validate__(mut calls: Array) -> felt252 { - validate_transaction() + fn __validate__(self: @ContractState, mut calls: Array) -> felt252 { + self.validate_transaction() } - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - if _is_valid_signature(hash, signature.span()) { + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { + if self._is_valid_signature(hash, signature.span()) { starknet::VALIDATED } else { 0 @@ -120,111 +118,105 @@ mod Account { } } - impl SRC6CamelImpl of ISRC6Camel { - fn __execute__(mut calls: Array) -> Array> { - SRC6Impl::__execute__(calls) - } - - fn __validate__(mut calls: Array) -> felt252 { - SRC6Impl::__validate__(calls) + #[external(v0)] + impl SRC6CamelOnlyImpl of interface::ISRC6CamelOnly { + fn isValidSignature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { + SRC6Impl::is_valid_signature(self, hash, signature) } + } - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - SRC6Impl::is_valid_signature(hash, signature) + #[external(v0)] + impl DeclarerImpl of interface::IDeclarer { + fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { + self.validate_transaction() } } - impl DeclarerImpl of IDeclarer { - fn __validate_declare__(class_hash: felt252) -> felt252 { - validate_transaction() + #[external(v0)] + impl SRC5Impl of ISRC5 { + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + let unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::SRC5Impl::supports_interface(@unsafe_state, interface_id) } } - impl SRC5Impl of ISRC5 { - fn supports_interface(interface_id: felt252) -> bool { - SRC5::supports_interface(interface_id) + #[external(v0)] + impl SRC5CamelImpl of ISRC5Camel { + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + let unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) } } - // - // Externals - // + #[external(v0)] + impl PublicKeyImpl of super::PublicKeyTrait { + fn get_public_key(self: @ContractState) -> felt252 { + self.public_key.read() + } - #[external] - fn __execute__(mut calls: Array) -> Array> { - SRC6Impl::__execute__(calls) + fn set_public_key(ref self: ContractState, new_public_key: felt252) { + assert_only_self(); + self.public_key.write(new_public_key); + } } - #[external] - fn __validate__(mut calls: Array) -> felt252 { - SRC6Impl::__validate__(calls) - } + #[external(v0)] + impl PublicKeyCamelImpl of super::PublicKeyCamelTrait { + fn getPublicKey(self: @ContractState) -> felt252 { + self.public_key.read() + } - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252 { - DeclarerImpl::__validate_declare__(class_hash) + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { + assert_only_self(); + self.public_key.write(newPublicKey); + } } - #[external] + #[external(v0)] fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + self: @ContractState, + class_hash: felt252, + contract_address_salt: felt252, + _public_key: felt252 ) -> felt252 { - validate_transaction() - } - - #[external] - fn set_public_key(new_public_key: felt252) { - assert_only_self(); - public_key::write(new_public_key); - } - - #[external] - fn setPublicKey(newPublicKey: felt252) { - set_public_key(newPublicKey); + self.validate_transaction() } // - // View + // Internal // - #[view] - fn get_public_key() -> felt252 { - public_key::read() - } - - #[view] - fn getPublicKey() -> felt252 { - get_public_key() - } - - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - SRC6Impl::is_valid_signature(hash, signature) - } - - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - SRC6CamelImpl::isValidSignature(hash, signature) - } - - #[view] - fn supports_interface(interface_id: felt252) -> bool { - SRC5Impl::supports_interface(interface_id) - } + #[generate_trait] + impl InternalImpl of InternalTrait { + fn initializer(ref self: ContractState, _public_key: felt252) { + let mut unsafe_state = SRC5::unsafe_new_contract_state(); + SRC5::InternalImpl::register_interface(ref unsafe_state, interface::ISRC6_ID); + self.public_key.write(_public_key); + } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - supports_interface(interfaceId) - } + fn validate_transaction(self: @ContractState) -> felt252 { + let tx_info = get_tx_info().unbox(); + let tx_hash = tx_info.transaction_hash; + let signature = tx_info.signature; + assert(self._is_valid_signature(tx_hash, signature), 'Account: invalid signature'); + starknet::VALIDATED + } - // - // Internals - // + fn _is_valid_signature( + self: @ContractState, hash: felt252, signature: Span + ) -> bool { + let valid_length = signature.len() == 2_u32; - #[internal] - fn initializer(_public_key: felt252) { - SRC5::register_interface(ISRC6_ID); - public_key::write(_public_key); + if valid_length { + check_ecdsa_signature( + hash, self.public_key.read(), *signature.at(0_u32), *signature.at(1_u32) + ) + } else { + false + } + } } #[internal] @@ -234,28 +226,6 @@ mod Account { assert(self == caller, 'Account: unauthorized'); } - #[internal] - fn validate_transaction() -> felt252 { - let tx_info = get_tx_info().unbox(); - let tx_hash = tx_info.transaction_hash; - let signature = tx_info.signature; - assert(_is_valid_signature(tx_hash, signature), 'Account: invalid signature'); - starknet::VALIDATED - } - - #[internal] - fn _is_valid_signature(hash: felt252, signature: Span) -> bool { - let valid_length = signature.len() == 2_u32; - - if valid_length { - check_ecdsa_signature( - hash, public_key::read(), *signature.at(0_u32), *signature.at(1_u32) - ) - } else { - false - } - } - #[internal] fn _execute_calls(mut calls: Array) -> Array> { let mut res = ArrayTrait::new(); diff --git a/src/openzeppelin/account/dual_account.cairo b/src/openzeppelin/account/dual_account.cairo index ad6903659..ee4e1c0b6 100644 --- a/src/openzeppelin/account/dual_account.cairo +++ b/src/openzeppelin/account/dual_account.cairo @@ -13,7 +13,7 @@ struct DualCaseAccount { contract_address: ContractAddress } -trait DualCaseAccountTrait { +trait DualCaseAccountABI { fn set_public_key(self: @DualCaseAccount, new_public_key: felt252); fn get_public_key(self: @DualCaseAccount) -> felt252; fn is_valid_signature( @@ -22,10 +22,9 @@ trait DualCaseAccountTrait { fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool; } -impl DualCaseAccountImpl of DualCaseAccountTrait { +impl DualCaseAccountImpl of DualCaseAccountABI { fn set_public_key(self: @DualCaseAccount, new_public_key: felt252) { - let mut args = ArrayTrait::new(); - args.append_serde(new_public_key); + let mut args = array![new_public_key]; try_selector_with_fallback( *self.contract_address, selectors::set_public_key, selectors::setPublicKey, args.span() @@ -34,7 +33,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { } fn get_public_key(self: @DualCaseAccount) -> felt252 { - let mut args = ArrayTrait::new(); + let mut args = array![]; try_selector_with_fallback( *self.contract_address, selectors::get_public_key, selectors::getPublicKey, args.span() @@ -45,8 +44,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { fn is_valid_signature( self: @DualCaseAccount, hash: felt252, signature: Array ) -> felt252 { - let mut args = ArrayTrait::new(); - args.append_serde(hash); + let mut args = array![hash]; args.append_serde(signature); try_selector_with_fallback( @@ -59,8 +57,7 @@ impl DualCaseAccountImpl of DualCaseAccountTrait { } fn supports_interface(self: @DualCaseAccount, interface_id: felt252) -> bool { - let mut args = ArrayTrait::new(); - args.append_serde(interface_id); + let mut args = array![interface_id]; try_selector_with_fallback( *self.contract_address, diff --git a/src/openzeppelin/account/interface.cairo b/src/openzeppelin/account/interface.cairo index af454163c..2027c0c99 100644 --- a/src/openzeppelin/account/interface.cairo +++ b/src/openzeppelin/account/interface.cairo @@ -1,28 +1,23 @@ use array::ArrayTrait; use array::SpanTrait; +use starknet::account::Call; use starknet::ContractAddress; const ISRC6_ID: felt252 = 0x2ceccef7f994940b3962a6c67e0ba4fcd37df7d131417c604f91e03caecc1cd; -#[derive(Serde, Drop)] -struct Call { - to: ContractAddress, - selector: felt252, - calldata: Array +#[starknet::interface] +trait ISRC6 { + fn __execute__(self: @TState, calls: Array) -> Array>; + fn __validate__(self: @TState, calls: Array) -> felt252; + fn is_valid_signature(self: @TState, hash: felt252, signature: Array) -> felt252; } -trait ISRC6 { - fn __execute__(calls: Array) -> Array>; - fn __validate__(calls: Array) -> felt252; - fn is_valid_signature(hash: felt252, signature: Array) -> felt252; +#[starknet::interface] +trait ISRC6CamelOnly { + fn isValidSignature(self: @TState, hash: felt252, signature: Array) -> felt252; } -trait ISRC6Camel { - fn __execute__(calls: Array) -> Array>; - fn __validate__(calls: Array) -> felt252; - fn isValidSignature(hash: felt252, signature: Array) -> felt252; -} - -trait IDeclarer { - fn __validate_declare__(class_hash: felt252) -> felt252; +#[starknet::interface] +trait IDeclarer { + fn __validate_declare__(self: @TState, class_hash: felt252) -> felt252; } diff --git a/src/openzeppelin/lib.cairo b/src/openzeppelin/lib.cairo index 6a2a521b4..5c658386e 100644 --- a/src/openzeppelin/lib.cairo +++ b/src/openzeppelin/lib.cairo @@ -1,7 +1,7 @@ // mod access; +mod account; mod introspection; mod security; -// mod account; -// mod token; mod tests; +// mod token; mod utils; diff --git a/src/openzeppelin/tests.cairo b/src/openzeppelin/tests.cairo index 01fb135b7..440fdfc2f 100644 --- a/src/openzeppelin/tests.cairo +++ b/src/openzeppelin/tests.cairo @@ -1,7 +1,7 @@ // mod access; +mod account; mod introspection; +mod mocks; mod security; -// mod account; // mod token; -mod mocks; mod utils; diff --git a/src/openzeppelin/tests/account/test_account.cairo b/src/openzeppelin/tests/account/test_account.cairo index 6ece0c5e9..48ab02685 100644 --- a/src/openzeppelin/tests/account/test_account.cairo +++ b/src/openzeppelin/tests/account/test_account.cairo @@ -2,6 +2,7 @@ use array::ArrayTrait; use core::traits::Into; use option::OptionTrait; use serde::Serde; +use starknet::account::Call; use starknet::contract_address_const; use starknet::ContractAddress; use starknet::testing; @@ -9,15 +10,14 @@ use starknet::testing; use openzeppelin::account::Account; use openzeppelin::account::AccountABIDispatcher; use openzeppelin::account::AccountABIDispatcherTrait; -use openzeppelin::account::interface::Call; use openzeppelin::account::interface::ISRC6_ID; use openzeppelin::account::QUERY_VERSION; use openzeppelin::account::TRANSACTION_VERSION; -use openzeppelin::introspection::src5::ISRC5_ID; +use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::utils; -use openzeppelin::token::erc20::ERC20; -use openzeppelin::token::erc20::interface::IERC20Dispatcher; -use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; +// use openzeppelin::token::erc20::ERC20; +// use openzeppelin::token::erc20::interface::IERC20Dispatcher; +// use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; use openzeppelin::utils::selectors; use openzeppelin::utils::serde::SerializedAppend; @@ -38,6 +38,9 @@ struct SignedTransactionData { s: felt252 } +fn STATE() -> Account::ContractState { + Account::contract_state_for_testing() +} fn CLASS_HASH() -> felt252 { Account::TEST_CLASS_HASH } @@ -59,44 +62,35 @@ fn SIGNED_TX_DATA() -> SignedTransactionData { // fn setup_dispatcher(data: Option<@SignedTransactionData>) -> AccountABIDispatcher { - // Set the transaction version testing::set_version(TRANSACTION_VERSION); - // Deploy the account contract - let mut calldata = ArrayTrait::new(); - + let mut calldata = array![]; if data.is_some() { let data = data.unwrap(); - - // Set the signature and transaction hash - let mut signature = ArrayTrait::new(); - signature.append(*data.r); - signature.append(*data.s); - testing::set_signature(signature.span()); + testing::set_signature(array![*data.r, *data.s].span()); testing::set_transaction_hash(*data.transaction_hash); calldata.append(*data.public_key); } else { calldata.append(PUBLIC_KEY); } - let address = utils::deploy(CLASS_HASH(), calldata); AccountABIDispatcher { contract_address: address } } -fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { - let name = 0; - let symbol = 0; - let mut calldata = ArrayTrait::new(); +// fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispatcher { +// let name = 0; +// let symbol = 0; +// let mut calldata = array![]; - calldata.append_serde(name); - calldata.append_serde(symbol); - calldata.append_serde(initial_supply); - calldata.append_serde(recipient); +// calldata.append_serde(name); +// calldata.append_serde(symbol); +// calldata.append_serde(initial_supply); +// calldata.append_serde(recipient); - let address = utils::deploy(ERC20::TEST_CLASS_HASH, calldata); - IERC20Dispatcher { contract_address: address } -} +// let address = utils::deploy(ERC20::TEST_CLASS_HASH, calldata); +// IERC20Dispatcher { contract_address: address } +// } // // constructor @@ -105,8 +99,11 @@ fn deploy_erc20(recipient: ContractAddress, initial_supply: u256) -> IERC20Dispa #[test] #[available_gas(2000000)] fn test_constructor() { - Account::constructor(PUBLIC_KEY); - assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); + assert( + Account::PublicKeyImpl::get_public_key(@state) == PUBLIC_KEY, 'Should return public key' + ); } // @@ -116,24 +113,26 @@ fn test_constructor() { #[test] #[available_gas(2000000)] fn test_supports_interface() { - Account::constructor(PUBLIC_KEY); + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); - let supports_default_interface = Account::supports_interface(ISRC5_ID); + let supports_default_interface = Account::SRC5Impl::supports_interface(@state, ISRC5_ID); assert(supports_default_interface, 'Should support base interface'); - let supports_account_interface = Account::supports_interface(ISRC6_ID); + let supports_account_interface = Account::SRC5Impl::supports_interface(@state, ISRC6_ID); assert(supports_account_interface, 'Should support account id'); } #[test] #[available_gas(2000000)] fn test_supportsInterface() { - Account::constructor(PUBLIC_KEY); + let mut state = STATE(); + Account::constructor(ref state, PUBLIC_KEY); - let supports_default_interface = Account::supportsInterface(ISRC5_ID); + let supports_default_interface = Account::SRC5CamelImpl::supportsInterface(@state, ISRC5_ID); assert(supports_default_interface, 'Should support base interface'); - let supports_account_interface = Account::supportsInterface(ISRC6_ID); + let supports_account_interface = Account::SRC5CamelImpl::supportsInterface(@state, ISRC6_ID); assert(supports_account_interface, 'Should support account id'); } @@ -144,46 +143,38 @@ fn test_supportsInterface() { #[test] #[available_gas(2000000)] fn test_is_valid_signature() { + let mut state = STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); - Account::set_public_key(data.public_key); - - let is_valid = Account::is_valid_signature(hash, good_signature); + let is_valid = Account::SRC6Impl::is_valid_signature(@state, hash, good_signature); assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - let is_valid = Account::is_valid_signature(hash, bad_signature); + let is_valid = Account::SRC6Impl::is_valid_signature(@state, hash, bad_signature); assert(is_valid == 0, 'Should reject invalid signature'); } #[test] #[available_gas(2000000)] fn test_isValidSignature() { + let mut state = STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); - - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; - Account::set_public_key(data.public_key); + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); - let is_valid = Account::is_valid_signature(hash, good_signature); + let is_valid = Account::SRC6CamelOnlyImpl::isValidSignature(@state, hash, good_signature); assert(is_valid == starknet::VALIDATED, 'Should accept valid signature'); - let is_valid = Account::is_valid_signature(hash, bad_signature); + let is_valid = Account::SRC6CamelOnlyImpl::isValidSignature(@state, hash, bad_signature); assert(is_valid == 0, 'Should reject invalid signature'); } @@ -221,7 +212,7 @@ fn test_validate_deploy_invalid_signature_data() { #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_invalid_signature_length() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut signature = ArrayTrait::new(); + let mut signature = array![]; signature.append(0x1); testing::set_signature(signature.span()); @@ -234,7 +225,7 @@ fn test_validate_deploy_invalid_signature_length() { #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_deploy_empty_signature() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let empty_sig = ArrayTrait::new(); + let empty_sig = array![]; testing::set_signature(empty_sig.span()); account.__validate_deploy__(CLASS_HASH(), SALT, PUBLIC_KEY); @@ -270,7 +261,7 @@ fn test_validate_declare_invalid_signature_data() { #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_invalid_signature_length() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut signature = ArrayTrait::new(); + let mut signature = array![]; signature.append(0x1); testing::set_signature(signature.span()); @@ -283,71 +274,71 @@ fn test_validate_declare_invalid_signature_length() { #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_declare_empty_signature() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let empty_sig = ArrayTrait::new(); + let empty_sig = array![]; testing::set_signature(empty_sig.span()); account.__validate_declare__(CLASS_HASH()); } -fn test_execute_with_version(version: Option) { - let data = SIGNED_TX_DATA(); - let account = setup_dispatcher(Option::Some(@data)); - let erc20 = deploy_erc20(account.contract_address, 1000); - let recipient = contract_address_const::<0x123>(); - - // Craft call and add to calls array - let mut calldata = ArrayTrait::new(); - let amount: u256 = 200; - calldata.append_serde(recipient); - calldata.append_serde(amount); - let call = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata - }; - let mut calls = ArrayTrait::new(); - calls.append(call); - - // Handle version for test - if version.is_some() { - testing::set_version(version.unwrap()); - } - - // Execute - let ret = account.__execute__(calls); - - // Assert that the transfer was successful - assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); - assert(erc20.balance_of(recipient) == amount, 'Should have transferred'); - - // Test return value - let mut call_serialized_retval = *ret.at(0); - let call_retval = Serde::::deserialize(ref call_serialized_retval); - assert(call_retval.unwrap(), 'Should have succeeded'); -} - -#[test] -#[available_gas(2000000)] -fn test_execute() { - test_execute_with_version(Option::None(())); -} - -#[test] -#[available_gas(2000000)] -fn test_execute_query_version() { - test_execute_with_version(Option::Some(QUERY_VERSION)); -} - -#[test] -#[available_gas(2000000)] -#[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] -fn test_execute_invalid_version() { - test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); -} +// fn test_execute_with_version(version: Option) { +// let data = SIGNED_TX_DATA(); +// let account = setup_dispatcher(Option::Some(@data)); +// let erc20 = deploy_erc20(account.contract_address, 1000); +// let recipient = contract_address_const::<0x123>(); + +// // Craft call and add to calls array +// let mut calldata = array![]; +// let amount: u256 = 200; +// calldata.append_serde(recipient); +// calldata.append_serde(amount); +// let call = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata +// }; +// let mut calls = array![]; +// calls.append(call); + +// // Handle version for test +// if version.is_some() { +// testing::set_version(version.unwrap()); +// } + +// // Execute +// let ret = account.__execute__(calls); + +// // Assert that the transfer was successful +// assert(erc20.balance_of(account.contract_address) == 800, 'Should have remainder'); +// assert(erc20.balance_of(recipient) == amount, 'Should have transferred'); + +// // Test return value +// let mut call_serialized_retval = *ret.at(0); +// let call_retval = Serde::::deserialize(ref call_serialized_retval); +// assert(call_retval.unwrap(), 'Should have succeeded'); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_execute() { +// test_execute_with_version(Option::None(())); +// } + +// #[test] +// #[available_gas(2000000)] +// fn test_execute_query_version() { +// test_execute_with_version(Option::Some(QUERY_VERSION)); +// } + +// #[test] +// #[available_gas(2000000)] +// #[should_panic(expected: ('Account: invalid tx version', 'ENTRYPOINT_FAILED'))] +// fn test_execute_invalid_version() { +// test_execute_with_version(Option::Some(TRANSACTION_VERSION - 1)); +// } #[test] #[available_gas(2000000)] fn test_validate() { - let calls = ArrayTrait::new(); + let calls = array![]; let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); assert(account.__validate__(calls) == starknet::VALIDATED, 'Should validate correctly'); @@ -357,7 +348,7 @@ fn test_validate() { #[available_gas(2000000)] #[should_panic(expected: ('Account: invalid signature', 'ENTRYPOINT_FAILED'))] fn test_validate_invalid() { - let calls = ArrayTrait::new(); + let calls = array![]; let mut data = SIGNED_TX_DATA(); data.transaction_hash += 1; let account = setup_dispatcher(Option::Some(@data)); @@ -365,57 +356,57 @@ fn test_validate_invalid() { account.__validate__(calls); } -#[test] -#[available_gas(2000000)] -fn test_multicall() { - let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let erc20 = deploy_erc20(account.contract_address, 1000); - let recipient1 = contract_address_const::<0x123>(); - let recipient2 = contract_address_const::<0x456>(); - let mut calls = ArrayTrait::new(); - - // Craft call1 - let mut calldata1 = ArrayTrait::new(); - let amount1: u256 = 300; - calldata1.append_serde(recipient1); - calldata1.append_serde(amount1); - let call1 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 - }; - - // Craft call2 - let mut calldata2 = ArrayTrait::new(); - let amount2: u256 = 500; - calldata2.append_serde(recipient2); - calldata2.append_serde(amount2); - let call2 = Call { - to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 - }; - - // Bundle calls and exeute - calls.append(call1); - calls.append(call2); - let ret = account.__execute__(calls); - - // Assert that the transfers were successful - assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); - assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); - assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); - - // Test return value - let mut call1_serialized_retval = *ret.at(0); - let mut call2_serialized_retval = *ret.at(1); - let call1_retval = Serde::::deserialize(ref call1_serialized_retval); - let call2_retval = Serde::::deserialize(ref call2_serialized_retval); - assert(call1_retval.unwrap(), 'Should have succeeded'); - assert(call2_retval.unwrap(), 'Should have succeeded'); -} +// #[test] +// #[available_gas(2000000)] +// fn test_multicall() { +// let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); +// let erc20 = deploy_erc20(account.contract_address, 1000); +// let recipient1 = contract_address_const::<0x123>(); +// let recipient2 = contract_address_const::<0x456>(); +// let mut calls = array![]; + +// // Craft call1 +// let mut calldata1 = array![]; +// let amount1: u256 = 300; +// calldata1.append_serde(recipient1); +// calldata1.append_serde(amount1); +// let call1 = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1 +// }; + +// // Craft call2 +// let mut calldata2 = array![]; +// let amount2: u256 = 500; +// calldata2.append_serde(recipient2); +// calldata2.append_serde(amount2); +// let call2 = Call { +// to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2 +// }; + +// // Bundle calls and exeute +// calls.append(call1); +// calls.append(call2); +// let ret = account.__execute__(calls); + +// // Assert that the transfers were successful +// assert(erc20.balance_of(account.contract_address) == 200, 'Should have remainder'); +// assert(erc20.balance_of(recipient1) == 300, 'Should have transferred'); +// assert(erc20.balance_of(recipient2) == 500, 'Should have transferred'); + +// // Test return value +// let mut call1_serialized_retval = *ret.at(0); +// let mut call2_serialized_retval = *ret.at(1); +// let call1_retval = Serde::::deserialize(ref call1_serialized_retval); +// let call2_retval = Serde::::deserialize(ref call2_serialized_retval); +// assert(call1_retval.unwrap(), 'Should have succeeded'); +// assert(call2_retval.unwrap(), 'Should have succeeded'); +// } #[test] #[available_gas(2000000)] fn test_multicall_zero_calls() { let account = setup_dispatcher(Option::Some(@SIGNED_TX_DATA())); - let mut calls = ArrayTrait::new(); + let mut calls = array![]; let ret = account.__execute__(calls); @@ -427,11 +418,13 @@ fn test_multicall_zero_calls() { #[available_gas(2000000)] #[should_panic(expected: ('Account: invalid caller', ))] fn test_account_called_from_contract() { - let calls = ArrayTrait::new(); + let calls = array![]; let caller = contract_address_const::<0x123>(); + testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); - Account::__execute__(calls); + + Account::SRC6Impl::__execute__(@STATE(), calls); } // @@ -441,11 +434,13 @@ fn test_account_called_from_contract() { #[test] #[available_gas(2000000)] fn test_public_key_setter_and_getter() { + let mut state = STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(ACCOUNT_ADDRESS()); - Account::set_public_key(NEW_PUBKEY); - let public_key = Account::get_public_key(); + Account::PublicKeyImpl::set_public_key(ref state, NEW_PUBKEY); + + let public_key = Account::PublicKeyImpl::get_public_key(@state); assert(public_key == NEW_PUBKEY, 'Should update key'); } @@ -453,10 +448,12 @@ fn test_public_key_setter_and_getter() { #[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized', ))] fn test_public_key_setter_different_account() { + let mut state = STATE(); let caller = contract_address_const::<0x123>(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); - Account::set_public_key(NEW_PUBKEY); + + Account::PublicKeyImpl::set_public_key(ref state, NEW_PUBKEY); } // @@ -466,11 +463,13 @@ fn test_public_key_setter_different_account() { #[test] #[available_gas(2000000)] fn test_public_key_setter_and_getter_camel() { + let mut state = STATE(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(ACCOUNT_ADDRESS()); - Account::setPublicKey(NEW_PUBKEY); - let public_key = Account::getPublicKey(); + Account::PublicKeyCamelImpl::setPublicKey(ref state, NEW_PUBKEY); + + let public_key = Account::PublicKeyCamelImpl::getPublicKey(@state); assert(public_key == NEW_PUBKEY, 'Should update key'); } @@ -478,10 +477,12 @@ fn test_public_key_setter_and_getter_camel() { #[available_gas(2000000)] #[should_panic(expected: ('Account: unauthorized', ))] fn test_public_key_setter_different_account_camel() { + let mut state = STATE(); let caller = contract_address_const::<0x123>(); testing::set_contract_address(ACCOUNT_ADDRESS()); testing::set_caller_address(caller); - Account::setPublicKey(NEW_PUBKEY); + + Account::PublicKeyCamelImpl::setPublicKey(ref state, NEW_PUBKEY); } // @@ -491,8 +492,11 @@ fn test_public_key_setter_different_account_camel() { #[test] #[available_gas(2000000)] fn test_initializer() { - Account::initializer(PUBLIC_KEY); - assert(Account::get_public_key() == PUBLIC_KEY, 'Should return public key'); + let mut state = STATE(); + Account::InternalImpl::initializer(ref state, PUBLIC_KEY); + assert( + Account::PublicKeyImpl::get_public_key(@state) == PUBLIC_KEY, 'Should return public key' + ); } #[test] @@ -516,28 +520,24 @@ fn test_assert_only_self_false() { #[test] #[available_gas(2000000)] fn test__is_valid_signature() { + let mut state = STATE(); let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - let mut good_signature = ArrayTrait::new(); - good_signature.append(data.r); - good_signature.append(data.s); + let mut good_signature = array![data.r, data.s]; + let mut bad_signature = array![0x987, 0x564]; + let mut invalid_length_signature = array![0x987]; - let mut bad_signature = ArrayTrait::new(); - bad_signature.append(0x987); - bad_signature.append(0x564); + Account::PublicKeyImpl::set_public_key(ref state, data.public_key); - let mut invalid_length_signature = ArrayTrait::new(); - invalid_length_signature.append(0x987); - - Account::set_public_key(data.public_key); - - let is_valid = Account::_is_valid_signature(hash, good_signature.span()); + let is_valid = Account::InternalImpl::_is_valid_signature(@state, hash, good_signature.span()); assert(is_valid, 'Should accept valid signature'); - let is_valid = Account::_is_valid_signature(hash, bad_signature.span()); + let is_valid = Account::InternalImpl::_is_valid_signature(@state, hash, bad_signature.span()); assert(!is_valid, 'Should reject invalid signature'); - let is_valid = Account::_is_valid_signature(hash, invalid_length_signature.span()); + let is_valid = Account::InternalImpl::_is_valid_signature( + @state, hash, invalid_length_signature.span() + ); assert(!is_valid, 'Should reject invalid length'); } diff --git a/src/openzeppelin/tests/account/test_dual_account.cairo b/src/openzeppelin/tests/account/test_dual_account.cairo index 1d4e23840..76ea9fb99 100644 --- a/src/openzeppelin/tests/account/test_dual_account.cairo +++ b/src/openzeppelin/tests/account/test_dual_account.cairo @@ -1,13 +1,12 @@ -use array::ArrayTrait; use starknet::testing; use openzeppelin::account::dual_account::DualCaseAccount; -use openzeppelin::account::dual_account::DualCaseAccountTrait; -use openzeppelin::account::AccountABICamelDispatcher; -use openzeppelin::account::AccountABICamelDispatcherTrait; +use openzeppelin::account::dual_account::DualCaseAccountABI; +use openzeppelin::account::AccountCamelABIDispatcher; +use openzeppelin::account::AccountCamelABIDispatcherTrait; use openzeppelin::account::AccountABIDispatcher; use openzeppelin::account::AccountABIDispatcherTrait; -use openzeppelin::introspection::src5::ISRC5_ID; +use openzeppelin::introspection::interface::ISRC5_ID; use openzeppelin::tests::account::test_account::SIGNED_TX_DATA; use openzeppelin::tests::mocks::account_panic_mock::CamelAccountPanicMock; use openzeppelin::tests::mocks::account_panic_mock::SnakeAccountPanicMock; @@ -15,7 +14,6 @@ use openzeppelin::tests::mocks::camel_account_mock::CamelAccountMock; use openzeppelin::tests::mocks::non_implementing_mock::NonImplementingMock; use openzeppelin::tests::mocks::snake_account_mock::SnakeAccountMock; use openzeppelin::tests::utils; -use openzeppelin::utils::serde::SerializedAppend; // // Constants @@ -29,8 +27,7 @@ const NEW_PUBLIC_KEY: felt252 = 0x444444; // fn setup_snake() -> (DualCaseAccount, AccountABIDispatcher) { - let mut calldata = ArrayTrait::new(); - calldata.append_serde(PUBLIC_KEY); + let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(SnakeAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, @@ -38,25 +35,24 @@ fn setup_snake() -> (DualCaseAccount, AccountABIDispatcher) { ) } -fn setup_camel() -> (DualCaseAccount, AccountABICamelDispatcher) { - let mut calldata = ArrayTrait::new(); - calldata.append_serde(PUBLIC_KEY); +fn setup_camel() -> (DualCaseAccount, AccountCamelABIDispatcher) { + let mut calldata = array![PUBLIC_KEY]; let target = utils::deploy(CamelAccountMock::TEST_CLASS_HASH, calldata); ( DualCaseAccount { contract_address: target }, - AccountABICamelDispatcher { contract_address: target } + AccountCamelABIDispatcher { contract_address: target } ) } fn setup_non_account() -> DualCaseAccount { - let calldata = ArrayTrait::new(); + let calldata = array![]; let target = utils::deploy(NonImplementingMock::TEST_CLASS_HASH, calldata); DualCaseAccount { contract_address: target } } fn setup_account_panic() -> (DualCaseAccount, DualCaseAccount) { - let snake_target = utils::deploy(SnakeAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); - let camel_target = utils::deploy(CamelAccountPanicMock::TEST_CLASS_HASH, ArrayTrait::new()); + let snake_target = utils::deploy(SnakeAccountPanicMock::TEST_CLASS_HASH, array![]); + let camel_target = utils::deploy(CamelAccountPanicMock::TEST_CLASS_HASH, array![]); ( DualCaseAccount { contract_address: snake_target }, DualCaseAccount { contract_address: camel_target } @@ -124,10 +120,7 @@ fn test_dual_is_valid_signature() { let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - - let mut signature = ArrayTrait::new(); - signature.append(data.r); - signature.append(data.s); + let mut signature = array![data.r, data.s]; testing::set_contract_address(snake_dispatcher.contract_address); target.set_public_key(data.public_key); @@ -141,7 +134,7 @@ fn test_dual_is_valid_signature() { #[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', ))] fn test_dual_no_is_valid_signature() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let dispatcher = setup_non_account(); dispatcher.is_valid_signature(hash, signature); @@ -152,13 +145,12 @@ fn test_dual_no_is_valid_signature() { #[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))] fn test_dual_is_valid_signature_exists_and_panics() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let (dispatcher, _) = setup_account_panic(); dispatcher.is_valid_signature(hash, signature); } - #[test] #[available_gas(2000000)] fn test_dual_supports_interface() { @@ -227,10 +219,7 @@ fn test_dual_isValidSignature() { let data = SIGNED_TX_DATA(); let hash = data.transaction_hash; - - let mut signature = ArrayTrait::new(); - signature.append(data.r); - signature.append(data.s); + let mut signature = array![data.r, data.s]; testing::set_contract_address(camel_dispatcher.contract_address); target.setPublicKey(data.public_key); @@ -244,13 +233,12 @@ fn test_dual_isValidSignature() { #[should_panic(expected: ('Some error', 'ENTRYPOINT_FAILED', ))] fn test_dual_isValidSignature_exists_and_panics() { let hash = 0x0; - let signature = ArrayTrait::::new(); + let signature = array![]; let (_, dispatcher) = setup_account_panic(); dispatcher.is_valid_signature(hash, signature); } - #[test] #[available_gas(2000000)] fn test_dual_supportsInterface() { @@ -265,3 +253,4 @@ fn test_dual_supportsInterface_exists_and_panics() { let (_, dispatcher) = setup_account_panic(); dispatcher.supports_interface(ISRC5_ID); } + diff --git a/src/openzeppelin/tests/mocks.cairo b/src/openzeppelin/tests/mocks.cairo index d8bdaa92b..3c1483fb3 100644 --- a/src/openzeppelin/tests/mocks.cairo +++ b/src/openzeppelin/tests/mocks.cairo @@ -8,11 +8,11 @@ // mod erc20_panic; // mod non721_mock; // mod accesscontrol_panic_mock; -// mod account_panic_mock; +mod account_panic_mock; // mod camel_accesscontrol_mock; -// mod camel_account_mock; +mod camel_account_mock; // mod snake_accesscontrol_mock; -// mod snake_account_mock; +mod snake_account_mock; // mod dual_ownable_mocks; // mod snake721_mock; // mod camel721_mock; diff --git a/src/openzeppelin/tests/mocks/account_panic_mock.cairo b/src/openzeppelin/tests/mocks/account_panic_mock.cairo index f3809b807..0a85c890c 100644 --- a/src/openzeppelin/tests/mocks/account_panic_mock.cairo +++ b/src/openzeppelin/tests/mocks/account_panic_mock.cairo @@ -4,53 +4,61 @@ // 3 for felt252 // false for bool -#[account_contract] +#[starknet::contract] mod SnakeAccountPanicMock { - #[external] - fn set_public_key(new_public_key: felt252) { + #[storage] + struct Storage {} + + #[external(v0)] + fn set_public_key(ref self: ContractState, new_public_key: felt252) { panic_with_felt252('Some error'); } - #[view] - fn get_public_key() -> felt252 { + #[external(v0)] + fn get_public_key(self: @ContractState) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { + #[external(v0)] + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array + ) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn supports_interface(interface_id: felt252) -> bool { + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { panic_with_felt252('Some error'); false } } -#[account_contract] +#[starknet::contract] mod CamelAccountPanicMock { - #[external] - fn setPublicKey(newPublicKey: felt252) { + #[storage] + struct Storage {} + + #[external(v0)] + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { panic_with_felt252('Some error'); } - #[view] - fn getPublicKey() -> felt252 { + #[external(v0)] + fn getPublicKey(self: @ContractState) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { + #[external(v0)] + fn isValidSignature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { panic_with_felt252('Some error'); 3 } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { panic_with_felt252('Some error'); false } diff --git a/src/openzeppelin/tests/mocks/camel_account_mock.cairo b/src/openzeppelin/tests/mocks/camel_account_mock.cairo index 01ee5b53e..19cf1725c 100644 --- a/src/openzeppelin/tests/mocks/camel_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/camel_account_mock.cairo @@ -1,31 +1,37 @@ -#[account_contract] +#[starknet::contract] mod CamelAccountMock { - use openzeppelin::account::interface::Call; use openzeppelin::account::Account; - use openzeppelin::utils::serde::SpanSerde; + + #[storage] + struct Storage {} #[constructor] - fn constructor(_publicKey: felt252) { - Account::initializer(_publicKey); + fn constructor(ref self: ContractState, _publicKey: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::InternalImpl::initializer(ref unsafe_state, _publicKey); } - #[external] - fn setPublicKey(newPublicKey: felt252) { - Account::setPublicKey(newPublicKey); + #[external(v0)] + fn setPublicKey(ref self: ContractState, newPublicKey: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyCamelImpl::setPublicKey(ref unsafe_state, newPublicKey); } - #[view] - fn getPublicKey() -> felt252 { - Account::getPublicKey() + #[external(v0)] + fn getPublicKey(self: @ContractState) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyCamelImpl::getPublicKey(@unsafe_state) } - #[view] - fn isValidSignature(hash: felt252, signature: Array) -> felt252 { - Account::isValidSignature(hash, signature) + #[external(v0)] + fn isValidSignature(self: @ContractState, hash: felt252, signature: Array) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6CamelOnlyImpl::isValidSignature(@unsafe_state, hash, signature) } - #[view] - fn supportsInterface(interfaceId: felt252) -> bool { - Account::supportsInterface(interfaceId) + #[external(v0)] + fn supportsInterface(self: @ContractState, interfaceId: felt252) -> bool { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC5CamelImpl::supportsInterface(@unsafe_state, interfaceId) } } diff --git a/src/openzeppelin/tests/mocks/snake_account_mock.cairo b/src/openzeppelin/tests/mocks/snake_account_mock.cairo index 03b9cd05d..80dc1f715 100644 --- a/src/openzeppelin/tests/mocks/snake_account_mock.cairo +++ b/src/openzeppelin/tests/mocks/snake_account_mock.cairo @@ -1,53 +1,39 @@ -#[account_contract] +#[starknet::contract] mod SnakeAccountMock { - use openzeppelin::account::interface::Call; use openzeppelin::account::Account; - use openzeppelin::utils::serde::SpanSerde; - #[constructor] - fn constructor(_public_key: felt252) { - Account::initializer(_public_key); - } + #[storage] + struct Storage {} - #[external] - fn __execute__(mut calls: Array) -> Array> { - Account::__execute__(calls) + #[constructor] + fn constructor(ref self: ContractState, _public_key: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::InternalImpl::initializer(ref unsafe_state, _public_key); } - #[external] - fn __validate__(mut calls: Array) -> felt252 { - Account::__validate__(calls) + #[external(v0)] + fn set_public_key(ref self: ContractState, new_public_key: felt252) { + let mut unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyImpl::set_public_key(ref unsafe_state, new_public_key); } - #[external] - fn __validate_declare__(class_hash: felt252) -> felt252 { - Account::__validate_declare__(class_hash) + #[external(v0)] + fn get_public_key(self: @ContractState) -> felt252 { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::PublicKeyImpl::get_public_key(@unsafe_state) } - #[external] - fn __validate_deploy__( - class_hash: felt252, contract_address_salt: felt252, _public_key: felt252 + #[external(v0)] + fn is_valid_signature( + self: @ContractState, hash: felt252, signature: Array ) -> felt252 { - Account::__validate_deploy__(class_hash, contract_address_salt, _public_key) - } - - #[external] - fn set_public_key(new_public_key: felt252) { - Account::set_public_key(new_public_key); - } - - #[view] - fn get_public_key() -> felt252 { - Account::get_public_key() - } - - #[view] - fn is_valid_signature(hash: felt252, signature: Array) -> felt252 { - Account::is_valid_signature(hash, signature) + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC6Impl::is_valid_signature(@unsafe_state, hash, signature) } - #[view] - fn supports_interface(interface_id: felt252) -> bool { - Account::supports_interface(interface_id) + #[external(v0)] + fn supports_interface(self: @ContractState, interface_id: felt252) -> bool { + let unsafe_state = Account::unsafe_new_contract_state(); + Account::SRC5Impl::supports_interface(@unsafe_state, interface_id) } }