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

add burn function #243

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
40 changes: 39 additions & 1 deletion apps/blockchain/starknet/src/token/erc721_bridgeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ mod erc721_bridgeable {
self.erc721._mint(to, token_id);
}

fn burn(ref self: ContractState, token_id: u256) {
mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
self.erc721._burn(token_id);
}


fn mint_from_bridge_uri(ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray) {
IERC721Bridgeable::mint_from_bridge(ref self, to, token_id);
self.token_uris.write(token_id, token_uri);
Expand Down Expand Up @@ -296,6 +301,39 @@ mod tests {
assert_eq!(erc721.token_uri(0), "myuri", "bad uri");
}

/// Should burn token from bridge call.
#[test]
fn burn_from_bridge() {
let BRIDGE = bridge_addr_mock();

let DUO_OWNER = starknet::contract_address_const::<128>();

let contract_address = deploy_everai_collection();

let erc721b = IERC721BridgeableDispatcher { contract_address };

// Mint a token first to be able to burn it later
start_prank(CheatTarget::One(contract_address), BRIDGE);
erc721b.mint_from_bridge(DUO_OWNER, 42_u256);
stop_prank(CheatTarget::One(contract_address));

// Check that the owner is set correctly after minting
let erc721 = IERC721Dispatcher { contract_address };
assert!(erc721.owner_of(42_u256) == DUO_OWNER, "bad owner after mint");

// Burn the token
start_prank(CheatTarget::One(contract_address), BRIDGE);
mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
erc721b.burn(42_u256);
stop_prank(CheatTarget::One(contract_address));

// balance_of
start_prank(CheatTarget::One(contract_address), BRIDGE);
mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
let balance = erc721.balance_of(BRIDGE);
mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
assert(balance == 0, 'token was not burn');
stop_prank(CheatTarget::One(contract_address));

}

/// Should not mint token if not bridge.
#[test]
#[should_panic(expected: ('ERC721: only bridge can mint', ))]
Expand Down Expand Up @@ -512,4 +550,4 @@ mod tests {
assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri);
}

}
}
4 changes: 3 additions & 1 deletion apps/blockchain/starknet/src/token/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait IERC721<T> {
fn owner_of(self: @T, token_id: u256) -> ContractAddress;
fn token_uri(self: @T, token_id: u256) -> ByteArray;
fn is_approved_for_all(self: @T, owner: ContractAddress, operator: ContractAddress) -> bool;

fn balance_of(self: @T, owner: ContractAddress) -> u256;
fn set_approval_for_all(ref self: T, operator: ContractAddress, approved: bool);
fn transfer_from(ref self: T, from: ContractAddress, to: ContractAddress, token_id: u256);
fn approve(ref self: T, to: ContractAddress, token_id: u256);
Expand All @@ -30,6 +30,8 @@ trait IERC721Mintable<T> {
/// ERC721 that can be manipulated by the bridge.
#[starknet::interface]
trait IERC721Bridgeable<T> {
fn burn(ref self: T, token_id: u256);

fn mint_from_bridge(ref self: T, to: ContractAddress, token_id: u256);

fn mint_from_bridge_uri(ref self: T, to: ContractAddress, token_id: u256, token_uri: ByteArray);
Expand Down
Loading