Skip to content

Commit

Permalink
lint go
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Dec 30, 2024
1 parent a383ccd commit f9fe424
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 11 additions & 11 deletions relayer/pkg/chainlink/ocr2/medianreport/onchainconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func (codec OnchainConfigCodec) DecodeToFelts(b []byte) ([]*big.Int, error) {
return []*big.Int{}, fmt.Errorf("unexpected version of OnchainConfig, expected %v, got %v", OnchainConfigVersion, configVersion.Int64())
}

min := new(big.Int).SetBytes(b[byteWidth : 2*byteWidth])
max := new(big.Int).SetBytes(b[2*byteWidth:])
minVal := new(big.Int).SetBytes(b[byteWidth : 2*byteWidth])
maxVal := new(big.Int).SetBytes(b[2*byteWidth:])

return []*big.Int{configVersion, min, max}, nil
return []*big.Int{configVersion, minVal, maxVal}, nil
}

// Decode converts the onchainconfig via the outputs of DecodeToFelts into unsigned big.Ints that libocr expects
Expand All @@ -49,34 +49,34 @@ func (codec OnchainConfigCodec) Decode(ctx context.Context, b []byte) (median.On
return median.OnchainConfig{}, err
}

min := felts[1]
max := felts[2]
minVal := felts[1]
maxVal := felts[2]

if !(min.Cmp(max) <= 0) {
return median.OnchainConfig{}, fmt.Errorf("OnchainConfig min (%v) should not be greater than max(%v)", min, max)
}

return median.OnchainConfig{Min: min, Max: max}, nil
return median.OnchainConfig{Min: minVal, Max: maxVal}, nil
}

// EncodeFromFelt encodes the config where min & max are big.Int representations of a felt
// Cairo has no notion of signed values: min and max values will be non-negative
func (codec OnchainConfigCodec) EncodeFromFelt(version, min, max *big.Int) ([]byte, error) {
func (codec OnchainConfigCodec) EncodeFromFelt(version, minVal, maxVal *big.Int) ([]byte, error) {
if version.Uint64() != OnchainConfigVersion {
return nil, fmt.Errorf("unexpected version of OnchainConfig, expected %v, got %v", OnchainConfigVersion, version.Int64())
}

if min.Sign() == -1 || max.Sign() == -1 {
return nil, fmt.Errorf("starknet does not support negative values: min = (%v) and max = (%v)", min, max)
if minVal.Sign() == -1 || maxVal.Sign() == -1 {
return nil, fmt.Errorf("starknet does not support negative values: min = (%v) and max = (%v)", minVal, maxVal)
}

result := []byte{}
versionBytes := make([]byte, byteWidth)
minBytes := make([]byte, byteWidth)
maxBytes := make([]byte, byteWidth)
result = append(result, version.FillBytes(versionBytes)...)
result = append(result, min.FillBytes(minBytes)...)
result = append(result, max.FillBytes(maxBytes)...)
result = append(result, minVal.FillBytes(minBytes)...)
result = append(result, maxVal.FillBytes(maxBytes)...)

return result, nil
}
Expand Down
5 changes: 2 additions & 3 deletions relayer/pkg/chainlink/ocr2/medianreport/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func TestMedianFromReport(t *testing.T) {
}

for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
ctx := tests.Context(t)
var pos []median.ParsedAttributedObservation
Expand All @@ -229,9 +228,9 @@ func TestMedianFromReport(t *testing.T) {
}
report, err := cdc.BuildReport(ctx, pos)
require.NoError(t, err)
max, err := cdc.MaxReportLength(ctx, len(tc.obs))
maxReportLength, err := cdc.MaxReportLength(ctx, len(tc.obs))
require.NoError(t, err)
assert.Equal(t, len(report), max)
assert.Equal(t, len(report), maxReportLength)
med, err := cdc.MedianFromReport(ctx, report)
require.NoError(t, err)
assert.Equal(t, tc.expectedMedian.String(), med.String())
Expand Down

0 comments on commit f9fe424

Please sign in to comment.