Skip to content

Commit

Permalink
remove formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mubarak23 committed Sep 29, 2024
1 parent ddfbd45 commit 4b86090
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 52 deletions.
94 changes: 43 additions & 51 deletions apps/blockchain/starknet/src/token/erc721_bridgeable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ mod erc721_bridgeable {
impl ERC721Impl = ERC721Component::ERC721Impl<ContractState>;
#[abi(embed_v0)]
impl ERC721CamelOnly = ERC721Component::ERC721CamelOnlyImpl<ContractState>;

impl ERC721InternalImpl = ERC721Component::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[abi(embed_v0)]
impl OwnableTwoStepMixinImpl =
OwnableComponent::OwnableTwoStepMixinImpl<ContractState>;
impl OwnableTwoStepMixinImpl = OwnableComponent::OwnableTwoStepMixinImpl<ContractState>;

impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

Expand Down Expand Up @@ -80,27 +79,26 @@ mod erc721_bridgeable {
impl ERC721BridgeableImpl of IERC721Bridgeable<ContractState> {
fn mint_from_bridge(ref self: ContractState, to: ContractAddress, token_id: u256) {
assert(
starknet::get_caller_address() == self.bridge.read(), 'ERC721: only bridge can mint'
starknet::get_caller_address() == self.bridge.read(),
'ERC721: only bridge can mint'
);

self.erc721._mint(to, 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);
}
fn burn(ref self: ContractState, token_id: u256) {
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);
}
}

#[abi(embed_v0)]
impl ERC721BridgeableMetadataImpl of ERC721Component::interface::IERC721Metadata<
ContractState
> {
impl ERC721BridgeableMetadataImpl of ERC721Component::interface::IERC721Metadata<ContractState> {
fn name(self: @ContractState) -> ByteArray {
self.erc721.name()
}
Expand All @@ -120,9 +118,7 @@ mod erc721_bridgeable {
}

#[abi(embed_v0)]
impl ERC721BridgeableMetadataCamelOnlyImpl of ERC721Component::interface::IERC721MetadataCamelOnly<
ContractState
> {
impl ERC721BridgeableMetadataCamelOnlyImpl of ERC721Component::interface::IERC721MetadataCamelOnly<ContractState> {
fn tokenURI(self: @ContractState, tokenId: u256) -> ByteArray {
self.token_uri(tokenId)
}
Expand Down Expand Up @@ -150,17 +146,15 @@ mod erc721_bridgeable {
fn mint_range(ref self: ContractState, to: ContractAddress, start: u256, end: u256) {
let mut token_id = start;
loop {
if token_id == end {
break ();
}
if token_id == end {
break ();
}
self.mint(to, token_id);
token_id += 1_u256;
}
}

fn mint_uri(
ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray
) {
fn mint_uri(ref self: ContractState, to: ContractAddress, token_id: u256, token_uri: ByteArray) {
self.mint(to, token_id);
self.token_uris.write(token_id, token_uri);
}
Expand Down Expand Up @@ -194,8 +188,9 @@ mod tests {
};

use starklane::token::interfaces::{
IERC721BridgeableDispatcher, IERC721BridgeableDispatcherTrait, IERC721Dispatcher,
IERC721DispatcherTrait, IERC721MintableDispatcher, IERC721MintableDispatcherTrait,
IERC721BridgeableDispatcher, IERC721BridgeableDispatcherTrait,
IERC721Dispatcher, IERC721DispatcherTrait,
IERC721MintableDispatcher, IERC721MintableDispatcherTrait,
IERC721UriDispatcher, IERC721UriDispatcherTrait,
};
use starklane::token::collection_manager;
Expand Down Expand Up @@ -251,8 +246,7 @@ mod tests {
"DUO",
"https://my.base.uri",
bridge_addr_mock(),
collection_owner_addr_mock()
)
collection_owner_addr_mock())
}

/// Should have correct constructor valules.
Expand All @@ -276,12 +270,11 @@ mod tests {
let TOKEN_ID = 244;

let contract_address = deploy_everai_collection();
let erc721 = IERC721Dispatcher { contract_address };

let erc721 = IERC721Dispatcher { contract_address };
let new_uri = "https:...";
start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721MintableDispatcher { contract_address }
.mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone());
IERC721MintableDispatcher { contract_address }.mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone());
stop_prank(CheatTarget::One(contract_address));

let fetched_uri = erc721.token_uri(TOKEN_ID);
Expand All @@ -292,7 +285,7 @@ mod tests {
#[test]
fn mint_from_bridge() {
let BRIDGE = bridge_addr_mock();

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

let contract_address = deploy_everai_collection();
Expand All @@ -310,7 +303,7 @@ mod tests {

/// Should not mint token if not bridge.
#[test]
#[should_panic(expected: ('ERC721: only bridge can mint',))]
#[should_panic(expected: ('ERC721: only bridge can mint', ))]
fn should_panic_mint_from_bridge_fail() {
let NEW_DUO_OWNER = starknet::contract_address_const::<128>();

Expand Down Expand Up @@ -360,9 +353,7 @@ mod tests {
erc721.mint_uri(NEW_DUO_OWNER, TOKEN_ID, new_uri.clone());
stop_prank(CheatTarget::One(contract_address));

let fetched_uri = collection_manager::token_uri_from_contract_call(
contract_address, TOKEN_ID
)
let fetched_uri = collection_manager::token_uri_from_contract_call(contract_address, TOKEN_ID)
.expect('token mint failed');
assert_eq!(fetched_uri, new_uri, "bad uri");
}
Expand Down Expand Up @@ -404,7 +395,7 @@ mod tests {
stop_prank(CheatTarget::One(contract_address));
assert_eq!(ownable.owner(), COLLECTION_OWNER, "bad owner");
assert_eq!(ownable.pending_owner(), ALICE, "bad pending owner");

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
ownable.transfer_ownership(BOB);
stop_prank(CheatTarget::One(contract_address));
Expand Down Expand Up @@ -442,7 +433,7 @@ mod tests {
let new_uri = "https://this.is.a.test.com";
let contract_address = deploy_everai_collection();

let contract = IERC721UriDispatcher { contract_address };
let contract = IERC721UriDispatcher { contract_address};
assert_eq!(contract.base_uri(), "https://my.base.uri");
start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
contract.set_base_uri(new_uri.clone());
Expand All @@ -462,7 +453,7 @@ mod tests {
assert_eq!(ownable.owner(), COLLECTION_OWNER, "bad owner");

start_prank(CheatTarget::One(contract_address), ALICE);
IERC721UriDispatcher { contract_address }.set_base_uri("https://this.is.a.test.com");
IERC721UriDispatcher { contract_address}.set_base_uri("https://this.is.a.test.com");
stop_prank(CheatTarget::One(contract_address));
}

Expand All @@ -475,14 +466,14 @@ mod tests {
let token_id = 42_u256;

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id);
IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id);
stop_prank(CheatTarget::One(contract_address));
assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone());
assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone());

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721UriDispatcher { contract_address }.set_token_uri(token_id, new_uri.clone());
IERC721UriDispatcher { contract_address}.set_token_uri(token_id, new_uri.clone());
stop_prank(CheatTarget::One(contract_address));
assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri);
assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri);
}

#[test]
Expand All @@ -496,14 +487,14 @@ mod tests {
let invalid_token_id = 68_u256;

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id);
IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id);
stop_prank(CheatTarget::One(contract_address));
assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone());
assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone());

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721UriDispatcher { contract_address }.set_token_uri(invalid_token_id, new_uri.clone());
IERC721UriDispatcher { contract_address}.set_token_uri(invalid_token_id, new_uri.clone());
stop_prank(CheatTarget::One(contract_address));
assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri);
assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri);
}

#[test]
Expand All @@ -516,13 +507,14 @@ mod tests {
let token_id = 42_u256;

start_prank(CheatTarget::One(contract_address), COLLECTION_OWNER);
IERC721MintableDispatcher { contract_address }.mint(ALICE, token_id);
IERC721MintableDispatcher { contract_address}.mint(ALICE, token_id);
stop_prank(CheatTarget::One(contract_address));
assert!(IERC721Dispatcher { contract_address }.token_uri(token_id) != new_uri.clone());
assert!(IERC721Dispatcher {contract_address}.token_uri(token_id) != new_uri.clone());

start_prank(CheatTarget::One(contract_address), ALICE);
IERC721UriDispatcher { contract_address }.set_token_uri(token_id, new_uri.clone());
IERC721UriDispatcher { contract_address}.set_token_uri(token_id, new_uri.clone());
stop_prank(CheatTarget::One(contract_address));
assert_eq!(IERC721Dispatcher { contract_address }.token_uri(token_id), new_uri);
assert_eq!(IERC721Dispatcher {contract_address}.token_uri(token_id), new_uri);
}
}

}
3 changes: 2 additions & 1 deletion apps/blockchain/starknet/src/token/interfaces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ 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);

fn burn(ref self: T, token_id: u256);
}

0 comments on commit 4b86090

Please sign in to comment.