Skip to content

Commit

Permalink
Post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Sep 30, 2024
1 parent f7e8c51 commit c3056a6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/capabilities/ccip/ccipevm/tokendata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewEVMTokenDataEncoder() EVMTokenDataEncoder {
}

func (e EVMTokenDataEncoder) EncodeUSDC(_ context.Context, message cciptypes.Bytes, attestation cciptypes.Bytes) (cciptypes.Bytes, error) {
return abihelpers.EncodeAbiStruct[usdcAttestationPayload](usdcAttestationPayload{
return abihelpers.EncodeAbiStruct(usdcAttestationPayload{
Message: message,
Attestation: attestation,
})
Expand Down
63 changes: 63 additions & 0 deletions core/capabilities/ccip/ccipevm/tokendata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ccipevm

import (
"testing"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
)

func Test_EVMTokenDataEncoder(t *testing.T) {
var empty usdcAttestationPayload
encoder := NewEVMTokenDataEncoder()

tt := []struct {
name string
message []byte
attestation []byte
}{
{
name: "empty both fields",
message: nil,
attestation: []byte{},
},
{
name: "empty attestation",
message: []byte("message"),
attestation: nil,
},
{
message: []byte("message"),
attestation: []byte("attestation"),
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got, err := encoder.EncodeUSDC(tests.Context(t), tc.message, tc.attestation)
require.NoError(t, err)

decoded, err := abihelpers.ABIDecode(empty.AbiString(), got)
require.NoError(t, err)

converted := abi.ConvertType(decoded[0], &empty)
casted, ok := converted.(*usdcAttestationPayload)
require.True(t, ok)

if tc.message == nil {
require.Empty(t, casted.Message)
} else {
require.Equal(t, tc.message, casted.Message)
}

if tc.attestation == nil {
require.Empty(t, casted.Attestation)
} else {
require.Equal(t, tc.attestation, casted.Attestation)
}
})
}
}

0 comments on commit c3056a6

Please sign in to comment.