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

Retain events #390

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions contract-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased changes

## 4.1.0

- Fix a bug in debug output. The events emitted before some contract queries
(such as querying account balance) were not emitted in the debug output. To
fix this, `DebugTraceElement` gets a new variant `Debug` to retain these
events.

## 4.0.0

- Add support for debug output when running smart contracts. This adds a new
Expand Down
2 changes: 1 addition & 1 deletion contract-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "concordium-smart-contract-testing"
version = "4.0.0"
version = "4.1.0"
edition = "2021"
rust-version = "1.67"
license = "MPL-2.0"
Expand Down
18 changes: 17 additions & 1 deletion contract-testing/src/invocation/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ macro_rules! exit_ooe {
};
}

impl InvocationData {
/// An internal helper function to construct a [`DebugTraceElement`] from a
/// set of debug events.
pub(crate) fn debug_trace(&self, debug_trace: DebugTracker) -> DebugTraceElement {
DebugTraceElement::Debug {
entrypoint: self.entrypoint.clone(),
address: self.address,
debug_trace,
}
}
}

/// Ok response from the `invoke_entrypoint_initial` method. This is the
/// execution up to either success, failure, or the first interrupt.
///
Expand Down Expand Up @@ -722,13 +734,13 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};

exit_ooe!(
self.remaining_energy.tick_energy(
constants::CONTRACT_INSTANCE_QUERY_ACCOUNT_BALANCE_COST,
),
trace
);
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -757,6 +769,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
),
trace
);
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand All @@ -782,6 +795,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
trace
);

trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -853,6 +867,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down Expand Up @@ -889,6 +904,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
kind: v1::InvokeFailure::NonExistentAccount,
},
};
trace_elements.push(invocation_data.debug_trace(trace));
stack.push(Next::Resume {
data: invocation_data,
config,
Expand Down
32 changes: 32 additions & 0 deletions contract-testing/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ impl ContractInvokeSuccess {
DebugTraceElement::WithFailures {
..
} => None,
DebugTraceElement::Debug {
..
} => None,
})
}

Expand All @@ -575,6 +578,9 @@ impl ContractInvokeSuccess {
DebugTraceElement::WithFailures {
..
} => None,
DebugTraceElement::Debug {
..
} => None,
})
.collect()
}
Expand Down Expand Up @@ -911,6 +917,18 @@ fn debug_events_worker(
self.stack.push(Next::Remaining((true, trace_elements)));
}
}
DebugTraceElement::Debug {
entrypoint,
address,
debug_trace,
} => {
return Some(DebugItem {
address: *address,
entrypoint: entrypoint.as_entrypoint_name(),
debug_trace,
rolled_back: false,
});
}
}
}
}
Expand Down Expand Up @@ -938,6 +956,20 @@ pub enum DebugTraceElement {
energy_used: Energy,
debug_trace: DebugTracker,
},
/// A record of debug events emitted before the interrupt.
/// Contract queries, such as querying account balance or exchange rates do
/// not produce any events visible in the
/// [`Regular`](DebugTraceElement::Regular) trace elements
/// or in the transaction outcomes, but the internal debug information is
/// still useful for debugging.
Debug {
/// The entrypoint that is being executed.
entrypoint: OwnedEntrypointName,
/// The address that is affected.
address: ContractAddress,
/// Events emitted until the interrupt.
debug_trace: DebugTracker,
},
/// One or multiple trace elements that fail. Useful for debugging.
/// This variant also contains additional information, such as the error,
/// entrypoint, and energy usage.
Expand Down
5 changes: 4 additions & 1 deletion examples/auction/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn test_multiple_scenarios() {
message: OwnedParameter::empty(),
},
)
.print_debug(DebugOutputKind::Full)
abizjak marked this conversation as resolved.
Show resolved Hide resolved
.expect("Alice successfully bids 2 CCD");
// Check that 1 CCD is transferred back to ALICE.
assert_eq!(update_2.account_transfers().collect::<Vec<_>>()[..], [(
Expand Down Expand Up @@ -260,7 +261,9 @@ fn initialize_chain_and_auction() -> (Chain, ContractAddress) {

// Load and deploy the module.
let module = module_load_v1("concordium-out/module.wasm.v1").expect("Module exists");
let deployment = chain.module_deploy_v1(SIGNER, CAROL, module).expect("Deploy valid module");
let deployment = chain
.module_deploy_v1_debug(SIGNER, CAROL, module, is_debug_enabled())
.expect("Deploy valid module");

// Create the InitParameter.
let parameter = InitParameter {
Expand Down
Loading