-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move MockContractUpgradeable to separate file
Move MockContractUpgradeableV0 and MockContractUpgradeableV1 contracts to new file
- Loading branch information
1 parent
5caaf28
commit fa3286d
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
cairo/kakarot-ssj/crates/contracts/src/test_contracts/mock_contract_upgradeable.cairo
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,102 @@ | ||
use crate::components::upgradeable::{upgradeable_component}; | ||
|
||
use upgradeable_component::{UpgradeableImpl}; | ||
|
||
#[starknet::interface] | ||
pub trait IMockContractUpgradeable<TContractState> { | ||
fn version(self: @TContractState) -> felt252; | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod MockContractUpgradeableV0 { | ||
use crate::components::upgradeable::{upgradeable_component}; | ||
use super::IMockContractUpgradeable; | ||
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); | ||
|
||
#[abi(embed_v0)] | ||
impl UpgradeableImpl = upgradeable_component::Upgradeable<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
upgradeable: upgradeable_component::Storage | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
pub enum Event { | ||
UpgradeableEvent: upgradeable_component::Event | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl MockContractUpgradeableImpl of IMockContractUpgradeable<ContractState> { | ||
fn version(self: @ContractState) -> felt252 { | ||
0 | ||
} | ||
} | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod MockContractUpgradeableV1 { | ||
use crate::components::upgradeable::{upgradeable_component}; | ||
use super::IMockContractUpgradeable; | ||
component!(path: upgradeable_component, storage: upgradeable, event: upgradeableEvent); | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
upgradeable: upgradeable_component::Storage | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
pub enum Event { | ||
upgradeableEvent: upgradeable_component::Event | ||
} | ||
|
||
#[abi(embed_v0)] | ||
impl MockContractUpgradeableImpl of IMockContractUpgradeable<ContractState> { | ||
fn version(self: @ContractState) -> felt252 { | ||
1 | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use core::starknet::syscalls::{deploy_syscall}; | ||
use crate::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait}; | ||
use snforge_std::{declare, DeclareResultTrait}; | ||
use starknet::{ClassHash}; | ||
use super::{IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait}; | ||
|
||
#[test] | ||
fn test_upgradeable_update_contract() { | ||
let mock_contract_upgradeable_v0_class_hash = (*declare("MockContractUpgradeableV0") | ||
.unwrap() | ||
.contract_class() | ||
.class_hash); | ||
let (contract_address, _) = deploy_syscall( | ||
mock_contract_upgradeable_v0_class_hash, 0, [].span(), false | ||
) | ||
.unwrap(); | ||
|
||
let version = IMockContractUpgradeableDispatcher { contract_address: contract_address } | ||
.version(); | ||
|
||
assert(version == 0, 'version is not 0'); | ||
|
||
let mock_contract_upgradeable_v1_class_hash = (*declare("MockContractUpgradeableV1") | ||
.unwrap() | ||
.contract_class() | ||
.class_hash); | ||
let new_class_hash: ClassHash = mock_contract_upgradeable_v1_class_hash; | ||
|
||
IUpgradeableDispatcher { contract_address: contract_address } | ||
.upgrade_contract(new_class_hash); | ||
|
||
let version = IMockContractUpgradeableDispatcher { contract_address: contract_address } | ||
.version(); | ||
assert(version == 1, 'version is not 1'); | ||
} | ||
} |