Skip to content

Commit

Permalink
Adding setup file with generic function which applies a proposal to u…
Browse files Browse the repository at this point in the history
…pgrade root and passes it
  • Loading branch information
Nerrolol committed Mar 25, 2024
1 parent ff93699 commit ac373e5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/airdrop.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod airdrop {
use governance::contract::Governance::ContractState;
use governance::traits::IGovernanceTokenDispatcher;
use governance::traits::IGovernanceTokenDispatcherTrait;

#[storage]
struct Storage {
airdrop_claimed: LegacyMap::<ContractAddress, u128>,
Expand Down
41 changes: 21 additions & 20 deletions tests/airdrop_tests.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use core::hash::HashStateExTrait;
use core::{ArrayTrait, SpanTrait};
use core::debug::PrintTrait;
use distributor::contract::{Distributor, IDistributorDispatcher, IDistributorDispatcherTrait};
use Distributor::STRK_ADDRESS;
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 starknet::{ContractAddress, deploy_syscall};
Expand All @@ -11,16 +11,17 @@ const ADMIN_ADDR: felt252 = 0x42;
const CLAIMEE_1: felt252 = 0x13;
const CLAIMEE_2: felt252 = 0x14;

fn deploy() -> IDistributorDispatcher {

fn deploy() -> IAirdropDispatcher {
let mut calldata = ArrayTrait::new();
calldata.append(ADMIN_ADDR);

let contract = declare('Distributor');
let address = contract.deploy(@calldata).expect('unable to deploy distributor');

IDistributorDispatcher { contract_address: address }
let contract = declare('Airdrop');
let address = contract.deploy().expect('unable to deploy Airdrop');
IAirdropDispatcher { contract_address: address }
}


fn deploy_token(recipient: ContractAddress) -> IERC20Dispatcher {
let mut calldata = ArrayTrait::new();
calldata.append(1000000000000000000);
Expand All @@ -36,22 +37,22 @@ fn deploy_token(recipient: ContractAddress) -> IERC20Dispatcher {

#[test]
fn test_claim_twice_with_same_proof() {
let contract = deploy();
let tok = deploy_token(contract.contract_address);
start_prank(CheatTarget::One(contract.contract_address), ADMIN_ADDR.try_into().unwrap());
contract.add_root(valid_root);
start_prank(CheatTarget::One(contract.contract_address), CLAIMEE_1.try_into().unwrap());
let airdrop_contract = deploy();
let token_contract = deploy_token(airdrop_contract.contract_address);

start_prank(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());
let initial_proof = array![valid_proof_element];
contract.claim(valid_claim_amount, initial_proof.span());
assert(tok.balance_of(CLAIMEE_1.try_into().unwrap()) == valid_claim_amount, "First claim failed");


contract.claim(valid_claim_amount, initial_proof.span());
assert(tok.balance_of(CLAIMEE_1.try_into().unwrap()) == valid_claim_amount, "Second claimed modified the claimee's balance");
airdrop_contract.claim(CLAIMEE_1, valid_claim_amount, initial_proof.span());
assert(token_contract.balance_of(CLAIMEE_1.try_into().unwrap()) == valid_claim_amount, "First claim failed");

airdrop_contract.claim(CLAIMEE_1, valid_claim_amount, initial_proof.span());
assert(token_contract.balance_of(CLAIMEE_1.try_into().unwrap()) == valid_claim_amount, "Second claim modified the claimee's balance");
}


#[test]
#[should_panic(expected: ('INVALID PROOF',))]
fn test_claim_invalid_proof() {
Expand Down
86 changes: 86 additions & 0 deletions tests/setup.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use array::ArrayTrait;
use core::traits::TryInto;
use debug::PrintTrait;
use starknet::ContractAddress;
use snforge_std::{BlockId, declare, ContractClassTrait, ContractClass, start_prank, CheatTarget};

use governance::contract::IGovernanceDispatcher;
use governance::contract::IGovernanceDispatcherTrait;
use governance::proposals::IProposalsDispatcher;
use governance::proposals::IProposalsDispatcherTrait;
use governance::upgrades::IUpgradesDispatcher;
use governance::upgrades::IUpgradesDispatcherTrait;

fn test_upgrade_root(new_merkle_root: felt) {

let gov_contract_addr: ContractAddress =
0x001405ab78ab6ec90fba09e6116f373cda53b0ba557789a4578d8c1ec374ba0f
.try_into()
.unwrap();

//let airdrop_contract_addr: ContractAddress = deploy_contract('Airdrop')

let proposals_dispatcher = IProposalsDispatcher { contract_address: gov_contract_addr };

let mut top_carm_holders = ArrayTrait::new();
let marek_address: ContractAddress =
0x0011d341c6e841426448ff39aa443a6dbb428914e05ba2259463c18308b86233
.try_into()
.unwrap();
top_carm_holders.append(marek_address);
let scaling_address: ContractAddress =
0x052df7acdfd3174241fa6bd5e1b7192cd133f8fc30a2a6ed99b0ddbfb5b22dcd
.try_into()
.unwrap();
top_carm_holders.append(scaling_address);
let ondrej_address: ContractAddress =
0x0583a9d956d65628f806386ab5b12dccd74236a3c6b930ded9cf3c54efc722a1
.try_into()
.unwrap();
top_carm_holders.append(ondrej_address);
let carlote_address: ContractAddress =
0x021b2b25dd73bc60b0549683653081f8963562cbe5cba2d123ec0cbcbf0913e4
.try_into()
.unwrap();
top_carm_holders.append(carlote_address);
let fifth_address: ContractAddress =
0x02af7135154dc27d9311b79c57ccc7b3a6ed74efd0c2b81116e8eb49dbf6aaf8
.try_into()
.unwrap();
top_carm_holders.append(fifth_address);
let sixth_address: ContractAddress =
0x07824efd915baa421d93909bd7f24e36c022b5cfbc5af6687328848a6490ada7
.try_into()
.unwrap();
top_carm_holders.append(sixth_address);
let madman_address: ContractAddress =
0x06717eaf502baac2b6b2c6ee3ac39b34a52e726a73905ed586e757158270a0af
.try_into()
.unwrap();
top_carm_holders.append(madman_address);
let eighth_address: ContractAddress =
0x03d1525605db970fa1724693404f5f64cba8af82ec4aab514e6ebd3dec4838ad
.try_into()
.unwrap();
top_carm_holders.append(eighth_address);

start_prank(CheatTarget::One(gov_contract_addr), scaling_address);
let new_prop_id = dispatcher.submit_proposal(new_merkle_root, 3);

loop {
match top_carm_holders.pop_front() {
Option::Some(holder) => {
start_prank(CheatTarget::One(gov_contract_addr), holder);
dispatcher.vote(new_prop_id, 1);
},
Option::None(()) => { break (); },
}
};
assert(dispatcher.get_proposal_status(new_prop_id) == 1, 'proposal not passed!');

let upgrade_dispatcher = IUpgradesDispatcher { contract_address: gov_contract_addr };
upgrade_dispatcher.apply_passed_proposal(new_prop_id);
assert(check_if_healthy(gov_contract_addr), 'new gov not healthy');

}

0 comments on commit ac373e5

Please sign in to comment.