Skip to content

Commit

Permalink
chore(gtest): Resolve multiple small issues in gtest (#4232)
Browse files Browse the repository at this point in the history
  • Loading branch information
techraed authored Sep 13, 2024
1 parent 9eb13db commit a5fa004
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
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

0 comments on commit a5fa004

Please sign in to comment.