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

Solana plugin codec implementation #15816

Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
71b06dc
add solana commit codec, need to add test
huangzhen1997 Nov 19, 2024
c79a406
ccipsolana: Import bindings
archseer Dec 24, 2024
0fe505c
Merge branch 'develop' into NONEVM-935/implement-ccip-solana-plugin-c…
huangzhen1997 Dec 30, 2024
de95bf1
update go list
huangzhen1997 Dec 30, 2024
e51bd46
add test and update commit price processing logic
huangzhen1997 Dec 31, 2024
86c9c17
fix lint
huangzhen1997 Dec 31, 2024
237e4f4
add exec, and test in progress
huangzhen1997 Dec 31, 2024
7ae43ed
added unit tests for execute, need clean up and verify requirements
huangzhen1997 Jan 1, 2025
4e2ea85
fix go mod in deployment
huangzhen1997 Jan 2, 2025
0d49c2e
fix lint
huangzhen1997 Jan 2, 2025
5849b3b
lint
huangzhen1997 Jan 2, 2025
70db87e
go mod
huangzhen1997 Jan 2, 2025
d2a7a39
update
huangzhen1997 Jan 2, 2025
ae3e43c
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
huangzhen1997 Jan 3, 2025
11cd2f3
add extra args and destExec support
huangzhen1997 Jan 3, 2025
40abc5c
minor
huangzhen1997 Jan 3, 2025
4e2f647
cleanup
huangzhen1997 Jan 3, 2025
558c0ff
update
huangzhen1997 Jan 3, 2025
07acdb1
fix mod
huangzhen1997 Jan 3, 2025
0c0b802
update
huangzhen1997 Jan 3, 2025
f0a5a0e
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
huangzhen1997 Jan 3, 2025
22ad68c
revert mod change
huangzhen1997 Jan 3, 2025
effd030
add changeset
huangzhen1997 Jan 3, 2025
26e9cb3
fix smoke test
huangzhen1997 Jan 3, 2025
b988745
fix lint
huangzhen1997 Jan 3, 2025
56d85d5
revert go mod
huangzhen1997 Jan 3, 2025
75ae059
fix
huangzhen1997 Jan 6, 2025
0272e75
revert
huangzhen1997 Jan 6, 2025
465d69c
revert
huangzhen1997 Jan 6, 2025
f314edc
again
huangzhen1997 Jan 6, 2025
a712c88
update
huangzhen1997 Jan 6, 2025
8c02e8b
remove file
huangzhen1997 Jan 6, 2025
bad1acb
revert
huangzhen1997 Jan 6, 2025
6023de7
update
huangzhen1997 Jan 6, 2025
23d9c80
update
huangzhen1997 Jan 6, 2025
82185a0
update version
huangzhen1997 Jan 6, 2025
8f42923
revert
huangzhen1997 Jan 6, 2025
4fdf7f7
downgrade version
huangzhen1997 Jan 6, 2025
b0b8d31
go mod tidy
huangzhen1997 Jan 6, 2025
85dfafd
tidy
huangzhen1997 Jan 6, 2025
9ec6505
add token indexes
huangzhen1997 Jan 6, 2025
a5b661d
update comment
huangzhen1997 Jan 6, 2025
e169af2
Merge branch 'solana-offchain-plugin' into NONEVM-935/implement-ccip-…
huangzhen1997 Jan 9, 2025
a52044d
gomod
huangzhen1997 Jan 9, 2025
3f4929a
part 1
huangzhen1997 Jan 10, 2025
d5413ae
fix lint
huangzhen1997 Jan 10, 2025
03ae3ee
data type
huangzhen1997 Jan 10, 2025
6ecbec2
make generate
huangzhen1997 Jan 13, 2025
67d689c
update with new generated go binding
huangzhen1997 Jan 16, 2025
e9abe63
Merge branch 'solana-offchain-plugin' into NONEVM-935/implement-ccip-…
huangzhen1997 Jan 17, 2025
9497f40
mod tidy
huangzhen1997 Jan 17, 2025
e9ae48d
add comment
huangzhen1997 Jan 21, 2025
9c4fff2
goimport
huangzhen1997 Jan 21, 2025
12ee1f4
Merge branch 'solana-offchain-plugin' into NONEVM-935/implement-ccip-…
huangzhen1997 Jan 22, 2025
443cfe1
step 1 for parse extra args map
huangzhen1997 Jan 22, 2025
c60a925
add comment
huangzhen1997 Jan 22, 2025
24e9fa3
fix test
huangzhen1997 Jan 22, 2025
912b91c
update
huangzhen1997 Jan 22, 2025
03787a8
improvement
huangzhen1997 Jan 22, 2025
25d2acd
update
huangzhen1997 Jan 22, 2025
48464b0
tidy
huangzhen1997 Jan 22, 2025
6f80799
fix test
huangzhen1997 Jan 22, 2025
58a9497
Matt comments
huangzhen1997 Jan 22, 2025
6ea469d
Makram comments part1
huangzhen1997 Jan 23, 2025
fee6bb6
refactor
huangzhen1997 Jan 23, 2025
2d79cb0
Merge branch 'solana-offchain-plugin' into NONEVM-935/implement-ccip-…
huangzhen1997 Jan 23, 2025
80496c9
fix
huangzhen1997 Jan 23, 2025
d856147
go md
huangzhen1997 Jan 23, 2025
ed8cd1c
change commit to little endian, to do for execute
huangzhen1997 Jan 24, 2025
1bcb320
use LE
huangzhen1997 Jan 24, 2025
3ec1574
update
huangzhen1997 Jan 24, 2025
2b79eac
update
huangzhen1997 Jan 25, 2025
626a423
update padding
huangzhen1997 Jan 25, 2025
32956a6
fix make
huangzhen1997 Jan 25, 2025
9779bd2
rename
huangzhen1997 Jan 27, 2025
9822b54
update
huangzhen1997 Jan 27, 2025
12cd5c9
lower case
huangzhen1997 Jan 27, 2025
e03c253
goimport
huangzhen1997 Jan 27, 2025
283c4e4
implement dest exec data handling
huangzhen1997 Jan 28, 2025
1ede47a
fix
huangzhen1997 Jan 29, 2025
d7e246f
fix
huangzhen1997 Jan 29, 2025
3598eaa
merge
huangzhen1997 Jan 29, 2025
3a1b986
fix test
huangzhen1997 Jan 29, 2025
8a14890
fix test
huangzhen1997 Jan 29, 2025
fd469bb
Merge branch 'solana-offchain-plugin' into NONEVM-935/implement-ccip-…
huangzhen1997 Jan 31, 2025
c088d5c
mod
huangzhen1997 Jan 31, 2025
ff083a4
update
huangzhen1997 Jan 31, 2025
57999be
clean up
huangzhen1997 Jan 31, 2025
951498b
add on-chain data decoding unit test coverage
huangzhen1997 Jan 31, 2025
0c91600
fix import
huangzhen1997 Jan 31, 2025
7e72097
more test
huangzhen1997 Jan 31, 2025
0589fb8
update
huangzhen1997 Jan 31, 2025
40ea8f7
update
huangzhen1997 Feb 2, 2025
97a8278
remove unused
huangzhen1997 Feb 3, 2025
7bdb472
downgrade
huangzhen1997 Feb 3, 2025
59fc6b5
downgrade
huangzhen1997 Feb 3, 2025
7193324
rm
huangzhen1997 Feb 3, 2025
761eb11
update
huangzhen1997 Feb 3, 2025
a8f4eea
update
huangzhen1997 Feb 3, 2025
e04db54
rm
huangzhen1997 Feb 3, 2025
8f5a842
update
huangzhen1997 Feb 3, 2025
bb84f23
revert
huangzhen1997 Feb 3, 2025
d88f48e
revert
huangzhen1997 Feb 3, 2025
a459033
revert
huangzhen1997 Feb 3, 2025
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
5 changes: 5 additions & 0 deletions .changeset/violet-bears-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Solana CCIP plugin codec support for both commit and execute report #added
159 changes: 159 additions & 0 deletions core/capabilities/ccip/ccipsolana/commitcodec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package ccipsolana

import (
"bytes"
"context"
"fmt"
"math/big"

agbinary "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"

"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router"
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

// CommitPluginCodecV1 is a codec for encoding and decoding commit plugin reports.
// Compatible with:
// - "OffRamp 1.6.0-dev"
type CommitPluginCodecV1 struct{}
Copy link
Contributor

@ilija42 ilija42 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't we use the Solana Codec for this? Just define the IDL for these types, I haven't looked closely into the types being encodec, so I may be missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could try Solana codec, @archseer suggested to use the generated gobinding for this earlier, and I also think it makes sense as the EVM codec right now is using similar approach with the generated type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a general topic earlier, where we said lets use the Codec for both EVM and Solana, to make this code here chain-abstract.
But it was more work, and complex, so we abandoned that approach to be looked at at a longer term.


func NewCommitPluginCodecV1() *CommitPluginCodecV1 {
return &CommitPluginCodecV1{}
}

func (c *CommitPluginCodecV1) Encode(ctx context.Context, report cciptypes.CommitPluginReport) ([]byte, error) {
var buf bytes.Buffer
encoder := agbinary.NewBorshEncoder(&buf)
if len(report.MerkleRoots) != 1 {
return nil, fmt.Errorf("unexpected merkle root length in report: %d", len(report.MerkleRoots))
}

mr := ccip_router.MerkleRoot{
SourceChainSelector: uint64(report.MerkleRoots[0].ChainSel),
OnRampAddress: report.MerkleRoots[0].OnRampAddress,
MinSeqNr: uint64(report.MerkleRoots[0].SeqNumsRange.Start()),
MaxSeqNr: uint64(report.MerkleRoots[0].SeqNumsRange.End()),
MerkleRoot: report.MerkleRoots[0].MerkleRoot,
}

tpu := make([]ccip_router.TokenPriceUpdate, 0, len(report.PriceUpdates.TokenPriceUpdates))
for _, update := range report.PriceUpdates.TokenPriceUpdates {
token, err := solana.PublicKeyFromBase58(string(update.TokenID))
if err != nil {
return nil, fmt.Errorf("invalid token address: %s, %w", update.TokenID, err)
}
if update.Price.IsEmpty() {
return nil, fmt.Errorf("empty price for token: %s", update.TokenID)
}
tpu = append(tpu, ccip_router.TokenPriceUpdate{
SourceToken: token,
UsdPerToken: [28]uint8(encodeBigIntToFixedLengthLE(update.Price.Int, 28)),
})
}

gpu := make([]ccip_router.GasPriceUpdate, 0, len(report.PriceUpdates.GasPriceUpdates))
for _, update := range report.PriceUpdates.GasPriceUpdates {
if update.GasPrice.IsEmpty() {
return nil, fmt.Errorf("empty gas price for chain: %d", update.ChainSel)
}

gpu = append(gpu, ccip_router.GasPriceUpdate{
DestChainSelector: uint64(update.ChainSel),
UsdPerUnitGas: [28]uint8(encodeBigIntToFixedLengthLE(update.GasPrice.Int, 28)),
})
}

commit := ccip_router.CommitInput{
MerkleRoot: mr,
PriceUpdates: ccip_router.PriceUpdates{
TokenPriceUpdates: tpu,
GasPriceUpdates: gpu,
},
}

err := commit.MarshalWithEncoder(encoder)
if err != nil {
return nil, err
}

return buf.Bytes(), nil
}

func (c *CommitPluginCodecV1) Decode(ctx context.Context, bytes []byte) (cciptypes.CommitPluginReport, error) {
decoder := agbinary.NewBorshDecoder(bytes)
commitReport := ccip_router.CommitInput{}
err := commitReport.UnmarshalWithDecoder(decoder)
if err != nil {
return cciptypes.CommitPluginReport{}, err
}

merkleRoots := []cciptypes.MerkleRootChain{
{
ChainSel: cciptypes.ChainSelector(commitReport.MerkleRoot.SourceChainSelector),
OnRampAddress: commitReport.MerkleRoot.OnRampAddress,
SeqNumsRange: cciptypes.NewSeqNumRange(
cciptypes.SeqNum(commitReport.MerkleRoot.MinSeqNr),
cciptypes.SeqNum(commitReport.MerkleRoot.MaxSeqNr),
),
MerkleRoot: commitReport.MerkleRoot.MerkleRoot,
},
}

tokenPriceUpdates := make([]cciptypes.TokenPrice, 0, len(commitReport.PriceUpdates.TokenPriceUpdates))
for _, update := range commitReport.PriceUpdates.TokenPriceUpdates {
tokenPriceUpdates = append(tokenPriceUpdates, cciptypes.TokenPrice{
TokenID: cciptypes.UnknownEncodedAddress(update.SourceToken.String()),
Price: decodeLEToBigInt(update.UsdPerToken[:]),
})
}

gasPriceUpdates := make([]cciptypes.GasPriceChain, 0, len(commitReport.PriceUpdates.GasPriceUpdates))
for _, update := range commitReport.PriceUpdates.GasPriceUpdates {
gasPriceUpdates = append(gasPriceUpdates, cciptypes.GasPriceChain{
GasPrice: decodeLEToBigInt(update.UsdPerUnitGas[:]),
ChainSel: cciptypes.ChainSelector(update.DestChainSelector),
})
}

return cciptypes.CommitPluginReport{
MerkleRoots: merkleRoots,
PriceUpdates: cciptypes.PriceUpdates{
TokenPriceUpdates: tokenPriceUpdates,
GasPriceUpdates: gasPriceUpdates,
},
}, nil
}

func encodeBigIntToFixedLengthLE(bi *big.Int, length int) []byte {
// Create a fixed-length byte array
paddedBytes := make([]byte, length)

// Use FillBytes to fill the array with big-endian data, zero-padded
bi.FillBytes(paddedBytes)

// Reverse the array for little-endian encoding
for i, j := 0, len(paddedBytes)-1; i < j; i, j = i+1, j-1 {
paddedBytes[i], paddedBytes[j] = paddedBytes[j], paddedBytes[i]
}

return paddedBytes
}

func decodeLEToBigInt(data []byte) cciptypes.BigInt {
// Reverse the byte array to convert it from little-endian to big-endian
for i, j := 0, len(data)-1; i < j; i, j = i+1, j-1 {
data[i], data[j] = data[j], data[i]
}

// Use big.Int.SetBytes to construct the big.Int
bi := new(big.Int).SetBytes(data)
if bi.Int64() == 0 {
return cciptypes.NewBigInt(big.NewInt(0))
}

return cciptypes.NewBigInt(bi)
}

// Ensure CommitPluginCodec implements the CommitPluginCodec interface
var _ cciptypes.CommitPluginCodec = (*CommitPluginCodecV1)(nil)
228 changes: 228 additions & 0 deletions core/capabilities/ccip/ccipsolana/commitcodec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
package ccipsolana

import (
"bytes"
"math/big"
"math/rand"
"strconv"
"testing"

agbinary "github.com/gagliardetto/binary"
solanago "github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router"

cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/evm/utils"
)

var randomCommitReport = func() cciptypes.CommitPluginReport {
pubkey, err := solanago.NewRandomPrivateKey()
if err != nil {
panic(err)
}

return cciptypes.CommitPluginReport{
MerkleRoots: []cciptypes.MerkleRootChain{
{
OnRampAddress: cciptypes.UnknownAddress(pubkey.PublicKey().String()),
ChainSel: cciptypes.ChainSelector(rand.Uint64()),
SeqNumsRange: cciptypes.NewSeqNumRange(
cciptypes.SeqNum(rand.Uint64()),
cciptypes.SeqNum(rand.Uint64()),
),
MerkleRoot: utils.RandomBytes32(),
},
},
PriceUpdates: cciptypes.PriceUpdates{
TokenPriceUpdates: []cciptypes.TokenPrice{
{
TokenID: "C8WSPj3yyus1YN3yNB6YA5zStYtbjQWtpmKadmvyUXq8",
Price: cciptypes.NewBigInt(big.NewInt(rand.Int63())),
},
},
GasPriceUpdates: []cciptypes.GasPriceChain{
{GasPrice: cciptypes.NewBigInt(big.NewInt(rand.Int63())), ChainSel: cciptypes.ChainSelector(rand.Uint64())},
{GasPrice: cciptypes.NewBigInt(big.NewInt(rand.Int63())), ChainSel: cciptypes.ChainSelector(rand.Uint64())},
{GasPrice: cciptypes.NewBigInt(big.NewInt(rand.Int63())), ChainSel: cciptypes.ChainSelector(rand.Uint64())},
},
},
}
}

func TestCommitPluginCodecV1(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that the EVM codec tests don't decode using the onchain contracts, which is probably an oversight since the exec codec does. Is there any way we can achieve the same coverage w/ this Solana encoder? Presumably the Solana contract will attempt to decode the commit report bytes into some data structure, having that covered here means we're good to go and covers an important part of the E2E flow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it might be possible.
In Solana, we have generated go bindings for all onchain types.
So technically we could construct the onchain types via structs, and encode them via go encoders.
Then, we compare that those encoded types are same as what our offchain code calculates.
Agreed, these will be a good e2e tests.
Will talk to @huangzhen1997 on this.

testCases := []struct {
name string
report func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport
expErr bool
}{
{
name: "base report",
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
return report
},
},
{
name: "empty token address",
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
report.PriceUpdates.TokenPriceUpdates[0].TokenID = ""
return report
},
expErr: true,
},
{
name: "empty merkle root",
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
report.MerkleRoots[0].MerkleRoot = cciptypes.Bytes32{}
return report
},
},
{
name: "zero token price",
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
report.PriceUpdates.TokenPriceUpdates[0].Price = cciptypes.NewBigInt(big.NewInt(0))
return report
},
},
{
name: "zero gas price",
huangzhen1997 marked this conversation as resolved.
Show resolved Hide resolved
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
report.PriceUpdates.GasPriceUpdates[0].GasPrice = cciptypes.NewBigInt(big.NewInt(0))
return report
},
},
{
name: "empty gas price",
report: func(report cciptypes.CommitPluginReport) cciptypes.CommitPluginReport {
report.PriceUpdates.GasPriceUpdates[0].GasPrice = cciptypes.NewBigInt(nil)
return report
},
expErr: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
report := tc.report(randomCommitReport())
commitCodec := NewCommitPluginCodecV1()
ctx := testutils.Context(t)
encodedReport, err := commitCodec.Encode(ctx, report)
if tc.expErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
decodedReport, err := commitCodec.Decode(ctx, encodedReport)
require.NoError(t, err)
require.Equal(t, report, decodedReport)
})
}
}

func BenchmarkCommitPluginCodecV1_Encode(b *testing.B) {
huangzhen1997 marked this conversation as resolved.
Show resolved Hide resolved
commitCodec := NewCommitPluginCodecV1()
ctx := testutils.Context(b)

rep := randomCommitReport()
for i := 0; i < b.N; i++ {
_, err := commitCodec.Encode(ctx, rep)
require.NoError(b, err)
}
}

func BenchmarkCommitPluginCodecV1_Decode(b *testing.B) {
commitCodec := NewCommitPluginCodecV1()
ctx := testutils.Context(b)
encodedReport, err := commitCodec.Encode(ctx, randomCommitReport())
require.NoError(b, err)

for i := 0; i < b.N; i++ {
_, err := commitCodec.Decode(ctx, encodedReport)
require.NoError(b, err)
}
}

func BenchmarkCommitPluginCodecV1_Encode_Decode(b *testing.B) {
commitCodec := NewCommitPluginCodecV1()
ctx := testutils.Context(b)

rep := randomCommitReport()
for i := 0; i < b.N; i++ {
encodedReport, err := commitCodec.Encode(ctx, rep)
require.NoError(b, err)
decodedReport, err := commitCodec.Decode(ctx, encodedReport)
require.NoError(b, err)
require.Equal(b, rep, decodedReport)
}
}

func Test_DecodingCommitReport(t *testing.T) {
t.Run("decode on-chain commit report", func(t *testing.T) {
chainSel := cciptypes.ChainSelector(rand.Uint64())
minSeqNr := rand.Uint64()
maxSeqNr := minSeqNr + 10
onRampAddr, err := solanago.NewRandomPrivateKey()
require.NoError(t, err)

tokenSource := solanago.MustPublicKeyFromBase58("C8WSPj3yyus1YN3yNB6YA5zStYtbjQWtpmKadmvyUXq8")
tokenPrice := encodeBigIntToFixedLengthLE(big.NewInt(rand.Int63()), 28)
gasPrice := encodeBigIntToFixedLengthLE(big.NewInt(rand.Int63()), 28)
merkleRoot := utils.RandomBytes32()

tpu := []ccip_router.TokenPriceUpdate{
{
SourceToken: tokenSource,
UsdPerToken: [28]uint8(tokenPrice),
},
}

gpu := []ccip_router.GasPriceUpdate{
{UsdPerUnitGas: [28]uint8(gasPrice), DestChainSelector: uint64(chainSel)},
{UsdPerUnitGas: [28]uint8(gasPrice), DestChainSelector: uint64(chainSel)},
{UsdPerUnitGas: [28]uint8(gasPrice), DestChainSelector: uint64(chainSel)},
}

onChainReport := ccip_router.CommitInput{
MerkleRoot: ccip_router.MerkleRoot{
SourceChainSelector: uint64(chainSel),
OnRampAddress: onRampAddr.PublicKey().Bytes(),
MinSeqNr: minSeqNr,
MaxSeqNr: maxSeqNr,
MerkleRoot: merkleRoot,
},
PriceUpdates: ccip_router.PriceUpdates{
TokenPriceUpdates: tpu,
GasPriceUpdates: gpu,
},
}

var buf bytes.Buffer
encoder := agbinary.NewBorshEncoder(&buf)
err = onChainReport.MarshalWithEncoder(encoder)
require.NoError(t, err)

commitCodec := NewCommitPluginCodecV1()
decode, err := commitCodec.Decode(testutils.Context(t), buf.Bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also do the reverse for the same data?
I mean encode with commitCodec, and then decode with borsch decoder?

require.NoError(t, err)
mr := decode.MerkleRoots[0]

// check decoded ocr report merkle root matches with on-chain report
require.Equal(t, strconv.FormatUint(minSeqNr, 10), mr.SeqNumsRange.Start().String())
require.Equal(t, strconv.FormatUint(maxSeqNr, 10), mr.SeqNumsRange.End().String())
require.Equal(t, cciptypes.UnknownAddress(onRampAddr.PublicKey().Bytes()), mr.OnRampAddress)
require.Equal(t, cciptypes.Bytes32(merkleRoot), mr.MerkleRoot)

// check decoded ocr report token price update matches with on-chain report
pu := decode.PriceUpdates.TokenPriceUpdates[0]
require.Equal(t, decodeLEToBigInt(tokenPrice), pu.Price)
require.Equal(t, cciptypes.UnknownEncodedAddress(tokenSource.String()), pu.TokenID)

// check decoded ocr report gas price update matches with on-chain report
gu := decode.PriceUpdates.GasPriceUpdates[0]
require.Equal(t, decodeLEToBigInt(gasPrice), gu.GasPrice)
require.Equal(t, chainSel, gu.ChainSel)
})
}
Loading
Loading