Skip to content

Commit

Permalink
run scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
credence0x committed Dec 14, 2023
1 parent 2ed4b38 commit bef873a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 39 deletions.
17 changes: 4 additions & 13 deletions contracts/src/tokens/memecoin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ mod UnruggableMemecoin {
}



/// Constructor called once when the contract is deployed.
/// # Arguments
/// * `owner` - The owner of the contract.
Expand Down Expand Up @@ -106,11 +105,10 @@ mod UnruggableMemecoin {
fn launch_memecoin(ref self: ContractState) {
// Checks: Only the owner can launch the memecoin.
self.ownable.assert_only_owner();
// Effects.
// Effects.

// Launch the coin
self.launched.write(true);

// Interactions.
}
}
Expand Down Expand Up @@ -186,32 +184,25 @@ mod UnruggableMemecoin {
//
#[generate_trait]
impl UnruggableMemecoinInternalImpl of UnruggableMemecoinInternalTrait {

#[inline(always)]
fn _check_holders_limit(ref self: ContractState) {

// enforce max number of holders before launch

if !self.launched.read() {
let current_holders_count = self.pre_launch_holders_count.read();
assert(
current_holders_count < MAX_HOLDERS_BEFORE_LAUNCH,
Errors::MAX_HOLDERS_REACHED
current_holders_count < MAX_HOLDERS_BEFORE_LAUNCH, Errors::MAX_HOLDERS_REACHED
);

self.pre_launch_holders_count.write(current_holders_count + 1);
}
}

fn _mint(
ref self: ContractState,
recipient: ContractAddress,
amount: u256
) {
fn _mint(ref self: ContractState, recipient: ContractAddress, amount: u256) {
self._check_holders_limit();
self.erc20._mint(recipient, amount);
}

fn _transfer(
ref self: ContractState,
sender: ContractAddress,
Expand Down
42 changes: 16 additions & 26 deletions contracts/tests/test_unruggable_memecoin.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ mod memecoin_entrypoints {
memecoin.launch_memecoin();

assert(memecoin.launched(), 'Coin not launched');

//TODO
}

Expand All @@ -336,14 +335,14 @@ mod memecoin_entrypoints {


mod memecoin_internals {
use core::option::OptionTrait;
use snforge_std::{start_prank, CheatTarget};
use starknet::{ContractAddress, contract_address_const};
use unruggable::tokens::memecoin::UnruggableMemecoin;
use UnruggableMemecoin::{
UnruggableMemecoinInternalImpl, SnakeEntrypoints, UnruggableEntrypoints,
MAX_HOLDERS_BEFORE_LAUNCH
};
use core::option::OptionTrait;
use snforge_std::{start_prank, CheatTarget};
use starknet::{ContractAddress, contract_address_const};
use unruggable::tokens::memecoin::UnruggableMemecoin;


#[test]
Expand All @@ -359,19 +358,15 @@ mod memecoin_internals {
);

// Transfer 100 tokens to the recipient
UnruggableMemecoinInternalImpl::_transfer(
ref contract_state, owner, recipient, 100
);
UnruggableMemecoinInternalImpl::_transfer(ref contract_state, owner, recipient, 100);

// Check balance. Should be equal to initial supply - 100.
let owner_balance
= SnakeEntrypoints::balance_of(@contract_state, owner);
let owner_balance = SnakeEntrypoints::balance_of(@contract_state, owner);
assert(owner_balance == (initial_supply - 100), 'Invalid balance owner');

// Check recipient balance. Should be equal to 100.
let recipient_balance
= SnakeEntrypoints::balance_of(@contract_state, recipient);
assert(recipient_balance == 100.into(), 'Invalid balance recipient');
let recipient_balance = SnakeEntrypoints::balance_of(@contract_state, recipient);
assert(recipient_balance == 100.into(), 'Invalid balance recipient');
}


Expand All @@ -387,7 +382,7 @@ mod memecoin_internals {
);

// index starts from 1 because owner has initial supply
let mut index = 1;
let mut index = 1;
loop {
if index == MAX_HOLDERS_BEFORE_LAUNCH {
break;
Expand All @@ -400,19 +395,16 @@ mod memecoin_internals {
);

// Check recipient balance. Should be equal to 1.
let recipient_balance
= SnakeEntrypoints::balance_of(
@contract_state, unique_recipient
);
let recipient_balance = SnakeEntrypoints::balance_of(@contract_state, unique_recipient);
assert(recipient_balance == 1.into(), 'Invalid balance recipient');

index += 1;
};
};
}


#[test]
#[should_panic(expected: ('memecoin: max holders reached', ))]
#[should_panic(expected: ('memecoin: max holders reached',))]
fn test__transfer_above_holder_cap() {
let owner = contract_address_const::<42>();
let initial_supply = 1000.into();
Expand All @@ -424,7 +416,7 @@ mod memecoin_internals {
);

// index starts from 1 because owner has initial supply
let mut index = 1;
let mut index = 1;
loop {
if index == MAX_HOLDERS_BEFORE_LAUNCH + 1 {
break;
Expand All @@ -437,7 +429,7 @@ mod memecoin_internals {
);

index += 1;
};
};
}


Expand All @@ -459,7 +451,7 @@ mod memecoin_internals {
UnruggableEntrypoints::launch_memecoin(ref contract_state);

// index starts from 1 because owner has initial supply
let mut index = 1;
let mut index = 1;
loop {
if index == MAX_HOLDERS_BEFORE_LAUNCH + 1 {
break;
Expand All @@ -472,9 +464,7 @@ mod memecoin_internals {
);

index += 1;
};
};
}
}



0 comments on commit bef873a

Please sign in to comment.