Created
August 10, 2023 11:42
-
-
Save codeWhizperer/3f3b7e2d2884cbf36030b5ab98f1f896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[starknet::interface] | |
| trait IJoesContract<TContractState> { | |
| fn get_owner(self:@TContractState) -> felt252; | |
| } | |
| #[starknet::contract] | |
| mod JoesContract { | |
| #[storage] | |
| struct Storage{ | |
| owner:felt252 | |
| } | |
| #[constructor] | |
| fn constructor(ref self: ContractState, _owner:felt252){ | |
| self.owner.write(_owner); | |
| } | |
| fn get_owner(self:@ContractState) -> felt252 { | |
| self.owner.read() | |
| } | |
| } | |
| ////test | |
| use array::ArrayTrait; | |
| use result::ResultTrait; | |
| use option::OptionTrait; | |
| use traits::TryInto; | |
| use starknet::ContractAddress; | |
| use starknet::Felt252TryIntoContractAddress; | |
| use cheatcodes::PreparedContract; | |
| use starknet::get_caller_address; | |
| use starknet_forge_template::IJoesContractDispatcher; | |
| use starknet_forge_template::IJoesContractDispatcherTrait; | |
| use starknet_forge_template::JoesContract; | |
| // use starknet::testing::set_caller_address; | |
| const ACCOUNT:felt252 = 'Sensei'; | |
| fn deploy_contract() -> ContractAddress { | |
| let class_hash = declare('JoesContract'); | |
| let mut constructor_calldata = ArrayTrait::new(); | |
| let owner = ACCOUNT; | |
| constructor_calldata.append(owner); | |
| let prepared = PreparedContract { | |
| class_hash, constructor_calldata: @constructor_calldata | |
| }; | |
| deploy(prepared).unwrap() | |
| } | |
| #[test] | |
| fn test_constructor_func(){ | |
| let deployer = ACCOUNT; | |
| let contract_address = deploy_contract(); | |
| let dispatcher = IJoesContractDispatcher{contract_address: contract_address}; | |
| let owner = dispatcher.get_owner(); | |
| assert( deployer == owner, 'not_owner'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment