Skip to content
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

Write test for backwards compatibility in automation report encoding function #11430

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading