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

chore(gtest): Resolve multiple small issues in gtest #4232

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 25 additions & 2 deletions gtest/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ impl<T: Codec + Debug> DecodedCoreLog<T> {
reply_to: log.reply_to,
})
}

pub fn id(&self) -> MessageId {
self.id
}

pub fn source(&self) -> ProgramId {
self.source
}

pub fn destination(&self) -> ProgramId {
self.destination
}

pub fn payload(&self) -> &T {
&self.payload
}

pub fn reply_code(&self) -> Option<ReplyCode> {
self.reply_code
}

pub fn reply_to(&self) -> Option<MessageId> {
self.reply_to
}
}

/// A log that can be emitted by a program.
Expand Down Expand Up @@ -395,8 +419,7 @@ pub struct BlockRunResult {
/// Total messages processed during the current
/// execution.
pub total_processed: u32,
// TODO #4122
/// Logs created during the current execution.
/// User message logs (events) created during the current execution.
pub log: Vec<CoreLog>,
/// Mapping gas burned for each message during
/// the current block execution.
Expand Down
2 changes: 0 additions & 2 deletions gtest/src/manager/block_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ impl ExtManager {
message_id
}

// TODO #4120 Charge for task pool processing the gas from gas allowance
// TODO #4121
pub(crate) fn run_new_block(&mut self, allowance: Gas) -> BlockRunResult {
self.gas_allowance = allowance;
self.blocks_manager.next_block();
Expand Down
4 changes: 3 additions & 1 deletion gtest/src/manager/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ impl TaskHandler<ProgramId> for ExtManager {
.unwrap_or_else(|e| unreachable!("GasTree corrupted: {e:?}"));
self.dispatches.push_back(trap_dispatch);
} else {
// TODO #4122
let trap_message =
trap_reply.into_stored(program_id, waitlisted.source(), message_id);
self.log.push(trap_message);
}
}

Expand Down
20 changes: 19 additions & 1 deletion gtest/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ mod tests {
}

#[test]
fn test_handle_messages_to_failing_program() {
fn test_queued_message_to_failed_program() {
let sys = System::new();
sys.init_logger();

Expand All @@ -933,6 +933,24 @@ mod tests {
assert!(res.contains(&expected_log));
}

#[test]
#[should_panic]
fn test_new_message_to_failed_program() {
let sys = System::new();
sys.init_logger();

let user_id = DEFAULT_USER_ALICE;

let prog = Program::from_binary_with_id(&sys, 137, demo_futures_unordered::WASM_BINARY);

let init_msg_payload = String::from("InvalidInput");
let failed_mid = prog.send(user_id, init_msg_payload);
let res = sys.run_next_block();
res.assert_panicked_with(failed_mid, "Failed to load destination: Decode(Error)");

let _panic = prog.send_bytes(user_id, b"");
}

#[test]
fn simple_balance() {
let sys = System::new();
Expand Down
Loading