Skip to content

Commit

Permalink
Merge pull request #5703 from multiversx/fix-disabled-fee-handler
Browse files Browse the repository at this point in the history
Fixed return value in the `MaxGasPriceSetGuardian` method on the disabled fee handler
  • Loading branch information
iulianpascalau authored Nov 14, 2023
2 parents 0101225 + d4da4b9 commit 1ef37e1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
93 changes: 93 additions & 0 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package bootstrap

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
"strconv"
"strings"
"testing"
Expand All @@ -14,7 +16,9 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/core/versioning"
"github.com/multiversx/mx-chain-core-go/data"
dataBatch "github.com/multiversx/mx-chain-core-go/data/batch"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand All @@ -23,6 +27,7 @@ import (
"github.com/multiversx/mx-chain-go/epochStart/bootstrap/types"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
processMock "github.com/multiversx/mx-chain-go/process/mock"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/state"
Expand Down Expand Up @@ -2308,3 +2313,91 @@ func TestEpochStartBootstrap_Close(t *testing.T) {
err := epochStartProvider.Close()
assert.Equal(t, expectedErr, err)
}

func TestSyncSetGuardianTransaction(t *testing.T) {
coreComp, cryptoComp := createComponentsForEpochStart()
args := createMockEpochStartBootstrapArgs(coreComp, cryptoComp)

epochStartProvider, _ := NewEpochStartBootstrap(args)
epochStartProvider.shardCoordinator = mock.NewMultipleShardsCoordinatorMock()
transactions := testscommon.NewShardedDataCacheNotifierMock()
epochStartProvider.dataPool = &dataRetrieverMock.PoolsHolderStub{
HeadersCalled: func() dataRetriever.HeadersPool {
return &mock.HeadersCacherStub{}
},
TransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier {
return transactions
},
UnsignedTransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier {
return testscommon.NewShardedDataStub()
},
RewardTransactionsCalled: func() dataRetriever.ShardedDataCacherNotifier {
return testscommon.NewShardedDataStub()
},
MiniBlocksCalled: func() storage.Cacher {
return testscommon.NewCacherStub()
},
TrieNodesCalled: func() storage.Cacher {
return testscommon.NewCacherStub()
},
PeerAuthenticationsCalled: func() storage.Cacher {
return testscommon.NewCacherStub()
},
HeartbeatsCalled: func() storage.Cacher {
return testscommon.NewCacherStub()
},
}
epochStartProvider.whiteListHandler = &testscommon.WhiteListHandlerStub{
IsWhiteListedCalled: func(interceptedData process.InterceptedData) bool {
return true
},
}
epochStartProvider.whiteListerVerifiedTxs = &testscommon.WhiteListHandlerStub{}
epochStartProvider.requestHandler = &testscommon.RequestHandlerStub{}
epochStartProvider.storageService = &storageMocks.ChainStorerStub{}

err := epochStartProvider.createSyncers()
assert.Nil(t, err)

topicName := "transactions_0"
interceptor, err := epochStartProvider.interceptorContainer.Get(topicName)
assert.Nil(t, err)

tx := &transaction.Transaction{
Nonce: 0,
Value: big.NewInt(0),
GasPrice: args.EconomicsData.MinGasPrice(),
GasLimit: args.EconomicsData.MinGasLimit() * 2,
Data: []byte("SetGuardian@aa@bb"),
ChainID: []byte(coreComp.ChainID()),
Signature: bytes.Repeat([]byte("2"), 32),
Version: 1,
}
txBytes, _ := coreComp.IntMarsh.Marshal(tx)

batch := &dataBatch.Batch{
Data: [][]byte{txBytes},
}
batchBytes, _ := coreComp.IntMarsh.Marshal(batch)

msg := &processMock.P2PMessageMock{
FromField: nil,
DataField: batchBytes,
SeqNoField: nil,
TopicField: "topicName",
SignatureField: nil,
KeyField: nil,
PeerField: "",
PayloadField: nil,
TimestampField: 0,
}

err = interceptor.ProcessReceivedMessage(msg, "pid")
assert.Nil(t, err)

time.Sleep(time.Second)

txHash := coreComp.Hash.Compute(string(txBytes))
_, found := transactions.SearchFirstData(txHash)
assert.True(t, found)
}
2 changes: 1 addition & 1 deletion genesis/process/disabled/feeHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (fh *FeeHandler) ExtraGasLimitGuardedTx() uint64 {

// MaxGasPriceSetGuardian returns 0
func (fh *FeeHandler) MaxGasPriceSetGuardian() uint64 {
return 0
return math.MaxUint64
}

// MaxGasLimitPerBlock returns max uint64
Expand Down
6 changes: 5 additions & 1 deletion testscommon/cryptoMocks/signerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func (s *SignerStub) Sign(private crypto.PrivateKey, msg []byte) ([]byte, error)

// Verify -
func (s *SignerStub) Verify(public crypto.PublicKey, msg []byte, sig []byte) error {
return s.VerifyCalled(public, msg, sig)
if s.VerifyCalled != nil {
return s.VerifyCalled(public, msg, sig)
}

return nil
}

// IsInterfaceNil returns true if there is no value under the interface
Expand Down

0 comments on commit 1ef37e1

Please sign in to comment.