Skip to content

Commit

Permalink
fmt + clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
manlikeHB committed Nov 29, 2024
1 parent a8960bd commit 8c8a0bf
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 52 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 2 additions & 16 deletions src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ mod TokengiverCampaign {
use tokengiver::base::errors::Errors::NOT_CAMPAIGN_OWNER;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};

// const REGISTRY_CLASS_HASH: felt252 = 0x46163525551f5a50ed027548e86e1ad023c44e0eeb0733f0dab2fb1fdc31ed0;


#[derive(Drop, Copy, Serde, starknet::Store)]
pub struct DonationDetails {
token_id: u256,
Expand Down Expand Up @@ -111,22 +108,11 @@ mod TokengiverCampaign {

let campaign_address = IRegistryLibraryDispatcher {
class_hash: registry_hash.try_into().unwrap()
}.create_account(
}
.create_account(
implementation_hash, token_giverNft_contract_address, token_id, salt
);

// let mut call_data: Array<felt252> = array![];
// Serde::serialize(@implementation_hash, ref call_data);
// Serde::serialize(@token_giverNft_contract_address, ref call_data);
// Serde::serialize(@token_id, ref call_data);
// Serde::serialize(@salt, ref call_data);

// let mut res = library_call_syscall(registry_hash.try_into().unwrap(), selector!("create_account"), call_data.span()).unwrap_syscall();

// let campaign_address = Serde::<ContractAddress>::deserialize(ref res).unwrap();



let new_campaign = Campaign {
campaign_address, campaign_owner: recipient, metadata_URI: "",
};
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/IRegistry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait IRegistry<TContractState> {
token_id: u256,
salt: felt252
) -> ContractAddress;
// fn total_deployed_accounts(
// self: @TContractState, token_contract: ContractAddress, token_id: u256
// ) -> u8;
fn total_deployed_accounts(
self: @TContractState, token_contract: ContractAddress, token_id: u256
) -> u8;
}
2 changes: 1 addition & 1 deletion src/presets.cairo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod campaign;
mod erc20;
mod erc20;
9 changes: 3 additions & 6 deletions src/presets/erc20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ mod MyToken {
}

#[constructor]
fn constructor(
ref self: ContractState,
recipient: ContractAddress,
) {
let name: ByteArray = "My Token";
fn constructor(ref self: ContractState, recipient: ContractAddress,) {
let name: ByteArray = "My Token";
let symbol: ByteArray = "MYT";
let initial_supply = 100_000_000_u256;

self.erc20.initializer(name, symbol);
self.mint(recipient, initial_supply);
}
Expand Down
43 changes: 29 additions & 14 deletions tests/test_campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use snforge_std::{

use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};

use starknet::{ContractAddress, ClassHash};
use starknet::{ContractAddress, ClassHash, get_block_timestamp};

use tokengiver::interfaces::ICampaign::{ICampaign, ICampaignDispatcher, ICampaignDispatcherTrait};
use tokengiver::campaign::TokengiverCampaign::{Event, DonationCreated};

// fn STRK_TOKEN_ADDRESS() -> ContractAddress {
// 0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d.try_into().unwrap()
// }
fn REGISTRY_HASH() -> felt252 {
0x046163525551f5a50ed027548e86e1ad023c44e0eeb0733f0dab2fb1fdc31ed0.try_into().unwrap()
}
Expand All @@ -37,7 +35,6 @@ fn OWNER() -> ContractAddress {

const ADMIN: felt252 = 'ADMIN';


fn __setup__() -> (ContractAddress, ContractAddress) {
let class_hash = declare("TokengiverCampaign").unwrap().contract_class();
let strk_address = deploy_erc20();
Expand Down Expand Up @@ -81,31 +78,49 @@ fn test_donate() {
let strk_dispatcher = IERC20Dispatcher { contract_address: strk_address };
let random_id = 1;

let mut spy = spy_events();

//create campaign
start_cheat_caller_address(token_giver_address, RECIPIENT());
let campaign_address = token_giver
.create_campaign(
token_giverNft_contract_address,
REGISTRY_HASH(),
IMPLEMENTATION_HASH(),
SALT(),
RECIPIENT()
);
.create_campaign(
token_giverNft_contract_address,
REGISTRY_HASH(),
IMPLEMENTATION_HASH(),
SALT(),
RECIPIENT()
);
stop_cheat_caller_address(token_giver_address);

/// Transfer STRK to Donor
start_cheat_caller_address(strk_address, OWNER());
let amount = 2000000; //
strk_dispatcher.transfer(DONOR(), amount);
assert(strk_dispatcher.balance_of(DONOR()) >= amount, 'strk bal too low');
stop_cheat_caller_address(strk_address);


// approve allowance
start_cheat_caller_address(strk_address, DONOR());
strk_dispatcher.approve(token_giver_address, amount);
stop_cheat_caller_address(strk_address);

// donate
start_cheat_caller_address(token_giver_address, DONOR());
token_giver.donate(campaign_address, amount, random_id);
stop_cheat_caller_address(token_giver_address);

assert(strk_dispatcher.balance_of(DONOR()) == 0, 'wrong balance');
assert(token_giver.get_donations(campaign_address) == amount, 'wrong donation amount');
assert(token_giver.get_donation_count(campaign_address) == 1, 'wrong donation amount');

let expected_event = Event::DonationCreated(
DonationCreated {
campaign_id: random_id,
donor_address: DONOR(),
amount: amount,
token_id: random_id,
block_timestamp: get_block_timestamp(),
}
);
spy.assert_emitted(@array![(token_giver.contract_address, expected_event)]);
}

0 comments on commit 8c8a0bf

Please sign in to comment.