Skip to content

Commit

Permalink
fix: resolve infinite loop in _white_list_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
JoE11-y committed Sep 30, 2024
1 parent fed93cb commit 93e9eac
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/blockchain/starknet/src/bridge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ mod bridge {
self.white_listed_list.write(prev, (active, target));
break;
}
prev = next;
};
self.white_listed_list.write(collection, (false, no_value));
}
Expand Down
96 changes: 96 additions & 0 deletions apps/blockchain/starknet/src/tests/bridge_t.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,102 @@ mod tests {

}

#[test]
fn admin_remove_whitelist_correctly() {
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'>();
let collection4 = starknet::contract_address_const::<'collection4'>();
let collection5 = starknet::contract_address_const::<'collection5'>();
start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.enable_white_list(true);
stop_prank(CheatTarget::One(bridge_address));

/// add whitelists
let mut spy = spy_events(SpyOn::One(bridge_address));
start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.white_list_collection(collection1, true);
bridge.white_list_collection(collection2, true);
bridge.white_list_collection(collection3, true);
bridge.white_list_collection(collection4, true);
bridge.white_list_collection(collection5, true);
stop_prank(CheatTarget::One(bridge_address));

spy.assert_emitted(@array![
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection1,
enabled: true,
}
)
),
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection2,
enabled: true,
}
)
),
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection3,
enabled: true,
}
)
),
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection4,
enabled: true,
}
)
),
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection5,
enabled: true,
}
)
)
]);

// now try to remove from whitelist collection 3.
// this tests the loop
start_prank(CheatTarget::One(bridge_address), BRIDGE_ADMIN);
bridge.white_list_collection(collection3, false);
stop_prank(CheatTarget::One(bridge_address));

spy.assert_emitted(@array![
(
bridge_address,
bridge::Event::CollectionWhiteListUpdated(
bridge::CollectionWhiteListUpdated {
collection: collection3,
enabled: false,
}
)
),
]);
}

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

0 comments on commit 93e9eac

Please sign in to comment.