Skip to content

Commit

Permalink
Fix mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Mar 12, 2024
1 parent 2f90f42 commit 4409102
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions core/web/resolver/eth_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ 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"
"github.com/stretchr/testify/mock"
)

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 @@ -70,7 +68,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "success",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(&txmgr.Tx{
f.Mocks.txmStore.On("FindTxByHash", mock.Anything, hash).Return(&txmgr.Tx{
ID: 1,
ToAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
FromAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
Expand All @@ -81,7 +79,7 @@ func TestResolver_EthTransaction(t *testing.T) {
ChainID: big.NewInt(22),
Sequence: nil,
}, nil)
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{1}).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", mock.Anything, []int64{1}).Return([]txmgr.TxAttempt{
{
TxID: 1,
Hash: hash,
Expand Down Expand Up @@ -135,7 +133,7 @@ func TestResolver_EthTransaction(t *testing.T) {
num := int64(2)
nonce := evmtypes.Nonce(num)

f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(&txmgr.Tx{
f.Mocks.txmStore.On("FindTxByHash", mock.Anything, hash).Return(&txmgr.Tx{
ID: 1,
ToAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
FromAddress: common.HexToAddress("0x5431F5F973781809D18643b87B44921b11355d81"),
Expand All @@ -146,7 +144,7 @@ func TestResolver_EthTransaction(t *testing.T) {
ChainID: big.NewInt(22),
Sequence: &nonce,
}, nil)
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", ctx, []int64{1}).Return([]txmgr.TxAttempt{
f.Mocks.txmStore.On("FindTxAttemptConfirmedByTxIDs", mock.Anything, []int64{1}).Return([]txmgr.TxAttempt{
{
TxID: 1,
Hash: hash,
Expand Down Expand Up @@ -197,7 +195,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "not found error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(nil, sql.ErrNoRows)
f.Mocks.txmStore.On("FindTxByHash", mock.Anything, hash).Return(nil, sql.ErrNoRows)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand All @@ -214,7 +212,7 @@ func TestResolver_EthTransaction(t *testing.T) {
name: "generic error",
authenticated: true,
before: func(f *gqlTestFramework) {
f.Mocks.txmStore.On("FindTxByHash", ctx, hash).Return(nil, gError)
f.Mocks.txmStore.On("FindTxByHash", mock.Anything, hash).Return(nil, gError)
f.App.On("TxmStorageService").Return(f.Mocks.txmStore)
},
query: query,
Expand All @@ -236,7 +234,6 @@ 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 @@ -271,7 +268,7 @@ func TestResolver_EthTransactions(t *testing.T) {
before: func(f *gqlTestFramework) {
num := int64(2)

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

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

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

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

0 comments on commit 4409102

Please sign in to comment.