Skip to content

Commit

Permalink
unit tests updates
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Jun 3, 2024
1 parent f7bb878 commit 8fde727
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
21 changes: 11 additions & 10 deletions factory/bootstrap/bootstrapComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
errorsMx "github.com/multiversx/mx-chain-go/errors"
mainFactory "github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/factory/bootstrap"
"github.com/multiversx/mx-chain-go/testscommon"
componentsMock "github.com/multiversx/mx-chain-go/testscommon/components"
Expand All @@ -23,23 +24,23 @@ import (
)

func createBootstrapFactoryArgs() bootstrap.BootstrapComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := componentsMock.GetCoreComponents(cfg)
statusCoreComp := componentsMock.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := componentsMock.GetCryptoComponents(coreComp)
networkComp := componentsMock.GetNetworkComponents(cryptoComp)
runTypeComp := componentsMock.GetRunTypeComponents(coreComp, cryptoComp)

return componentsMock.GetBootStrapFactoryArgs(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
return createFactoryArgs(componentsMock.GetCoreComponents, componentsMock.GetRunTypeComponents)
}

func createSovereignBootstrapFactoryArgs() bootstrap.BootstrapComponentsFactoryArgs {
return createFactoryArgs(componentsMock.GetSovereignCoreComponents, componentsMock.GetSovereignRunTypeComponents)
}

func createFactoryArgs(
getCoreComponents func(cfg config.Config) mainFactory.CoreComponentsHolder,
getRunTypeComponents func(coreComp mainFactory.CoreComponentsHolder, cryptoComp mainFactory.CryptoComponentsHolder) mainFactory.RunTypeComponentsHolder,
) bootstrap.BootstrapComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := componentsMock.GetSovereignCoreComponents(cfg)
coreComp := getCoreComponents(cfg)
statusCoreComp := componentsMock.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := componentsMock.GetCryptoComponents(coreComp)
networkComp := componentsMock.GetNetworkComponents(cryptoComp)
runTypeComp := componentsMock.GetSovereignRunTypeComponents(coreComp, cryptoComp)
runTypeComp := getRunTypeComponents(coreComp, cryptoComp)

return componentsMock.GetBootStrapFactoryArgs(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
}
Expand Down
27 changes: 12 additions & 15 deletions factory/consensus/consensusComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"time"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
retriever "github.com/multiversx/mx-chain-go/dataRetriever"
errorsMx "github.com/multiversx/mx-chain-go/errors"
mainFactory "github.com/multiversx/mx-chain-go/factory"
consensusComp "github.com/multiversx/mx-chain-go/factory/consensus"
"github.com/multiversx/mx-chain-go/factory/mock"
testsMocks "github.com/multiversx/mx-chain-go/integrationTests/mock"
Expand Down Expand Up @@ -1047,28 +1049,23 @@ func TestConsensusComponentsFactory_Create(t *testing.T) {
}

func createConsensusFactoryArgs() consensusComp.ConsensusComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := componentsMock.GetCoreComponents(cfg)
statusCoreComp := componentsMock.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := componentsMock.GetCryptoComponents(coreComp)
networkComp := componentsMock.GetNetworkComponents(cryptoComp)
runTypeComp := componentsMock.GetRunTypeComponents(coreComp, cryptoComp)
bootstrapComp := componentsMock.GetBootstrapComponents(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
dataComp := componentsMock.GetDataComponents(cfg, statusCoreComp, coreComp, bootstrapComp, cryptoComp, runTypeComp)
stateComp := componentsMock.GetStateComponents(cfg, coreComp, dataComp, statusCoreComp, runTypeComp)
statusComp := componentsMock.GetStatusComponents(cfg, statusCoreComp, coreComp, networkComp, bootstrapComp, stateComp, &shardingMocks.NodesCoordinatorMock{}, cryptoComp)
processComp := componentsMock.GetProcessComponents(cfg, runTypeComp, coreComp, cryptoComp, networkComp, bootstrapComp, stateComp, dataComp, statusComp, statusCoreComp)

return componentsMock.GetConsensusFactoryArgs(cfg, runTypeComp, coreComp, cryptoComp, networkComp, stateComp, dataComp, statusComp, statusCoreComp, processComp)
return createFactoryArgs(componentsMock.GetCoreComponents, componentsMock.GetRunTypeComponents)
}

func createSovereignConsensusFactoryArgs() consensusComp.ConsensusComponentsFactoryArgs {
return createFactoryArgs(componentsMock.GetSovereignCoreComponents, componentsMock.GetSovereignRunTypeComponents)
}

func createFactoryArgs(
getCoreComponents func(cfg config.Config) mainFactory.CoreComponentsHolder,
getRunTypeComponents func(coreComp mainFactory.CoreComponentsHolder, cryptoComp mainFactory.CryptoComponentsHolder) mainFactory.RunTypeComponentsHolder,
) consensusComp.ConsensusComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := componentsMock.GetSovereignCoreComponents(cfg)
coreComp := getCoreComponents(cfg)
statusCoreComp := componentsMock.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := componentsMock.GetCryptoComponents(coreComp)
networkComp := componentsMock.GetNetworkComponents(cryptoComp)
runTypeComp := componentsMock.GetSovereignRunTypeComponents(coreComp, cryptoComp)
runTypeComp := getRunTypeComponents(coreComp, cryptoComp)
bootstrapComp := componentsMock.GetBootstrapComponents(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
dataComp := componentsMock.GetDataComponents(cfg, statusCoreComp, coreComp, bootstrapComp, cryptoComp, runTypeComp)
stateComp := componentsMock.GetStateComponents(cfg, coreComp, dataComp, statusCoreComp, runTypeComp)
Expand Down
50 changes: 27 additions & 23 deletions factory/processing/processComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/consensus"
errorsMx "github.com/multiversx/mx-chain-go/errors"
runType "github.com/multiversx/mx-chain-go/factory"
mainFactory "github.com/multiversx/mx-chain-go/factory"
"github.com/multiversx/mx-chain-go/factory/mock"
processComp "github.com/multiversx/mx-chain-go/factory/processing"
"github.com/multiversx/mx-chain-go/genesis"
Expand Down Expand Up @@ -284,28 +284,25 @@ func createProcessComponentsFactoryArgs(runTypeComponents *mainFactoryMocks.RunT
}

func createProcessFactoryArgs(t *testing.T, shardCoordinator sharding.Coordinator) processComp.ProcessComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := components.GetCoreComponents(cfg)
statusCoreComp := components.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := components.GetCryptoComponents(coreComp)
networkComp := components.GetNetworkComponents(cryptoComp)
runTypeComp := components.GetRunTypeComponents(coreComp, cryptoComp)
bootstrapComp := components.GetBootstrapComponents(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
components.SetShardCoordinator(t, bootstrapComp, shardCoordinator)
dataComp := components.GetDataComponents(cfg, statusCoreComp, coreComp, bootstrapComp, cryptoComp, runTypeComp)
stateComp := components.GetStateComponents(cfg, coreComp, dataComp, statusCoreComp, runTypeComp)
statusComp := components.GetStatusComponents(cfg, statusCoreComp, coreComp, networkComp, bootstrapComp, stateComp, &shardingMocks.NodesCoordinatorMock{}, cryptoComp)

return components.GetProcessFactoryArgs(cfg, runTypeComp, coreComp, cryptoComp, networkComp, bootstrapComp, stateComp, dataComp, statusComp, statusCoreComp)
return createFactoryArgs(t, shardCoordinator, components.GetCoreComponents, components.GetRunTypeComponents)
}

func createSovereignProcessFactoryArgs(t *testing.T, shardCoordinator sharding.Coordinator) processComp.ProcessComponentsFactoryArgs {
return createFactoryArgs(t, shardCoordinator, components.GetSovereignCoreComponents, components.GetSovereignRunTypeComponents)
}

func createFactoryArgs(
t *testing.T,
shardCoordinator sharding.Coordinator,
getCoreComponents func(cfg config.Config) mainFactory.CoreComponentsHolder,
getRunTypeComponents func(coreComp mainFactory.CoreComponentsHolder, cryptoComp mainFactory.CryptoComponentsHolder) mainFactory.RunTypeComponentsHolder,
) processComp.ProcessComponentsFactoryArgs {
cfg := testscommon.GetGeneralConfig()
coreComp := components.GetSovereignCoreComponents(cfg)
coreComp := getCoreComponents(cfg)
statusCoreComp := components.GetStatusCoreComponents(cfg, coreComp)
cryptoComp := components.GetCryptoComponents(coreComp)
networkComp := components.GetNetworkComponents(cryptoComp)
runTypeComp := components.GetSovereignRunTypeComponents(coreComp, cryptoComp)
runTypeComp := getRunTypeComponents(coreComp, cryptoComp)
bootstrapComp := components.GetBootstrapComponents(cfg, statusCoreComp, coreComp, cryptoComp, networkComp, runTypeComp)
components.SetShardCoordinator(t, bootstrapComp, shardCoordinator)
dataComp := components.GetDataComponents(cfg, statusCoreComp, coreComp, bootstrapComp, cryptoComp, runTypeComp)
Expand All @@ -315,7 +312,7 @@ func createSovereignProcessFactoryArgs(t *testing.T, shardCoordinator sharding.C
return components.GetProcessFactoryArgs(cfg, runTypeComp, coreComp, cryptoComp, networkComp, bootstrapComp, stateComp, dataComp, statusComp, statusCoreComp)
}

func createStateComponents() runType.StateComponentsHolder {
func createStateComponents() mainFactory.StateComponentsHolder {
cfg := testscommon.GetGeneralConfig()
coreComp := components.GetCoreComponents(cfg)
statusCoreComp := components.GetStatusCoreComponents(cfg, coreComp)
Expand Down Expand Up @@ -1003,18 +1000,25 @@ func TestNewProcessComponentsFactory(t *testing.T) {
}

func getRunTypeComponentsMock() *mainFactoryMocks.RunTypeComponentsStub {
coreComp := components.GetCoreComponents(testscommon.GetGeneralConfig())
cryptoComp := components.GetCryptoComponents(coreComp)
return getRunTypeComponents(components.GetRunTypeComponents(coreComp, cryptoComp))
return createRunTypeComponentsStub(components.GetCoreComponents, components.GetRunTypeComponents)
}

func getSovereignRunTypeComponentsMock() *mainFactoryMocks.RunTypeComponentsStub {
coreComp := components.GetSovereignCoreComponents(testscommon.GetGeneralConfig())
return createRunTypeComponentsStub(components.GetSovereignCoreComponents, components.GetSovereignRunTypeComponents)
}

func createRunTypeComponentsStub(
getCoreComponents func(cfg config.Config) mainFactory.CoreComponentsHolder,
getRunTypeComponents func(coreComp mainFactory.CoreComponentsHolder, cryptoComp mainFactory.CryptoComponentsHolder) mainFactory.RunTypeComponentsHolder,
) *mainFactoryMocks.RunTypeComponentsStub {
cfg := testscommon.GetGeneralConfig()
coreComp := getCoreComponents(cfg)
cryptoComp := components.GetCryptoComponents(coreComp)
return getRunTypeComponents(components.GetSovereignRunTypeComponents(coreComp, cryptoComp))
runTypeComp := getRunTypeComponents(coreComp, cryptoComp)
return getRunTypeComponentsStub(runTypeComp)
}

func getRunTypeComponents(rt runType.RunTypeComponentsHolder) *mainFactoryMocks.RunTypeComponentsStub {
func getRunTypeComponentsStub(rt mainFactory.RunTypeComponentsHolder) *mainFactoryMocks.RunTypeComponentsStub {
return &mainFactoryMocks.RunTypeComponentsStub{
BlockChainHookHandlerFactory: rt.BlockChainHookHandlerCreator(),
BlockProcessorFactory: rt.BlockProcessorCreator(),
Expand Down

0 comments on commit 8fde727

Please sign in to comment.