Skip to content

Format utility functions for consistency#802

Merged
ChrisAmora merged 1 commit intomainfrom
feat/utils
Feb 27, 2026
Merged

Format utility functions for consistency#802
ChrisAmora merged 1 commit intomainfrom
feat/utils

Conversation

@ChrisAmora
Copy link
Contributor

@ChrisAmora ChrisAmora commented Feb 27, 2026

This pull request introduces improvements to the representation and formatting of decoded parameters and field values in proposal analysis, with a focus on providing richer type information and enhanced formatting for numeric values.
https://smartcontract-it.atlassian.net/browse/OPT-443

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

⚠️ No Changeset found

Latest commit: f997d51

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ChrisAmora ChrisAmora marked this pull request as ready for review February 27, 2026 15:39
@ChrisAmora ChrisAmora requested a review from a team as a code owner February 27, 2026 15:39
Copilot AI review requested due to automatic review settings February 27, 2026 15:39
@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
70.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

Copy link
Contributor

Copilot AI left a 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 enhances the proposal analysis system by adding richer type information to decoded parameters and introducing utility functions for consistent number formatting. The changes introduce a TypeName field to the NamedField struct, which stores ABI type information (e.g., "uint64", "bytes32") for EVM transactions, and refactor numeric formatting logic into a reusable format package.

Changes:

  • Added TypeName field to NamedField struct for storing explicit type information from ABI definitions
  • Created new format package with CommaGroupBigInt and FormatTokenAmount utilities for consistent number formatting
  • Refactored commaGrouped function in funcmap.go to use the new format package and handle more numeric types via reflection
  • Updated decoder conversion logic to prioritize explicit TypeName over inferred types while maintaining backward compatibility
  • Minor template whitespace adjustment that adds consistent spacing after annotation blocks

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
experimental/analyzer/fields.go Adds TypeName field to NamedField struct
experimental/analyzer/evm_tx_decoder.go Populates TypeName from ABI type information in EVM decoder
experimental/analyzer/evm_tx_decoder_test.go Updates test expectations to include TypeName values
engine/cld/mcms/proposalanalysis/format/format.go New utility functions for number formatting
engine/cld/mcms/proposalanalysis/format/format_test.go Comprehensive tests for format utilities
engine/cld/mcms/proposalanalysis/renderer/funcmap.go Refactored commaGrouped to use format package with enhanced type support
engine/cld/mcms/proposalanalysis/decoder/convert.go Updated to use TypeName with fallback to GetType() for backward compatibility
engine/cld/mcms/proposalanalysis/renderer/templates/markdown/annotations.tmpl Consolidated template end statements affecting whitespace
engine/cld/mcms/proposalanalysis/renderer/testdata/golden_markdown.md Updated golden file with new whitespace format
Comments suppressed due to low confidence (1)

engine/cld/mcms/proposalanalysis/decoder/convert.go:112

  • Consider adding a test case to verify that when TypeName is populated (as it now is in EVM decoders), the adaptNamedFields function correctly prioritizes it over the Value's GetType() method. This would ensure the new TypeName field is properly utilized in the decoder pipeline.
func adaptNamedFields(fields []experimentalanalyzer.NamedField) DecodedParameters {
	if len(fields) == 0 {
		return nil
	}

	params := make(DecodedParameters, len(fields))
	for i, field := range fields {
		ptype := field.TypeName
		if ptype == "" && field.Value != nil {
			ptype = field.Value.GetType()
		}

		value := any(field.Value)
		if value == nil {
			value = field.RawValue
		}

		params[i] = &decodedParameter{
			name:     field.Name,
			ptype:    ptype,
			value:    value,
			rawValue: field.RawValue,
		}
	}

	return params
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChrisAmora ChrisAmora added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 7d9b3e1 Feb 27, 2026
24 of 25 checks passed
@ChrisAmora ChrisAmora deleted the feat/utils branch February 27, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants