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

Only transfer 1 kudos at a time and mint 5 intially #15

Merged
merged 3 commits into from
Jan 2, 2025
Merged
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
1 change: 0 additions & 1 deletion contracts/src/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use starknet::ContractAddress;
pub trait IKudos<TState> {
fn give_kudos(
ref self: TState,
amount: u256,
sender_credentials: felt252,
receiver_credentials: felt252,
description: felt252,
Expand Down
12 changes: 5 additions & 7 deletions contracts/src/kudos.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod Kudos {
use kudos::credential_registry::{ICredentialRegistry, CredentialRegistryComponent};
use kudos::oz16::IERC20ReadOnly;
use kudos::oz16::erc20::{ERC20Component, ERC20HooksEmptyImpl, ERC20Component::InternalTrait};
use kudos::utils::constants::REGISTRATION_AMOUNT;
use kudos::utils::constants::{REGISTRATION_AMOUNT, ONE};
use starknet::storage::{
StoragePointerReadAccess, StoragePointerWriteAccess, StoragePathEntry, Map
};
Expand Down Expand Up @@ -50,7 +50,6 @@ pub mod Kudos {
pub sender: ContractAddress,
#[key]
pub receiver: ContractAddress,
pub amount: u256,
pub description: felt252,
}

Expand All @@ -68,7 +67,6 @@ pub mod Kudos {
impl Kudos of IKudos<ContractState> {
fn give_kudos(
ref self: ContractState,
amount: u256,
sender_credentials: felt252,
receiver_credentials: felt252,
description: felt252,
Expand All @@ -79,15 +77,15 @@ pub mod Kudos {
let receiver = self.credential_registry.get_credential_address(receiver_credentials);
assert(self.credential_registry.is_registered(receiver), Errors::RECEIVER_UNREGISTERED);

self.erc20.transfer(receiver, amount);
self.erc20.transfer(receiver, ONE);

let total_given = self.total_given.entry(sender).read();
self.total_given.entry(sender).write(total_given + amount);
self.total_given.entry(sender).write(total_given + ONE);

let total_received = self.total_given.entry(receiver).read();
self.total_received.entry(receiver).write(total_received + amount);
self.total_received.entry(receiver).write(total_received + ONE);

self.emit(KudosGiven { sender, receiver, amount, description });
self.emit(KudosGiven { sender, receiver, description });
}

fn register_sw_employee(ref self: ContractState, credential_hash: felt252,) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/utils/constants.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn ZERO_ADDRESS() -> ContractAddress {

pub const DECIMALS: u8 = 18;
pub const ONE: u256 = 1_000_000_000_000_000_000;
pub const REGISTRATION_AMOUNT: u256 = 1_000_000_000_000_000_000_000;
pub const REGISTRATION_AMOUNT: u256 = 5_000_000_000_000_000_000;

pub fn NAME() -> ByteArray {
"Kudos"
Expand Down
17 changes: 7 additions & 10 deletions contracts/tests/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use kudos::utils::constants::{
};
use kudos::{Kudos, IKudosDispatcher, IKudosDispatcherTrait};
use snforge_std::{spy_events, EventSpyAssertionsTrait, start_cheat_caller_address};
use utils::{setup, setup_registered, test_amount, test_description};
use utils::{setup, setup_registered, test_description, one};

#[test]
fn test_erc20_metadata() {
Expand Down Expand Up @@ -85,17 +85,14 @@ fn test_give_kudos() {

let kudos = IKudosDispatcher { contract_address: setup_registered() };
start_cheat_caller_address(kudos.contract_address, CALLER());
kudos.give_kudos(test_amount(), CREDENTIAL_HASH, CREDENTIAL_HASH_2, test_description());
kudos.give_kudos(CREDENTIAL_HASH, CREDENTIAL_HASH_2, test_description());

assert_eq!(kudos.get_total_given(CALLER()), test_amount());
assert_eq!(kudos.get_total_received(RECEIVER()), test_amount());
assert_eq!(kudos.get_total_given(CALLER()), one());
assert_eq!(kudos.get_total_received(RECEIVER()), one());

let expected_kudos_event = Kudos::Event::KudosGiven(
Kudos::KudosGiven {
sender: CALLER(),
receiver: RECEIVER(),
amount: test_amount(),
description: test_description()
sender: CALLER(), receiver: RECEIVER(), description: test_description()
}
);
spy.assert_emitted(@array![(kudos.contract_address, expected_kudos_event)]);
Expand All @@ -106,13 +103,13 @@ fn test_give_kudos() {
fn test_give_kudos_sender_unregistered() {
let kudos = IKudosDispatcher { contract_address: setup_registered() };
start_cheat_caller_address(kudos.contract_address, DUMMY());
kudos.give_kudos(test_amount(), CREDENTIAL_HASH, CREDENTIAL_HASH_2, test_description());
kudos.give_kudos(CREDENTIAL_HASH, CREDENTIAL_HASH_2, test_description());
}

#[test]
#[should_panic(expected: 'Receiver not registered')]
fn test_give_kudos_receiver_unregistered() {
let kudos = IKudosDispatcher { contract_address: setup_registered() };
start_cheat_caller_address(kudos.contract_address, CALLER());
kudos.give_kudos(test_amount(), CREDENTIAL_HASH, CREDENTIAL_HASH_BAD, test_description());
kudos.give_kudos(CREDENTIAL_HASH, CREDENTIAL_HASH_BAD, test_description());
}
4 changes: 2 additions & 2 deletions contracts/tests/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn setup_registered() -> ContractAddress {
contract_address
}

pub fn test_amount() -> u256 {
ONE * 25
pub fn one() -> u256 {
ONE * 1
}

pub fn test_description() -> felt252 {
Expand Down
Loading