Skip to content

Commit

Permalink
feat: add mint item function
Browse files Browse the repository at this point in the history
  • Loading branch information
brolag committed Nov 11, 2024
1 parent 1af2212 commit a023a09
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
31 changes: 31 additions & 0 deletions apps/snfoundry/contracts/src/cofi_collection.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ pub trait ICofiCollection<TContractState> {
data: Span<felt252>,
);

/// Mints a new token item with a specific URI to a recipient.
///
/// # Arguments
/// * `recipient` - The address that will receive the minted token.
/// * `token_id` - The ID of the token to mint.
/// * `value` - The amount of tokens to mint.
/// * `data` - Additional data to accompany the minting.
/// * `uri` - The URI containing metadata for this token.
fn mint_item(
ref self: TContractState,
recipient: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>,
uri: ByteArray
);

/// Burns `value` amount of `token_id` from `account`.
///
/// # Arguments
Expand Down Expand Up @@ -326,6 +343,20 @@ mod CofiCollection {
self.erc1155.mint_with_acceptance_check(account, token_id, value, data);
}

#[external(v0)]
fn mint_item(
ref self: ContractState,
recipient: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>,
uri: ByteArray
) {
self.accesscontrol.assert_only_role(MINTER_ROLE);
self.erc1155.mint_with_acceptance_check(recipient, token_id, value, data);
self.erc1155._set_base_uri(uri);
}

#[external(v0)]
fn batch_mint(
ref self: ContractState,
Expand Down
21 changes: 21 additions & 0 deletions apps/snfoundry/contracts/src/test/test_cofi_collection.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,24 @@ fn test_uri() {
let another_token_uri = cofi_collection.uri(another_token_id);
assert(another_token_uri == base_uri, 'Incorrect token URI');
}


#[test]
fn test_mint_item() {
let cofi_collection = deploy_cofi_collection();
let owner = OWNER();
let token_id = 1_u256;
let uri: ByteArray = "https://api.example.com/token/";
let value = 1_u256;
let data: Array<felt252> = array![];
let receiver = deploy_receiver();

start_cheat_caller_address(cofi_collection.contract_address, owner);
cofi_collection.mint_item(receiver, token_id, value, data.span(), uri.clone());

let balance = cofi_collection.balance_of(receiver, token_id);
assert(balance == value, 'Incorrect balance');

let token_uri = cofi_collection.uri(token_id);
assert(token_uri == uri, 'Incorrect token URI');
}

0 comments on commit a023a09

Please sign in to comment.