diff --git a/core/services/relay/evm/chain_components_test.go b/core/services/relay/evm/chain_components_test.go index c103c04bd64..01881c3388c 100644 --- a/core/services/relay/evm/chain_components_test.go +++ b/core/services/relay/evm/chain_components_test.go @@ -209,32 +209,29 @@ func TestContractReaderEventsInitValidation(t *testing.T) { func TestChainComponents(t *testing.T) { // 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) 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)) + wrapped := commontestutils.WrapContractReaderTesterForLoop(it) + wrapped.Init(t) + fmt.Printf("Type of tester: %T", wrapped) + RunChainComponentsInLoopEvmTests[*testing.T](t, wrapped) }) 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} + wrapped := WrapContractReaderTesterWithBindings(t, it) + wrapped.Init(t) // TODO, generated binding tests are broken - it.DisableTests([]string{interfacetests.ContractReaderGetLatestValue}) - RunChainComponentsInLoopEvmTests(t, WrapContractReaderTesterWithBindings(t, it)) + wrapped.DisableTests([]string{interfacetests.ContractReaderGetLatestValue}) + RunChainComponentsInLoopEvmTests(t, wrapped) }) } @@ -317,6 +314,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) } diff --git a/core/services/relay/evm/evmtesting/bindings_test_adapter.go b/core/services/relay/evm/evmtesting/bindings_test_adapter.go index 6c391aa0a7f..a808a94893f 100644 --- a/core/services/relay/evm/evmtesting/bindings_test_adapter.go +++ b/core/services/relay/evm/evmtesting/bindings_test_adapter.go @@ -93,6 +93,7 @@ func newBindingsMapping() bindingsMapping { } func getChainReaderConfig(wrapped *EVMChainComponentsInterfaceTester[*testing.T]) types.ChainReaderConfig { + fmt.Println("wrapped config") testStruct := interfacetests.CreateTestStruct[*testing.T](0, wrapped) chainReaderConfig := bindings.NewChainReaderConfig() chainReaderConfig.Contracts["ChainReaderTester"].Configs["ReturnSeen"] = &types.ChainReaderDefinition{ diff --git a/core/services/relay/evm/evmtesting/chain_components_interface_tester.go b/core/services/relay/evm/evmtesting/chain_components_interface_tester.go index 652982d48ea..2827a1ceb22 100644 --- a/core/services/relay/evm/evmtesting/chain_components_interface_tester.go +++ b/core/services/relay/evm/evmtesting/chain_components_interface_tester.go @@ -3,7 +3,9 @@ package evmtesting import ( "context" "encoding/json" + "fmt" "math/big" + "sync" "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -48,6 +50,7 @@ type EVMChainComponentsInterfaceTesterHelper[T TestingT[T]] interface { Client(t T) client.Client Commit() Backend() bind.ContractBackend + Database() *sqlx.DB ChainID() *big.Int Context(t T) context.Context NewSqlxDB(t T) *sqlx.DB @@ -64,61 +67,26 @@ type EVMChainComponentsInterfaceTester[T TestingT[T]] struct { TestSelectionSupport Helper EVMChainComponentsInterfaceTesterHelper[T] client client.Client - address string - address2 string - contractTesters map[string]*chain_reader_tester.ChainReaderTester chainReaderConfig types.ChainReaderConfig chainWriterConfig types.ChainWriterConfig deployerAuth *bind.TransactOpts senderAuth *bind.TransactOpts - cr evm.ChainReaderService - cw evm.ChainWriterService - dirtyContracts bool txm evmtxmgr.TxManager gasEstimator gas.EvmFeeEstimator chainReaderConfigSupplier func(t T) types.ChainReaderConfig chainWriterConfigSupplier func(t T) types.ChainWriterConfig dirtyConfig bool + nonceMu sync.Mutex + setupMu sync.Mutex + lp logpoller.LogPoller + ht logpoller.HeadTracker } func (it *EVMChainComponentsInterfaceTester[T]) Setup(t T) { - t.Cleanup(func() { - // DB may be closed by the test already, ignore errors - if it.cr != nil { - _ = it.cr.Close() - } - it.cr = nil - - if it.dirtyContracts { - it.contractTesters = nil - } - - if it.cw != nil { - _ = it.cw.Close() - } - it.cw = nil - }) - - // can re-use the same chain for tests, just make new contract for each test - if it.client != nil && !it.dirtyConfig { - it.deployNewContracts(t) - return - } - - // Need to separate accounts to ensure the nonce doesn't get misaligned after the - // contract deployments. - accounts := it.Helper.Accounts(t) - it.deployerAuth = accounts[0] - it.senderAuth = accounts[1] - - it.chainReaderConfig = it.chainReaderConfigSupplier(t) - it.GetContractReader(t) - - it.txm = it.Helper.TXM(t, it.client) - it.chainWriterConfig = it.chainWriterConfigSupplier(t) +} - it.deployNewContracts(t) - it.dirtyConfig = false +func (it *EVMChainComponentsInterfaceTester[T]) GetBindings(t T) []clcommontypes.BoundContract { + return it.deployNewContracts(t) } func (it *EVMChainComponentsInterfaceTester[T]) getChainReaderConfig(t T) types.ChainReaderConfig { @@ -263,6 +231,7 @@ func (it *EVMChainComponentsInterfaceTester[T]) getChainReaderConfig(t T) types. } func (it *EVMChainComponentsInterfaceTester[T]) getChainWriterConfig(t T) types.ChainWriterConfig { + fmt.Println("unwrapped config") return types.ChainWriterConfig{ Contracts: map[string]*types.ContractConfig{ AnyContractName: { @@ -356,73 +325,52 @@ func (it *EVMChainComponentsInterfaceTester[T]) GetAccountString(i int) string { } func (it *EVMChainComponentsInterfaceTester[T]) GetContractReader(t T) clcommontypes.ContractReader { + it.setupMu.Lock() + defer it.setupMu.Unlock() ctx := it.Helper.Context(t) - if it.cr != nil { - return it.cr - } - lggr := logger.NullLogger - db := it.Helper.NewSqlxDB(t) - lpOpts := logpoller.Opts{ - PollPeriod: time.Millisecond, - FinalityDepth: finalityDepth, - BackfillBatchSize: 1, - RpcBatchSize: 1, - KeepFinalizedBlocksDepth: 10000, - } - ht := headtracker.NewSimulatedHeadTracker(it.Helper.Client(t), lpOpts.UseFinalityTag, lpOpts.FinalityDepth) - lp := logpoller.NewLogPoller(logpoller.NewORM(it.Helper.ChainID(), db, lggr), it.Helper.Client(t), lggr, ht, lpOpts) - require.NoError(t, lp.Start(ctx)) - // encode and decode the config to ensure the test covers type issues - confBytes, err := json.Marshal(it.chainReaderConfig) - require.NoError(t, err) - - conf, err := types.ChainReaderConfigFromBytes(confBytes) + cr, err := evm.NewChainReaderService(ctx, lggr, it.lp, it.ht, it.client, it.chainReaderConfig) require.NoError(t, err) + require.NoError(t, cr.Start(ctx)) - cwh := it.Helper.ChainReaderEVMClient(ctx, t, ht, conf) - it.client = cwh + t.Cleanup(func() { + cr.Close() + }) - cr, err := evm.NewChainReaderService(ctx, lggr, lp, ht, it.client, conf) - require.NoError(t, err) - require.NoError(t, cr.Start(ctx)) - it.cr = cr return cr } -// This function is no longer necessary for Simulated Backend or Testnet tests. -func (it *EVMChainComponentsInterfaceTester[T]) GenerateBlocksTillConfidenceLevel(t T, contractName, readName string, confidenceLevel primitives.ConfidenceLevel) { -} - func (it *EVMChainComponentsInterfaceTester[T]) GetContractWriter(t T) clcommontypes.ContractWriter { + it.setupMu.Lock() + defer it.setupMu.Unlock() + ctx := it.Helper.Context(t) - if it.cw != nil { - return it.cw - } cw, err := evm.NewChainWriterService(logger.NullLogger, it.client, it.txm, it.gasEstimator, it.chainWriterConfig) require.NoError(t, err) - it.cw = it.Helper.WrappedChainWriter(cw, it.client) + + cw = it.Helper.WrappedChainWriter(cw, it.client) require.NoError(t, err) require.NoError(t, cw.Start(ctx)) - return it.cw + + t.Cleanup(func() { + cw.Close() + }) + + return cw } -func (it *EVMChainComponentsInterfaceTester[T]) GetBindings(_ T) []clcommontypes.BoundContract { - return []clcommontypes.BoundContract{ - {Name: AnyContractName, Address: it.address}, - {Name: AnySecondContractName, Address: it.address2}, - } +// This function is no longer necessary for Simulated Backend or Testnet tests. +func (it *EVMChainComponentsInterfaceTester[T]) GenerateBlocksTillConfidenceLevel(t T, contractName, readName string, confidenceLevel primitives.ConfidenceLevel) { } func (it *EVMChainComponentsInterfaceTester[T]) DirtyContracts() { - it.dirtyContracts = true } func (it *EVMChainComponentsInterfaceTester[T]) GetAuthWithGasSet(t T) *bind.TransactOpts { - gasPrice, err := it.client.SuggestGasPrice(it.Helper.Context(t)) + gasPrice, err := it.Helper.Client(t).SuggestGasPrice(it.Helper.Context(t)) require.NoError(t, err) extra := new(big.Int).Mul(gasPrice, big.NewInt(it.Helper.GasPriceBufferPercent())) extra = extra.Div(extra, big.NewInt(100)) @@ -440,35 +388,33 @@ func (it *EVMChainComponentsInterfaceTester[T]) IncNonce() { func (it *EVMChainComponentsInterfaceTester[T]) AwaitTx(t T, tx *gethtypes.Transaction) { ctx := it.Helper.Context(t) - receipt, err := bind.WaitMined(ctx, it.client, tx) + receipt, err := bind.WaitMined(ctx, it.Helper.Client(t), tx) require.NoError(t, err) require.Equal(t, gethtypes.ReceiptStatusSuccessful, receipt.Status) } -func (it *EVMChainComponentsInterfaceTester[T]) deployNewContracts(t T) { - // First test deploy both contracts, otherwise only deploy contracts if cleanup decides that we need to. - if it.address == "" || it.contractTesters == nil { - it.contractTesters = make(map[string]*chain_reader_tester.ChainReaderTester, 2) - address, ts1 := it.deployNewContract(t) - address2, ts2 := it.deployNewContract(t) - it.address, it.address2 = address, address2 - it.contractTesters[it.address] = ts1 - it.contractTesters[it.address2] = ts2 - it.dirtyContracts = false +func (it *EVMChainComponentsInterfaceTester[T]) deployNewContracts(t T) []clcommontypes.BoundContract { + it.nonceMu.Lock() + defer it.nonceMu.Unlock() + address := it.deployNewContract(t) + address2 := it.deployNewContract(t) + return []clcommontypes.BoundContract{ + {Name: AnyContractName, Address: address}, + {Name: AnySecondContractName, Address: address2}, } } -func (it *EVMChainComponentsInterfaceTester[T]) deployNewContract(t T) (string, *chain_reader_tester.ChainReaderTester) { +func (it *EVMChainComponentsInterfaceTester[T]) deployNewContract(t T) string { // 105528 was in the error: gas too low: have 0, want 105528 // Not sure if there's a better way to get it. it.deployerAuth.GasLimit = 10552800 - address, tx, ts, err := chain_reader_tester.DeployChainReaderTester(it.GetAuthWithGasSet(t), it.Helper.Backend()) + address, tx, _, err := chain_reader_tester.DeployChainReaderTester(it.GetAuthWithGasSet(t), it.Helper.Backend()) require.NoError(t, err) it.IncNonce() it.AwaitTx(t, tx) - return address.String(), ts + return address.String() } func (it *EVMChainComponentsInterfaceTester[T]) MaxWaitTimeForEvents() time.Duration { @@ -477,8 +423,47 @@ func (it *EVMChainComponentsInterfaceTester[T]) MaxWaitTimeForEvents() time.Dura func (it *EVMChainComponentsInterfaceTester[T]) Init(t T) { it.Helper.Init(t) - it.chainWriterConfigSupplier = func(t T) types.ChainWriterConfig { return it.getChainWriterConfig(t) } - it.chainReaderConfigSupplier = func(t T) types.ChainReaderConfig { return it.getChainReaderConfig(t) } + if it.chainReaderConfigSupplier == nil { + it.chainReaderConfigSupplier = func(t T) types.ChainReaderConfig { return it.getChainReaderConfig(t) } + } + if it.chainWriterConfigSupplier == nil { + it.chainWriterConfigSupplier = func(t T) types.ChainWriterConfig { return it.getChainWriterConfig(t) } + } + // Need to separate accounts to ensure the nonce doesn't get misaligned after the + // contract deployments. + accounts := it.Helper.Accounts(t) + ctx := it.Helper.Context(t) + it.deployerAuth = accounts[0] + it.senderAuth = accounts[1] + + lggr := logger.NullLogger + db := it.Helper.Database() + lpOpts := logpoller.Opts{ + PollPeriod: time.Millisecond, + FinalityDepth: finalityDepth, + BackfillBatchSize: 1, + RpcBatchSize: 1, + KeepFinalizedBlocksDepth: 10000, + } + + it.ht = headtracker.NewSimulatedHeadTracker(it.Helper.Client(t), lpOpts.UseFinalityTag, lpOpts.FinalityDepth) + it.lp = logpoller.NewLogPoller(logpoller.NewORM(it.Helper.ChainID(), db, lggr), it.Helper.Client(t), lggr, it.ht, lpOpts) + require.NoError(t, it.lp.Start(ctx)) + + it.chainReaderConfig = it.chainReaderConfigSupplier(t) + it.chainWriterConfig = it.chainWriterConfigSupplier(t) + + // encode and decode the config to ensure the test covers type issues + confBytes, err := json.Marshal(it.chainReaderConfig) + require.NoError(t, err) + + conf, err := types.ChainReaderConfigFromBytes(confBytes) + require.NoError(t, err) + + it.client = it.Helper.ChainReaderEVMClient(ctx, t, it.ht, conf) + it.txm = it.Helper.TXM(t, it.client) + + it.dirtyConfig = false } func (it *EVMChainComponentsInterfaceTester[T]) SetChainReaderConfigSupplier(chainReaderConfigSupplier func(t T) types.ChainReaderConfig) { diff --git a/core/services/relay/evm/evmtesting/run_tests.go b/core/services/relay/evm/evmtesting/run_tests.go index b6abffdcb2f..1be017f81bf 100644 --- a/core/services/relay/evm/evmtesting/run_tests.go +++ b/core/services/relay/evm/evmtesting/run_tests.go @@ -2,6 +2,7 @@ package evmtesting import ( "encoding/binary" + "fmt" "math/big" "reflect" "time" @@ -49,19 +50,21 @@ func RunContractReaderEvmTests[T TestingT[T]](t T, it *EVMChainComponentsInterfa { Name: ContractReaderDynamicTypedTopicsFilterAndCorrectReturn, Test: func(t T) { + cr := it.GetContractReader(t) + cw := it.GetContractWriter(t) + bindings := it.GetBindings(t) + it.Setup(t) anyString := "foo" ctx := it.Helper.Context(t) - cr := it.GetContractReader(t) - bindings := it.GetBindings(t) require.NoError(t, cr.Bind(ctx, bindings)) type DynamicEvent struct { Field string } - SubmitTransactionToCW(t, it, "triggerEventWithDynamicTopic", DynamicEvent{Field: anyString}, bindings[0], types.Unconfirmed) + SubmitTransactionToCW(t, it, cw, "triggerEventWithDynamicTopic", DynamicEvent{Field: anyString}, bindings[0], types.Unconfirmed) input := struct{ Field string }{Field: anyString} tp := cr.(clcommontypes.ContractTypeProvider) @@ -88,17 +91,18 @@ func RunContractReaderEvmTests[T TestingT[T]](t T, it *EVMChainComponentsInterfa { Name: ContractReaderMultipleTopicCanFilterTogether, Test: func(t T) { - it.Setup(t) - ctx := it.Helper.Context(t) cr := it.GetContractReader(t) + cw := it.GetContractWriter(t) bindings := it.GetBindings(t) + it.Setup(t) + ctx := it.Helper.Context(t) require.NoError(t, cr.Bind(ctx, bindings)) - triggerFourTopics(t, it, int32(1), int32(2), int32(3)) - triggerFourTopics(t, it, int32(2), int32(2), int32(3)) - triggerFourTopics(t, it, int32(1), int32(3), int32(3)) - triggerFourTopics(t, it, int32(1), int32(2), int32(4)) + triggerFourTopics(t, it, cw, bindings, int32(1), int32(2), int32(3)) + triggerFourTopics(t, it, cw, bindings, int32(2), int32(2), int32(3)) + triggerFourTopics(t, it, cw, bindings, int32(1), int32(3), int32(3)) + triggerFourTopics(t, it, cw, bindings, int32(1), int32(2), int32(4)) var bound types.BoundContract for idx := range bindings { @@ -121,17 +125,18 @@ func RunContractReaderEvmTests[T TestingT[T]](t T, it *EVMChainComponentsInterfa { Name: ContractReaderFilteringCanBeDoneOnHashedIndexedTopics, Test: func(t T) { + cr := it.GetContractReader(t) + cw := it.GetContractWriter(t) + bindings := it.GetBindings(t) it.Setup(t) - cr := it.GetContractReader(t) ctx := it.Helper.Context(t) - bindings := it.GetBindings(t) require.NoError(t, cr.Bind(ctx, bindings)) - triggerFourTopicsWithHashed(t, it, "1", [32]uint8{2}, [32]byte{5}) - triggerFourTopicsWithHashed(t, it, "2", [32]uint8{2}, [32]byte{3}) - triggerFourTopicsWithHashed(t, it, "1", [32]uint8{3}, [32]byte{3}) + triggerFourTopicsWithHashed(t, it, cw, bindings, "1", [32]uint8{2}, [32]byte{5}) + triggerFourTopicsWithHashed(t, it, cw, bindings, "2", [32]uint8{2}, [32]byte{3}) + triggerFourTopicsWithHashed(t, it, cw, bindings, "1", [32]uint8{3}, [32]byte{3}) var bound types.BoundContract for idx := range bindings { @@ -158,10 +163,10 @@ func RunContractReaderEvmTests[T TestingT[T]](t T, it *EVMChainComponentsInterfa { Name: ContractReaderBindReturnsErrorOnMissingContractAtAddress, Test: func(t T) { + reader := it.GetContractReader(t) it.Setup(t) addr := common.BigToAddress(big.NewInt(42)) - reader := it.GetContractReader(t) ctx := it.Helper.Context(t) err := reader.Bind(ctx, []clcommontypes.BoundContract{{Name: AnyContractName, Address: addr.Hex()}}) @@ -180,19 +185,19 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac { Name: ContractReaderQueryKeyFilterOnDataWordsWithValueComparator, Test: func(t T) { - ctx := tests.Context(t) cr := it.GetContractReader(t) - require.NoError(t, cr.Bind(ctx, it.GetBindings(t))) + cw := it.GetContractWriter(t) bindings := it.GetBindings(t) - boundContract := BindingsByName(bindings, AnyContractName)[0] + ctx := tests.Context(t) require.NoError(t, cr.Bind(ctx, bindings)) + boundContract := BindingsByName(bindings, AnyContractName)[0] ts1 := CreateTestStruct[T](0, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) ts2 := CreateTestStruct[T](15, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) ts3 := CreateTestStruct[T](35, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) ts := &TestStruct{} assert.Eventually(t, func() bool { sequences, err := cr.QueryKey(ctx, boundContract, query.KeyFilter{ @@ -211,19 +216,20 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac { Name: ContractReaderQueryKeyOnDataWordsWithValueComparatorOnNestedField, Test: func(t T) { - ctx := tests.Context(t) cr := it.GetContractReader(t) - require.NoError(t, cr.Bind(ctx, it.GetBindings(t))) + cw := it.GetContractWriter(t) bindings := it.GetBindings(t) + ctx := tests.Context(t) + boundContract := BindingsByName(bindings, AnyContractName)[0] require.NoError(t, cr.Bind(ctx, bindings)) ts1 := CreateTestStruct[T](0, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) ts2 := CreateTestStruct[T](15, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) ts3 := CreateTestStruct[T](35, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) ts := &TestStruct{} assert.Eventually(t, func() bool { sequences, err := cr.QueryKey(ctx, boundContract, query.KeyFilter{ @@ -247,19 +253,22 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac { Name: ContractReaderQueryKeyFilterOnDataWordsWithValueComparatorOnDynamicField, Test: func(t T) { - ctx := tests.Context(t) cr := it.GetContractReader(t) - require.NoError(t, cr.Bind(ctx, it.GetBindings(t))) + cw := it.GetContractWriter(t) bindings := it.GetBindings(t) - boundContract := BindingsByName(bindings, AnyContractName)[0] + ctx := tests.Context(t) require.NoError(t, cr.Bind(ctx, bindings)) + boundContract := BindingsByName(bindings, AnyContractName)[0] ts1 := CreateTestStruct[T](0, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) + fmt.Printf("ts1 bigfield: %v\n", ts1.BigField) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed) ts2 := CreateTestStruct[T](15, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) + fmt.Printf("ts2 bigfield: %v\n", ts2.BigField) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed) ts3 := CreateTestStruct[T](35, it) - _ = SubmitTransactionToCW(t, it, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) + fmt.Printf("ts3 bigfield: %v\n", ts3.BigField) + _ = SubmitTransactionToCW(t, it, cw, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed) ts := &TestStruct{} assert.Eventually(t, func() bool { sequences, err := cr.QueryKey(ctx, boundContract, query.KeyFilter{ @@ -283,12 +292,12 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac { Name: ContractReaderQueryKeyFilteringOnDataWordsUsingValueComparatorsOnFieldsWithManualIndex, Test: func(t T) { - ctx := tests.Context(t) cr := it.GetContractReader(t) - require.NoError(t, cr.Bind(ctx, it.GetBindings(t))) + cw := it.GetContractWriter(t) bindings := it.GetBindings(t) - boundContract := BindingsByName(bindings, AnyContractName)[0] + ctx := tests.Context(t) require.NoError(t, cr.Bind(ctx, bindings)) + boundContract := BindingsByName(bindings, AnyContractName)[0] empty12Bytes := [12]byte{} val1, val2, val3, val4 := uint32(1), uint32(2), uint32(3), uint64(4) val5, val6, val7 := [32]byte{}, [32]byte{6}, [32]byte{7} @@ -313,10 +322,10 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac wrapExpectedRes := eventResAsStruct{Message: &resExpected} // emit the one we want to search for and a couple of random ones to confirm that filtering works - triggerStaticBytes(t, it, val1, val2, val3, val4, val5, val6, val7, raw) - triggerStaticBytes(t, it, 1337, 7331, 4747, val4, val5, val6, val7, raw) - triggerStaticBytes(t, it, 7331, 4747, 1337, val4, val5, val6, val7, raw) - triggerStaticBytes(t, it, 4747, 1337, 7331, val4, val5, val6, val7, raw) + triggerStaticBytes(t, it, cw, bindings, val1, val2, val3, val4, val5, val6, val7, raw) + triggerStaticBytes(t, it, cw, bindings, 1337, 7331, 4747, val4, val5, val6, val7, raw) + triggerStaticBytes(t, it, cw, bindings, 7331, 4747, 1337, val4, val5, val6, val7, raw) + triggerStaticBytes(t, it, cw, bindings, 4747, 1337, 7331, val4, val5, val6, val7, raw) assert.Eventually(t, func() bool { sequences, err := cr.QueryKey(ctx, boundContract, query.KeyFilter{ @@ -336,28 +345,26 @@ func RunContractReaderInLoopTests[T TestingT[T]](t T, it ChainComponentsInterfac RunTests(t, it, testCases) } -func triggerFourTopics[T TestingT[T]](t T, it *EVMChainComponentsInterfaceTester[T], i1, i2, i3 int32) { +func triggerFourTopics[T TestingT[T]](t T, it *EVMChainComponentsInterfaceTester[T], cw clcommontypes.ContractWriter, bindings []clcommontypes.BoundContract, i1, i2, i3 int32) { type DynamicEvent struct { Field1 int32 Field2 int32 Field3 int32 } - contracts := it.GetBindings(t) - SubmitTransactionToCW(t, it, "triggerWithFourTopics", DynamicEvent{Field1: i1, Field2: i2, Field3: i3}, contracts[0], types.Unconfirmed) + SubmitTransactionToCW(t, it, cw, "triggerWithFourTopics", DynamicEvent{Field1: i1, Field2: i2, Field3: i3}, bindings[0], types.Unconfirmed) } -func triggerFourTopicsWithHashed[T TestingT[T]](t T, it *EVMChainComponentsInterfaceTester[T], i1 string, i2 [32]uint8, i3 [32]byte) { +func triggerFourTopicsWithHashed[T TestingT[T]](t T, it *EVMChainComponentsInterfaceTester[T], cw clcommontypes.ContractWriter, bindings []clcommontypes.BoundContract, i1 string, i2 [32]uint8, i3 [32]byte) { type DynamicEvent struct { Field1 string Field2 [32]uint8 Field3 [32]byte } - contracts := it.GetBindings(t) - SubmitTransactionToCW(t, it, "triggerWithFourTopicsWithHashed", DynamicEvent{Field1: i1, Field2: i2, Field3: i3}, contracts[0], types.Unconfirmed) + SubmitTransactionToCW(t, it, cw, "triggerWithFourTopicsWithHashed", DynamicEvent{Field1: i1, Field2: i2, Field3: i3}, bindings[0], types.Unconfirmed) } // triggerStaticBytes emits a staticBytes events and returns the expected event bytes. -func triggerStaticBytes[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T], val1, val2, val3 uint32, val4 uint64, val5, val6, val7 [32]byte, raw []byte) { +func triggerStaticBytes[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T], cw clcommontypes.ContractWriter, bindings []clcommontypes.BoundContract, val1, val2, val3 uint32, val4 uint64, val5, val6, val7 [32]byte, raw []byte) { type StaticBytesEvent struct { Val1 uint32 Val2 uint32 @@ -369,8 +376,7 @@ func triggerStaticBytes[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T] Raw []byte } - contracts := it.GetBindings(t) - SubmitTransactionToCW(t, it, "triggerStaticBytes", + SubmitTransactionToCW(t, it, cw, "triggerStaticBytes", StaticBytesEvent{ Val1: val1, Val2: val2, @@ -381,5 +387,5 @@ func triggerStaticBytes[T TestingT[T]](t T, it ChainComponentsInterfaceTester[T] Val7: val7, Raw: raw, }, - contracts[0], types.Unconfirmed) + bindings[0], types.Unconfirmed) } diff --git a/go.mod b/go.mod index dc967527dd5..fed80b53fdd 100644 --- a/go.mod +++ b/go.mod @@ -392,5 +392,7 @@ replace ( // replicating the replace directive on cosmos SDK github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + github.com/smartcontractkit/chainlink-common => ../chainlink-common + github.com/sourcegraph/sourcegraph/lib => github.com/sourcegraph/sourcegraph-public-snapshot/lib v0.0.0-20240822153003-c864f15af264 ) diff --git a/go.sum b/go.sum index 3aaa5a67303..cc7dad25689 100644 --- a/go.sum +++ b/go.sum @@ -1125,8 +1125,6 @@ github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgB 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-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.20241202141438-a90db35252db h1:N1RH1hSr2ACzOFc9hkCcjE8pRBTdcU3p8nsTJByaLes=