Skip to content

Commit

Permalink
fixing rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Oct 11, 2023
1 parent 2b13716 commit 3c12320
Show file tree
Hide file tree
Showing 34 changed files with 614 additions and 284 deletions.
64 changes: 32 additions & 32 deletions ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@
# `cargo install cargo-generate`
# `cargo install cargo-udeps`

cargo clippy --all-features --all-targets -- -D warnings
cargo sort -w --check
cargo sort -w --check templates/sway-test-rs/template
cargo fmt --all -- --check
cargo build --locked --workspace --all-features --all-targets
cargo test --locked
cargo +nightly udeps --locked --all-targets
cargo install --locked --debug --path ./forc
cargo install --locked --debug --path ./forc-plugins/forc-fmt
cargo install --locked --debug --path ./forc-plugins/forc-lsp
cargo install --locked --debug --path ./forc-plugins/forc-client
cargo install --locked --debug --path ./forc-plugins/forc-tx
cargo install --locked --debug forc-explore
cargo install --locked --debug --path ./scripts/mdbook-forc-documenter
forc build --path sway-lib-core
forc test --path sway-lib-core
forc build --path sway-lib-std
forc test --path sway-lib-std
cargo run --locked -p forc -- build --locked --path ./examples/Forc.toml
cargo run --locked -p forc-fmt -- --check --path ./examples
cargo run --locked -p forc -- build --path ./docs/reference/src/code/Forc.toml
rm -Rf test-proj
forc new test-proj
echo "std = { path = \"../sway-lib-std/\" }" >> test-proj/Forc.toml
forc build --path test-proj
(cd test-proj cargo generate --init --path ../templates/sway-test-rs --name test-proj)
echo "[workspace]" >> test-proj/Cargo.toml
(cd test-proj cargo test)
rm -R test-proj
cargo run --locked --release --bin test -- --target evm --locked
cargo run --locked -p forc -- build --locked --path ./test/src/sdk-harness
cargo test --locked --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture
cargo clippy --all-features --all-targets -- -D warnings &&
cargo sort -w --check &&
cargo sort -w --check templates/sway-test-rs/template &&
cargo fmt --all -- --check &&
cargo build --locked --workspace --all-features --all-targets &&
cargo test --locked &&
cargo +nightly udeps --locked --all-targets &&
cargo install --locked --debug --path ./forc &&
cargo install --locked --debug --path ./forc-plugins/forc-fmt &&
cargo install --locked --debug --path ./forc-plugins/forc-lsp &&
cargo install --locked --debug --path ./forc-plugins/forc-client &&
cargo install --locked --debug --path ./forc-plugins/forc-tx &&
cargo install --locked --debug forc-explore &&
cargo install --locked --debug --path ./scripts/mdbook-forc-documenter &&
forc build --path sway-lib-core &&
forc test --path sway-lib-core &&
forc build --path sway-lib-std &&
forc test --path sway-lib-std &&
cargo run --locked -p forc -- build --locked --path ./examples/Forc.toml &&
cargo run --locked -p forc-fmt -- --check --path ./examples &&
cargo run --locked -p forc -- build --path ./docs/reference/src/code/Forc.toml &&
rm -Rf test-proj &&
forc new test-proj &&
echo "std = { path = \"../sway-lib-std/\" }" >> test-proj/Forc.toml &&
forc build --path test-proj &&
(cd test-proj && cargo generate --init --path ../templates/sway-test-rs --name test-proj) &&
echo "[workspace]" >> test-proj/Cargo.toml &&
(cd test-proj && cargo test) &&
rm -R test-proj &&
cargo run --locked --release --bin test -- --target evm --locked &&
cargo run --locked -p forc -- build --locked --path ./test/src/sdk-harness &&
cargo test --locked --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture &&
cargo run --locked --release --bin test -- --locked
10 changes: 0 additions & 10 deletions sway-lib-std/src/storage/storage_api.sw
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,11 @@ pub fn write<T>(slot: b256, offset: u64, value: T) {
let padded_value = alloc::<u64>(number_of_slots * 32);

// Read the values that currently exist in the affected storage slots.
use ::logging::*;
log(88888888888888);
log(offset_slot);
log(number_of_slots);
let _ = __state_load_quad(offset_slot, padded_value, number_of_slots);

log(place_in_slot);
log(value);

// Copy the value to be stored to `padded_value + offset`.
padded_value.add::<u64>(place_in_slot).write::<T>(value);


log(9999999999999);

// Now store back the data at `padded_value` which now contains the old data but partially
// overwritten by the new data in the desired locations.
let _ = __state_store_quad(offset_slot, padded_value, number_of_slots);
Expand Down
3 changes: 0 additions & 3 deletions sway-lib-std/src/storage/storage_key.sw
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ impl<T> StorageKey<T> {
/// ```
#[storage(read, write)]
pub fn write(self, value: T) {
use ::logging::*;
log(444444444444444);
log(value);
write(self.slot, self.offset, value);
}

Expand Down
5 changes: 4 additions & 1 deletion sway-lib-std/src/storage/storage_vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,9 @@ impl<V> StorageKey<StorageVec<V>> {
}
}

// Add padding to type so it can correctly use the storage api
fn offset_calculator<T>(offset: u64) -> u64 {
(offset * __size_of::<T>()) / 8
let size_in_bytes = __size_of::<T>();
let size_in_bytes = (size_in_bytes + (8 - 1)) - ((size_in_bytes + (8 - 1)) % 8);
(offset * size_in_bytes) / 8
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,192 @@ fn main() -> bool {
let contract_id = 0xfed45169b58cbba43b6d63c325aa6275113ce44ca5a890aff7991c3d02baf6ab;
let caller = abi(StorageAccess, contract_id);

// Test initializers
assert(caller.get_x() == 64);
assert(caller.get_y() == 0x0101010101010101010101010101010101010101010101010101010101010101);
assert(caller.get_boolean() == true);
assert(caller.get_int8() == 8);
assert(caller.get_int16() == 16);
assert(caller.get_int32() == 32);
let s = caller.get_s();
assert(s.x == 1);
assert(s.y == 2);
assert(s.z == 0x0000000000000000000000000000000000000000000000000000000000000003);
assert(s.t.x == 4);
assert(s.t.y == 5);
assert(s.t.z == 0x0000000000000000000000000000000000000000000000000000000000000006);
assert(s.t.boolean == true);
assert(s.t.int8 == 7);
assert(s.t.int16 == 8);
assert(s.t.int32 == 9);
let e = caller.get_e();
match e {
E::B(t) => {
assert(t.x == 1);
assert(t.y == 2);
assert(t.z == 0x0000000000000000000000000000000000000000000000000000000000000003);
assert(t.boolean == true);
assert(t.int8 == 4);
assert(t.int16 == 5);
assert(t.int32 == 6);
}
_ => {
revert(0)
}
}
let e2 = caller.get_e2();
match e2 {
E::A(val) => {
assert(val == 777);
}
_ => {
revert(0)
}
}
assert(sha256_str_array(caller.get_string()) == sha256("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));

// Test 1
caller.set_x(1);
assert(caller.get_x() == 1);

// Test 2
caller.set_y(0x0000000000000000000000000000000000000000000000000000000000000001);
assert(caller.get_y() == 0x0000000000000000000000000000000000000000000000000000000000000001);

// Test 3
let s = S {
x: 3,
y: 4,
z: 0x0000000000000000000000000000000000000000000000000000000000000002,
t: T {
x: 5,
y: 6,
z: 0x0000000000000000000000000000000000000000000000000000000000000003,
boolean: true,
int8: 88,
int16: 1616,
int32: 3232,
},
};
caller.set_s(s);
assert(caller.get_s_dot_x() == 3);
assert(caller.get_s_dot_y() == 4);
assert(caller.get_s_dot_z() == 0x0000000000000000000000000000000000000000000000000000000000000002);
assert(caller.get_s_dot_t_dot_x() == 5);
assert(caller.get_s_dot_t_dot_y() == 6);
assert(caller.get_s_dot_t_dot_z() == 0x0000000000000000000000000000000000000000000000000000000000000003);

caller.set_boolean(true);
assert(caller.get_boolean() == true);
caller.set_boolean(false);
assert(caller.get_boolean() == false);
caller.set_int8(8u8);
assert(caller.get_int8() == 8u8);
caller.set_int16(16u16);
assert(caller.get_int16() == 16u16);
caller.set_int32(32u32);
assert(caller.get_int32() == 32u32);

// Test 4
let t = T {
x: 7,
y: 8,
z: 0x0000000000000000000000000000000000000000000000000000000000000004,
boolean: true,
int8: 222u8,
int16: 1616u16,
int32: 323232u32,
};
caller.set_s_dot_t(t);
assert(caller.get_s_dot_t_dot_x() == 7);
assert(caller.get_s_dot_t_dot_y() == 8);
assert(caller.get_s_dot_t_dot_z() == 0x0000000000000000000000000000000000000000000000000000000000000004);
assert(caller.get_s_dot_t_dot_boolean() == true);
assert(caller.get_s_dot_t_dot_int8() == 222u8);
assert(caller.get_s_dot_t_dot_int16() == 1616u16);
assert(caller.get_s_dot_t_dot_int32() == 323232u32);

// Test 5
caller.set_s_dot_x(9);
assert(caller.get_s_dot_x() == 9);

// Test 6
caller.set_s_dot_y(10);
assert(caller.get_s_dot_y() == 10);

// Test 7
caller.set_s_dot_z(0x0000000000000000000000000000000000000000000000000000000000000005);
assert(caller.get_s_dot_z() == 0x0000000000000000000000000000000000000000000000000000000000000005);

// Test 8
caller.set_s_dot_t_dot_x(11);
assert(caller.get_s_dot_t_dot_x() == 11);

// Test 9
caller.set_s_dot_t_dot_y(12);
assert(caller.get_s_dot_t_dot_y() == 12);

// Test 10
caller.set_s_dot_t_dot_z(0x0000000000000000000000000000000000000000000000000000000000000006);
assert(caller.get_s_dot_t_dot_z() == 0x0000000000000000000000000000000000000000000000000000000000000006);

caller.set_s_dot_t_dot_boolean(true);
assert(caller.get_s_dot_t_dot_boolean() == true);

caller.set_s_dot_t_dot_int8(22u8);
assert(caller.get_s_dot_t_dot_int8() == 22u8);

caller.set_s_dot_t_dot_int16(33u16);
assert(caller.get_s_dot_t_dot_int16() == 33u16);

caller.set_s_dot_t_dot_int32(44u32);
assert(caller.get_s_dot_t_dot_int32() == 44u32);

// Test 11
let s = caller.get_s();
assert(s.x == 9);
assert(s.y == 10);
assert(s.z == 0x0000000000000000000000000000000000000000000000000000000000000005);
assert(s.t.x == 11);
assert(s.t.y == 12);
assert(s.t.z == 0x0000000000000000000000000000000000000000000000000000000000000006);

// Test 12
let t = caller.get_s_dot_t();
assert(t.x == 11);
assert(t.y == 12);
assert(t.z == 0x0000000000000000000000000000000000000000000000000000000000000006);

// Test 13
caller.set_e(E::A(42));
let e = caller.get_e();
match e {
E::A(val) => assert(val == 42), _ => {
revert(0)
}
}

caller.set_e(E::B(t));
let e = caller.get_e();
match e {
E::B(val) => {
assert(val.x == t.x);
assert(val.y == t.y);
assert(val.z == t.z);
assert(val.boolean == t.boolean);
assert(val.int8 == t.int8);
assert(val.int16 == t.int16);
assert(val.int32 == t.int32);
}
_ => {
revert(0)
}
};

caller.set_string(__to_str_array("fuelfuelfuelfuelfuelfuelfuelfuelfuelfuel"));

// Can't compare strings right now so compare hashes instead
assert(sha256_str_array(caller.get_string()) == sha256("fuelfuelfuelfuelfuelfuelfuelfuelfuelfuel"));

true
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ impl StorageAccess for Contract {
storage.s.write(s);
}
#[storage(write)]fn set_boolean(boolean: bool) {
use std::logging::*;
log(3333333333333333);
log(boolean);
storage.boolean.write(boolean);
}
#[storage(write)]fn set_int8(int8: u8) {
Expand Down
7 changes: 7 additions & 0 deletions test/src/sdk-harness/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/src/sdk-harness/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ path = "test_projects/harness.rs"

[workspace]

[patch."https://github.com/FuelLabs/fuels-rs.git"]
fuels = { path = "/home/xunilrj/github/fuels-rs/packages/fuels" }
#[patch."https://github.com/FuelLabs/fuels-rs.git"]
#fuels = { path = "/home/xunilrj/github/fuels-rs/packages/fuels" }
2 changes: 0 additions & 2 deletions test/src/sdk-harness/test_artifacts/pow/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ impl PowTest for Contract {
}

fn u8_overflow(a: u8, b: u8) -> u8 {
log(a);
log(b);
a.pow(b)
}
}
2 changes: 1 addition & 1 deletion test/src/sdk-harness/test_projects/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn msg_sender_from_contract() {
let result = caller_instance
.methods()
.call_auth_contract(auth_id, caller_id)
.set_contracts(&[&auth_instance])
.with_contracts(&[&auth_instance])
.call()
.await
.unwrap();
Expand Down
Loading

0 comments on commit 3c12320

Please sign in to comment.