Skip to content

Commit

Permalink
write test for backwards compatibility in automation report encoding …
Browse files Browse the repository at this point in the history
…function (#11430)
  • Loading branch information
RyanRHall authored and Borja Aranda committed Dec 14, 2023
1 parent d2bbc37 commit a933ba1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package encoding

import (
"bytes"
"encoding/hex"
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -12,6 +15,19 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core"
)

var expectedEncodedReport []byte

func init() {
b, err := os.ReadFile("../fixtures/expected_encoded_report.txt")
if err != nil {
panic(err)
}
expectedEncodedReport, err = hex.DecodeString(string(b))
if err != nil {
panic(err)
}
}

func TestReportEncoder_EncodeExtract(t *testing.T) {
encoder := reportEncoder{
packer: NewAbiPacker(),
Expand Down Expand Up @@ -93,6 +109,25 @@ func TestReportEncoder_EncodeExtract(t *testing.T) {
}
}

func TestReportEncoder_BackwardsCompatibility(t *testing.T) {
encoder := reportEncoder{
packer: NewAbiPacker(),
}
results := []ocr2keepers.CheckResult{
newResult(1, 2, core.GenUpkeepID(ocr2keepers.LogTrigger, "10"), 5, 6),
newResult(3, 4, core.GenUpkeepID(ocr2keepers.ConditionTrigger, "20"), 7, 8),
}
encoded, err := encoder.Encode(results...)
assert.NoError(t, err)
if !bytes.Equal(encoded, expectedEncodedReport) {
assert.Fail(t,
"encoded report does not match expected encoded report; "+
"this means a breaking change has been made to the report encoding function; "+
"only update this test if non-backwards-compatible changes are necessary",
)
}
}

func newResult(block int64, checkBlock ocr2keepers.BlockNumber, id ocr2keepers.UpkeepIdentifier, fastGasWei, linkNative int64) ocr2keepers.CheckResult {
tp := core.GetUpkeepType(id)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000020100000000000000000000000000000131300000000000000000000000000000010000000000000000000000000000003230000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000a0aaaaaaaa9012345678901234567890123456789012345678901234567890123412345678901234567890123456789012345678901234567890123456789012340000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000101020304050607080102030405060708010203040506070801020304050607080000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000301020304050607080102030405060708010203040506070801020304050607080000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005646174613000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000056461746130000000000000000000000000000000000000000000000000000000

0 comments on commit a933ba1

Please sign in to comment.