Skip to content

Commit

Permalink
adds test for minting with full balance
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackAttax committed Jan 3, 2025
1 parent 015ecac commit e20b83b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions contracts/src/kudos.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub mod Kudos {
pub const RECEIVER_UNREGISTERED: felt252 = 'Receiver not registered';
pub const MINTER_UNREGISTERED: felt252 = 'Minter not registered';
pub const MINTED_BALANCE_ZERO: felt252 = 'Minted balance is zero';
pub const MINTED_BALANCE_IS_FULL: felt252 = 'Minted balance is full';
pub const MINTED_AMOUNT_IS_ZERO: felt252 = 'Minted amount is zero';
pub const MINTED_LESS_THAN_30_DAYS_AGO: felt252 = 'Minted less than 30 days ago';
}
Expand All @@ -86,7 +87,6 @@ pub mod Kudos {
assert(self.credential_registry.is_registered(receiver), Errors::RECEIVER_UNREGISTERED);

let minted_balance = self.minted_balance.entry(sender).read();
println!("minted_balance: {}", minted_balance);
assert(minted_balance > 0, Errors::MINTED_BALANCE_ZERO);

self.erc20.transfer(receiver, ONE);
Expand All @@ -112,7 +112,7 @@ pub mod Kudos {
assert(time_since_last_mint > SECONDS_IN_30_DAYS, Errors::MINTED_LESS_THAN_30_DAYS_AGO);

let amount_to_mint = MONTHLT_MINT_AMOUNT - self.minted_balance.entry(address).read();
assert(amount_to_mint > 0, Errors::MINTED_AMOUNT_IS_ZERO);
assert(amount_to_mint > 0, Errors::MINTED_BALANCE_IS_FULL);

self.erc20.mint(address, amount_to_mint);
self.minted_balance.entry(address).write(MONTHLT_MINT_AMOUNT);
Expand Down
35 changes: 32 additions & 3 deletions contracts/tests/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use kudos::utils::constants::{
ZERO_ADDRESS, RECEIVER, DUMMY, CREDENTIAL_HASH_BAD, SECONDS_IN_30_DAYS, FIVE, ZERO
};
use kudos::{Kudos, IKudosDispatcher, IKudosDispatcherTrait};
use snforge_std::{spy_events, EventSpyAssertionsTrait, start_cheat_caller_address, start_cheat_block_timestamp_global, stop_cheat_block_timestamp_global};
use snforge_std::{
spy_events, EventSpyAssertionsTrait, start_cheat_caller_address,
start_cheat_block_timestamp_global, stop_cheat_block_timestamp_global
};
use starknet::get_block_timestamp;
use utils::{setup, setup_registered, test_description, one, send_5_kudos};

Expand Down Expand Up @@ -128,15 +131,41 @@ fn test_give_kudos_minted_balance_zero() {
#[test]
fn test_monthly_mint_full_amount() {
let kudos = IKudosDispatcher { contract_address: setup_registered() };

start_cheat_caller_address(kudos.contract_address, CALLER());
send_5_kudos(kudos);

let thirty_days_pass = get_block_timestamp() + SECONDS_IN_30_DAYS + 1;
start_cheat_block_timestamp_global(block_timestamp: thirty_days_pass);
assert(kudos.get_minted_balance(CALLER()) == ZERO, 'Minted balance is not zero');
println!("minted balance before: {}", kudos.get_minted_balance(CALLER()));

kudos.monthly_mint();
println!("minted balance after: {}", kudos.get_minted_balance(CALLER()));

assert(kudos.get_minted_balance(CALLER()) == FIVE, 'Minted balance is not five');

stop_cheat_block_timestamp_global()
}

#[test]
#[should_panic(expected: 'Minted balance is full')]
fn test_monthly_mint_with_a_full_balance() {
let kudos = IKudosDispatcher { contract_address: setup_registered() };

start_cheat_caller_address(kudos.contract_address, CALLER());

let thirty_days_pass = get_block_timestamp() + SECONDS_IN_30_DAYS + 1;
start_cheat_block_timestamp_global(block_timestamp: thirty_days_pass);
assert(kudos.get_minted_balance(CALLER()) == FIVE, 'Minted balance is not five');

kudos.monthly_mint();

stop_cheat_block_timestamp_global()
}

#[test]
#[should_panic(expected: 'Minter not registered')]
fn test_monthly_mint_minter_unregistered() {
let kudos = IKudosDispatcher { contract_address: setup_registered() };
start_cheat_caller_address(kudos.contract_address, DUMMY());
kudos.monthly_mint();
}

0 comments on commit e20b83b

Please sign in to comment.