Skip to content

Commit

Permalink
Merge pull request #33 from casweeney/test/withdraw-e2e
Browse files Browse the repository at this point in the history
Test/withdraw e2e
  • Loading branch information
mubarak23 authored Nov 29, 2024
2 parents bd32042 + 5a0ece5 commit 0f8a85c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.snfoundry_cache
target
.DS_Store
Scarb.lock
26 changes: 0 additions & 26 deletions Scarb.lock

This file was deleted.

11 changes: 10 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v

[[target.starknet-contract]]
casm = true
sierra = true
sierra = true

[scripts]
test = "snforge test"

[[tool.snforge.fork]]
name = "SEPOLIA_LATEST"
url = "https://starknet-sepolia.public.blastapi.io/rpc/v0_7"
block_id.tag = "latest"
# block_id.number = "325081"
30 changes: 17 additions & 13 deletions src/campaign.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ mod TokengiverCampaign {
salt: felt252,
recipient: ContractAddress
) -> ContractAddress {
let caller = get_caller_address();
let count: u16 = self.count.read() + 1;

let token_giverNft_contract_address = self
.deploy_token_giver_nft(self.token_giver_nft_class_hash.read(), count.into());
.deploy_token_giver_nft(self.token_giver_nft_class_hash.read(), caller);

let token_id = ITokenGiverNftDispatcher {
contract_address: token_giverNft_contract_address
}
Expand All @@ -120,9 +123,11 @@ mod TokengiverCampaign {
.create_account(
implementation_hash, token_giverNft_contract_address, token_id, salt
);

let new_campaign = Campaign {
campaign_address, campaign_owner: recipient, metadata_URI: "",
};

self.campaign.write(campaign_address, new_campaign);
self.campaigns.write(count, campaign_address);
self.count.write(count);
Expand All @@ -135,6 +140,7 @@ mod TokengiverCampaign {
token_giverNft_contract_address
}
);

campaign_address
}

Expand Down Expand Up @@ -284,11 +290,9 @@ mod TokengiverCampaign {
#[generate_trait]
impl InternalImpl of InternalTrait {
fn deploy_token_giver_nft(
ref self: ContractState, token_giver_nft_class_hash: ClassHash, campaign_id: u256
ref self: ContractState, token_giver_nft_class_hash: ClassHash, admin: ContractAddress
) -> ContractAddress {
let mut constructor_calldata: Array<felt252> = array![
campaign_id.low.into(), campaign_id.high.into()
];
let mut constructor_calldata = array![admin.into()];

let (token_giver_nft_address, _) = deploy_syscall(
token_giver_nft_class_hash,
Expand All @@ -298,14 +302,14 @@ mod TokengiverCampaign {
)
.unwrap();

self
.emit(
DeployedTokenGiverNFT {
campaign_id: campaign_id,
token_giver_nft_contract_address: token_giver_nft_address,
block_timestamp: get_block_timestamp()
}
);
// self
// .emit(
// DeployedTokenGiverNFT {
// campaign_id: campaign_id,
// token_giver_nft_contract_address: token_giver_nft_address,
// block_timestamp: get_block_timestamp()
// }
// );
token_giver_nft_address
}
}
Expand Down
45 changes: 44 additions & 1 deletion tests/test_token_giver_nft.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::num::traits::zero::Zero;
use core::starknet::SyscallResultTrait;
use core::traits::{TryInto, Into};
use starknet::{ContractAddress};
use starknet::{ContractAddress, ClassHash, get_block_timestamp};
// use snforge_std::{declare, ContractClassTrait, CheatTarget, start_prank, stop_prank,};
use snforge_std::{
declare, start_cheat_caller_address, stop_cheat_caller_address, ContractClassTrait,
Expand All @@ -13,6 +13,7 @@ use tokengiver::interfaces::ITokenGiverNft::{
ITokenGiverNftDispatcher, ITokenGiverNftDispatcherTrait
};
use tokengiver::base::errors::Errors::ALREADY_MINTED;
use tokengiver::interfaces::ICampaign::{ICampaignDispatcher, ICampaignDispatcherTrait};

const ADMIN: felt252 = 'ADMIN';
const USER_ONE: felt252 = 'BOB';
Expand All @@ -27,6 +28,48 @@ fn __setup__() -> ContractAddress {
return (nft_contract_address);
}

fn deploy_campaign_contract() -> ContractAddress {
let nft_class_hash = declare("TokenGiverNFT").unwrap().contract_class();

let mut constructor_calldata: Array<felt252> = ArrayTrait::new();
nft_class_hash.serialize(ref constructor_calldata);

let contract = declare("TokengiverCampaign").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@constructor_calldata).unwrap();

contract_address
}

// #[test]
// #[fork("SEPOLIA_LATEST")]
// fn test_create_campaign() {
// let campaign_contract_address = deploy_campaign_contract();
// let campaign_contract = ICampaignDispatcher { contract_address: campaign_contract_address };

// // Using Sepolia V2 (Audited contract)

// let registry_hash: ClassHash = starknet::class_hash_const::<
// 0x046163525551f5a50ed027548e86e1ad023c44e0eeb0733f0dab2fb1fdc31ed0
// >();
// let registry_hash_in_felt: felt252 = registry_hash.into();

// let implementation_hash = starknet::class_hash_const::<
// 0x45d67b8590561c9b54e14dd309c9f38c4e2c554dd59414021f9d079811621bd
// >();
// let implementation_hash_in_felt: felt252 = implementation_hash.into();

// let salt = get_block_timestamp();
// let salt_in_felt: felt252 = salt.into();

// let recipient: ContractAddress = starknet::contract_address_const::<
// 0x01526C92E52c337b7B04d1307c6080Ece3a17071F2F0295197cEa8d077c6FF80
// >();

// campaign_contract
// .create_campaign(
// registry_hash_in_felt, implementation_hash_in_felt, salt_in_felt, recipient
// );
// }

// #[test]
// fn test_metadata() {
Expand Down

0 comments on commit 0f8a85c

Please sign in to comment.