-
Notifications
You must be signed in to change notification settings - Fork 10
Add Reports type to outcome. Currently unused. #892
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
Draft
winder
wants to merge
10
commits into
main
Choose a base branch
from
will/exec-reports-outcome
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
35bbaed
Add Reports type to outcome. Currently unused.
winder 791f53b
Don't remove sort in this PR.
winder 7200132
Add compatibility to Observation
winder 8903ee3
More compatibility stuff.
winder 3a96e1d
Support legacy field in protobuf layer.
winder 6576ad7
More compatibility stuff..._
winder 4a5ec79
Add compatibility testcase.
winder 8ffeb47
Add backwards compatability test and fix NeweOutcome.
winder 78a4cdd
Merge branch 'main' into will/exec-reports-outcome
asoliman92 b871f99
Add more compatability tests and small fixes
asoliman92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
package v1_test | ||
|
||
import ( | ||
"encoding/base64" | ||
"github.com/smartcontractkit/chainlink-ccip/pkg/ocrtypecodec/v1/ocrtypecodecpb" | ||
"google.golang.org/protobuf/proto" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-ccip/execute/exectypes" | ||
v1 "github.com/smartcontractkit/chainlink-ccip/pkg/ocrtypecodec/v1" | ||
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" | ||
) | ||
|
||
var inputObjectOld = exectypes.Outcome{ | ||
State: "yee haw", | ||
CommitReports: []exectypes.CommitData{ | ||
{ | ||
SourceChain: 99, | ||
Timestamp: time.UnixMilli(9000), | ||
BlockNum: 201, | ||
SequenceNumberRange: cciptypes.NewSeqNumRange(250, 300), | ||
}, | ||
}, | ||
Report: cciptypes.ExecutePluginReport{ | ||
ChainReports: []cciptypes.ExecutePluginReportSingleChain{ | ||
{ | ||
SourceChainSelector: 123, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var inputObjectReports = exectypes.Outcome{ | ||
State: "yee haw", | ||
CommitReports: []exectypes.CommitData{ | ||
{ | ||
SourceChain: 99, | ||
Timestamp: time.UnixMilli(9000), | ||
BlockNum: 201, | ||
SequenceNumberRange: cciptypes.NewSeqNumRange(250, 300), | ||
}, | ||
}, | ||
Reports: []cciptypes.ExecutePluginReport{ | ||
{ | ||
ChainReports: []cciptypes.ExecutePluginReportSingleChain{ | ||
{ | ||
SourceChainSelector: 123, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func TestProtobufBackwardCompatability(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
encodedOutcome string // b64 | ||
input exectypes.Outcome | ||
}{ | ||
{ | ||
name: "original outcome", | ||
encodedOutcome: "Cgd5ZWUgaGF3EjMIYxoCCAkgyQEqIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMgYI+gEQrAIaBAoCCHs=", | ||
input: inputObjectOld, | ||
}, | ||
{ | ||
name: "reports outcome", | ||
encodedOutcome: "Cgd5ZWUgaGF3EjMIYxoCCAkgyQEqIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMgYI+gEQrAIaBAoCCHs=", | ||
input: inputObjectReports, | ||
}, | ||
} | ||
|
||
for _, testcase := range testcases { | ||
t.Run(testcase.name, func(t *testing.T) { | ||
enc := v1.NewExecCodecProto() | ||
encoded, err := enc.EncodeOutcome(testcase.input) | ||
require.NoError(t, err) | ||
b64Encoded := base64.StdEncoding.EncodeToString(encoded) | ||
require.Equal(t, testcase.encodedOutcome, b64Encoded) | ||
}) | ||
} | ||
} | ||
|
||
// TestExistingEncodingCompatibility verifies existing encoded data can be decoded correctly | ||
func TestExistingEncodingCompatibility(t *testing.T) { | ||
// Base64 encoded data from original test | ||
encodedB64 := "Cgd5ZWUgaGF3EjMIYxoCCAkgyQEqIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMgYI+gEQrAIaBAoCCHs=" | ||
|
||
codec := v1.NewExecCodecProto() | ||
encoded, err := base64.StdEncoding.DecodeString(encodedB64) | ||
require.NoError(t, err) | ||
|
||
outcome, err := codec.DecodeOutcome(encoded) | ||
require.NoError(t, err) | ||
|
||
// Verify the outcome has both fields populated | ||
require.Equal(t, exectypes.PluginState("yee haw"), outcome.State) | ||
require.NotEmpty(t, outcome.Report.ChainReports) | ||
require.Equal(t, cciptypes.ChainSelector(123), outcome.Report.ChainReports[0].SourceChainSelector) | ||
require.Len(t, outcome.Reports, 1) | ||
require.Equal(t, outcome.Report, outcome.Reports[0]) | ||
} | ||
|
||
// TestSingleReportBackwardCompatibility tests that single reports use the legacy field | ||
func TestSingleReportBackwardCompatibility(t *testing.T) { | ||
codec := v1.NewExecCodecProto() | ||
|
||
// Create an outcome with a single report in Reports | ||
outcome := exectypes.Outcome{ | ||
State: "test state", | ||
Reports: []cciptypes.ExecutePluginReport{ | ||
{ | ||
ChainReports: []cciptypes.ExecutePluginReportSingleChain{ | ||
{SourceChainSelector: 42}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
encoded, err := codec.EncodeOutcome(outcome) | ||
require.NoError(t, err) | ||
|
||
// Manually decode the protobuf to verify structure | ||
pbOutcome := &ocrtypecodecpb.ExecOutcome{} | ||
err = proto.Unmarshal(encoded, pbOutcome) | ||
require.NoError(t, err) | ||
|
||
// With a single report, it should use the legacy field only | ||
require.NotNil(t, pbOutcome.ExecutePluginReport) | ||
require.Empty(t, pbOutcome.ExecutePluginReports) | ||
require.Equal(t, uint64(42), pbOutcome.ExecutePluginReport.ChainReports[0].SourceChainSelector) | ||
|
||
decodedOutcome, err := codec.DecodeOutcome(encoded) | ||
require.NoError(t, err) | ||
|
||
// Both fields should now be populated in the decoded outcome | ||
require.Equal(t, cciptypes.ChainSelector(42), decodedOutcome.Report.ChainReports[0].SourceChainSelector) | ||
require.Len(t, decodedOutcome.Reports, 1) | ||
require.Equal(t, cciptypes.ChainSelector(42), decodedOutcome.Reports[0].ChainReports[0].SourceChainSelector) | ||
} | ||
|
||
// TestMultipleReportEncoding verifies that multiple reports use the new field | ||
func TestMultipleReportEncoding(t *testing.T) { | ||
codec := v1.NewExecCodecProto() | ||
|
||
// Create an outcome with multiple reports | ||
outcome := exectypes.Outcome{ | ||
State: "test state", | ||
Reports: []cciptypes.ExecutePluginReport{ | ||
{ | ||
ChainReports: []cciptypes.ExecutePluginReportSingleChain{ | ||
{SourceChainSelector: 42}, | ||
}, | ||
}, | ||
{ | ||
ChainReports: []cciptypes.ExecutePluginReportSingleChain{ | ||
{SourceChainSelector: 43}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
encoded, err := codec.EncodeOutcome(outcome) | ||
require.NoError(t, err) | ||
|
||
// Manually decode the protobuf to verify structure | ||
pbOutcome := &ocrtypecodecpb.ExecOutcome{} | ||
err = proto.Unmarshal(encoded, pbOutcome) | ||
require.NoError(t, err) | ||
|
||
// With multiple reports, it should use the new field only | ||
require.Nil(t, pbOutcome.ExecutePluginReport) | ||
require.Len(t, pbOutcome.ExecutePluginReports, 2) | ||
require.Equal(t, uint64(42), pbOutcome.ExecutePluginReports[0].ChainReports[0].SourceChainSelector) | ||
require.Equal(t, uint64(43), pbOutcome.ExecutePluginReports[1].ChainReports[0].SourceChainSelector) | ||
|
||
decodedOutcome, err := codec.DecodeOutcome(encoded) | ||
require.NoError(t, err) | ||
require.Len(t, decodedOutcome.Reports, 2) | ||
require.Equal(t, cciptypes.ChainSelector(42), decodedOutcome.Reports[0].ChainReports[0].SourceChainSelector) | ||
require.Equal(t, cciptypes.ChainSelector(43), decodedOutcome.Reports[1].ChainReports[0].SourceChainSelector) | ||
} | ||
|
||
// TestEdgeCases tests various edge cases | ||
func TestEdgeCases(t *testing.T) { | ||
codec := v1.NewExecCodecProto() | ||
|
||
// Test with empty Reports array | ||
t.Run("empty reports array", func(t *testing.T) { | ||
outcome := exectypes.Outcome{ | ||
State: "test state", | ||
Reports: []cciptypes.ExecutePluginReport{}, | ||
} | ||
|
||
encoded, err := codec.EncodeOutcome(outcome) | ||
require.NoError(t, err) | ||
|
||
decoded, err := codec.DecodeOutcome(encoded) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, outcome.State, decoded.State) | ||
require.Empty(t, decoded.Reports) | ||
require.Nil(t, decoded.Report.ChainReports) | ||
}) | ||
|
||
t.Run("report with zero chain reports", func(t *testing.T) { | ||
outcome := exectypes.Outcome{ | ||
State: "test state", | ||
Report: cciptypes.ExecutePluginReport{}, | ||
} | ||
|
||
encoded, err := codec.EncodeOutcome(outcome) | ||
require.NoError(t, err) | ||
|
||
decoded, err := codec.DecodeOutcome(encoded) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, outcome.State, decoded.State) | ||
require.Empty(t, decoded.Reports) | ||
require.Nil(t, decoded.Report.ChainReports) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[nitpick] Revisit the sorting logic in NewSortedOutcome to ensure that the ordering of outcomes remains predictable when multiple reports are provided. Clarify in documentation how the sorting should behave across different plugin states.
Copilot uses AI. Check for mistakes.