Skip to content

Commit 4f2b0db

Browse files
author
aradix16
committed
add basic burn function
1 parent 18d0f0c commit 4f2b0db

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

backend-sc/src/components/certificate/certificate.cairo

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod NFTComponent {
2222
+SRC5Component::HasComponent<TContractState>,
2323
impl ERC721: ERC721Component::HasComponent<TContractState>,
2424
> of INFTComponent<ComponentState<TContractState>> {
25-
25+
// internal
2626
fn initializer(
2727
ref self: ComponentState<TContractState>,
2828
name: ByteArray,
@@ -37,5 +37,10 @@ mod NFTComponent {
3737
let mut erc721 = get_dep_component_mut!(ref self, ERC721);
3838
erc721._mint(to, token_id);
3939
}
40+
41+
fn burn(ref self: ComponentState<TContractState>, token_id: u256) {
42+
let mut erc721 = get_dep_component_mut!(ref self, ERC721);
43+
erc721._burn(token_id);
44+
}
4045
}
4146
}

backend-sc/src/components/certificate/interface.cairo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ use starknet::ContractAddress;
44
trait INFTComponent<TContractState> {
55
fn initializer(ref self: TContractState, name: ByteArray, symbol: ByteArray, base_uri: ByteArray);
66
fn mint(ref self: TContractState, to: ContractAddress, token_id: u256);
7+
fn burn(ref self: TContractState, token_id: u256);
78
}

backend-sc/tests/tests_certificate.cairo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,16 @@ fn test_mint_function() {
5656
let mut balance = erc721.balance_of(user_address);
5757
assert(balance == 1, 'Balance should be 1');
5858
}
59+
60+
#[test]
61+
fn test_burn_function() {
62+
let certificate_address = deploy_nft_certificate();
63+
let certificate = INFTComponentDispatcher { contract_address: certificate_address };
64+
let user_address: ContractAddress = contract_address_const::<'USER'>();
65+
let erc721 = IERC721Dispatcher { contract_address: certificate_address };
66+
67+
certificate.mint(user_address, 1);
68+
certificate.burn(1);
69+
let mut balance = erc721.balance_of(user_address);
70+
assert(balance == 0, 'Balance should be 0');
71+
}

0 commit comments

Comments
 (0)