Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/deploy-default-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
SwayStar123 authored Aug 7, 2024
2 parents 809c2c1 + f623b52 commit bd1f0a5
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 43 deletions.
43 changes: 0 additions & 43 deletions sway-lib-std/src/storage/storage_key.sw
Original file line number Diff line number Diff line change
Expand Up @@ -152,46 +152,3 @@ impl<T> StorageKey<T> {
self.slot() == b256::zero() && self.field_id() == b256::zero() && self.offset() == 0
}
}

#[test]
fn test_storage_key_new() {
use ::assert::assert;

let key = StorageKey::<u64>::new(b256::zero(), 0, b256::zero());
assert(key.slot() == b256::zero());
assert(key.offset() == 0);
assert(key.field_id() == b256::zero());

let key = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000001,
1,
0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(
key
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(key.offset() == 1);
assert(
key
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);
}

#[test]
fn test_storage_key_zero() {
use ::assert::assert;

let key = StorageKey::<u64>::zero();
assert(key.is_zero());
assert(key.slot() == b256::zero());
assert(key.offset() == 0);
assert(key.field_id() == b256::zero());

let key = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000001,
1,
0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(!key.is_zero());
}
1 change: 1 addition & 0 deletions test/src/in_language_tests/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"test_programs/output_inline_tests",
"test_programs/result_inline_tests",
"test_programs/revert_inline_tests",
"test_programs/storage_key_inline_tests",
"test_programs/string_inline_tests",
"test_programs/u128_inline_tests",
"test_programs/vec_inline_tests",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "storage_key_inline_tests"

[dependencies]
std = { path = "../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
library;

#[test]
fn storage_key_slot() {
let key_1 = StorageKey::<u64>::new(b256::min(), u64::zero(), b256::zero());
assert(key_1.slot() == b256::min());

let key_2 = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000001,
u64::zero(),
b256::zero(),
);
assert(
key_2
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);

let key_3 = StorageKey::<u64>::new(b256::max(), u64::zero(), b256::zero());
assert(key_3.slot() == b256::max());
}

#[test]
fn storage_key_offset() {
let key_1 = StorageKey::<u64>::new(b256::zero(), u64::min(), b256::zero());
assert(key_1.offset() == u64::min());

let key_2 = StorageKey::<u64>::new(b256::zero(), 1, b256::zero());
assert(key_2.offset() == 1);

let key_3 = StorageKey::<u64>::new(b256::zero(), u64::max(), b256::zero());
assert(key_3.offset() == u64::max());
}

#[test]
fn storage_key_field_id() {
let key_1 = StorageKey::<u64>::new(b256::zero(), u64::zero(), b256::min());
assert(key_1.field_id() == b256::min());

let key_2 = StorageKey::<u64>::new(
b256::zero(),
u64::zero(),
0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(
key_2
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);

let key_3 = StorageKey::<u64>::new(b256::zero(), u64::zero(), b256::max());
assert(key_3.field_id() == b256::max());
}

#[test]
fn storage_key_new() {
let key = StorageKey::<u64>::new(b256::min(), u64::min(), b256::min());
assert(key.slot() == b256::min());
assert(key.offset() == u64::min());
assert(key.field_id() == b256::min());

let key = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000001,
1,
0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(
key
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(key.offset() == 1);
assert(
key
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);

let key = StorageKey::<u64>::new(b256::max(), u64::max(), b256::max());
assert(key.slot() == b256::max());
assert(key.offset() == u64::max());
assert(key.field_id() == b256::max());
}

#[test]
fn storage_key_zero() {
let storage_key = StorageKey::<u64>::zero();
assert(
storage_key
.slot() == 0x0000000000000000000000000000000000000000000000000000000000000000,
);
assert(storage_key.offset() == 0);
assert(
storage_key
.field_id() == 0x0000000000000000000000000000000000000000000000000000000000000000,
);
}

#[test]
fn storage_key_is_zero() {
let zero_storage_key = StorageKey::<u64>::zero();
assert(zero_storage_key.is_zero());

let storage_key_2 = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000001,
0,
0x0000000000000000000000000000000000000000000000000000000000000000,
);
assert(!storage_key_2.is_zero());

let storage_key_3 = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000000,
1,
0x0000000000000000000000000000000000000000000000000000000000000000,
);
assert(!storage_key_3.is_zero());

let storage_key_4 = StorageKey::<u64>::new(
0x0000000000000000000000000000000000000000000000000000000000000000,
0,
0x0000000000000000000000000000000000000000000000000000000000000001,
);
assert(!storage_key_4.is_zero());

let storage_key_5 = StorageKey::<u64>::new(b256::max(), u64::max(), b256::max());
assert(!storage_key_5.is_zero());
}

0 comments on commit bd1f0a5

Please sign in to comment.