Skip to content

Commit

Permalink
Fixed implementation of Option and Result Store.
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi committed Jun 10, 2024
1 parent 2203a47 commit 1ff9f6b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 7 additions & 7 deletions corelib/src/starknet/storage_access.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,12 @@ impl ResultStore<T, E, +Store<T>, +Store<E>, +Drop<T>, +Drop<E>> of Store<Result
) -> SyscallResult<()> {
match value {
Result::Ok(x) => {
Store::write(address_domain, base, 0)?;
Store::write_at_offset(address_domain, base, 1_u8, x)?;
Store::write_at_offset(address_domain, base, offset, 0)?;
Store::write_at_offset(address_domain, base, offset + 1_u8, x)?;
},
Result::Err(x) => {
Store::write(address_domain, base, 1)?;
Store::write_at_offset(address_domain, base, 1_u8, x)?;
Store::write_at_offset(address_domain, base, offset, 0)?;
Store::write_at_offset(address_domain, base, offset + 1_u8, x)?;
}
};
starknet::SyscallResult::Ok(())
Expand Down Expand Up @@ -649,10 +649,10 @@ impl OptionStore<T, +Store<T>, +Drop<T>,> of Store<Option<T>> {
) -> SyscallResult<()> {
match value {
Option::Some(x) => {
Store::write(address_domain, base, 1)?;
Store::write_at_offset(address_domain, base, 1_u8, x)?;
Store::write_at_offset(address_domain, base, offset, 1)?;
Store::write_at_offset(address_domain, base, offset + 1_u8, x)?;
},
Option::None(_x) => { Store::write(address_domain, base, 0)?; }
Option::None(_x) => { Store::write_at_offset(address_domain, base, offset, 0)?; }
};
starknet::SyscallResult::Ok(())
}
Expand Down
9 changes: 9 additions & 0 deletions tests/bug_samples/issue5764.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use core::starknet::SyscallResultTrait;

#[test]
fn test_store_opt_and_result_at_offset() {
let base = starknet::storage_access::storage_base_address_const::<1000>();
let v = (Option::Some(1_u256), Result::<_, u128>::Ok(2_u8), Option::Some(3_u64));
starknet::Store::write(0, base, v).unwrap_syscall();
assert_eq!(starknet::Store::read(0, base), Result::Ok(v));
}
1 change: 1 addition & 0 deletions tests/bug_samples/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod issue4318;
mod issue4380;
mod issue4897;
mod issue4937;
mod issue5764;
mod loop_break_in_match;
mod loop_only_change;
mod partial_param_local;
Expand Down

0 comments on commit 1ff9f6b

Please sign in to comment.