Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update snforge and openzeppelin #123

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 2.6.3; curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh; snfoundryup -v 0.23.0",
"postCreateCommand": "curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v 2.7.0; curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh; snfoundryup -v 0.27.0",
"customizations": {
"vscode": {
"extensions": [
Expand Down
8 changes: 4 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ dependencies = [

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
version = "0.14.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b"

[[package]]
name = "snforge_std"
version = "0.23.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.23.0#f2bff8f796763ada77fe6033ec1b034ceee22abd"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ cairo-version = "2.6.3"

[dependencies]
starknet = ">=2.0.0"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.14.0" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.23.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" }

[lib]

Expand Down
18 changes: 9 additions & 9 deletions tests/airdrop_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// use governance::airdrop::{airdrop, IAirdropDispatcher, IAirdropDispatcherTrait};
// use airdrop::STRK_ADDRESS;
// use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
// use snforge_std::{ContractClassTrait, declare, start_prank, CheatTarget};
// use snforge_std::{ContractClassTrait, declare, start_cheat_caller_address, CheatTarget};
// use starknet::{ContractAddress, deploy_syscall};

// const ADMIN_ADDR: felt252 = 0x42;
Expand All @@ -25,12 +25,12 @@
// let airdrop_contract = deploy();
// let token_contract = deploy_token(airdrop_contract.contract_address);

// start_prank(
// start_cheat_caller_address(
// CheatTarget::One(airdrop_contract.contract_address), ADMIN_ADDR.try_into().unwrap()
// );
// airdrop_contract.add_root(valid_root);

// start_prank(CheatTarget::One(airdrop_contract.contract_address), CLAIMEE_1.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(airdrop_contract.contract_address), CLAIMEE_1.try_into().unwrap());
// let initial_proof = array![valid_proof_element];
// airdrop_contract.claim(CLAIMEE_1, valid_claim_amount, initial_proof.span());
// assert(
Expand All @@ -50,10 +50,10 @@
// fn test_claim_invalid_proof() {
// let contract = deploy();
// deploy_token(contract.contract_address);
// start_prank(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
// contract.add_root(0xf7c8d3f309262572ad35df8ff6c33f24d8114c60eac3bc27bf42382ca82faf);

// start_prank(CheatTarget::One(contract.contract_address), CLAIMEE_1.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), CLAIMEE_1.try_into().unwrap());
// let proof = array![0x2a18afb0550a011d54ca3940648e59894c06e4c3d0a611256c0b575bd528b3b, 0x1];
// contract.claim(0x88, proof.span());
// }
Expand All @@ -62,20 +62,20 @@
// fn test_update_root_and_claim_attempts() {
// let contract = deploy();
// let tok = deploy_token(contract.contract_address);
// start_prank(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());

// // add intial root and valid claim
// contract.add_root(initial_root);
// start_prank(CheatTarget::One(contract.contract_address), CLAIMEE_1.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), CLAIMEE_1.try_into().unwrap());
// contract.claim(claim_amount, valid_proof_for_initial_root.span());
// assert(tok.balance_of(CLAIMEE_1.try_into().unwrap()) == claim_amount, 'initial claim failed');

// // update root
// start_prank(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
// contract.add_root(new_root);

// // claim with old root + new proof, should fail
// start_prank(CheatTarget::One(contract.contract_address), CLAIMEE_2.try_into().unwrap());
// start_cheat_caller_address(CheatTarget::One(contract.contract_address), CLAIMEE_2.try_into().unwrap());
// contract.claim(claim_amount, new_proof_not_matching_old_root.span());
// // check fail : to do, use should panic ?

Expand Down
8 changes: 4 additions & 4 deletions tests/basic.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use konoha::proposals::{IProposalsDispatcher, IProposalsDispatcherTrait};
use konoha::upgrades::IUpgradesDispatcher;
use konoha::upgrades::IUpgradesDispatcherTrait;
use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, CheatTarget, start_warp
BlockId, declare, ContractClassTrait, ContractClass, start_cheat_caller_address, CheatTarget, start_cheat_block_timestamp
};
use starknet::{ContractAddress, get_block_timestamp};

Expand Down Expand Up @@ -52,12 +52,12 @@ fn test_upgrade_mainnet_to_master() {

// declare current and submit proposal
let new_contract: ContractClass = declare("Governance").expect('unable to declare governance');
start_prank(CheatTarget::One(gov_contract_addr), team1_address);
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), team1_address);
let new_prop_id = dispatcher.submit_proposal(new_contract.class_hash.into(), 1);
loop {
match top_carm_holders.pop_front() {
Option::Some(holder) => {
start_prank(CheatTarget::One(gov_contract_addr), holder);
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), holder);
dispatcher.vote(new_prop_id, 1);
},
Option::None(()) => { break (); },
Expand All @@ -67,7 +67,7 @@ fn test_upgrade_mainnet_to_master() {
//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);
start_cheat_block_timestamp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);

assert(dispatcher.get_proposal_status(new_prop_id) == 1, 'proposal not passed!');

Expand Down
34 changes: 17 additions & 17 deletions tests/proposals_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use openzeppelin::token::erc20::interface::{
IERC20CamelOnlyDispatcherTrait
};
use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, start_warp, CheatTarget,
BlockId, declare, ContractClassTrait, ContractClass, start_cheat_caller_address, start_cheat_block_timestamp, CheatTarget,
prank, CheatSpan
};
use starknet::ContractAddress;
Expand All @@ -41,10 +41,10 @@ fn test_express_proposal() {

let dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };

start_prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

start_prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
dispatcher.vote(prop_id, 1);

assert!(dispatcher.get_proposal_status(prop_id) == 1, "proposal not passed!");
Expand All @@ -57,13 +57,13 @@ fn test_proposal_expiry() {
stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
let dispatcher = IProposalsDispatcher { contract_address: gov.contract_address };

start_prank(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov.contract_address), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov.contract_address), end_timestamp + 1);
start_cheat_block_timestamp(CheatTarget::One(gov.contract_address), end_timestamp + 1);

let status = dispatcher.get_proposal_status(prop_id);
assert!(status == constants::MINUS_ONE, "proposal not expired!");
Expand All @@ -88,7 +88,7 @@ fn test_vote_on_expired_proposal() {
//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov.contract_address), end_timestamp + 1);
start_cheat_block_timestamp(CheatTarget::One(gov.contract_address), end_timestamp + 1);

prank(
CheatTarget::One(gov.contract_address),
Expand Down Expand Up @@ -142,7 +142,7 @@ fn test_vote_on_quorum_not_met() {
assert(total_votes < quorum_threshold, 'Total votes >= quorum threshold');
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);
start_cheat_block_timestamp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);
assert(
dispatcher.get_proposal_status(prop_id) == constants::MINUS_ONE,
'Proposal pass & quorum not met'
Expand Down Expand Up @@ -220,7 +220,7 @@ fn test_delegate_vote_with_incorrect_calldata() {

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let mut calldata: Array<(ContractAddress, u128)> = ArrayTrait::new();
let addr: felt252 = 0x4;
calldata.append((addr.try_into().unwrap(), 50000.try_into().unwrap()));
Expand All @@ -238,10 +238,10 @@ fn test_withdraw_delegation_with_incorrect_calldata() {
let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

start_prank(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
let mut calldata: Array<(ContractAddress, u128)> = ArrayTrait::new();
calldata.append((second_address.try_into().unwrap(), 50000.try_into().unwrap()));
dispatcher
Expand Down Expand Up @@ -323,10 +323,10 @@ fn test_delegate_vote_and_delegation_withdrawal() {
dispatcher.delegate_vote(second_address.try_into().unwrap(), calldata, 1);

stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

start_prank(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);

prank(
Expand Down Expand Up @@ -365,7 +365,7 @@ fn test_withdraw_more_than_delegated_amount() {
let calldata: Array<(ContractAddress, u128)> = ArrayTrait::new();
dispatcher.delegate_vote(second_address.try_into().unwrap(), calldata, 10.try_into().unwrap());

start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

prank(
Expand Down Expand Up @@ -404,7 +404,7 @@ fn test_full_withdraw_and_vote() {
dispatcher.delegate_vote(second_address.try_into().unwrap(), calldata, 10.try_into().unwrap());

stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(42, 1);

prank(
Expand All @@ -416,7 +416,7 @@ fn test_full_withdraw_and_vote() {
calldata.append((second_address.try_into().unwrap(), 10));
dispatcher.withdraw_delegation(second_address.try_into().unwrap(), calldata, 10, prop_id);

start_prank(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);
}

Expand All @@ -428,7 +428,7 @@ fn test_successful_proposal_submission() {

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };
stake_all(gov.contract_address, floating, admin_addr.try_into().unwrap());
start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id_1: u128 = dispatcher.submit_proposal(42, 1).try_into().unwrap();
let prop_id_2: u128 = dispatcher.submit_proposal(43, 1).try_into().unwrap();

Expand Down Expand Up @@ -463,7 +463,7 @@ fn test_add_comment_on_non_live_proposal() {
//simulate passage of time
let current_timestamp = get_block_timestamp();
let end_timestamp = current_timestamp + constants::PROPOSAL_VOTING_SECONDS;
start_warp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);
start_cheat_block_timestamp(CheatTarget::One(gov_contract_addr), end_timestamp + 1);

IDiscussionDispatcher { contract_address: gov_contract_addr }
.add_comment(prop_id.try_into().unwrap(), ipfs_hash);
Expand Down
10 changes: 5 additions & 5 deletions tests/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use konoha::upgrades::IUpgradesDispatcherTrait;
use openzeppelin::token::erc20::interface::IERC20;
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, start_prank, start_warp, CheatTarget
BlockId, declare, ContractClassTrait, ContractClass, start_cheat_caller_address, start_cheat_block_timestamp, CheatTarget
};
use starknet::ContractAddress;
use starknet::get_block_timestamp;
Expand Down Expand Up @@ -92,14 +92,14 @@ fn test_vote_upgrade_root(new_merkle_root: felt252) {

let dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
let prop_id = dispatcher.submit_proposal(new_merkle_root, 3);

start_prank(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), first_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);
start_prank(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), second_address.try_into().unwrap());
dispatcher.vote(prop_id, 1);
start_prank(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
start_cheat_caller_address(CheatTarget::One(gov_contract_addr), admin_addr.try_into().unwrap());
dispatcher.vote(prop_id, 1);

assert(dispatcher.get_proposal_status(prop_id) == 1, 'proposal not passed!');
Expand Down
14 changes: 7 additions & 7 deletions tests/staking_tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use konoha::staking::{IStakingDispatcher, IStakingDispatcherTrait};
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};

use snforge_std::{
BlockId, declare, ContractClassTrait, ContractClass, CheatTarget, prank, CheatSpan, start_warp,
stop_warp
BlockId, declare, ContractClassTrait, ContractClass, CheatTarget, prank, CheatSpan, start_cheat_block_timestamp,
stop_cheat_block_timestamp
};
use starknet::{ContractAddress, get_block_timestamp};
use super::setup::{admin_addr, first_address, second_address, deploy_governance_and_both_tokens};
Expand Down Expand Up @@ -70,9 +70,9 @@ fn test_basic_stake_unstake() {
let stake_id = staking.stake(ONE_MONTH, balance_of_staker);

let current_timestamp = get_block_timestamp();
start_warp(CheatTarget::One(gov.contract_address), current_timestamp + ONE_MONTH + 1);
start_cheat_block_timestamp(CheatTarget::One(gov.contract_address), current_timestamp + ONE_MONTH + 1);
staking.unstake(stake_id);
stop_warp(CheatTarget::One(gov.contract_address));
stop_cheat_block_timestamp(CheatTarget::One(gov.contract_address));
}

#[test]
Expand All @@ -98,7 +98,7 @@ fn test_multiple_overlapping_stake_unstake() {
assert(voting.balance_of(admin) == 420 + 2342, 'wrong bal yearone+monthone');
assert(staking.get_total_voting_power(admin) == 420 + 2342, 'voting power baad');

start_warp(CheatTarget::One(gov.contract_address), time_zero + ONE_MONTH + 1);
start_cheat_block_timestamp(CheatTarget::One(gov.contract_address), time_zero + ONE_MONTH + 1);
assert(staking.get_total_voting_power(admin) == 2342, 'voting power baaad');
prank(CheatTarget::One(gov.contract_address), admin, CheatSpan::TargetCalls(1));
staking.unstake(stake_id_month_one);
Expand All @@ -110,9 +110,9 @@ fn test_multiple_overlapping_stake_unstake() {
prank(CheatTarget::One(gov.contract_address), admin, CheatSpan::TargetCalls(1));
let stake_id_month_one_three_months = staking.stake(ONE_MONTH * 3, 101);
assert(voting.balance_of(admin) == 2342 + 121, 'wrong bal yearone+monthtwo');
stop_warp(CheatTarget::One(gov.contract_address));
stop_cheat_block_timestamp(CheatTarget::One(gov.contract_address));

start_warp(CheatTarget::One(gov.contract_address), time_zero + ONE_YEAR * 4 + 1);
start_cheat_block_timestamp(CheatTarget::One(gov.contract_address), time_zero + ONE_YEAR * 4 + 1);
assert(staking.get_total_voting_power(admin) == 0, 'voting power baaaaad');
prank(CheatTarget::One(gov.contract_address), admin, CheatSpan::TargetCalls(1));
staking.unstake(stake_id_year);
Expand Down
Loading
Loading