forked from OpenZeppelin/cairo-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Upgrades to component (OpenZeppelin#792)
* fix: link (OpenZeppelin#545) * feat: update logic to component * feat: update docs * feat: apply review updates * feat: fix pop_log util to check no extra keys as well * docs: flatten events in examples
- Loading branch information
1 parent
28a1ee7
commit 6269c5d
Showing
20 changed files
with
220 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// These contracts are mocks used to test the core functionality of the upgrade functions. | ||
// The functions are NOT PROTECTED. | ||
// DO NOT USE IN PRODUCTION. | ||
|
||
use starknet::ClassHash; | ||
|
||
#[starknet::interface] | ||
trait IUpgradesV1<TState> { | ||
fn upgrade(ref self: TState, new_class_hash: ClassHash); | ||
fn set_value(ref self: TState, val: felt252); | ||
fn get_value(self: @TState) -> felt252; | ||
fn remove_selector(self: @TState); | ||
} | ||
|
||
trait UpgradesV1Trait<TState> { | ||
fn set_value(ref self: TState, val: felt252); | ||
fn get_value(self: @TState) -> felt252; | ||
fn remove_selector(self: @TState); | ||
} | ||
|
||
#[starknet::contract] | ||
mod UpgradesV1 { | ||
use openzeppelin::upgrades::Upgradeable as upgradeable_component; | ||
use starknet::ClassHash; | ||
use starknet::ContractAddress; | ||
|
||
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); | ||
|
||
impl InternalImpl = upgradeable_component::InternalImpl<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
upgradeable: upgradeable_component::Storage, | ||
value: felt252 | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
UpgradeableEvent: upgradeable_component::Event | ||
} | ||
|
||
#[external(v0)] | ||
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { | ||
self.upgradeable._upgrade(new_class_hash); | ||
} | ||
|
||
#[external(v0)] | ||
impl UpgradesV1Impl of super::UpgradesV1Trait<ContractState> { | ||
fn set_value(ref self: ContractState, val: felt252) { | ||
self.value.write(val); | ||
} | ||
|
||
fn get_value(self: @ContractState) -> felt252 { | ||
self.value.read() | ||
} | ||
|
||
fn remove_selector(self: @ContractState) {} | ||
} | ||
} | ||
|
||
#[starknet::interface] | ||
trait IUpgradesV2<TState> { | ||
fn upgrade(ref self: TState, new_class_hash: ClassHash); | ||
fn set_value(ref self: TState, val: felt252); | ||
fn set_value2(ref self: TState, val: felt252); | ||
fn get_value(self: @TState) -> felt252; | ||
fn get_value2(self: @TState) -> felt252; | ||
} | ||
|
||
trait UpgradesV2Trait<TState> { | ||
fn set_value(ref self: TState, val: felt252); | ||
fn set_value2(ref self: TState, val: felt252); | ||
fn get_value(self: @TState) -> felt252; | ||
fn get_value2(self: @TState) -> felt252; | ||
} | ||
|
||
#[starknet::contract] | ||
mod UpgradesV2 { | ||
use openzeppelin::upgrades::Upgradeable as upgradeable_component; | ||
use starknet::ClassHash; | ||
use starknet::ContractAddress; | ||
|
||
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); | ||
|
||
impl InternalImpl = upgradeable_component::InternalImpl<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
upgradeable: upgradeable_component::Storage, | ||
value: felt252, | ||
value2: felt252 | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
UpgradeableEvent: upgradeable_component::Event | ||
} | ||
|
||
#[external(v0)] | ||
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { | ||
self.upgradeable._upgrade(new_class_hash); | ||
} | ||
|
||
#[external(v0)] | ||
impl UpgradesV2Impl of super::UpgradesV2Trait<ContractState> { | ||
fn set_value(ref self: ContractState, val: felt252) { | ||
self.value.write(val); | ||
} | ||
|
||
fn set_value2(ref self: ContractState, val: felt252) { | ||
self.value2.write(val); | ||
} | ||
|
||
fn get_value(self: @ContractState) -> felt252 { | ||
self.value.read() | ||
} | ||
|
||
fn get_value2(self: @ContractState) -> felt252 { | ||
self.value2.read() | ||
} | ||
} | ||
} |
Oops, something went wrong.