Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't pass ctx around in tests #11528

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ require (
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6 // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk=
github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6 h1:Vqi/po+LG3J47USCh83vvjutn2KX8nr7PsU9q4qHt2o=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c h1:YgizNDPRAP2ObjetDIQTJlrpzLBBkYsNjA10Mo5HByo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 h1:iu1pNbUoSDTrp+7BUtfTygZ2C0f5C2ZOBQhIoJjp+S0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679/go.mod h1:2Jx7bTEk4ujFQdsZpZq3A0BydvaVPs6mX8clUfxHOEM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
Expand Down
42 changes: 22 additions & 20 deletions core/services/relay/evm/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package evm_test
//go:generate ./testfiles/chainlink_reader_test_setup.sh

import (
"context"
"crypto/ecdsa"
"math"
"math/big"
Expand Down Expand Up @@ -55,7 +54,7 @@ type chainReaderInterfaceTester struct {
cr evm.ChainReaderService
}

func (it *chainReaderInterfaceTester) Setup(ctx context.Context, t *testing.T) {
func (it *chainReaderInterfaceTester) Setup(t *testing.T) {
t.Cleanup(func() {
it.address = ""
require.NoError(t, it.cr.Close())
Expand All @@ -64,7 +63,7 @@ func (it *chainReaderInterfaceTester) Setup(ctx context.Context, t *testing.T) {

// can re-use the same chain for tests, just make new contract for each test
if it.chain != nil {
it.deployNewContract(ctx, t)
it.deployNewContract(t)
return
}

Expand Down Expand Up @@ -111,7 +110,7 @@ func (it *chainReaderInterfaceTester) Setup(ctx context.Context, t *testing.T) {
},
}
it.chain.On("Client").Return(client.NewSimulatedBackendClient(t, it.sim, big.NewInt(1337)))
it.deployNewContract(ctx, t)
it.deployNewContract(t)
}

func (it *chainReaderInterfaceTester) Name() string {
Expand All @@ -125,7 +124,8 @@ func (it *chainReaderInterfaceTester) GetAccountBytes(i int) []byte {
return account
}

func (it *chainReaderInterfaceTester) GetChainReader(ctx context.Context, t *testing.T) clcommontypes.ChainReader {
func (it *chainReaderInterfaceTester) GetChainReader(t *testing.T) clcommontypes.ChainReader {
ctx := testutils.Context(t)
if it.cr != nil {
return it.cr
}
Expand All @@ -143,39 +143,39 @@ func (it *chainReaderInterfaceTester) GetChainReader(ctx context.Context, t *tes
return cr
}

func (it *chainReaderInterfaceTester) GetPrimitiveContract(_ context.Context, t *testing.T) clcommontypes.BoundContract {
func (it *chainReaderInterfaceTester) GetPrimitiveContract(_ *testing.T) clcommontypes.BoundContract {
return clcommontypes.BoundContract{
Address: it.address,
Name: MethodReturningUint64,
}
}

func (it *chainReaderInterfaceTester) GetReturnSeenContract(ctx context.Context, t *testing.T) clcommontypes.BoundContract {
it.deployNewContract(ctx, t)
func (it *chainReaderInterfaceTester) GetReturnSeenContract(t *testing.T) clcommontypes.BoundContract {
it.deployNewContract(t)
return clcommontypes.BoundContract{
Address: it.address,
Name: returnSeenName,
}
}
func (it *chainReaderInterfaceTester) GetSliceContract(ctx context.Context, t *testing.T) clcommontypes.BoundContract {
func (it *chainReaderInterfaceTester) GetSliceContract(t *testing.T) clcommontypes.BoundContract {
// Since most tests don't use the contract, it's set up lazily to save time
it.deployNewContract(ctx, t)
it.deployNewContract(t)
return clcommontypes.BoundContract{
Address: it.address,
Name: MethodReturningUint64Slice,
}
}

func (it *chainReaderInterfaceTester) SetLatestValue(ctx context.Context, t *testing.T, testStruct *TestStruct) clcommontypes.BoundContract {
it.sendTxWithTestStruct(ctx, t, testStruct, (*testfiles.TestfilesTransactor).AddTestStruct)
func (it *chainReaderInterfaceTester) SetLatestValue(t *testing.T, testStruct *TestStruct) clcommontypes.BoundContract {
it.sendTxWithTestStruct(t, testStruct, (*testfiles.TestfilesTransactor).AddTestStruct)
return clcommontypes.BoundContract{
Address: it.address,
Name: MethodTakingLatestParamsReturningTestStruct,
}
}

func (it *chainReaderInterfaceTester) TriggerEvent(ctx context.Context, t *testing.T, testStruct *TestStruct) clcommontypes.BoundContract {
it.sendTxWithTestStruct(ctx, t, testStruct, (*testfiles.TestfilesTransactor).TriggerEvent)
func (it *chainReaderInterfaceTester) TriggerEvent(t *testing.T, testStruct *TestStruct) clcommontypes.BoundContract {
it.sendTxWithTestStruct(t, testStruct, (*testfiles.TestfilesTransactor).TriggerEvent)
return clcommontypes.BoundContract{
Address: it.address,
Name: EventName,
Expand All @@ -184,9 +184,9 @@ func (it *chainReaderInterfaceTester) TriggerEvent(ctx context.Context, t *testi

type testStructFn = func(*testfiles.TestfilesTransactor, *bind.TransactOpts, int32, string, uint8, [32]uint8, [32]byte, [][32]byte, *big.Int, testfiles.MidLevelTestStruct) (*evmtypes.Transaction, error)

func (it *chainReaderInterfaceTester) sendTxWithTestStruct(ctx context.Context, t *testing.T, testStruct *TestStruct, fn testStructFn) {
func (it *chainReaderInterfaceTester) sendTxWithTestStruct(t *testing.T, testStruct *TestStruct, fn testStructFn) {
// Since most tests don't use the contract, it's set up lazily to save time
it.deployNewContract(ctx, t)
it.deployNewContract(t)

tx, err := fn(
&it.evmTest.TestfilesTransactor,
Expand All @@ -203,7 +203,7 @@ func (it *chainReaderInterfaceTester) sendTxWithTestStruct(ctx context.Context,
require.NoError(t, err)
it.sim.Commit()
it.incNonce()
it.awaitTx(ctx, t, tx)
it.awaitTx(t, tx)
}

func convertOracleIDs(oracleIDs [32]commontypes.OracleID) [32]byte {
Expand Down Expand Up @@ -234,7 +234,8 @@ func (it *chainReaderInterfaceTester) setupChainNoClient(t require.TestingT) {
it.sim.Commit()
}

func (it *chainReaderInterfaceTester) deployNewContract(ctx context.Context, t *testing.T) {
func (it *chainReaderInterfaceTester) deployNewContract(t *testing.T) {
ctx := testutils.Context(t)
if it.address != "" {
return
}
Expand All @@ -252,11 +253,12 @@ func (it *chainReaderInterfaceTester) deployNewContract(ctx context.Context, t *
it.sim.Commit()
it.evmTest = ts
it.incNonce()
it.awaitTx(ctx, t, tx)
it.awaitTx(t, tx)
it.address = address.String()
}

func (it *chainReaderInterfaceTester) awaitTx(ctx context.Context, t *testing.T, tx *evmtypes.Transaction) {
func (it *chainReaderInterfaceTester) awaitTx(t *testing.T, tx *evmtypes.Transaction) {
ctx := testutils.Context(t)
receipt, err := it.sim.TransactionReceipt(ctx, tx.Hash())
require.NoError(t, err)
require.Equal(t, evmtypes.ReceiptStatusSuccessful, receipt.Status)
Expand Down
3 changes: 1 addition & 2 deletions core/services/relay/evm/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package evm_test

import (
"context"
"encoding/json"
"testing"

Expand Down Expand Up @@ -50,7 +49,7 @@ func TestCodec(t *testing.T) {

type codecInterfaceTester struct{}

func (it *codecInterfaceTester) Setup(_ context.Context, _ *testing.T) {}
func (it *codecInterfaceTester) Setup(_ *testing.T) {}

func (it *codecInterfaceTester) GetAccountBytes(i int) []byte {
account := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704
github.com/smartcontractkit/chainlink-automation v1.0.0-alpha.0.0.20231120164534-d4cab696c459
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.0-alpha.0.0.20231120164534-d4cab696c459 h1:hJhuShYv9eUQxHJQdOmyEymVmApOrICrQdOY7kKQ5Io=
github.com/smartcontractkit/chainlink-automation v1.0.0-alpha.0.0.20231120164534-d4cab696c459/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6 h1:Vqi/po+LG3J47USCh83vvjutn2KX8nr7PsU9q4qHt2o=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c h1:YgizNDPRAP2ObjetDIQTJlrpzLBBkYsNjA10Mo5HByo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 h1:iu1pNbUoSDTrp+7BUtfTygZ2C0f5C2ZOBQhIoJjp+S0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679/go.mod h1:2Jx7bTEk4ujFQdsZpZq3A0BydvaVPs6mX8clUfxHOEM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/segmentio/ksuid v1.0.4
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/chainlink-automation v1.0.1
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c
github.com/smartcontractkit/chainlink-testing-framework v1.20.0
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1507,8 +1507,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk=
github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6 h1:Vqi/po+LG3J47USCh83vvjutn2KX8nr7PsU9q4qHt2o=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208012003-888e7dbdb9c6/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c h1:YgizNDPRAP2ObjetDIQTJlrpzLBBkYsNjA10Mo5HByo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231208164731-2783ddbbdd8c/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679 h1:iu1pNbUoSDTrp+7BUtfTygZ2C0f5C2ZOBQhIoJjp+S0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231128204301-ee4297eff679/go.mod h1:2Jx7bTEk4ujFQdsZpZq3A0BydvaVPs6mX8clUfxHOEM=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
Expand Down
Loading