Skip to content

Commit 24b160a

Browse files
authored
Merge pull request #390 from Concordium/retain-events
Retain events
2 parents 144f55b + 0574f68 commit 24b160a

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

concordium-std/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
## Unreleased changes
44

5-
- Fix a bug that caused a linking error when using `concordium_dbg!`.
5+
## concordium-std 9.0.1 (2024-01-26)
6+
7+
- Fix a bug that caused a linking error when using `concordium_dbg!` on some
8+
platforms.
69
- The error message states that `_debug_print` cannot be found.
710

8-
## concordium-std 6.0.0 (2024-01-22)
11+
## concordium-std 9.0.0 (2024-01-22)
912

1013
- Add a `concordium_dbg!` macro and the associated `debug` feature to enable,
1114
together with `cargo concordium`, to emit debug information during contract

concordium-std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "concordium-std"
3-
version = "9.0.0"
3+
version = "9.0.1"
44
authors = ["Concordium <[email protected]>"]
55
edition = "2021"
66
rust-version = "1.66"

contract-testing/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## Unreleased changes
44

5+
## 4.1.0
6+
7+
- Fix a bug in debug output. The events emitted before some contract queries
8+
(such as querying account balance) were not emitted in the debug output. To
9+
fix this, `DebugTraceElement` gets a new variant `Debug` to retain these
10+
events.
11+
512
## 4.0.0
613

714
- Add support for debug output when running smart contracts. This adds a new

contract-testing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "concordium-smart-contract-testing"
3-
version = "4.0.0"
3+
version = "4.1.0"
44
edition = "2021"
55
rust-version = "1.67"
66
license = "MPL-2.0"

contract-testing/src/invocation/impls.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ macro_rules! exit_ooe {
4343
};
4444
}
4545

46+
impl InvocationData {
47+
/// An internal helper function to construct a [`DebugTraceElement`] from a
48+
/// set of debug events.
49+
pub(crate) fn debug_trace(&self, debug_trace: DebugTracker) -> DebugTraceElement {
50+
DebugTraceElement::Debug {
51+
entrypoint: self.entrypoint.clone(),
52+
address: self.address,
53+
debug_trace,
54+
}
55+
}
56+
}
57+
4658
/// Ok response from the `invoke_entrypoint_initial` method. This is the
4759
/// execution up to either success, failure, or the first interrupt.
4860
///
@@ -722,13 +734,13 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
722734
kind: v1::InvokeFailure::NonExistentAccount,
723735
},
724736
};
725-
726737
exit_ooe!(
727738
self.remaining_energy.tick_energy(
728739
constants::CONTRACT_INSTANCE_QUERY_ACCOUNT_BALANCE_COST,
729740
),
730741
trace
731742
);
743+
trace_elements.push(invocation_data.debug_trace(trace));
732744
stack.push(Next::Resume {
733745
data: invocation_data,
734746
config,
@@ -757,6 +769,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
757769
),
758770
trace
759771
);
772+
trace_elements.push(invocation_data.debug_trace(trace));
760773
stack.push(Next::Resume {
761774
data: invocation_data,
762775
config,
@@ -782,6 +795,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
782795
trace
783796
);
784797

798+
trace_elements.push(invocation_data.debug_trace(trace));
785799
stack.push(Next::Resume {
786800
data: invocation_data,
787801
config,
@@ -853,6 +867,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
853867
kind: v1::InvokeFailure::NonExistentAccount,
854868
},
855869
};
870+
trace_elements.push(invocation_data.debug_trace(trace));
856871
stack.push(Next::Resume {
857872
data: invocation_data,
858873
config,
@@ -889,6 +904,7 @@ impl<'a, 'b> EntrypointInvocationHandler<'a, 'b> {
889904
kind: v1::InvokeFailure::NonExistentAccount,
890905
},
891906
};
907+
trace_elements.push(invocation_data.debug_trace(trace));
892908
stack.push(Next::Resume {
893909
data: invocation_data,
894910
config,

contract-testing/src/types.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ impl ContractInvokeSuccess {
553553
DebugTraceElement::WithFailures {
554554
..
555555
} => None,
556+
DebugTraceElement::Debug {
557+
..
558+
} => None,
556559
})
557560
}
558561

@@ -575,6 +578,9 @@ impl ContractInvokeSuccess {
575578
DebugTraceElement::WithFailures {
576579
..
577580
} => None,
581+
DebugTraceElement::Debug {
582+
..
583+
} => None,
578584
})
579585
.collect()
580586
}
@@ -911,6 +917,18 @@ fn debug_events_worker(
911917
self.stack.push(Next::Remaining((true, trace_elements)));
912918
}
913919
}
920+
DebugTraceElement::Debug {
921+
entrypoint,
922+
address,
923+
debug_trace,
924+
} => {
925+
return Some(DebugItem {
926+
address: *address,
927+
entrypoint: entrypoint.as_entrypoint_name(),
928+
debug_trace,
929+
rolled_back: false,
930+
});
931+
}
914932
}
915933
}
916934
}
@@ -938,6 +956,20 @@ pub enum DebugTraceElement {
938956
energy_used: Energy,
939957
debug_trace: DebugTracker,
940958
},
959+
/// A record of debug events emitted before the interrupt.
960+
/// Contract queries, such as querying account balance or exchange rates do
961+
/// not produce any events visible in the
962+
/// [`Regular`](DebugTraceElement::Regular) trace elements
963+
/// or in the transaction outcomes, but the internal debug information is
964+
/// still useful for debugging.
965+
Debug {
966+
/// The entrypoint that is being executed.
967+
entrypoint: OwnedEntrypointName,
968+
/// The address that is affected.
969+
address: ContractAddress,
970+
/// Events emitted until the interrupt.
971+
debug_trace: DebugTracker,
972+
},
941973
/// One or multiple trace elements that fail. Useful for debugging.
942974
/// This variant also contains additional information, such as the error,
943975
/// entrypoint, and energy usage.

0 commit comments

Comments
 (0)