Skip to content

Commit

Permalink
init ocr3 build lint test (#951)
Browse files Browse the repository at this point in the history
Add a new workflow that builds lints and tests the new ccip module.
  • Loading branch information
dimkouv authored Jun 4, 2024
1 parent 4de8351 commit c786388
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-pandas-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ccip": patch
---

#added Add ccip ocr3 offchain workflow for building, linting and testing the code.
33 changes: 33 additions & 0 deletions .github/workflows/ccip-ocr3-build-lint-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Build lint and test CCIP-OCR3"

on:
pull_request:
paths:
- core/services/ocr3/plugins/ccip/**

jobs:
build-lint-test:
runs-on: ubuntu-20.04
strategy:
matrix:
go-version: ['1.21']
defaults:
run:
working-directory: ./core/services/ocr3/plugins/ccip
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
run: go version
- name: Build
run: go build -v ./...
- name: Install linter
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0
- name: Run linter
run: golangci-lint run
- name: Run tests
run: go test -race -fullpath -shuffle on -count 20 ./...
6 changes: 6 additions & 0 deletions core/services/ocr3/plugins/ccip/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

ensure_go_1_21:
@go version | grep -q 'go1.21' || (echo "Please use go1.21" && exit 1)

test: ensure_go_1_21
go test -race -fullpath -shuffle on -count 10 ./...
6 changes: 1 addition & 5 deletions core/services/ocr3/plugins/ccip/commit/plugin_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,9 @@ func gasPricesConsensus(lggr logger.Logger, observations []model.CommitPluginObs
continue
}

values := make([]model.BigInt, 0, len(gasPrices))
for _, gasPrice := range gasPrices {
values = append(values, gasPrice)
}
consensusGasPrices = append(
consensusGasPrices,
model.NewGasPriceChain(slicelib.BigIntSortedMiddle(values).Int, chain),
model.NewGasPriceChain(slicelib.BigIntSortedMiddle(gasPrices).Int, chain),
)
}

Expand Down
7 changes: 4 additions & 3 deletions core/services/ocr3/plugins/ccip/execute/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func getPendingExecutedReports(ctx context.Context, ccipReader reader.CCIP, dest

var executedMessages []model.SeqNumRange
for _, seqRange := range ranges {
executedMessagesForRange, err := ccipReader.ExecutedMessageRanges(ctx, selector, dest, seqRange)
if err != nil {
return nil, time.Time{}, err
executedMessagesForRange, err2 := ccipReader.ExecutedMessageRanges(ctx, selector, dest, seqRange)
if err2 != nil {
return nil, time.Time{}, err2
}
executedMessages = append(executedMessages, executedMessagesForRange...)
}
Expand Down Expand Up @@ -125,6 +125,7 @@ func (p *Plugin) Observation(ctx context.Context, outctx ocr3types.OutcomeContex
// Phase 2: Gather messages from the source chains and build the execution report.
messages := make(model.ExecutePluginMessageObservations)
if len(previousOutcome.Messages) == 0 {
fmt.Println("TODO: No messages to execute. This is expected after a cold start.")
// No messages to execute.
// This is expected after a cold start.
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hashlib

import (
"math/rand"
"crypto/rand"
"testing"

"github.com/stretchr/testify/assert"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ func TestBigIntSortedMiddle(t *testing.T) {
{
name: "base case",
vals: []model.BigInt{
{big.NewInt(1)},
{big.NewInt(2)},
{big.NewInt(4)},
{big.NewInt(5)},
{Int: big.NewInt(1)},
{Int: big.NewInt(2)},
{Int: big.NewInt(4)},
{Int: big.NewInt(5)},
},
want: model.BigInt{Int: big.NewInt(4)},
},
{
name: "not sorted",
vals: []model.BigInt{
{big.NewInt(100)},
{big.NewInt(50)},
{big.NewInt(30)},
{big.NewInt(110)},
{Int: big.NewInt(100)},
{Int: big.NewInt(50)},
{Int: big.NewInt(30)},
{Int: big.NewInt(110)},
},
want: model.BigInt{Int: big.NewInt(100)},
},
Expand All @@ -42,7 +42,7 @@ func TestBigIntSortedMiddle(t *testing.T) {
{
name: "one item",
vals: []model.BigInt{
{big.NewInt(123)},
{Int: big.NewInt(123)},
},
want: model.BigInt{Int: big.NewInt(123)},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestGroupBy(t *testing.T) {
for _, k := range keys {
assert.Equal(t, tc.expGroups[k], groups[k])
}
return
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package testhelpers

import (
"context"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -173,7 +173,7 @@ type RoundResult[RI any] struct {
func countUniqueOutcomes(outcomes []ocr3types.Outcome) int {
flattenedHashes := make([]string, 0, len(outcomes))
for _, o := range outcomes {
h := sha1.New()
h := sha256.New()
h.Write(o)
flattenedHashes = append(flattenedHashes, hex.EncodeToString(h.Sum(nil)))
}
Expand All @@ -183,7 +183,7 @@ func countUniqueOutcomes(outcomes []ocr3types.Outcome) int {
func countUniqueReports[RI any](reports []ocr3types.ReportWithInfo[RI]) int {
flattenedHashes := make([]string, 0, len(reports))
for _, report := range reports {
h := sha1.New()
h := sha256.New()
h.Write(report.Report)
flattenedHashes = append(flattenedHashes, hex.EncodeToString(h.Sum(nil)))
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr3/plugins/ccip/internal/model/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type CCIPMsg struct {

func (c CCIPMsg) String() string {
js, _ := json.Marshal(c)
return fmt.Sprintf("%s", js)
return string(js)
}

type CCIPMsgBaseDetails struct {
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr3/plugins/ccip/internal/model/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type CommitPluginObservation struct {
NewMsgs []CCIPMsgBaseDetails `json:"newMsgs"`
GasPrices []GasPriceChain `json:"gasPrices,string"`
GasPrices []GasPriceChain `json:"gasPrices"`
TokenPrices []TokenPrice `json:"tokenPrices"`
MaxSeqNums []SeqNumChain `json:"maxSeqNums"`
PluginConfig CommitPluginConfig `json:"pluginConfig"`
Expand Down

0 comments on commit c786388

Please sign in to comment.