Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Feb 1, 2025
1 parent 0e8d7d7 commit 0fbde6a
Showing 1 changed file with 57 additions and 47 deletions.
104 changes: 57 additions & 47 deletions pkg/reader/ccip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,29 +462,23 @@ func TestCCIPChainReader_DiscoverContracts_HappyPath_Round1(t *testing.T) {
mockReaders[destChain] = reader_mocks.NewMockExtended(t)
addDestinationContractAssertions(mockReaders[destChain], destNonceMgr, destRMNRemote, destFeeQuoter)

mockReaders[destChain].EXPECT().ExtendedGetLatestValue(
mockReaders[destChain].EXPECT().ExtendedBatchGetLatestValuesSingleMethod(
mock.Anything,
consts.ContractNameOffRamp,
consts.MethodNameOffRampGetAllSourceChainConfigs,
primitives.Unconfirmed,
map[string]any{},
consts.MethodNameGetSourceChainConfig,
mock.Anything,
).Return(nil).Run(withReturnValueOverridden(func(returnVal interface{}) {
v := returnVal.(*selectorsAndConfigs)
v.Selectors = []uint64{uint64(sourceChain[0]), uint64(sourceChain[1])}
v.SourceChainConfigs = []sourceChainConfig{
{
OnRamp: onramps[0],
Router: destRouter,
IsEnabled: true,
},
{
OnRamp: onramps[1],
Router: destRouter,
IsEnabled: true,
},
}
}))
mock.Anything,
).RunAndReturn(withBatchReadSourceChainConfigReturnValues(t,
[]any{sourceChainConfig{
OnRamp: onramps[0],
Router: destRouter,
IsEnabled: true,
}, sourceChainConfig{
OnRamp: onramps[1],
Router: destRouter,
IsEnabled: true,
}},
))

// mock calls to get fee quoter from onramps and source chain config from offramp.
for _, selector := range sourceChain {
Expand Down Expand Up @@ -605,29 +599,24 @@ func TestCCIPChainReader_DiscoverContracts_HappyPath_Round2(t *testing.T) {
mockReaders[destChain] = reader_mocks.NewMockExtended(t)
addDestinationContractAssertions(mockReaders[destChain], destNonceMgr, destRMNRemote, destFeeQuoter)

mockReaders[destChain].EXPECT().ExtendedGetLatestValue(
mockReaders[destChain].EXPECT().ExtendedBatchGetLatestValuesSingleMethod(
mock.Anything,
consts.ContractNameOffRamp,
consts.MethodNameOffRampGetAllSourceChainConfigs,
primitives.Unconfirmed,
map[string]any{},
consts.MethodNameGetSourceChainConfig,
mock.Anything,
).Return(nil).Run(withReturnValueOverridden(func(returnVal interface{}) {
v := returnVal.(*selectorsAndConfigs)
v.Selectors = []uint64{uint64(sourceChain[0]), uint64(sourceChain[1])}
v.SourceChainConfigs = []sourceChainConfig{
{
OnRamp: onramps[0],
Router: destRouter[0],
IsEnabled: true,
},
{
mock.Anything,
).RunAndReturn(withBatchReadSourceChainConfigReturnValues(t,
[]any{sourceChainConfig{
OnRamp: onramps[0],
Router: destRouter[0],
IsEnabled: true,
},
sourceChainConfig{
OnRamp: onramps[1],
Router: destRouter[1],
IsEnabled: true,
},
}
}))
}))

// mock calls to get fee quoter from onramps and source chain config from offramp.
for i, selector := range sourceChain {
Expand Down Expand Up @@ -687,14 +676,13 @@ func TestCCIPChainReader_DiscoverContracts_GetAllSourceChainConfig_Errors(t *tes

// mock the call for sourceChain2 - failure
getLatestValueErr := errors.New("some error")
destExtended.EXPECT().ExtendedGetLatestValue(
destExtended.EXPECT().ExtendedBatchGetLatestValuesSingleMethod(
mock.Anything,
consts.ContractNameOffRamp,
consts.MethodNameOffRampGetAllSourceChainConfigs,
primitives.Unconfirmed,
map[string]any{},
consts.MethodNameGetSourceChainConfig,
mock.Anything,
).Return(getLatestValueErr)
mock.Anything,
).Return(nil, getLatestValueErr)

// get static config call won't occur because the source chain config call failed.

Expand Down Expand Up @@ -725,15 +713,16 @@ func TestCCIPChainReader_DiscoverContracts_GetOfframpStaticConfig_Errors(t *test
destExtended := reader_mocks.NewMockExtended(t)

// mock the call for source chain configs
destExtended.EXPECT().ExtendedGetLatestValue(
destExtended.EXPECT().ExtendedBatchGetLatestValuesSingleMethod(
mock.Anything,
consts.ContractNameOffRamp,
consts.MethodNameOffRampGetAllSourceChainConfigs,
primitives.Unconfirmed,
map[string]any{},
consts.MethodNameGetSourceChainConfig,
mock.Anything,
).Return(nil) // doesn't matter for this test
// mock the call to get the nonce manager - failure
sourceChainConfig{},
).RunAndReturn(withBatchReadSourceChainConfigReturnValues(t,
[]any{sourceChainConfig{}, sourceChainConfig{}}))

// mock the call to get the static config - failure
getLatestValueErr := errors.New("some error")
destExtended.EXPECT().ExtendedGetLatestValue(
mock.Anything,
Expand Down Expand Up @@ -781,6 +770,27 @@ func withReturnValueOverridden(mapper func(returnVal interface{})) func(ctx cont
}
}

func withBatchReadSourceChainConfigReturnValues(
t testing.TB,
retVals []any) func(context.Context, string, string, []any, any) (types.ContractBatchResults, error) {
return func(ctx context.Context,
contractName string,
methodName string,
params []any,
retValType any) (types.ContractBatchResults, error) {
require.GreaterOrEqual(t, len(retVals), 1)
_, ok := retVals[0].(sourceChainConfig)
require.True(t, ok)
results := make(types.ContractBatchResults, 0, len(retVals))
for _, retVal := range retVals {
res := types.BatchReadResult{ReadName: methodName}
res.SetResult(retVal, nil)
results = append(results, res)
}
return results, nil
}
}

func TestCCIPChainReader_getDestFeeQuoterStaticConfig(t *testing.T) {
destCR := reader_mocks.NewMockContractReaderFacade(t)
destCR.EXPECT().Bind(mock.Anything, mock.Anything).Return(nil)
Expand Down

0 comments on commit 0fbde6a

Please sign in to comment.