Skip to content

Commit

Permalink
Merge pull request #2017 from radixdlt/tweak/further-cuttlefish-tests…
Browse files Browse the repository at this point in the history
…-and-neatenings

Further additional cuttlefish tests
  • Loading branch information
dhedey authored Jan 13, 2025
2 parents fa700ad + 9c98fde commit c641467
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 115 deletions.
4 changes: 2 additions & 2 deletions radix-common/src/types/addresses/component_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ impl fmt::Debug for ComponentAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ComponentAddress {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/addresses/global_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ impl fmt::Debug for GlobalAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for GlobalAddress {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/addresses/internal_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ impl fmt::Debug for InternalAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for InternalAddress {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/addresses/package_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ impl fmt::Debug for PackageAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for PackageAddress {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/addresses/resource_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ impl fmt::Debug for ResourceAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for ResourceAddress {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/blueprint_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl BlueprintId {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for BlueprintId {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
write!(
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/node_and_substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ impl Debug for NodeId {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NodeId {
type Error = AddressBech32EncodeError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
if let Some(encoder) = context.encoder {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/types/non_fungible_global_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ impl fmt::Display for ParseNonFungibleGlobalIdError {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for NonFungibleGlobalId {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
write!(
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-interface/src/types/event_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub enum Emitter {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for Emitter {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
match self {
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-interface/src/types/indexed_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl<'s, 'a> ContextualDisplay<ValueDisplayParameters<'s, 'a, ScryptoCustomExten
{
type Error = sbor::representations::FormattingError;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ValueDisplayParameters<'_, '_, ScryptoCustomExtension>,
) -> Result<(), Self::Error> {
ScryptoRawPayload::new_from_valid_slice(self.as_slice()).format(f, *context)
Expand Down
4 changes: 2 additions & 2 deletions radix-engine-interface/src/types/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub struct FnIdentifier {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for FnIdentifier {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
write!(
Expand Down
16 changes: 8 additions & 8 deletions radix-engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ pub enum RejectionReason {
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RejectionReason {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ScryptoValueDisplayContext,
) -> Result<(), Self::Error> {
self.create_persistable().contextual_format(f, context)
Expand All @@ -172,9 +172,9 @@ impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableReject
type Error = fmt::Error;

/// See [`SerializableRuntimeError::contextual_format`] for more information.
fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ScryptoValueDisplayContext,
) -> Result<(), Self::Error> {
let value = &self.encoded_rejection_reason;
Expand Down Expand Up @@ -339,9 +339,9 @@ pub enum RuntimeError {
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for RuntimeError {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ScryptoValueDisplayContext,
) -> Result<(), Self::Error> {
self.create_persistable().contextual_format(f, context)
Expand Down Expand Up @@ -383,9 +383,9 @@ pub struct PersistableRuntimeError {
impl<'a> ContextualDisplay<ScryptoValueDisplayContext<'a>> for PersistableRuntimeError {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ScryptoValueDisplayContext,
) -> Result<(), Self::Error> {
let value = &self.encoded_error;
Expand Down
8 changes: 4 additions & 4 deletions radix-engine/src/transaction/transaction_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,9 +1020,9 @@ impl<'a> TransactionReceiptDisplayContextBuilder<'a> {
impl<'a> ContextualDisplay<TransactionReceiptDisplayContext<'a>> for TransactionReceipt {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &TransactionReceiptDisplayContext<'a>,
) -> Result<(), Self::Error> {
let result = &self.result;
Expand Down Expand Up @@ -1195,9 +1195,9 @@ impl<'a, 'b> ContextualDisplay<TransactionReceiptDisplayContext<'a>>
{
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &TransactionReceiptDisplayContext<'a>,
) -> Result<(), Self::Error> {
let state_updates = self.0;
Expand Down
42 changes: 38 additions & 4 deletions radix-rust/src/contextual_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub trait ContextualDisplay<Context> {
/// instead of a `&Context`.
///
/// [`format`]: #method.format
fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &Context,
) -> Result<(), Self::Error>;

Expand All @@ -34,9 +34,9 @@ pub trait ContextualDisplay<Context> {
///
/// [`contextual_format`]: #method.contextual_format
/// [`display`]: #method.display
fn format<F: fmt::Write, TContext: Into<Context>>(
fn format<TContext: Into<Context>>(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: TContext,
) -> Result<(), Self::Error> {
self.contextual_format(f, &context.into())
Expand Down Expand Up @@ -70,6 +70,21 @@ pub trait ContextualDisplay<Context> {
}
}

/// Returns an object implementing [`fmt::Debug`] using the contextual display implementation.
///
/// Typically you should use [`format`] instead.
///
/// [`format`]: #method.format
fn debug_as_display<'a, 'b, TContext: Into<Context>>(
&'a self,
context: TContext,
) -> ContextDebuggableAsDisplay<'a, Self, Context> {
ContextDebuggableAsDisplay {
value: self,
context: context.into(),
}
}

fn to_string<'a, 'b, TContext: Into<Context>>(&'a self, context: TContext) -> String {
self.display(context).to_string()
}
Expand All @@ -93,3 +108,22 @@ where
.map_err(|_| fmt::Error) // We eat any errors into fmt::Error
}
}

pub struct ContextDebuggableAsDisplay<'a, TValue, TContext>
where
TValue: ContextualDisplay<TContext> + ?Sized,
{
value: &'a TValue,
context: TContext,
}

impl<'a, 'b, TValue, TContext> fmt::Debug for ContextDebuggableAsDisplay<'a, TValue, TContext>
where
TValue: ContextualDisplay<TContext> + ?Sized,
{
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
self.value
.contextual_format(f, &self.context)
.map_err(|_| fmt::Error) // We eat any errors into fmt::Error
}
}
4 changes: 2 additions & 2 deletions radix-transaction-scenarios/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ pub enum DescribedAddress {
impl<'a> ContextualDisplay<AddressDisplayContext<'a>> for DescribedAddress {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &AddressDisplayContext<'a>,
) -> Result<(), Self::Error> {
match self {
Expand Down
8 changes: 4 additions & 4 deletions radix-transactions/src/data/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ impl<'a> Into<ManifestDecompilationDisplayContext<'a>> for Option<&'a AddressBec
impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for ManifestValue {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ManifestDecompilationDisplayContext<'a>,
) -> Result<(), Self::Error> {
format_manifest_value(f, self, context, false, 0)
Expand Down Expand Up @@ -515,9 +515,9 @@ impl<'a> fmt::Display for DisplayableManifestValueKind<'a> {
impl<'a> ContextualDisplay<ManifestDecompilationDisplayContext<'a>> for ManifestCustomValue {
type Error = fmt::Error;

fn contextual_format<F: fmt::Write>(
fn contextual_format(
&self,
f: &mut F,
f: &mut fmt::Formatter,
context: &ManifestDecompilationDisplayContext<'a>,
) -> Result<(), Self::Error> {
format_custom_value(f, self, context, false, 0)
Expand Down
Loading

0 comments on commit c641467

Please sign in to comment.