Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gtest): Improve value and ED managment #4111

Merged
merged 35 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a60dc13
State todos
techraed Aug 1, 2024
5b040b1
Change block execution model
techraed Aug 7, 2024
32ced45
State proper todos
techraed Aug 7, 2024
b23c60a
Fix most of workspace tests
techraed Aug 8, 2024
7d8ac30
Adjust signals test
techraed Aug 9, 2024
389bd45
Merge branch 'master' of github.com:gear-tech/gear into st-block-exec…
techraed Aug 9, 2024
17bcfa2
Fix workspace tests
techraed Aug 9, 2024
aeabdb2
Fix test
techraed Aug 9, 2024
977913e
feat(gtest): Decrease value after message sent
ByteNacked Aug 4, 2024
d42557b
WIP
ByteNacked Aug 11, 2024
aad49be
Update tests
ByteNacked Aug 11, 2024
2b52970
Update test, fix ED charging
ByteNacked Aug 12, 2024
322bd57
Clean up, return send_value on child program creation
ByteNacked Aug 12, 2024
6d8115d
Fix mailbox test
ByteNacked Aug 12, 2024
cd44374
Update cargo-gbuild tests
ByteNacked Aug 12, 2024
1867a54
Fix CI
techraed Aug 12, 2024
9183214
Review fixes
ByteNacked Aug 12, 2024
6eda532
Update gtest doc-comments
ByteNacked Aug 12, 2024
032c74e
Merge branch 'master' of github.com:gear-tech/gear into st-block-exec…
techraed Aug 13, 2024
e684bb4
Merge remote-tracking branch 'origin/st-block-exec-gtest' into rmasl-…
ByteNacked Aug 13, 2024
7ce2a48
Fix tests
ByteNacked Aug 13, 2024
e66c7e7
Fix tests II
ByteNacked Aug 13, 2024
8edf691
Add test and additional check
ByteNacked Aug 13, 2024
3fb0d65
Merge remote-tracking branch 'origin/master' into rmasl-gtest-improve…
ByteNacked Aug 14, 2024
e2594b2
Fix doc-comment
ByteNacked Aug 14, 2024
09e7882
refactor Actors storages
ByteNacked Aug 15, 2024
e32e4ee
Merge remote-tracking branch 'origin/master' into rmasl-gtest-improve…
ByteNacked Aug 15, 2024
fffbe78
Fix fn withdraw_gas params
ByteNacked Aug 15, 2024
26548fc
Update gtest/src/lib.rs
ByteNacked Aug 19, 2024
ccd3104
Review fixes
ByteNacked Aug 19, 2024
6ddf71a
Review fixes II
ByteNacked Aug 19, 2024
9421b16
Merge remote-tracking branch 'origin/master' into rmasl-gtest-improve…
ByteNacked Aug 19, 2024
820cbd1
Fix docs
ByteNacked Aug 19, 2024
8c17db4
Fix docs II
ByteNacked Aug 19, 2024
1317078
Review fixes III
ByteNacked Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/autoreply/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod wasm;
mod tests {
use alloc::vec::Vec;
use gstd::ActorId;
use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};

#[test]
fn auto_reply_received() {
Expand All @@ -45,7 +45,7 @@ mod tests {
let prog1 = Program::current(&system);
let prog1_id = ActorId::try_from(prog1.id().as_ref()).unwrap();

let from = 42;
let from = DEFAULT_USER_ALICE;

// Init Program-1
let init_msg1 = prog1.send(from, ActorId::zero());
Expand Down
6 changes: 3 additions & 3 deletions examples/custom/src/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
use super::{Reply, Request};
use crate::InitMessage;
use alloc::vec;
use gtest::{Log, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Log, Program, System};

#[test]
fn program_can_be_initialized() {
Expand All @@ -103,7 +103,7 @@ mod tests {

let program = Program::current(&system);

let from = 42;
let from = DEFAULT_USER_ALICE;

program.send(from, InitMessage::BTree);
let res = system.run_next_block();
Expand All @@ -118,7 +118,7 @@ mod tests {

let program = Program::current_opt(&system);

let from = 42;
let from = DEFAULT_USER_ALICE;

program.send(from, InitMessage::BTree);
IntoIterator::into_iter([
Expand Down
12 changes: 6 additions & 6 deletions examples/distributor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod wasm;
#[cfg(test)]
mod tests {
use super::{Reply, Request};
use gtest::{Log, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Log, Program, System};

#[test]
fn program_can_be_initialized() {
Expand All @@ -67,7 +67,7 @@ mod tests {

let program = Program::current(&system);

let from = 42;
let from = DEFAULT_USER_ALICE;

program.send_bytes(from, b"init");
let res = system.run_next_block();
Expand All @@ -82,7 +82,7 @@ mod tests {

let program = Program::current(&system);

let from = 42;
let from = DEFAULT_USER_ALICE;

// Init
program.send_bytes(from, b"init");
Expand Down Expand Up @@ -112,7 +112,7 @@ mod tests {
) -> (Program, Program, Program) {
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program_1 = Program::current_with_id(system, program_1_id);
program_1.send_bytes(from, b"init");
Expand Down Expand Up @@ -147,7 +147,7 @@ mod tests {
let system = System::new();
let (program_1, program_2, _program_3) = multi_program_setup(&system, 1, 2, 3);

let from = 42;
let from = DEFAULT_USER_ALICE;

program_1.send(from, Request::Receive(11));
let res = system.run_next_block();
Expand Down Expand Up @@ -181,7 +181,7 @@ mod tests {
let (program_1, _program_2, _program_3) = multi_program_setup(&system, 1, 2, 3);

let program_4_id = 4;
let from = 42;
let from = DEFAULT_USER_ALICE;

let program_4 = Program::current_with_id(&system, program_4_id);
program_4.send_bytes(from, b"init");
Expand Down
4 changes: 2 additions & 2 deletions examples/gas-burned/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ mod wasm;

#[cfg(test)]
mod tests {
use gtest::{Gas, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Gas, Program, System};

#[test]
fn gas_burned() {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program = Program::current(&system);
let init_msg_id = program.send_bytes(from, "init");
Expand Down
5 changes: 2 additions & 3 deletions examples/new-meta/tests/read_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use demo_new_meta::{
MessageInitIn, Person, Wallet, META_EXPORTS_V1, META_EXPORTS_V2, META_WASM_V1, META_WASM_V2,
};
use gstd::Encode;
use gtest::{state_args, state_args_encoded, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, state_args, state_args_encoded, Program, System};

#[test]
fn read_state_bytes_returns_full_state() {
Expand Down Expand Up @@ -183,10 +183,9 @@ fn read_state_with_two_args_wasm_func_returns_transformed_state() {
}

fn initialize_current_program(system: &System) -> Program {
const SOME_USER_ID: u64 = 3;
let program = Program::current(system);
program.send(
SOME_USER_ID,
DEFAULT_USER_ALICE,
MessageInitIn {
amount: 123,
currency: "USD".into(),
Expand Down
10 changes: 5 additions & 5 deletions examples/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ mod wasm;
#[cfg(test)]
mod tests {
use super::{Initialization, Operation, Reply, Request};
use gtest::{Log, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Log, Program, System};

#[test]
fn test_message_send_to_failed_program() {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program = Program::current(&system);
let msg_id = program.send(from, Request::IsReady);
Expand All @@ -81,7 +81,7 @@ mod tests {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program = Program::current(&system);
let msg_id = program.send(from, Initialization { status: 5 });
Expand All @@ -96,7 +96,7 @@ mod tests {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program = Program::current(&system);
program.send(from, Initialization { status: 5 });
Expand Down Expand Up @@ -131,7 +131,7 @@ mod tests {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program_1_id = 1;
let program_2_id = 2;
Expand Down
18 changes: 11 additions & 7 deletions examples/program-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ mod tests {
extern crate std;

use super::*;
use gtest::{calculate_program_id, constants::UNITS, Program, System};
use gtest::{
calculate_program_id,
constants::{DEFAULT_USER_ALICE, UNITS},
Program, System,
};
use std::io::Write;

// Creates a new factory and initializes it.
Expand All @@ -67,7 +71,7 @@ mod tests {
// Instantiate factory
let factory = Program::current_with_id(sys, 100);

let user_id = 10001;
let user_id = DEFAULT_USER_ALICE;
sys.mint_to(user_id, 100 * UNITS);

// Send init msg to factory
Expand Down Expand Up @@ -98,7 +102,7 @@ mod tests {
let factory = prepare_factory(&sys);

// Send handle msg to factory to create a new child
let msg_id = factory.send_bytes(10001, CreateProgram::Default.encode());
let msg_id = factory.send_bytes(DEFAULT_USER_ALICE, CreateProgram::Default.encode());
let res = sys.run_next_block();
let child_id_expected =
calculate_program_id(CHILD_CODE_HASH.into(), &0i32.to_le_bytes(), Some(msg_id));
Expand All @@ -116,7 +120,7 @@ mod tests {
let payload = CreateProgram::Custom(vec![(CHILD_CODE_HASH, salt.to_vec(), 100_000_000)]);

// Send handle msg to factory to create a new child
let msg_id = factory.send_bytes(10001, payload.encode());
let msg_id = factory.send_bytes(DEFAULT_USER_ALICE, payload.encode());
let res = sys.run_next_block();

let child_id_expected = calculate_program_id(CHILD_CODE_HASH.into(), &salt, Some(msg_id));
Expand All @@ -125,7 +129,7 @@ mod tests {
assert!(sys.is_active_program(child_id_expected));

// Send handle msg to create a duplicate
let msg_id = factory.send_bytes(10001, payload.encode());
let msg_id = factory.send_bytes(DEFAULT_USER_ALICE, payload.encode());
let res = sys.run_next_block();

let child_id_expected = calculate_program_id(CHILD_CODE_HASH.into(), &salt, Some(msg_id));
Expand All @@ -146,7 +150,7 @@ mod tests {
let non_existing_code_hash = [10u8; 32];
let salt = b"some_salt";
let payload = CreateProgram::Custom(vec![(non_existing_code_hash, salt.to_vec(), 100_000)]);
let msg_id = factory.send_bytes(10001, payload.encode());
let msg_id = factory.send_bytes(DEFAULT_USER_ALICE, payload.encode());
let res = sys.run_next_block();
let fictional_program_id =
calculate_program_id(non_existing_code_hash.into(), salt, Some(msg_id));
Expand All @@ -171,7 +175,7 @@ mod tests {
b"some_salt".to_vec(),
100_000,
)]);
factory.send_bytes(10001, payload.encode());
factory.send_bytes(DEFAULT_USER_ALICE, payload.encode());
let _ = sys.run_next_block();
}
}
4 changes: 2 additions & 2 deletions examples/reserve-gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod wasm;
mod tests {
use crate::InitAction;
use alloc::vec;
use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};

#[test]
fn program_can_be_initialized() {
Expand All @@ -79,7 +79,7 @@ mod tests {
let program = Program::current(&system);

let msg_id = program.send(
0,
DEFAULT_USER_ALICE,
InitAction::Normal(vec![
// orphan reservation; will be removed automatically
(50_000, 3),
Expand Down
4 changes: 2 additions & 2 deletions examples/signal-entry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ mod wasm;
#[cfg(test)]
mod tests {
use crate::HandleAction;
use gtest::{Log, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Log, Program, System};

#[test]
fn signal_can_be_sent() {
let system = System::new();
system.init_logger();

let user_id = 42;
let user_id = DEFAULT_USER_ALICE;
let program = Program::current(&system);

// Initialize program
Expand Down
4 changes: 2 additions & 2 deletions examples/stack-allocations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod wasm;
#[cfg(test)]
mod tests {
use super::*;
use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};
use parity_scale_codec::Decode;
use rand::{Rng, SeedableRng};

Expand All @@ -84,7 +84,7 @@ mod tests {
assert!(MAX_ACTIONS_AMOUNT * HANDLE_DATA_SIZE <= 64 * 1024 * 10);
}

let from = 42;
let from = DEFAULT_USER_ALICE;
let system = System::new();
system.init_logger();

Expand Down
4 changes: 2 additions & 2 deletions examples/syscall-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod wasm;
mod tests {
extern crate std;

use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};

#[test]
fn program_can_be_initialized() {
Expand All @@ -42,7 +42,7 @@ mod tests {

let program = Program::current(&system);

let msg_id = program.send_bytes(0, b"dummy");
let msg_id = program.send_bytes(DEFAULT_USER_ALICE, b"dummy");
let res = system.run_next_block();
assert!(res.succeed.contains(&msg_id));
}
Expand Down
8 changes: 4 additions & 4 deletions examples/wait_wake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mod tests {
extern crate std;

use super::Request;
use gtest::{Log, Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Log, Program, System};

#[test]
fn program_can_be_initialized() {
Expand All @@ -51,7 +51,7 @@ mod tests {

let program = Program::current(&system);

let from = 42;
let from = DEFAULT_USER_ALICE;

program.send_bytes(from, b"init");
let res = system.run_next_block();
Expand All @@ -64,7 +64,7 @@ mod tests {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program = Program::current(&system);
program.send_bytes(from, b"init");
Expand Down Expand Up @@ -102,7 +102,7 @@ mod tests {
let system = System::new();
system.init_logger();

let from = 42;
let from = DEFAULT_USER_ALICE;

let program_1 = Program::current(&system);
program_1.send_bytes(from, b"init");
Expand Down
4 changes: 2 additions & 2 deletions examples/waiter/tests/mx_lock_access.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use demo_waiter::{Command, LockContinuation, LockStaticAccessSubcommand, MxLockContinuation};
use gear_core::ids::MessageId;
use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};

pub const USER_ID: u64 = 10;
pub const USER_ID: u64 = DEFAULT_USER_ALICE;

#[test]
fn drop_mx_lock_guard_from_different_msg_fails() {
Expand Down
4 changes: 2 additions & 2 deletions examples/waiter/tests/rw_lock_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use demo_waiter::{
Command, LockContinuation, LockStaticAccessSubcommand, RwLockContinuation, RwLockType,
};
use gear_core::ids::MessageId;
use gtest::{Program, System};
use gtest::{constants::DEFAULT_USER_ALICE, Program, System};

pub const USER_ID: u64 = 10;
pub const USER_ID: u64 = DEFAULT_USER_ALICE;

#[test]
fn drop_r_lock_guard_from_different_msg_fails() {
Expand Down
Loading
Loading