Skip to content

Commit

Permalink
Add context to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Mar 8, 2024
1 parent 80186d0 commit 2f90f42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/web/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestLoader_EthTransactionsAttempts(t *testing.T) {
TxID: ethTxIDs[1],
}

txStore.On("FindTxAttemptConfirmedByTxIDs", []int64{ethTxIDs[2], ethTxIDs[1], ethTxIDs[0]}).Return([]txmgr.TxAttempt{
txStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{ethTxIDs[2], ethTxIDs[1], ethTxIDs[0]}).Return([]txmgr.TxAttempt{
attempt1, attempt2,
}, nil)
app.On("TxmStorageService").Return(txStore)
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestLoader_loadByEthTransactionID(t *testing.T) {
Receipts: []txmgr.ChainReceipt{txmgr.DbReceiptToEvmReceipt(&receipt)},
}

txStore.On("FindTxAttemptConfirmedByTxIDs", []int64{ethTxID}).Return([]txmgr.TxAttempt{
txStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{ethTxID}).Return([]txmgr.TxAttempt{
attempt1,
}, nil)

Expand Down
29 changes: 17 additions & 12 deletions core/web/resolver/eth_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
internalTest "github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
chainlinkmocks "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/mocks"
"github.com/smartcontractkit/chainlink/v2/core/web/testutils"
)

func TestResolver_EthTransaction(t *testing.T) {
t.Parallel()
// Get context for test
ctx := internalTest.Context(t)

query := `
query GetEthTransaction($hash: ID!) {
Expand Down Expand Up @@ -67,7 +70,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "success",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", hash).Return(&txmgr.Tx{
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(&txmgr.Tx{
ID: 1,
ToAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
FromAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
Expand All @@ -78,7 +81,7 @@ func TestResolver_EthTransaction(t *testing.T) {
ChainID: big.NewInt(22),
Sequence: nil,
}, nil)
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", []int64{1}).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{1}).Return([]txmgr.TxAttempt{
{
TxID: 1,
Hash: hash,
Expand Down Expand Up @@ -132,7 +135,7 @@ func TestResolver_EthTransaction(t *testing.T) {
num := int64(2)
nonce := evmtypes.Nonce(num)

f.Mocks.txmStore.On("FindTxByHash", hash).Return(&txmgr.Tx{
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(&txmgr.Tx{
ID: 1,
ToAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
FromAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
Expand All @@ -143,7 +146,7 @@ func TestResolver_EthTransaction(t *testing.T) {
ChainID: big.NewInt(22),
Sequence: &nonce,
}, nil)
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", []int64{1}).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{1}).Return([]txmgr.TxAttempt{
{
TxID: 1,
Hash: hash,
Expand Down Expand Up @@ -194,7 +197,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "not found error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", hash).Return(nil, sql.ErrNoRows)
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(nil, sql.ErrNoRows)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand All @@ -211,7 +214,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "generic error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", hash).Return(nil, gError)
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(nil, gError)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand All @@ -233,6 +236,7 @@ func TestResolver_EthTransaction(t *testing.T) {

func TestResolver_EthTransactions(t *testing.T) {
t.Parallel()
ctx := internalTest.Context(t)

query := `
query GetEthTransactions {
Expand Down Expand Up @@ -267,7 +271,7 @@ func TestResolver_EthTransactions(t *testing.T) {
before: func(f *gqlTestFramework) {
num := int64(2)

f.Mocks.txmStore.On("Transactions", PageDefaultOffset, PageDefaultLimit).Return([]txmgr.Tx{
f.Mocks.txmStore.On("Transactions", ctx, PageDefaultOffset, PageDefaultLimit).Return([]txmgr.Tx{
{
ID: 1,
ToAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
Expand All @@ -279,7 +283,7 @@ func TestResolver_EthTransactions(t *testing.T) {
ChainID: big.NewInt(22),
},
}, 1, nil)
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", []int64{1}).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{1}).Return([]txmgr.TxAttempt{
{
TxID: 1,
Hash: hash,
Expand Down Expand Up @@ -318,7 +322,7 @@ func TestResolver_EthTransactions(t *testing.T) {
name: "generic error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("Transactions", PageDefaultOffset, PageDefaultLimit).Return(nil, 0, gError)
f.Mocks.txmStore.On("Transactions", ctx, PageDefaultOffset, PageDefaultLimit).Return(nil, 0, gError)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand All @@ -339,6 +343,7 @@ func TestResolver_EthTransactions(t *testing.T) {

func TestResolver_EthTransactionsAttempts(t *testing.T) {
t.Parallel()
ctx := internalTest.Context(t)

query := `
query GetEthTransactionsAttempts {
Expand All @@ -365,7 +370,7 @@ func TestResolver_EthTransactionsAttempts(t *testing.T) {
before: func(f *gqlTestFramework) {
num := int64(2)

f.Mocks.txmStore.On("TxAttempts", PageDefaultOffset, PageDefaultLimit).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("TxAttempts", ctx, PageDefaultOffset, PageDefaultLimit).Return([]txmgr.TxAttempt{
{
Hash: hash,
TxFee: gas.EvmFee{Legacy: assets.NewWeiI(12)},
Expand Down Expand Up @@ -396,7 +401,7 @@ func TestResolver_EthTransactionsAttempts(t *testing.T) {
name: "success with nil values",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("TxAttempts", PageDefaultOffset, PageDefaultLimit).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("TxAttempts", ctx, PageDefaultOffset, PageDefaultLimit).Return([]txmgr.TxAttempt{
{
Hash: hash,
TxFee: gas.EvmFee{Legacy: assets.NewWeiI(12)},
Expand Down Expand Up @@ -426,7 +431,7 @@ func TestResolver_EthTransactionsAttempts(t *testing.T) {
name: "generic error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("TxAttempts", PageDefaultOffset, PageDefaultLimit).Return(nil, 0, gError)
f.Mocks.txmStore.On("TxAttempts", ctx, PageDefaultOffset, PageDefaultLimit).Return(nil, 0, gError)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand Down

0 comments on commit 2f90f42

Please sign in to comment.