Skip to content

Commit

Permalink
Remove pg from evm tests (#12521)
Browse files Browse the repository at this point in the history
* Remove pg from tests

* Add changeset

* Update tx store test

* Update evm_tx_store.go

* lint
  • Loading branch information
DylanTinianov authored Mar 21, 2024
1 parent b257647 commit a27d466
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
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
34 changes: 18 additions & 16 deletions core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand All @@ -22,7 +23,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 @@ -1212,30 +1212,34 @@ func TestORM_LoadEthTxesAttempts(t *testing.T) {

t.Run("load new attempt inserted in current postgres transaction", func(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
dbAttempt.FromTxAttempt(&newAttempt)
err := q.Transaction(func(tx pg.Queryer) error {

func() {
tx, err := db.BeginTx(ctx, nil)
require.NoError(t, err)

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)
: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 *`
query, args, err := sqlutil.DataSource(db).BindNamed(insertEthTxAttemptSQL, dbAttempt)
require.NoError(t, err)
_, err = tx.ExecContext(ctx, query, args...)
require.NoError(t, err)

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

return nil
})
require.NoError(t, err)
err = tx.Commit()
require.NoError(t, err)
}()

// also check after postgres transaction is committed
etx.TxAttempts = []txmgr.TxAttempt{}
err = txStore.LoadTxesAttempts(ctx, []*txmgr.Tx{&etx})
err := txStore.LoadTxesAttempts(ctx, []*txmgr.Tx{&etx})
require.NoError(t, err)
assert.Len(t, etx.TxAttempts, 2)
})
Expand Down Expand Up @@ -1359,7 +1363,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 +1385,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 +1397,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
7 changes: 3 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,9 @@ 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/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/config"
)

func ptr[T any](t T) *T { return &t }
Expand Down Expand Up @@ -145,7 +144,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: utils.DefaultQueryTimeout}
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
3 changes: 3 additions & 0 deletions core/chains/evm/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
// EVMWordByteLen the length of an EVM Word Byte
const EVMWordByteLen = 32

// DefaultQueryTimeout is the default timeout for database queries
const DefaultQueryTimeout = 10 * time.Second

// ZeroAddress is an address of all zeroes, otherwise in Ethereum as
// 0x0000000000000000000000000000000000000000
var ZeroAddress = common.Address{}
Expand Down

0 comments on commit a27d466

Please sign in to comment.