Skip to content

Commit

Permalink
error case
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Jun 25, 2024
1 parent 9e28765 commit 3c458a4
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions core/services/ocr3/plugins/ccip/execute/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,19 @@ func (t tdr) ReadTokenData(ctx context.Context, srcChain cciptypes.ChainSelector
return nil, nil
}

func makeTestMessage(numMessages, srcChain, firstSeqNum, block int, timestamp int64, executed []cciptypes.SeqNum) cciptypes.ExecutePluginCommitDataWithMessages {
func breakCommitReport(commitReport cciptypes.ExecutePluginCommitDataWithMessages) cciptypes.ExecutePluginCommitDataWithMessages {
commitReport.Messages = append(commitReport.Messages, cciptypes.CCIPMsg{
CCIPMsgBaseDetails: cciptypes.CCIPMsgBaseDetails{
ID: crypto.CRandHex(32),
SourceChain: cciptypes.ChainSelector(1),
SeqNum: cciptypes.SeqNum(999),
MsgHash: cciptypes.Bytes32{},
},
})
return commitReport
}

func makeTestCommitReport(numMessages, srcChain, firstSeqNum, block int, timestamp int64, executed []cciptypes.SeqNum) cciptypes.ExecutePluginCommitDataWithMessages {
for _, e := range executed {
if e < cciptypes.SeqNum(firstSeqNum) || e > cciptypes.SeqNum(firstSeqNum+numMessages-1) {
panic("executed message out of range")
Expand Down Expand Up @@ -278,12 +290,20 @@ func Test_selectReport(t *testing.T) {
lastReportExecuted []cciptypes.SeqNum
wantErr string
}{
{
name: "empty report",
args: args{
reports: []cciptypes.ExecutePluginCommitDataWithMessages{},
},
expectedExecReports: 0,
expectedCommitReports: 0,
},
{
name: "half report",
args: args{
maxReportSize: 2200,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, nil),
makeTestCommitReport(10, 1, 100, 999, 10101010101, nil),
},
},
expectedExecReports: 1,
Expand All @@ -296,7 +316,7 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 10000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, nil),
makeTestCommitReport(10, 1, 100, 999, 10101010101, nil),
},
},
expectedExecReports: 1,
Expand All @@ -308,8 +328,8 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 15000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, nil),
makeTestMessage(20, 2, 100, 999, 10101010101, nil),
makeTestCommitReport(10, 1, 100, 999, 10101010101, nil),
makeTestCommitReport(20, 2, 100, 999, 10101010101, nil),
},
},
expectedExecReports: 2,
Expand All @@ -321,8 +341,8 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 8000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, nil),
makeTestMessage(20, 2, 100, 999, 10101010101, nil),
makeTestCommitReport(10, 1, 100, 999, 10101010101, nil),
makeTestCommitReport(20, 2, 100, 999, 10101010101, nil),
},
},
expectedExecReports: 2,
Expand All @@ -335,8 +355,8 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 3900,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, nil),
makeTestMessage(20, 2, 100, 999, 10101010101, nil),
makeTestCommitReport(10, 1, 100, 999, 10101010101, nil),
makeTestCommitReport(20, 2, 100, 999, 10101010101, nil),
},
},
expectedExecReports: 1,
Expand All @@ -349,7 +369,7 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 2500,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 101, 102, 103, 104}),
makeTestCommitReport(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 101, 102, 103, 104}),
},
},
expectedExecReports: 1,
Expand All @@ -361,7 +381,7 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 2000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 101, 102, 103, 104}),
makeTestCommitReport(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 101, 102, 103, 104}),
},
},
expectedExecReports: 1,
Expand All @@ -374,7 +394,7 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 2500,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 102, 104, 106, 108}),
makeTestCommitReport(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 102, 104, 106, 108}),
},
},
expectedExecReports: 1,
Expand All @@ -386,15 +406,24 @@ func Test_selectReport(t *testing.T) {
args: args{
maxReportSize: 2000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
makeTestMessage(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 102, 104, 106, 108}),
makeTestCommitReport(10, 1, 100, 999, 10101010101, []cciptypes.SeqNum{100, 102, 104, 106, 108}),
},
},
expectedExecReports: 1,
expectedCommitReports: 1,
expectedExecThings: []int{4},
lastReportExecuted: []cciptypes.SeqNum{100, 101, 102, 103, 104, 105, 106, 107, 108},
},
// TODO: error cases
{
name: "broken report",
args: args{
maxReportSize: 10000,
reports: []cciptypes.ExecutePluginCommitDataWithMessages{
breakCommitReport(makeTestCommitReport(10, 1, 100, 999, 10101010101, nil)),
},
},
wantErr: "unable to build a single chain report",
},
}
for _, tt := range tests {
tt := tt
Expand All @@ -406,6 +435,7 @@ func Test_selectReport(t *testing.T) {
assert.Contains(t, err.Error(), tt.wantErr)
return
}
require.NoError(t, err)
require.Len(t, execReports, tt.expectedExecReports)
require.Len(t, commitReports, tt.expectedCommitReports)
for i, execReport := range execReports {
Expand All @@ -414,6 +444,7 @@ func Test_selectReport(t *testing.T) {
assert.NotEmptyf(t, execReport.Proofs, "Proof should not be empty.")
assertMerkleRoot(t, hasher, execReport, tt.args.reports[i])
}
// If the last report is partially executed, the executed messages can be checked.
if len(execReports) > 0 && len(tt.lastReportExecuted) > 0 {
lastReport := commitReports[len(commitReports)-1]
assert.ElementsMatch(t, tt.lastReportExecuted, lastReport.ExecutedMessages)
Expand Down

0 comments on commit 3c458a4

Please sign in to comment.