Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Jan 15, 2024
1 parent 5217abc commit 48ab8e7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
16 changes: 5 additions & 11 deletions factory/api/apiResolverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,38 +416,32 @@ func createArgsSCQueryService(args *scQueryElementArgs) (*smartContract.ArgsNewS
MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(),
}

var apiBlockchain data.ChainHandler
var accAdapter state.AccountsAdapterAPI
var vmFactory process.VirtualMachinesContainerFactory
maxGasForVmQueries := args.generalConfig.VirtualMachine.GasConfig.ShardMaxGasPerVmQuery
if args.processComponents.ShardCoordinator().SelfId() == core.MetachainShardId {
maxGasForVmQueries = args.generalConfig.VirtualMachine.GasConfig.MetaMaxGasPerVmQuery

apiBlockchain, err = blockchain.NewMetaChain(disabled.NewAppStatusHandler())
argsHook.BlockChain, err = blockchain.NewMetaChain(disabled.NewAppStatusHandler())
if err != nil {
return nil, err
}
argsHook.BlockChain = apiBlockchain

accAdapter, err = createNewAccountsAdapterApi(args, apiBlockchain)
argsHook.Accounts, err = createNewAccountsAdapterApi(args, argsHook.BlockChain)
if err != nil {
return nil, err
}
argsHook.Accounts = accAdapter

vmFactory, err = createMetaVmContainerFactory(args, argsHook)
} else {
apiBlockchain, err = blockchain.NewBlockChain(disabled.NewAppStatusHandler())
argsHook.BlockChain, err = blockchain.NewBlockChain(disabled.NewAppStatusHandler())
if err != nil {
return nil, err
}
argsHook.BlockChain = apiBlockchain

accAdapter, err = createNewAccountsAdapterApi(args, apiBlockchain)
argsHook.Accounts, err = createNewAccountsAdapterApi(args, argsHook.BlockChain)
if err != nil {
return nil, err
}
argsHook.Accounts = accAdapter

vmFactory, err = createShardVmContainerFactory(args, argsHook)
}
Expand Down Expand Up @@ -482,7 +476,7 @@ func createArgsSCQueryService(args *scQueryElementArgs) (*smartContract.ArgsNewS
EconomicsFee: args.coreComponents.EconomicsData(),
BlockChainHook: vmFactory.BlockChainHookImpl(),
MainBlockChain: args.dataComponents.Blockchain(),
APIBlockChain: apiBlockchain,
APIBlockChain: argsHook.BlockChain,
WasmVMChangeLocker: args.coreComponents.WasmVMChangeLocker(),
Bootstrapper: args.bootstrapper,
AllowExternalQueriesChan: args.allowVMQueriesChan,
Expand Down
38 changes: 28 additions & 10 deletions factory/api/apiResolverFactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestCreateApiResolver(t *testing.T) {
})
}

func createMockSCQueryElementArgs() api.SCQueryElementArgs {
func createMockSCQueryElementArgs(shardId uint32) api.SCQueryElementArgs {
return api.SCQueryElementArgs{
GeneralConfig: &config.Config{
BuiltInFunctions: config.BuiltInFunctionsConfig{
Expand Down Expand Up @@ -356,7 +356,9 @@ func createMockSCQueryElementArgs() api.SCQueryElementArgs {
DataPool: &dataRetriever.PoolsHolderMock{},
},
ProcessComponents: &mock.ProcessComponentsMock{
ShardCoord: &testscommon.ShardsCoordinatorMock{},
ShardCoord: &testscommon.ShardsCoordinatorMock{
CurrentShard: shardId,
},
},
GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{
LatestGasScheduleCalled: func() map[string]map[string]uint64 {
Expand Down Expand Up @@ -424,7 +426,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("nil guardian handler should error", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.GuardedAccountHandler = nil
scQueryService, err := api.CreateScQueryElement(args)
require.Equal(t, process.ErrNilGuardedAccountHandler, err)
Expand All @@ -433,7 +435,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("DecodeAddresses fails", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.CoreComponents = &mock.CoreComponentsMock{
AddrPubKeyConv: nil,
}
Expand All @@ -445,7 +447,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("createBuiltinFuncs fails", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
coreCompMock := args.CoreComponents.(*mock.CoreComponentsMock)
coreCompMock.IntMarsh = nil
scQueryService, err := api.CreateScQueryElement(args)
Expand All @@ -456,7 +458,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("NewCache fails", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.GeneralConfig.SmartContractDataPool = config.CacheConfig{
Type: "LRU",
SizeInBytes: 1,
Expand All @@ -469,7 +471,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("metachain - NewVMContainerFactory fails", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.ProcessComponents = &mock.ProcessComponentsMock{
ShardCoord: &testscommon.ShardsCoordinatorMock{
SelfIDCalled: func() uint32 {
Expand All @@ -487,7 +489,7 @@ func TestCreateApiResolver_createScQueryElement(t *testing.T) {
t.Run("shard - NewVMContainerFactory fails", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
coreCompMock := args.CoreComponents.(*mock.CoreComponentsMock)
coreCompMock.Hash = nil
scQueryService, err := api.CreateScQueryElement(args)
Expand All @@ -504,7 +506,7 @@ func TestCreateApiResolver_createArgsSCQueryService(t *testing.T) {
t.Run("sovereign chain should add systemVM", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.ChainRunType = common.ChainRunTypeSovereign

argsScQueryService, err := api.CreateArgsSCQueryService(args)
Expand All @@ -526,7 +528,7 @@ func TestCreateApiResolver_createArgsSCQueryService(t *testing.T) {
t.Run("regular chain should NOT add systemVM", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs()
args := createMockSCQueryElementArgs(0)
args.ChainRunType = common.ChainRunTypeRegular

argsScQueryService, err := api.CreateArgsSCQueryService(args)
Expand All @@ -544,4 +546,20 @@ func TestCreateApiResolver_createArgsSCQueryService(t *testing.T) {
require.NotNil(t, wasmvm)
require.Equal(t, "*hostCore.vmHost", fmt.Sprintf("%T", wasmvm))
})
t.Run("metachain chain should NOT add systemVM", func(t *testing.T) {
t.Parallel()

args := createMockSCQueryElementArgs(common.MetachainShardId)
args.ChainRunType = common.MetachainShardName

argsScQueryService, err := api.CreateArgsSCQueryService(args)
require.Nil(t, err)
require.NotNil(t, argsScQueryService.VmContainer)

require.Equal(t, 1, argsScQueryService.VmContainer.Len())

svm, err := argsScQueryService.VmContainer.Get(vmFactory.SystemVirtualMachine)
require.Nil(t, err)
require.NotNil(t, svm)
})
}

0 comments on commit 48ab8e7

Please sign in to comment.