Skip to content

Commit 8f950d6

Browse files
committed
[CAL][3] - Implement GetChainFeeComponents
1 parent 2f73064 commit 8f950d6

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

pkg/chainaccessor/legacy_accessor.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ func (l *LegacyAccessor) GetContractAddress(contractName string) ([]byte, error)
5959
return addressBytes, nil
6060
}
6161

62-
func (l *LegacyAccessor) GetChainFeeComponents(
63-
ctx context.Context,
64-
) map[cciptypes.ChainSelector]cciptypes.ChainFeeComponents {
65-
// TODO(NONEVM-1865): implement
66-
panic("implement me")
67-
}
62+
func (l *LegacyAccessor) GetChainFeeComponents(ctx context.Context) (cciptypes.ChainFeeComponents, error) {
63+
fc, err := l.contractWriter.GetFeeComponents(ctx)
64+
if err != nil {
65+
return cciptypes.ChainFeeComponents{}, fmt.Errorf("get fee components: %w", err)
66+
}
6867

69-
func (l *LegacyAccessor) GetDestChainFeeComponents(ctx context.Context) (types.ChainFeeComponents, error) {
70-
// TODO(NONEVM-1865): implement
71-
panic("implement me")
68+
return *fc, nil
7269
}
7370

7471
func (l *LegacyAccessor) Sync(ctx context.Context, contracts cciptypes.ContractAddresses) error {

pkg/reader/ccip.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,12 +881,12 @@ func (r *ccipChainReader) GetChainsFeeComponents(
881881
feeComponents := make(map[cciptypes.ChainSelector]types.ChainFeeComponents, len(r.contractWriters))
882882

883883
for _, chain := range chains {
884-
chainWriter, ok := r.contractWriters[chain]
885-
if !ok {
886-
lggr.Errorw("contract writer not found", "chain", chain)
884+
if err := validateAccessorExistence(r.accessors, chain); err != nil {
885+
lggr.Errorw("accessor not found", "chain", chain, "err", err)
887886
continue
888887
}
889-
feeComponent, err := chainWriter.GetFeeComponents(ctx)
888+
889+
feeComponent, err := r.accessors[chain].GetChainFeeComponents(ctx)
890890
if err != nil {
891891
lggr.Errorw("failed to get chain fee components", "chain", chain, "err", err)
892892
continue
@@ -901,7 +901,7 @@ func (r *ccipChainReader) GetChainsFeeComponents(
901901
continue
902902
}
903903

904-
feeComponents[chain] = *feeComponent
904+
feeComponents[chain] = feeComponent
905905
}
906906
return feeComponents
907907
}

pkg/reader/ccip_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,6 @@ func TestCCIPChainReader_getFeeQuoterTokenPriceUSD(t *testing.T) {
10851085
}
10861086

10871087
func TestCCIPFeeComponents_HappyPath(t *testing.T) {
1088-
destCR := reader_mocks.NewMockContractReaderFacade(t)
1089-
destCR.EXPECT().Bind(mock.Anything, mock.Anything).Return(nil)
1090-
10911088
cw := writer_mocks.NewMockContractWriter(t)
10921089
cw.EXPECT().GetFeeComponents(mock.Anything).Return(
10931090
&types.ChainFeeComponents{
@@ -1097,15 +1094,25 @@ func TestCCIPFeeComponents_HappyPath(t *testing.T) {
10971094
)
10981095

10991096
contractWriters := make(map[cciptypes.ChainSelector]types.ContractWriter)
1100-
// Missing writer for chainB
11011097
contractWriters[chainA] = cw
1098+
contractWriters[chainB] = cw
11021099
contractWriters[chainC] = cw
11031100

1101+
sourceCRs := make(map[cciptypes.ChainSelector]*reader_mocks.MockContractReaderFacade)
1102+
for _, chain := range []cciptypes.ChainSelector{chainA, chainB, chainC} {
1103+
sourceCRs[chain] = reader_mocks.NewMockContractReaderFacade(t)
1104+
}
1105+
1106+
destChain := chainC
1107+
sourceCRs[destChain].EXPECT().Bind(mock.Anything, mock.Anything).Return(nil)
1108+
11041109
ccipReader, err := newCCIPChainReaderInternal(
11051110
tests.Context(t),
11061111
logger.Test(t),
11071112
map[cciptypes.ChainSelector]contractreader.ContractReaderFacade{
1108-
chainC: destCR,
1113+
chainA: sourceCRs[chainA],
1114+
chainB: sourceCRs[chainB],
1115+
chainC: sourceCRs[chainC],
11091116
},
11101117
contractWriters,
11111118
chainC,
@@ -1124,10 +1131,12 @@ func TestCCIPFeeComponents_HappyPath(t *testing.T) {
11241131

11251132
ctx := context.Background()
11261133
feeComponents := ccipReader.GetChainsFeeComponents(ctx, []cciptypes.ChainSelector{chainA, chainB, chainC})
1127-
assert.Len(t, feeComponents, 2)
1134+
assert.Len(t, feeComponents, 3)
11281135
assert.Equal(t, big.NewInt(1), feeComponents[chainA].ExecutionFee)
1129-
assert.Equal(t, big.NewInt(2), feeComponents[chainA].DataAvailabilityFee)
1136+
assert.Equal(t, big.NewInt(1), feeComponents[chainB].ExecutionFee)
11301137
assert.Equal(t, big.NewInt(1), feeComponents[chainC].ExecutionFee)
1138+
assert.Equal(t, big.NewInt(2), feeComponents[chainA].DataAvailabilityFee)
1139+
assert.Equal(t, big.NewInt(2), feeComponents[chainB].DataAvailabilityFee)
11311140
assert.Equal(t, big.NewInt(2), feeComponents[chainC].DataAvailabilityFee)
11321141

11331142
destChainFeeComponent, err := ccipReader.GetDestChainFeeComponents(ctx)

pkg/types/ccipocr3/chain_accessor.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,7 @@ type AllAccessors interface {
6868
// Access Type: ChainWriter
6969
// Contract: N/A
7070
// Confidence: N/A
71-
GetChainFeeComponents(
72-
ctx context.Context,
73-
) map[ChainSelector]ChainFeeComponents
74-
75-
// GetDestChainFeeComponents seems redundant. If the error is needed lets
76-
// add it to GetChainFeeComponents.
77-
//
78-
// Deprecated: use GetChainFeeComponents instead.
79-
GetDestChainFeeComponents(
80-
ctx context.Context,
81-
) (types.ChainFeeComponents, error)
71+
GetChainFeeComponents(ctx context.Context) (ChainFeeComponents, error)
8272

8373
// Sync can be used to perform frequent syncing operations inside the reader implementation.
8474
// Returns a bool indicating whether something was updated.

0 commit comments

Comments
 (0)