From a6f59823ce50d63a1b5f8128ed1041ba89b1a9ef Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 30 Jan 2025 10:17:13 +0200 Subject: [PATCH] fix tests after merge --- .../sovereignChainTransactions_test.go | 22 +++++++++------- testscommon/txCacherStub.go | 26 ++++++++----------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/process/block/preprocess/sovereignChainTransactions_test.go b/process/block/preprocess/sovereignChainTransactions_test.go index a71e2b3d4dd..1494b4165be 100644 --- a/process/block/preprocess/sovereignChainTransactions_test.go +++ b/process/block/preprocess/sovereignChainTransactions_test.go @@ -4,10 +4,14 @@ import ( "errors" "math/big" "testing" + "time" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" state2 "github.com/multiversx/mx-chain-go/state" @@ -17,8 +21,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/state" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestTxsPreprocessor_NewSovereignChainTransactionPreprocessorShouldErrNilPreProcessor(t *testing.T) { @@ -144,10 +146,10 @@ func TestTxsPreprocessor_CreateAndProcessMiniBlocksShouldWork(t *testing.T) { args.TxDataPool = &testscommon.ShardedDataStub{ ShardDataStoreCalled: func(id string) (c storage.Cacher) { return &testscommon.TxCacherStub{ - SelectTransactionsWithBandwidthCalled: func(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction { + SelectTransactionsCalled: func(_ txcache.SelectionSession, _ uint64, _ int, _ time.Duration) ([]*txcache.WrappedTransaction, uint64) { return []*txcache.WrappedTransaction{ {Tx: &transaction.Transaction{Nonce: 1}}, - } + }, 0 }, } }, @@ -169,10 +171,10 @@ func TestTxsPreprocessor_CreateAndProcessMiniBlocksShouldWork(t *testing.T) { args.TxDataPool = &testscommon.ShardedDataStub{ ShardDataStoreCalled: func(id string) (c storage.Cacher) { return &testscommon.TxCacherStub{ - SelectTransactionsWithBandwidthCalled: func(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction { + SelectTransactionsCalled: func(_ txcache.SelectionSession, _ uint64, _ int, _ time.Duration) ([]*txcache.WrappedTransaction, uint64) { return []*txcache.WrappedTransaction{ {Tx: &transaction.Transaction{Nonce: 1}}, - } + }, 0 }, } }, @@ -224,12 +226,12 @@ func TestTxsPreprocessor_CreateAndProcessMiniBlocksShouldWork(t *testing.T) { args.TxDataPool = &testscommon.ShardedDataStub{ ShardDataStoreCalled: func(id string) (c storage.Cacher) { return &testscommon.TxCacherStub{ - SelectTransactionsWithBandwidthCalled: func(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction { + SelectTransactionsCalled: func(_ txcache.SelectionSession, _ uint64, _ int, _ time.Duration) ([]*txcache.WrappedTransaction, uint64) { return []*txcache.WrappedTransaction{ {Tx: tx1, TxHash: txHash1}, {Tx: tx2, TxHash: txHash2}, {Tx: tx3, TxHash: txHash3}, - } + }, 0 }, } }, @@ -275,10 +277,10 @@ func TestTxsPreprocessor_ComputeSortedTxsShouldWork(t *testing.T) { args.TxDataPool = &testscommon.ShardedDataStub{ ShardDataStoreCalled: func(id string) (c storage.Cacher) { return &testscommon.TxCacherStub{ - SelectTransactionsWithBandwidthCalled: func(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction { + SelectTransactionsCalled: func(_ txcache.SelectionSession, _ uint64, _ int, _ time.Duration) ([]*txcache.WrappedTransaction, uint64) { return []*txcache.WrappedTransaction{ {Tx: tx, TxHash: txHash}, - } + }, 0 }, } }, diff --git a/testscommon/txCacherStub.go b/testscommon/txCacherStub.go index 783ac062b0c..68800ab9d2c 100644 --- a/testscommon/txCacherStub.go +++ b/testscommon/txCacherStub.go @@ -1,25 +1,21 @@ package testscommon -import "github.com/multiversx/mx-chain-go/storage/txcache" +import ( + "time" + + "github.com/multiversx/mx-chain-go/storage/txcache" +) type TxCacherStub struct { CacherStub - SelectTransactionsWithBandwidthCalled func(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction - NotifyAccountNonceCalled func(accountKey []byte, nonce uint64) + SelectTransactionsCalled func(session txcache.SelectionSession, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) } -// SelectTransactionsWithBandwidth - -func (tcs *TxCacherStub) SelectTransactionsWithBandwidth(numRequested int, batchSizePerSender int, bandwidthPerSender uint64) []*txcache.WrappedTransaction { - if tcs.SelectTransactionsWithBandwidthCalled != nil { - return tcs.SelectTransactionsWithBandwidthCalled(numRequested, batchSizePerSender, bandwidthPerSender) +// SelectTransactions - +func (tcs *TxCacherStub) SelectTransactions(session txcache.SelectionSession, gasRequested uint64, maxNum int, selectionLoopMaximumDuration time.Duration) ([]*txcache.WrappedTransaction, uint64) { + if tcs.SelectTransactionsCalled != nil { + return tcs.SelectTransactionsCalled(session, gasRequested, maxNum, selectionLoopMaximumDuration) } - return make([]*txcache.WrappedTransaction, 0) -} - -// NotifyAccountNonce - -func (tcs *TxCacherStub) NotifyAccountNonce(accountKey []byte, nonce uint64) { - if tcs.NotifyAccountNonceCalled != nil { - tcs.NotifyAccountNonceCalled(accountKey, nonce) - } + return make([]*txcache.WrappedTransaction, 0), 0 }