Skip to content

Commit

Permalink
Refactored test interface to enable parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
silaslenihan committed Dec 18, 2024
1 parent 8f13138 commit 96ccc8a
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 246 deletions.
6 changes: 2 additions & 4 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ replace github.com/smartcontractkit/chainlink/deployment => ../../deployment
// creating potential merge conflicts.
require (
github.com/smartcontractkit/chainlink/deployment v0.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/v2 v2.0.0-20241206210521-125d98cdaf66
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241106193309-5560cd76211a
)

require (
Expand All @@ -33,9 +33,7 @@ require (
github.com/prometheus/client_golang v1.20.5
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v0.8.1
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206162350-10f03fd2126b
github.com/smartcontractkit/chainlink/deployment v0.0.0-00010101000000-000000000000
github.com/smartcontractkit/chainlink/v2 v2.14.0-mercury-20240807.0.20241106193309-5560cd76211a
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241218155636-e23c08f22a84

Check failure on line 36 in core/scripts/go.mod

View workflow job for this annotation

GitHub Actions / Validate go.mod dependencies

[./core/scripts/go.mod] dependency github.com/smartcontractkit/[email protected] not on default branch (main). Version(commit): e23c08f22a84 Tree: https://github.com/smartcontractkit/chainlink-common/tree/e23c08f22a84 Commit: https://github.com/smartcontractkit/chainlink-common/commit/e23c08f22a84
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,10 @@ github.com/smartcontractkit/chain-selectors v1.0.34 h1:MJ17OGu8+jjl426pcKrJkCf3f
github.com/smartcontractkit/chain-selectors v1.0.34/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8=
github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU=
github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241204015713-8956bb614e9e h1:GnM6ZWV6vlk2+n6c6o+v/R1LtXzBGVVx7r37nt/h6Uc=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241204015713-8956bb614e9e/go.mod h1:80vGBbOfertJig0xFKsRfm+i17FkjdKkk1dAaGE45Os=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206162350-10f03fd2126b h1:+QEa/OYBQmzN2woqflQc3bf3SULvindn5xeLiLlT4EM=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241206162350-10f03fd2126b/go.mod h1:bQktEJf7sJ0U3SmIcXvbGUox7SmXcnSEZ4kUbT8R5Nk=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241218114855-f74219171000 h1:6Zzr/R1j6P7bbvcUlt5WUIbItvrrGdGzIsiAzQezcwo=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241218114855-f74219171000/go.mod h1:ncjd6mPZSRlelEqH/2KeLE1pU3UlqzBSn8RYkEoECzY=
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241218155636-e23c08f22a84 h1:bfKrKQ9nWsM5iljcDViUtZ4cEFy/ZCWLtzSUC6WlFQM=
github.com/smartcontractkit/chainlink-common v0.4.1-0.20241218155636-e23c08f22a84/go.mod h1:yti7e1+G9hhkYhj+L5sVUULn9Bn3bBL5/AxaNqdJ5YQ=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241202195413-82468150ac1e h1:PRoeby6ZlTuTkv2f+7tVU4+zboTfRzI+beECynF4JQ0=
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241202195413-82468150ac1e/go.mod h1:mUh5/woemsVaHgTorA080hrYmO3syBCmPdnWc/5dOqk=
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241216163550-fa030d178ba3 h1:aeiBdBHGY8QNftps+VqrIk6OnfeeOD5z4jrAabW4ZSc=
Expand Down
88 changes: 72 additions & 16 deletions core/services/relay/evm/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"
"os"
"strconv"
"sync"
"testing"
"time"

Expand All @@ -27,11 +28,11 @@ import (
commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils"
clcommontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

htMocks "github.com/smartcontractkit/chainlink/v2/common/headtracker/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
lpMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller/mocks"
evmtxmgr "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
Expand All @@ -50,6 +51,7 @@ import (
)

const commonGasLimitOnEvms = uint64(4712388)
const finalityDepth = 4

func TestContractReaderEventsInitValidation(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -228,34 +230,49 @@ func TestChainReader_HealthReport(t *testing.T) {
}

func TestChainComponents(t *testing.T) {
// shared helper so all tests can run efficiently in parallel
helper := &helper{}
helper.Init(t)
deployLock := sync.Mutex{}
// add new subtests here so that it can be run on real chains too
t.Run("RunChainComponentsEvmTests", func(t *testing.T) {
t.Parallel()
helper := &helper{}
// shared helper for separate parallel testers
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper}
it.Init(t)
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper, DeployLock: &deployLock}
// These tests are broken in develop as well, so disable them for now
it.DisableTests([]string{
interfacetests.ContractReaderQueryKeysReturnsDataTwoEventTypes,
interfacetests.ContractReaderQueryKeysReturnsDataAsValuesDotValue,
interfacetests.ContractReaderQueryKeysCanFilterWithValueComparator,
})
it.Setup(t)

RunChainComponentsEvmTests(t, it)
})

t.Run("RunChainComponentsInLoopEvmTests", func(t *testing.T) {
t.Parallel()
helper := &helper{}
// shared helper for separate parallel testers
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper}
it.Init(t)
RunChainComponentsInLoopEvmTests[*testing.T](t, commontestutils.WrapContractReaderTesterForLoop(it))
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper, DeployLock: &deployLock}
wrapped := commontestutils.WrapContractReaderTesterForLoop(it)
// These tests are broken in develop as well, so disable them for now
wrapped.DisableTests([]string{
interfacetests.ContractReaderQueryKeysReturnsDataTwoEventTypes,
interfacetests.ContractReaderQueryKeysReturnsDataAsValuesDotValue,
interfacetests.ContractReaderQueryKeysCanFilterWithValueComparator,
})
wrapped.Setup(t)

RunChainComponentsInLoopEvmTests[*testing.T](t, wrapped, true)
})

t.Run("RunChainComponentsInLoopEvmTestsWithBindings", func(t *testing.T) {
t.Parallel()
helper := &helper{}
// shared helper for separate parallel testers
helper.Init(t)
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper}
it := &EVMChainComponentsInterfaceTester[*testing.T]{Helper: helper, DeployLock: &deployLock}
wrapped := WrapContractReaderTesterWithBindings(t, it)
// TODO, generated binding tests are broken
it.DisableTests([]string{interfacetests.ContractReaderGetLatestValue})
RunChainComponentsInLoopEvmTests(t, WrapContractReaderTesterWithBindings(t, it))
wrapped.DisableTests([]string{interfacetests.ContractReaderGetLatestValue})
wrapped.Setup(t)
// generated tests are not compatible with parallel running atm
RunChainComponentsInLoopEvmTests(t, wrapped, false)
})
}

Expand All @@ -267,6 +284,40 @@ type helper struct {
txm evmtxmgr.TxManager
client client.Client
db *sqlx.DB
lp logpoller.LogPoller
ht logpoller.HeadTracker
}

func getLPOpts() logpoller.Opts {
return logpoller.Opts{
PollPeriod: time.Millisecond,
FinalityDepth: finalityDepth,
BackfillBatchSize: 1,
RpcBatchSize: 1,
KeepFinalizedBlocksDepth: 10000,
}
}

func (h *helper) LogPoller(t *testing.T) logpoller.LogPoller {
if h.lp != nil {
return h.lp
}
ctx := testutils.Context(t)
lggr := logger.NullLogger
db := h.Database()

h.lp = logpoller.NewLogPoller(logpoller.NewORM(h.ChainID(), db, lggr), h.Client(t), lggr, h.HeadTracker(t), getLPOpts())
require.NoError(t, h.lp.Start(ctx))
return h.lp
}

func (h *helper) HeadTracker(t *testing.T) logpoller.HeadTracker {
if h.ht != nil {
return h.ht
}
lpOpts := getLPOpts()
h.ht = headtracker.NewSimulatedHeadTracker(h.Client(t), lpOpts.UseFinalityTag, lpOpts.FinalityDepth)
return h.ht
}

func (h *helper) Init(t *testing.T) {
Expand All @@ -278,6 +329,7 @@ func (h *helper) Init(t *testing.T) {

h.Backend()
h.client = h.Client(t)
h.LogPoller(t)

h.txm = h.TXM(t, h.client)
}
Expand Down Expand Up @@ -338,6 +390,10 @@ func (h *helper) ChainID() *big.Int {
return testutils.SimulatedChainID
}

func (h *helper) Database() *sqlx.DB {
return h.db
}

func (h *helper) NewSqlxDB(t *testing.T) *sqlx.DB {
return pgtest.NewSqlxDB(t)
}
Expand Down
Loading

0 comments on commit 96ccc8a

Please sign in to comment.