Skip to content

Commit 441f3fe

Browse files
with timeout
1 parent 2240e92 commit 441f3fe

File tree

9 files changed

+287
-135
lines changed

9 files changed

+287
-135
lines changed

engine/cld/mcms/proposalanalysis/analyzer_context.go

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

33
import (
44
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/types"
5-
experimentalanalyzer "github.com/smartcontractkit/chainlink-deployments-framework/experimental/analyzer"
65
)
76

87
var _ types.AnalyzerContext = &analyzerContext{}
@@ -11,8 +10,6 @@ type analyzerContext struct {
1110
proposal types.AnalyzedProposal
1211
batchOperation types.AnalyzedBatchOperation
1312
call types.AnalyzedCall
14-
evmRegistry experimentalanalyzer.EVMABIRegistry
15-
solanaRegistry experimentalanalyzer.SolanaDecoderRegistry
1613
}
1714

1815
func (ac *analyzerContext) Proposal() types.AnalyzedProposal {
@@ -27,14 +24,6 @@ func (ac *analyzerContext) Call() types.AnalyzedCall {
2724
return ac.call
2825
}
2926

30-
func (ac *analyzerContext) GetEVMRegistry() experimentalanalyzer.EVMABIRegistry {
31-
return ac.evmRegistry
32-
}
33-
34-
func (ac *analyzerContext) GetSolanaRegistry() experimentalanalyzer.SolanaDecoderRegistry {
35-
return ac.solanaRegistry
36-
}
37-
3827
// GetAnnotationsFrom returns annotations from a specific analyzer
3928
func (ac *analyzerContext) GetAnnotationsFrom(analyzerID string) types.Annotations {
4029
var annotations types.Annotations

engine/cld/mcms/proposalanalysis/decoder/decoder.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ type ProposalDecoder interface {
1818

1919
// legacyDecoder adapts the legacy experimental/analyzer package to the new decoder interface
2020
type legacyDecoder struct {
21-
proposalContext experimentalanalyzer.ProposalContext
21+
evmABIMappings map[string]string
22+
solanaDecoders map[string]experimentalanalyzer.DecodeInstructionFn
2223
}
2324

2425
// NewLegacyDecoder creates a decoder that wraps legacy experimental/analyzer decoding logic.
2526
// Use functional options to configure:
26-
// - WithProposalContext: provide a custom ProposalContext (otherwise default is created)
27+
// - WithEVMABIMappings: override proposal context EVM ABI mappings
28+
// - WithSolanaDecoders: override proposal context Solana decoder mappings
2729
func NewLegacyDecoder(opts ...DecoderOption) ProposalDecoder {
2830
decoder := &legacyDecoder{}
2931

@@ -37,11 +39,17 @@ func NewLegacyDecoder(opts ...DecoderOption) ProposalDecoder {
3739
// DecoderOption is a functional option for configuring the decoder
3840
type DecoderOption func(*legacyDecoder)
3941

40-
// WithProposalContext injects a custom ProposalContext for decoding.
41-
// If not provided, a default context will be created during decoding.
42-
func WithProposalContext(ctx experimentalanalyzer.ProposalContext) DecoderOption {
42+
// WithEVMABIMappings overrides the proposal context EVM ABI mappings used during decoding.
43+
func WithEVMABIMappings(mappings map[string]string) DecoderOption {
4344
return func(d *legacyDecoder) {
44-
d.proposalContext = ctx
45+
d.evmABIMappings = mappings
46+
}
47+
}
48+
49+
// WithSolanaDecoders overrides the proposal context Solana decoder mappings used during decoding.
50+
func WithSolanaDecoders(decoders map[string]experimentalanalyzer.DecodeInstructionFn) DecoderOption {
51+
return func(d *legacyDecoder) {
52+
d.solanaDecoders = decoders
4553
}
4654
}
4755

@@ -50,18 +58,12 @@ func (d *legacyDecoder) Decode(
5058
env deployment.Environment,
5159
proposal *mcms.TimelockProposal,
5260
) (types.DecodedTimelockProposal, error) {
53-
// Create proposal context for legacy experimental analyzer
54-
// Use the provided context if available, otherwise create a default one
55-
var proposalCtx experimentalanalyzer.ProposalContext
56-
57-
if d.proposalContext != nil {
58-
proposalCtx = d.proposalContext
59-
} else {
60-
var err error
61-
proposalCtx, err = experimentalanalyzer.NewDefaultProposalContext(env)
62-
if err != nil {
63-
return nil, fmt.Errorf("failed to create proposal context: %w", err)
64-
}
61+
proposalCtx, err := experimentalanalyzer.NewDefaultProposalContext(env,
62+
experimentalanalyzer.WithEVMABIMappings(d.evmABIMappings),
63+
experimentalanalyzer.WithSolanaDecoders(d.solanaDecoders),
64+
)
65+
if err != nil {
66+
return nil, fmt.Errorf("failed to create proposal context: %w", err)
6567
}
6668

6769
// Build the report using legacy experimental analyzer

engine/cld/mcms/proposalanalysis/decoder/decoder_test.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/decoder"
7-
experimentalanalyzer "github.com/smartcontractkit/chainlink-deployments-framework/experimental/analyzer"
87
"github.com/stretchr/testify/require"
98
)
109

@@ -15,35 +14,11 @@ func TestDecoderOptions(t *testing.T) {
1514
require.NotNil(t, d)
1615
})
1716

18-
t.Run("can inject custom proposal context", func(t *testing.T) {
19-
customContext := &mockProposalContext{}
20-
17+
t.Run("can configure registry options", func(t *testing.T) {
2118
d := decoder.NewLegacyDecoder(
22-
decoder.WithProposalContext(customContext),
19+
decoder.WithEVMABIMappings(nil),
20+
decoder.WithSolanaDecoders(nil),
2321
)
2422
require.NotNil(t, d)
2523
})
2624
}
27-
28-
// mockProposalContext is a minimal mock for testing
29-
type mockProposalContext struct{}
30-
31-
func (m *mockProposalContext) GetEVMRegistry() experimentalanalyzer.EVMABIRegistry {
32-
return nil
33-
}
34-
35-
func (m *mockProposalContext) GetSolanaDecoderRegistry() experimentalanalyzer.SolanaDecoderRegistry {
36-
return nil
37-
}
38-
39-
func (m *mockProposalContext) FieldsContext(chainSelector uint64) *experimentalanalyzer.FieldContext {
40-
return nil
41-
}
42-
43-
func (m *mockProposalContext) GetRenderer() experimentalanalyzer.Renderer {
44-
return nil
45-
}
46-
47-
func (m *mockProposalContext) SetRenderer(renderer experimentalanalyzer.Renderer) {
48-
// no-op
49-
}

engine/cld/mcms/proposalanalysis/decoder/legacy_adapter.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ func (d *decodedCall) AdditionalFields() json.RawMessage {
7373
return json.RawMessage("{}")
7474
}
7575

76+
func (d *decodedCall) ContractType() string {
77+
// return d.call.ContractType
78+
return ""
79+
}
80+
81+
func (d *decodedCall) ContractVersion() string {
82+
// return d.call.ContractVersion
83+
return ""
84+
}
85+
7686
// decodedParameter adapts legacy experimental named field
7787
type decodedParameter struct {
7888
field experimentalanalyzer.NamedField
@@ -86,6 +96,11 @@ func (d *decodedParameter) Value() any {
8696
return convertFieldValue(d.field.Value)
8797
}
8898

99+
func (d *decodedParameter) Type() string {
100+
// return d.field.Type
101+
return ""
102+
}
103+
89104
// convertNamedFields converts legacy experimental NamedFields to DecodedParameters
90105
func convertNamedFields(fields []experimentalanalyzer.NamedField) types.DecodedParameters {
91106
params := make(types.DecodedParameters, len(fields))

0 commit comments

Comments
 (0)