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

Remove pg from evm tests #12521

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/ten-waves-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Remove pg from evm tests
26 changes: 7 additions & 19 deletions core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"

"github.com/google/uuid"
Expand Down Expand Up @@ -1214,25 +1213,16 @@ func TestORM_LoadEthTxesAttempts(t *testing.T) {
etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 3, 9, time.Now(), fromAddress)
etx.TxAttempts = []txmgr.TxAttempt{}

q := pg.NewQ(db, logger.Test(t), cfg.Database())

newAttempt := cltest.NewDynamicFeeEthTxAttempt(t, etx.ID)
var dbAttempt txmgr.DbEthTxAttempt
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
dbAttempt.FromTxAttempt(&newAttempt)
err := q.Transaction(func(tx pg.Queryer) error {
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
const insertEthTxAttemptSQL = `INSERT INTO evm.tx_attempts (eth_tx_id, gas_price, signed_raw_tx, hash, broadcast_before_block_num, state, created_at, chain_specific_gas_limit, tx_type, gas_tip_cap, gas_fee_cap) VALUES (
:eth_tx_id, :gas_price, :signed_raw_tx, :hash, :broadcast_before_block_num, :state, NOW(), :chain_specific_gas_limit, :tx_type, :gas_tip_cap, :gas_fee_cap
) RETURNING *`
_, err := tx.NamedExec(insertEthTxAttemptSQL, dbAttempt)
require.NoError(t, err)

err = txStore.LoadTxesAttempts(ctx, []*txmgr.Tx{&etx})
require.NoError(t, err)
assert.Len(t, etx.TxAttempts, 2)

return nil
})

err := txStore.InsertTxAttempt(ctx, &newAttempt)
require.NoError(t, err)

err = txStore.LoadTxesAttempts(ctx, []*txmgr.Tx{&etx})
require.NoError(t, err)
assert.Len(t, etx.TxAttempts, 2)
// also check after postgres transaction is committed
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
etx.TxAttempts = []txmgr.TxAttempt{}
err = txStore.LoadTxesAttempts(ctx, []*txmgr.Tx{&etx})
Expand Down Expand Up @@ -1359,7 +1349,6 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) {
txStore := cltest.NewTestTxStore(t, db)
ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth()
_, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
q := pg.NewQ(db, logger.Test(t), cfg.Database())
nonce := evmtypes.Nonce(123)

t.Run("update successful", func(t *testing.T) {
Expand All @@ -1382,7 +1371,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) {

attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID)

err := q.ExecQ("DELETE FROM evm.txes WHERE id = $1", etx.ID)
_, err := db.ExecContext(ctx, "DELETE FROM evm.txes WHERE id = $1", etx.ID)
require.NoError(t, err)

err = txStore.UpdateTxUnstartedToInProgress(testutils.Context(t), &etx, &attempt)
Expand All @@ -1394,7 +1383,6 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) {
txStore = cltest.NewTestTxStore(t, db)
ethKeyStore = cltest.NewKeyStore(t, db, cfg.Database()).Eth()
_, fromAddress = cltest.MustInsertRandomKeyReturningState(t, ethKeyStore)
q = pg.NewQ(db, logger.Test(t), cfg.Database())

t.Run("update replaces abandoned tx with same hash", func(t *testing.T) {
etx := mustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress)
Expand Down
6 changes: 2 additions & 4 deletions core/chains/evm/txmgr/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (

commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"

evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/config"
)

func ptr[T any](t T) *T { return &t }
Expand Down Expand Up @@ -145,7 +143,7 @@ func (c *MockConfig) FinalityTagEnabled() bool { return c.finalityTagEn
func (c *MockConfig) RPCDefaultBatchSize() uint32 { return c.RpcDefaultBatchSize }

func MakeTestConfigs(t *testing.T) (*MockConfig, *TestDatabaseConfig, *TestEvmConfig) {
db := &TestDatabaseConfig{defaultQueryTimeout: pg.DefaultQueryTimeout}
db := &TestDatabaseConfig{defaultQueryTimeout: 10 * time.Second}
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
ec := &TestEvmConfig{BumpThreshold: 42, MaxInFlight: uint32(42), MaxQueued: uint64(0), ReaperInterval: time.Duration(0), ReaperThreshold: time.Duration(0)}
config := &MockConfig{EvmConfig: ec}
return config, db, ec
Expand Down
Loading