-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option for renaming a storage varialble path. (#6758)
- Loading branch information
Showing
10 changed files
with
237 additions
and
34 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
47 changes: 47 additions & 0 deletions
47
crates/cairo-lang-starknet/cairo_level_tests/renamed_storage_test.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,47 @@ | ||
use core::starknet::storage::{StoragePointerWriteAccess, StoragePointerReadAccess}; | ||
|
||
#[starknet::storage_node] | ||
struct A { | ||
pub a: felt252, | ||
} | ||
|
||
#[starknet::storage_node] | ||
struct B { | ||
#[rename("a")] | ||
pub b: felt252, | ||
} | ||
|
||
#[starknet::storage_node] | ||
struct AB { | ||
#[flat] | ||
pub a: A, | ||
#[allow(starknet::colliding_storage_paths)] | ||
#[flat] | ||
pub b: B, | ||
} | ||
|
||
#[starknet::contract] | ||
mod contract { | ||
#[storage] | ||
pub struct Storage { | ||
pub a: super::A, | ||
#[allow(starknet::colliding_storage_paths)] | ||
#[rename("a")] | ||
pub b: super::B, | ||
pub ab: super::AB, | ||
} | ||
} | ||
|
||
#[test] | ||
fn rename_test() { | ||
let mut state = contract::contract_state_for_testing(); | ||
state.a.a.write(1); | ||
assert_eq!(state.b.b.read(), 1); | ||
state.b.b.write(2); | ||
assert_eq!(state.a.a.read(), 2); | ||
assert_eq!(state.ab.a.a.read(), 0); | ||
state.ab.a.a.write(3); | ||
assert_eq!(state.ab.b.b.read(), 3); | ||
state.ab.b.b.write(4); | ||
assert_eq!(state.ab.a.a.read(), 4); | ||
} |
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
Oops, something went wrong.