Skip to content

Instantly share code, notes, and snippets.

@codeWhizperer
Created August 10, 2023 11:42
Show Gist options
  • Select an option

  • Save codeWhizperer/3f3b7e2d2884cbf36030b5ab98f1f896 to your computer and use it in GitHub Desktop.

Select an option

Save codeWhizperer/3f3b7e2d2884cbf36030b5ab98f1f896 to your computer and use it in GitHub Desktop.
#[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