From 68636992055a3598915a6caf5e44775b5d1987a6 Mon Sep 17 00:00:00 2001 From: Paolo Galli Date: Thu, 5 Dec 2024 10:03:38 +0100 Subject: [PATCH] test: add more tests including dynamic fee txs --- api/transactions/transactions_test.go | 2 ++ logdb/logdb_test.go | 2 +- tx/builder_dynamic_fee.go | 2 +- tx/builder_legacy.go | 2 +- tx/transaction.go | 3 +-- txpool/tx_object_test.go | 4 ++-- txpool/tx_pool_test.go | 24 ++++++++++++++++++++++++ 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/api/transactions/transactions_test.go b/api/transactions/transactions_test.go index cfc1f93f7..56b54c092 100644 --- a/api/transactions/transactions_test.go +++ b/api/transactions/transactions_test.go @@ -206,6 +206,8 @@ func txWithBadHeader(t *testing.T) { badHeaderURL := []string{ "/transactions/" + legacyTx.ID().String() + "?head=badHead", "/transactions/" + legacyTx.ID().String() + "/receipt?head=badHead", + "/transactions/" + dynFeeTx.ID().String() + "?head=badHead", + "/transactions/" + dynFeeTx.ID().String() + "/receipt?head=badHead", } for _, url := range badHeaderURL { diff --git a/logdb/logdb_test.go b/logdb/logdb_test.go index 9ea2a6564..0de44770c 100644 --- a/logdb/logdb_test.go +++ b/logdb/logdb_test.go @@ -27,7 +27,7 @@ func newTx(txType int) *tx.Transaction { case tx.DynamicFeeTxType: trx = new(tx.DynFeeBuilder).Build() default: - panic(tx.ErrInvalidTxType) + panic(tx.ErrTxTypeNotSupported) } pk, _ := crypto.GenerateKey() diff --git a/tx/builder_dynamic_fee.go b/tx/builder_dynamic_fee.go index 2259fe0eb..703a89328 100644 --- a/tx/builder_dynamic_fee.go +++ b/tx/builder_dynamic_fee.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The VeChainThor developers +// Copyright (c) 2024 The VeChainThor developers // Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying // file LICENSE or diff --git a/tx/builder_legacy.go b/tx/builder_legacy.go index 0ae1fa7cc..ebcdde955 100644 --- a/tx/builder_legacy.go +++ b/tx/builder_legacy.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018 The VeChainThor developers +// Copyright (c) 2024 The VeChainThor developers // Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying // file LICENSE or diff --git a/tx/transaction.go b/tx/transaction.go index dc674f4a0..298cf35c3 100644 --- a/tx/transaction.go +++ b/tx/transaction.go @@ -24,7 +24,6 @@ import ( var ( errIntrinsicGasOverflow = errors.New("intrinsic gas overflow") - ErrInvalidTxType = errors.New("transaction type not valid in this context") ErrTxTypeNotSupported = errors.New("transaction type not supported") errEmptyTypedTx = errors.New("empty typed transaction bytes") ) @@ -169,7 +168,7 @@ func (t *Transaction) EvaluateWork(origin thor.Address) func(nonce uint64) *big. case DynamicFeeTxType: hashWithoutNonce = t.hashWithoutNonceDynamicFeeTx(origin) default: - panic(ErrInvalidTxType) + panic(ErrTxTypeNotSupported) } return func(nonce uint64) *big.Int { diff --git a/txpool/tx_object_test.go b/txpool/tx_object_test.go index 9ed09e48e..512d6fb64 100644 --- a/txpool/tx_object_test.go +++ b/txpool/tx_object_test.go @@ -36,7 +36,7 @@ func newTx(txType int, chainTag byte, clauses []*tx.Clause, gas uint64, blockRef case tx.DynamicFeeTxType: trx = dynFeeTxBuilder(chainTag, clauses, gas, blockRef, expiration, dependsOn, features).Build() default: - panic(tx.ErrInvalidTxType) + panic(tx.ErrTxTypeNotSupported) } return tx.MustSign(trx, from.PrivateKey) } @@ -52,7 +52,7 @@ func newDelegatedTx(txType int, chainTag byte, clauses []*tx.Clause, gas uint64, case tx.DynamicFeeTxType: trx = dynFeeTxBuilder(chainTag, clauses, gas, blockRef, expiration, dependsOn, features).Build() default: - panic(tx.ErrInvalidTxType) + panic(tx.ErrTxTypeNotSupported) } trx = tx.MustSignDelegated( diff --git a/txpool/tx_pool_test.go b/txpool/tx_pool_test.go index 8538fe0f5..76b7e4949 100644 --- a/txpool/tx_pool_test.go +++ b/txpool/tx_pool_test.go @@ -134,6 +134,23 @@ func FillPoolWithDynFeeTxs(pool *TxPool, t *testing.T) { assert.Equal(t, err.Error(), "tx rejected: pool is full") } +func FillPoolWithMixedTxs(pool *TxPool, t *testing.T) { + // Create a slice of transactions to be added to the pool. + txs := make(Tx.Transactions, 0, 15) + for i := 0; i < 6; i++ { + trx := newTx(tx.LegacyTxType, pool.repo.ChainTag(), nil, 21000, tx.BlockRef{}, 100, nil, tx.Features(0), devAccounts[0]) + txs = append(txs, trx) + trx = newTx(tx.DynamicFeeTxType, pool.repo.ChainTag(), nil, 21000, tx.BlockRef{}, 100, nil, tx.Features(0), devAccounts[0]) + txs = append(txs, trx) + } + + // Call the Fill method + pool.Fill(txs) + + err := pool.Add(newTx(tx.DynamicFeeTxType, pool.repo.ChainTag(), nil, 21000, tx.NewBlockRef(10), 100, nil, Tx.Features(0), devAccounts[0])) + assert.Equal(t, err.Error(), "tx rejected: pool is full") +} + func TestAddWithFullErrorUnsyncedChain(t *testing.T) { // First fill the pool with legacy transactions pool := newPool(LIMIT, LIMIT_PER_ACCOUNT) @@ -144,6 +161,10 @@ func TestAddWithFullErrorUnsyncedChain(t *testing.T) { // Now fill the pool with dynamic fee transactions pool = newPool(LIMIT, LIMIT_PER_ACCOUNT) FillPoolWithDynFeeTxs(pool, t) + + // Now fill the pool with mixed transactions + pool = newPool(LIMIT, LIMIT_PER_ACCOUNT) + FillPoolWithMixedTxs(pool, t) } func TestAddWithFullErrorSyncedChain(t *testing.T) { @@ -154,6 +175,9 @@ func TestAddWithFullErrorSyncedChain(t *testing.T) { pool = newPoolWithParams(LIMIT, LIMIT_PER_ACCOUNT, "./", "", uint64(time.Now().Unix())) FillPoolWithDynFeeTxs(pool, t) + + pool = newPoolWithParams(LIMIT, LIMIT_PER_ACCOUNT, "./", "", uint64(time.Now().Unix())) + FillPoolWithMixedTxs(pool, t) } func TestNewCloseWithError(t *testing.T) {