Skip to content

Commit

Permalink
test: add more tests including dynamic fee txs
Browse files Browse the repository at this point in the history
  • Loading branch information
paologalligit committed Dec 5, 2024
1 parent cd46be5 commit 6863699
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions api/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion logdb/logdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tx/builder_dynamic_fee.go
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>
Expand Down
2 changes: 1 addition & 1 deletion tx/builder_legacy.go
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/lgpl-3.0.html>
Expand Down
3 changes: 1 addition & 2 deletions tx/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions txpool/tx_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions txpool/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 6863699

Please sign in to comment.