Skip to content

Commit

Permalink
unit test for burn function
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Oct 2, 2024
1 parent 4b86090 commit ca16fc9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
33 changes: 33 additions & 0 deletions apps/blockchain/starknet/src/token/erc721_bridgeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -301,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);
erc721b.burn(42_u256);
stop_prank(CheatTarget::One(contract_address));

// balance_of
start_prank(CheatTarget::One(contract_address), BRIDGE);
let balance = erc721.balance_of(BRIDGE);
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
5 changes: 2 additions & 3 deletions 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 @@ -31,9 +31,8 @@ trait IERC721Mintable<T> {
#[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);

}

0 comments on commit ca16fc9

Please sign in to comment.