- 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
Introduce a debug utility that allows to generate an example file #107
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
base: main
Are you sure you want to change the base?
Conversation
Previously in a code we required entire value to have an Ord instance. While it's possible to have such one it leads to problems when we work with generic values of the types we do not know. The other problem is that during the computation we should check the equality for the keys only and do not allow two values with the same key even if they are not equal. So the new type reflects that properly.
ByteStringSized wrapper allows to store a ByteString of the known size without prefixing it with a size. It's expected to be used as a helper for storing keys
Introdunce two new types: - GenericCBOREntry for storing and reading any CBOR Term stored in utxo - SomeCBOREntry that is used only for generation, and allows to bypass the restriction that the types on all entries in the Plan should be the same. This restriction is problematic because namespaces should be able to use differently sized keys and as a result differrent types
Introduces API that allow to generate files using specification
for the namespaces defined. It can be used for implementation
testing and as for the node developemnet and other implementations
```
cabal run scls-util -- debug generate --help
Usage: scls-util debug generate FILE [--namespace NAMESPACE[:COUNT]]
  Generate a debug SCLS file with random data
Available options:
  FILE                     Path to SCLS file
  --namespace NAMESPACE[:COUNT]
                           Namespace and optional number of entries to generate,
                           default is 16
  -h,--help                Show this help text
```
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a debug file generation utility to create SCLS files with random data for testing and debugging purposes. The implementation allows generating files with specified namespaces and entry counts.
Key changes:
- Added 
generateDebugFilefunction that creates SCLS files with randomly generated keys and CBOR-encoded values based on namespace specifications - Enhanced serialization infrastructure to support generic CBOR entries with existential type wrappers
 - Modified sorting logic to use key-based comparison instead of full value comparison for better flexibility
 
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description | 
|---|---|
| scls-util/src/Cardano/SCLS/Util/Debug.hs | New module providing debug file generation functionality with random data | 
| scls-util/app/Main.hs | Added CLI commands for debug utilities, changed subparser to hsubparser | 
| scls-format/src/Cardano/SCLS/Internal/Entry.hs | Added GenericCBOREntry and SomeCBOREntry types for handling CBOR entries generically | 
| scls-format/src/Cardano/SCLS/Internal/Serializer/MemPack.hs | Added ByteStringSized, CBORTerm, and consumeBytes utilities for generic serialization | 
| scls-format/src/Cardano/SCLS/Internal/Serializer/Reference/Impl.hs | Changed constraint from Ord a to Ord (Key a) and updated sorting to use key-based comparison | 
| scls-format/src/Cardano/SCLS/Internal/Serializer/External/Impl.hs | Updated constraints and refactored sorting logic into finalizeVector helper | 
| scls-util/scls-util.cabal | Added dependencies: cborg, cuddle, random, scls-cddl | 
| scls-format/scls-format.cabal | Added cborg dependency | 
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 
               | 
          ||
| {- | Generate a scls file with random data for debugging purposes. | ||
| Keys and values are deterministic pseudo-random hex strings derived from | 
    
      
    
      Copilot
AI
    
    
    
      Nov 3, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation claims keys and values are 'deterministic pseudo-random hex strings', but the implementation uses uniformByteStringM with globalStdGen (line 76), which is not deterministic across runs, and the values are CBOR terms generated from the cuddle spec (line 77), not hex strings.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Introduced a new command that allows to generate a file.
While working on that I had to introduce a lots of helpers for encoding:
ByteStringSized (n::Nat)— bytestring with size known at the runtimeSomeByteStringSized— existential wrapper that allows to keep ByteStringSized of the different size and compare them (in the length-first order)GenericCBOREntry n— an entry that is CBOR with a fixed size key, it's useful for reading entries and later verificationSomeCBOREntry— existential wrapper that allows to haveGenericCBOREntriesif the different key size in the same plan