Skip to content

Commit

Permalink
Addressed Lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kidambisrinivas committed Sep 30, 2024
1 parent 4a56bb5 commit 344f6eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (s *TriggerService) Start(ctx context.Context) error {
// After this call the Service cannot be started again,
// The service will need to be re-built to start scheduling again.
func (s *TriggerService) Close() error {
for _, trigger := range s.triggers.ReadAll() {
trigger.Stop()
}
return nil
}

Expand Down
14 changes: 8 additions & 6 deletions core/capabilities/triggers/logevent/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"testing"
"time"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
commonmocks "github.com/smartcontractkit/chainlink-common/pkg/types/core/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/test-go/testify/mock"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
commonmocks "github.com/smartcontractkit/chainlink-common/pkg/types/core/mocks"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/testutils"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/triggers/logevent"
coretestutils "github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestLogEventTriggerEVMHappyPath(t *testing.T) {

// Send a blockchain transaction that emits logs
go func() {
_, err :=
_, err =
th.LogEmitterContract.EmitLog1(th.BackendTH.ContractsOwner, []*big.Int{big.NewInt(expectedLogVal)})
require.NoError(t, err)
th.BackendTH.Backend.Commit()
Expand All @@ -67,14 +67,16 @@ func TestLogEventTriggerEVMHappyPath(t *testing.T) {
// Wait for logs with a timeout
_, output, err := testutils.WaitForLog(th.BackendTH.Lggr, log1Ch, 5*time.Second)
require.NoError(t, err)
err = testutils.PrintMap(output, "EmitLog", th.BackendTH.Lggr)
require.NoError(t, err)
// Verify if valid cursor is returned
cursor, err := testutils.GetStrVal(output, "Cursor")
require.NoError(t, err)
require.True(t, len(cursor) > 130)
require.True(t, len(cursor) > 60)
// Verify if Arg0 is correct
actualLogVal, err := testutils.GetBigIntValL2(output, "Data", "Arg0")
require.NoError(t, err)
require.Equal(t, expectedLogVal, actualLogVal.Int64())

testutils.PrintMap(output, "EmitLog", th.BackendTH.Lggr)
logEventTriggerService.Close()
}
9 changes: 7 additions & 2 deletions core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/common/math"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types"
Expand Down Expand Up @@ -87,8 +88,12 @@ func newLogEventTrigger(ctx context.Context,
}

// Setup callback channel, logger and ticker to poll ContractReader
callbackCh := make(chan capabilities.TriggerResponse)
ticker := time.NewTicker(time.Duration(int64(logEventConfig.PollPeriod)) * time.Millisecond)
callbackCh := make(chan capabilities.TriggerResponse, defaultSendChannelBufferSize)
pollPeriod := int64(1000) // default pollPeriod is 1s
if logEventConfig.PollPeriod <= math.MaxInt64 {
pollPeriod = int64(logEventConfig.PollPeriod)

Check failure on line 94 in core/capabilities/triggers/logevent/trigger.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)
}
ticker := time.NewTicker(time.Duration(pollPeriod) * time.Millisecond)
done := make(chan bool)
lggr, err := logger.New()
if err != nil {
Expand Down

0 comments on commit 344f6eb

Please sign in to comment.