Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Sep 25, 2023
1 parent 0d7efb2 commit a8885dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
23 changes: 11 additions & 12 deletions core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,24 @@ func NewOnRampV1_2_0(
if err != nil {
panic(err) // ABI failure ok to panic
}
onRampABI, err := abi.JSON(strings.NewReader(evm_2_evm_onramp.EVM2EVMOnRampABI))
if err != nil {
return nil, err
}
// Subscribe to the relevant logs
// Note we can keep the same prefix across 1.0/1.1 and 1.2 because the onramp addresses will be different
name := logpoller.FilterName(COMMIT_CCIP_SENDS, onRampAddress)
err = sourceLP.RegisterFilter(logpoller.Filter{

Check failure on line 259 in core/services/ocr2/plugins/ccip/internal/ccipdata/onramp_v1_2_0.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
Name: name,
EventSigs: []common.Hash{abihelpers.GetIDOrPanic("CCIPSendRequested", onRampABI)},
EventSigs: []common.Hash{CCIPSendRequestEventSigV1_2_0},
Addresses: []common.Address{onRampAddress},
})
return &OnRampV1_2_0{
finalityTags: finalityTags,
lggr: lggr,
client: source,
lp: sourceLP,
leafHasher: NewLeafHasherV1_2_0(sourceSelector, destSelector, onRampAddress, hashlib.NewKeccakCtx(), onRamp),
onRamp: onRamp,
filterName: name,
finalityTags: finalityTags,
lggr: lggr,
client: source,
lp: sourceLP,
leafHasher: NewLeafHasherV1_2_0(sourceSelector, destSelector, onRampAddress, hashlib.NewKeccakCtx(), onRamp),
onRamp: onRamp,
filterName: name,
address: onRampAddress,
sendRequestedSeqNumberWord: CCIPSendRequestSeqNumIndexV1_2_0,
sendRequestedEventSig: CCIPSendRequestEventSigV1_2_0,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestLogPollerClient_GetSendRequestsGteSeqNum(t *testing.T) {
lggr := logger.TestLogger(t)
t.Run("using confs", func(t *testing.T) {
lp := mocks.NewLogPoller(t)
lp.On("RegisterFilter", mock.Anything).Return(nil)
onRampV2, err := NewOnRampV1_2_0(lggr, 1, 1, onRampAddr, lp, nil, false)
require.NoError(t, err)
lp.On("LogsDataWordGreaterThan",
Expand All @@ -49,8 +50,11 @@ func TestLogPollerClient_GetSendRequestsGteSeqNum(t *testing.T) {

t.Run("using latest confirmed block", func(t *testing.T) {
h := &types.Header{Number: big.NewInt(100000)}
cl := evmClientMocks.NewClient(t)
cl.On("HeaderByNumber", mock.Anything, mock.Anything).Return(h, nil)
lp := mocks.NewLogPoller(t)
onRampV2, err := NewOnRampV1_2_0(lggr, 1, 1, onRampAddr, lp, nil, false)
lp.On("RegisterFilter", mock.Anything).Return(nil)
onRampV2, err := NewOnRampV1_2_0(lggr, 1, 1, onRampAddr, lp, cl, true)
require.NoError(t, err)
lp.On("LogsUntilBlockHashDataWordGreaterThan",
onRampV2.sendRequestedEventSig,
Expand All @@ -61,9 +65,6 @@ func TestLogPollerClient_GetSendRequestsGteSeqNum(t *testing.T) {
mock.Anything,
).Return([]logpoller.Log{}, nil)

cl := evmClientMocks.NewClient(t)
cl.On("HeaderByNumber", mock.Anything, mock.Anything).Return(h, nil)

events, err := onRampV2.GetSendRequestsGteSeqNum(
context.Background(),
seqNum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestLogPollerClient_GetLastUSDCMessagePriorToLogIndexInTx(t *testing.T) {

t.Run("multiple found", func(t *testing.T) {
lp := mocks.NewLogPoller(t)
lp.On("RegisterFilter", mock.Anything).Return(nil)
u, err := NewUSDCReader(lggr, utils.RandomAddress(), lp)
require.NoError(t, err)
lp.On("IndexedLogsByTxHash",
Expand All @@ -47,6 +48,7 @@ func TestLogPollerClient_GetLastUSDCMessagePriorToLogIndexInTx(t *testing.T) {

t.Run("none found", func(t *testing.T) {
lp := mocks.NewLogPoller(t)
lp.On("RegisterFilter", mock.Anything).Return(nil)
u, err := NewUSDCReader(lggr, utils.RandomAddress(), lp)
require.NoError(t, err)
lp.On("IndexedLogsByTxHash",
Expand Down
8 changes: 4 additions & 4 deletions core/services/ocr2/plugins/ccip/tokendata/usdc/usdc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ func getMockUSDCEndpoint(t *testing.T, response attestationResponse) *httptest.S
}

func TestGetUSDCMessageBody(t *testing.T) {

expectedBody := []byte("0x0000000000000001000000020000000000048d71000000000000000000000000eb08f243e5d3fcff26a9e38ae5520a669f4019d000000000000000000000000023a04d5935ed8bc8e3eb78db3541f0abfb001c6e0000000000000000000000006cb3ed9b441eb674b58495c8b3324b59faff5243000000000000000000000000000000005425890298aed601595a70ab815c96711a31bc65000000000000000000000000ab4f961939bfe6a93567cc57c59eed7084ce2131000000000000000000000000000000000000000000000000000000000000271000000000000000000000000035e08285cfed1ef159236728f843286c55fc0861")
sourceChainEventsMock := ccipdata.MockUSDCReader{}
sourceChainEventsMock.On("GetLastUSDCMessagePriorToLogIndexInTx", mock.Anything, mock.Anything, mock.Anything).Return(expectedBody, nil)

lggr := logger.TestLogger(t)
usdcReader, err := ccipdata.NewUSDCReader(lggr, mockMsgTransmitter, nil)
require.NoError(t, err)
usdcService := NewUSDCTokenDataReader(lggr, usdcReader, attestationURI)
usdcService := NewUSDCTokenDataReader(lggr, usdcReader, nil)

// Make the first call and assert the underlying function is called
body, err := usdcService.getUSDCMessageBody(context.Background(), internal.EVM2EVMOnRampCCIPSendRequestedWithMeta{})
require.NoError(t, err)
require.Equal(t, body, parsedBody)
require.Equal(t, body, expectedBody)

sourceChainEventsMock.AssertNumberOfCalls(t, "GetLastUSDCMessagePriorToLogIndexInTx", 1)

// Make another call and assert that the cache is used
body, err = usdcService.getUSDCMessageBody(context.Background(), internal.EVM2EVMOnRampCCIPSendRequestedWithMeta{})
require.NoError(t, err)
require.Equal(t, body, parsedBody)
require.Equal(t, body, expectedBody)
sourceChainEventsMock.AssertNumberOfCalls(t, "GetLastUSDCMessagePriorToLogIndexInTx", 1)
}

0 comments on commit a8885dd

Please sign in to comment.