Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 15 additions & 18 deletions packages/utils/src/components/replaceability/replaceability.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ pub(crate) mod ReplaceabilityComponent {
fn replace_to(
ref self: ComponentState<TContractState>, implementation_data: ImplementationData,
) {
// The call is restricted to the upgrade governor.
// The call is restricted to the upgrade agent or upgrade governor.
let roles_comp = get_dep_component!(@self, Roles);
roles_comp.only_upgrade_governor();
roles_comp.only_upgrader();

// Validate implementation is not finalized.
assert!(!self.is_finalized(), "{}", ReplaceErrors::FINALIZED);
Expand All @@ -136,22 +136,19 @@ pub(crate) mod ReplaceabilityComponent {
}

// Handle EIC.
match implementation_data.eic_data {
Option::Some(eic_data) => {
// Wrap the calldata as a span, as preparation for the library_call_syscall
// invocation.
let mut calldata_wrapper = ArrayTrait::new();
eic_data.eic_init_data.serialize(ref calldata_wrapper);

// Invoke the EIC's initialize function as a library call.
let res = library_call_syscall(
class_hash: eic_data.eic_hash,
function_selector: EIC_INITIALIZE_SELECTOR,
calldata: calldata_wrapper.span(),
);
assert!(res.is_ok(), "{}", ReplaceErrors::EIC_LIB_CALL_FAILED);
},
Option::None(()) => {},
if let Option::Some(eic_data) = implementation_data.eic_data {
// Wrap the calldata as a span, as preparation for the library_call_syscall
// invocation.
let mut calldata_wrapper = ArrayTrait::new();
eic_data.eic_init_data.serialize(ref calldata_wrapper);

// Invoke the EIC's initialize function as a library call.
let res = library_call_syscall(
class_hash: eic_data.eic_hash,
function_selector: EIC_INITIALIZE_SELECTOR,
calldata: calldata_wrapper.span(),
);
assert!(res.is_ok(), "{}", ReplaceErrors::EIC_LIB_CALL_FAILED);
}

// Replace the class hash.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/components/replaceability/test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ mod ReplaceabilityTests {
}

#[test]
#[should_panic(expected: "ONLY_UPGRADE_GOVERNOR")]
#[should_panic(expected: "ONLY_UPGRADER")]
fn test_replace_to_not_upgrade_governor() {
let replaceable_dispatcher = deploy_replaceability_mock();
let contract_address = replaceable_dispatcher.contract_address;
Expand Down