Skip to content

Commit 7e822af

Browse files
committed
update tests, naming
1 parent 4c7d7a9 commit 7e822af

File tree

8 files changed

+141
-12
lines changed

8 files changed

+141
-12
lines changed

pkg/loop/internal/pb/ccipocr3/codec.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/ccipocr3/codec.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ message DecodeDestExecDataToMapResponse {
118118
// ExtraDataCodecBundle messages
119119
message DecodeExtraArgsWithChainSelectorRequest {
120120
bytes extra_args = 1;
121-
uint64 source_chain_selector = 2; // ChainSelector
121+
uint64 source_chain_selector = 2;
122122
}
123123

124124
message DecodeExtraArgsWithChainSelectorResponse {
@@ -127,7 +127,7 @@ message DecodeExtraArgsWithChainSelectorResponse {
127127

128128
message DecodeTokenAmountDestExecDataRequest {
129129
bytes dest_exec_data = 1;
130-
uint64 source_chain_selector = 2; // ChainSelector
130+
uint64 source_chain_selector = 2;
131131
}
132132

133133
message DecodeTokenAmountDestExecDataResponse {

pkg/loop/internal/pb/relayer.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/loop/internal/pb/relayer.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ message CCIPProviderArgs {
6363
string OffRampAddress = 4;
6464
uint32 pluginType = 5;
6565
map<string, bytes> synced_addresses = 6; // map[contract_name]contract_address
66-
uint32 extraDataCodecBundleID = 7; // LOOP service ID for ExtraDataCodecBundle
66+
uint32 extraDataCodecBundleID = 7; // LOOP service ID for ExtraDataCodecBundle served by core node
6767
}
6868

6969
// NewContractWriterRequest has request parameters for [github.com/smartcontractkit/chainlink-common/pkg/loop.Relayer.NewContractWriter].

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/codec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
9-
9+
1010
ccipocr3pb "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb/ccipocr3"
1111
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
1212
)

pkg/loop/internal/relayer/pluginprovider/ext/ccipocr3/convert_test.go

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,3 +1594,132 @@ func TestTokenInfoMapNilHandling(t *testing.T) {
15941594
assert.Len(t, convertedMap, 0)
15951595
})
15961596
}
1597+
1598+
// TestExtraDataCodecBundleConversion tests the map conversion logic used by ExtraDataCodecBundle methods
1599+
// This test verifies that round-trip conversion preserves structure and semantic meaning
1600+
func TestExtraDataCodecBundleConversion(t *testing.T) {
1601+
t.Run("Nil map round-trip", func(t *testing.T) {
1602+
// Test that nil maps remain nil after round-trip
1603+
pbMap, err := goMapToPbMap(nil)
1604+
require.NoError(t, err)
1605+
1606+
result, err := pbMapToGoMap(pbMap)
1607+
require.NoError(t, err)
1608+
assert.Nil(t, result, "nil input should result in nil output")
1609+
})
1610+
1611+
t.Run("Empty map round-trip", func(t *testing.T) {
1612+
// Test that empty maps remain empty after round-trip
1613+
emptyMap := map[string]any{}
1614+
pbMap, err := goMapToPbMap(emptyMap)
1615+
require.NoError(t, err)
1616+
1617+
result, err := pbMapToGoMap(pbMap)
1618+
require.NoError(t, err)
1619+
assert.NotNil(t, result, "empty map should not become nil")
1620+
assert.Equal(t, 0, len(result), "empty map should remain empty")
1621+
})
1622+
1623+
t.Run("ExtraArgs-like data structure preservation", func(t *testing.T) {
1624+
// Test typical ExtraArgs structure with basic types
1625+
input := map[string]any{
1626+
"gasLimit": uint64(100000),
1627+
"gasPrice": uint64(20000000000),
1628+
"enabled": true,
1629+
"data": []byte{0x01, 0x02, 0x03},
1630+
}
1631+
1632+
pbMap, err := goMapToPbMap(input)
1633+
require.NoError(t, err, "conversion to protobuf should succeed")
1634+
1635+
result, err := pbMapToGoMap(pbMap)
1636+
require.NoError(t, err, "conversion from protobuf should succeed")
1637+
1638+
// Verify structure is preserved
1639+
assert.Equal(t, len(input), len(result), "map size should be preserved")
1640+
1641+
// Verify all keys exist
1642+
for key := range input {
1643+
assert.Contains(t, result, key, "key %s should exist after round-trip", key)
1644+
}
1645+
1646+
// Verify specific values that should be exactly preserved
1647+
assert.Equal(t, input["enabled"], result["enabled"], "bool values should be preserved")
1648+
assert.Equal(t, input["data"], result["data"], "byte slice values should be preserved")
1649+
1650+
// For numeric values, verify semantic equivalence (protobuf may normalize types)
1651+
assert.Equal(t, fmt.Sprintf("%v", input["gasLimit"]), fmt.Sprintf("%v", result["gasLimit"]), "gasLimit should be semantically equal")
1652+
assert.Equal(t, fmt.Sprintf("%v", input["gasPrice"]), fmt.Sprintf("%v", result["gasPrice"]), "gasPrice should be semantically equal")
1653+
})
1654+
1655+
t.Run("BigInt preservation", func(t *testing.T) {
1656+
// Test various BigInt values that are commonly used in ExtraArgs/DestExecData
1657+
input := map[string]any{
1658+
"zero": big.NewInt(0),
1659+
"small": big.NewInt(42),
1660+
"large": big.NewInt(1000000000000000000), // 1 ETH in wei
1661+
"negative": big.NewInt(-123456789),
1662+
}
1663+
1664+
pbMap, err := goMapToPbMap(input)
1665+
require.NoError(t, err)
1666+
1667+
result, err := pbMapToGoMap(pbMap)
1668+
require.NoError(t, err)
1669+
1670+
// Verify all BigInt values are preserved exactly
1671+
for key, originalVal := range input {
1672+
resultVal, exists := result[key]
1673+
require.True(t, exists, "key %s should exist", key)
1674+
1675+
originalBigInt := originalVal.(*big.Int)
1676+
resultBigInt, ok := resultVal.(*big.Int)
1677+
require.True(t, ok, "result[%s] should be *big.Int", key)
1678+
assert.Equal(t, originalBigInt.String(), resultBigInt.String(), "BigInt value should be preserved for key %s", key)
1679+
}
1680+
})
1681+
1682+
t.Run("Nested structure preservation", func(t *testing.T) {
1683+
// Test nested maps and arrays as might appear in DestExecData
1684+
input := map[string]any{
1685+
"version": uint32(1),
1686+
"config": map[string]any{
1687+
"maxGas": uint64(500000),
1688+
"multiplier": float64(1.5),
1689+
},
1690+
"amounts": []any{
1691+
big.NewInt(1000),
1692+
big.NewInt(2000),
1693+
},
1694+
}
1695+
1696+
pbMap, err := goMapToPbMap(input)
1697+
require.NoError(t, err)
1698+
1699+
result, err := pbMapToGoMap(pbMap)
1700+
require.NoError(t, err)
1701+
1702+
// Verify top-level structure
1703+
assert.Equal(t, len(input), len(result), "top-level map size should be preserved")
1704+
1705+
// Verify nested map structure
1706+
configResult, ok := result["config"].(map[string]any)
1707+
require.True(t, ok, "config should remain a map")
1708+
configInput := input["config"].(map[string]any)
1709+
assert.Equal(t, len(configInput), len(configResult), "nested map size should be preserved")
1710+
1711+
// Verify array structure
1712+
amountsResult, ok := result["amounts"].([]any)
1713+
require.True(t, ok, "amounts should remain an array")
1714+
amountsInput := input["amounts"].([]any)
1715+
assert.Equal(t, len(amountsInput), len(amountsResult), "array size should be preserved")
1716+
1717+
// Verify BigInt values in array are preserved
1718+
for i, originalAmount := range amountsInput {
1719+
originalBigInt := originalAmount.(*big.Int)
1720+
resultBigInt, ok := amountsResult[i].(*big.Int)
1721+
require.True(t, ok, "array element should remain *big.Int")
1722+
assert.Equal(t, originalBigInt.String(), resultBigInt.String(), "BigInt value should be preserved")
1723+
}
1724+
})
1725+
}

pkg/loop/internal/relayer/relayer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/relayer/pluginprovider/ocr2"
3333
looptypes "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/types"
3434
"github.com/smartcontractkit/chainlink-common/pkg/types"
35-
"github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
35+
ccipocr3types "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
3636
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
3737
)
3838

@@ -744,7 +744,7 @@ func (r *relayerServer) NewCCIPProvider(ctx context.Context, request *pb.NewCCIP
744744
return nil, fmt.Errorf("invalid uuid bytes for ExternalJobID: %w", err)
745745
}
746746

747-
var extraDataCodecBundle ccipocr3.ExtraDataCodecBundle
747+
var extraDataCodecBundle ccipocr3types.ExtraDataCodecBundle
748748
var extraDataCodecRes net.Resource
749749

750750
// If ExtraDataCodecBundleID is provided, dial the service
@@ -763,7 +763,7 @@ func (r *relayerServer) NewCCIPProvider(ctx context.Context, request *pb.NewCCIP
763763
ChainWriterConfig: rargs.ChainWriterConfig,
764764
OffRampAddress: rargs.OffRampAddress,
765765
PluginType: rargs.PluginType,
766-
ExtraDataCodecBundle: extraDataCodecBundle, // Pass the dialed client
766+
ExtraDataCodecBundle: extraDataCodecBundle,
767767
}
768768

769769
provider, err := r.impl.NewCCIPProvider(ctx, ccipProviderArgs)

pkg/types/ccipocr3/plugincodec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestExtraDataCodec_DecodeExtraArgs(t *testing.T) {
12-
extraDataCodec := ExtraDataCodec{
12+
extraDataCodec := ExtraDataCodecMap{
1313
chainsel.FamilySolana: nil,
1414
}
1515

@@ -41,7 +41,7 @@ func TestExtraDataCodec_DecodeExtraArgs(t *testing.T) {
4141
}
4242

4343
func TestExtraDataCodec_DecodeTokenAmountDestExecData(t *testing.T) {
44-
extraDataCodec := ExtraDataCodec{
44+
extraDataCodec := ExtraDataCodecMap{
4545
chainsel.FamilySolana: nil,
4646
}
4747

0 commit comments

Comments
 (0)