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

feat(starknet): ERC721 uri, bridge ownership and collection white list #201

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
feat(starknet): emit event when collection whitelist list is updated
ptisserand committed Apr 24, 2024
commit 1dc38d14073fffb4e75b5e2b6906beca994e0e66
10 changes: 10 additions & 0 deletions apps/blockchain/starknet/src/bridge.cairo
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ mod bridge {
CollectionDeployedFromL1,
ReplacedClassHash,
BridgeEnabled,
CollectionWhiteListUpdated,
};

use starklane::request::{
@@ -108,6 +109,7 @@ mod bridge {
WithdrawRequestCompleted: WithdrawRequestCompleted,
ReplacedClassHash: ReplacedClassHash,
BridgeEnabled: BridgeEnabled,
CollectionWhiteListUpdated: CollectionWhiteListUpdated,
#[flat]
OwnableEvent: OwnableComponent::Event,
}
@@ -315,6 +317,10 @@ mod bridge {
fn white_list_collection(ref self: ContractState, collection: ContractAddress, enabled: bool) {
ensure_is_admin(@self);
_white_list_collection(ref self, collection, enabled);
self.emit(CollectionWhiteListUpdated {
collection,
enabled,
});
}

fn is_white_listed(self: @ContractState, collection: ContractAddress) -> bool {
@@ -465,6 +471,10 @@ mod bridge {
let (already_white_listed, _) = self.white_listed_list.read(l2_addr_from_deploy);
if already_white_listed != true {
_white_list_collection(ref self, l2_addr_from_deploy, true);
self.emit(CollectionWhiteListUpdated {
collection: l2_addr_from_deploy,
enabled: true,
});
}
l2_addr_from_deploy
}
9 changes: 8 additions & 1 deletion apps/blockchain/starknet/src/interfaces.cairo
Original file line number Diff line number Diff line change
@@ -99,4 +99,11 @@ struct L1L2CollectionMappingUpdated {
collection_l1: EthAddress,
#[key]
collection_l2: ContractAddress
}
}

#[derive(Drop, starknet::Event)]
struct CollectionWhiteListUpdated {
#[key]
collection: ContractAddress,
enabled: bool,
}
60 changes: 60 additions & 0 deletions apps/blockchain/starknet/src/tests/bridge_t.cairo
Original file line number Diff line number Diff line change
@@ -771,6 +771,66 @@ mod tests {
assert!(!bridge.is_white_listed(collection3), "Collection1 should not be whitelisted");
}

#[test]
fn whitelist_collection_update_events() {
let erc721b_contract_class = declare("erc721_bridgeable");

let BRIDGE_ADMIN = starknet::contract_address_const::<'starklane'>();
let BRIDGE_L1 = EthAddress { address: 'starklane_l1' };

let bridge_address = deploy_starklane(BRIDGE_ADMIN, BRIDGE_L1, erc721b_contract_class.class_hash);
let bridge = IStarklaneDispatcher { contract_address: bridge_address };

let collection1 = starknet::contract_address_const::<'collection1'>();
let collection2 = starknet::contract_address_const::<'collection2'>();
let collection3 = starknet::contract_address_const::<'collection3'>();
start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.enable_white_list(true);
stop_prank(CheatTarget::One(bridge_address));

let mut spy = spy_events(SpyOn::One(bridge_address));
start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.white_list_collection(collection1, true);
stop_prank(CheatTarget::One(bridge_address));
spy.assert_emitted(@array![
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection1,
enabled: true,
}
)
)
]);

start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.white_list_collection(collection2, true);
bridge.white_list_collection(collection1, false);
stop_prank(CheatTarget::One(bridge_address));
spy.assert_emitted(@array![
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection2,
enabled: true,
}
)
),
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection1,
enabled: false,
}
)
)
]);

}

#[test]
#[should_panic]
fn deposit_token_not_enabled() {