From 5e708b5e0efe54113e8b07c1489b307e6f67393e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 15 Feb 2024 13:33:26 +0200 Subject: [PATCH 1/6] added tests for testOnlyProcessingNode --- .../components/testOnlyProcessingNode.go | 4 +- .../components/testOnlyProcessingNode_test.go | 422 +++++++++++++++++- testscommon/state/userAccountStub.go | 6 +- 3 files changed, 407 insertions(+), 25 deletions(-) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 14ec26cba86..8fe8fdaf6b6 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -220,7 +220,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - err = instance.createBroadcastMessanger() + err = instance.createBroadcastMessenger() if err != nil { return nil, err } @@ -308,7 +308,7 @@ func (node *testOnlyProcessingNode) createNodesCoordinator(pref config.Preferenc return nil } -func (node *testOnlyProcessingNode) createBroadcastMessanger() error { +func (node *testOnlyProcessingNode) createBroadcastMessenger() error { broadcastMessenger, err := sposFactory.GetBroadcastMessenger( node.CoreComponentsHolder.InternalMarshalizer(), node.CoreComponentsHolder.Hasher(), diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index 64dbf32b8e3..bb44ec5a9be 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -1,17 +1,26 @@ package components import ( + "errors" + "math/big" "strings" "testing" "time" "github.com/multiversx/mx-chain-core-go/data/endProcess" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/testscommon/factory" + "github.com/multiversx/mx-chain-go/testscommon/state" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +var expectedErr = errors.New("expected error") + func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ NumOfShards: 3, @@ -40,20 +49,15 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { t.Parallel() t.Run("should work", func(t *testing.T) { - if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") - } + t.Parallel() args := createMockArgsTestOnlyProcessingNode(t) node, err := NewTestOnlyProcessingNode(args) assert.Nil(t, err) assert.NotNil(t, node) }) - t.Run("try commit a block", func(t *testing.T) { - if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") - } + t.Parallel() args := createMockArgsTestOnlyProcessingNode(t) node, err := NewTestOnlyProcessingNode(args) @@ -81,27 +85,401 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { err = node.ProcessComponentsHolder.BlockProcessor().CommitBlock(header, block) assert.Nil(t, err) }) + t.Run("CreateCoreComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.Configs.GeneralConfig.Marshalizer.Type = "invalid type" + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("CreateCryptoComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.Configs.GeneralConfig.PublicKeyPIDSignature.Type = "invalid type" + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("CreateNetworkComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.SyncedBroadcastNetwork = nil + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("CreateBootstrapComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.Configs.FlagsConfig.WorkingDir = "" + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("CreateStateComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.ShardIDStr = common.MetachainShardName // coverage only + args.Configs.GeneralConfig.StateTriesConfig.MaxStateTrieLevelInMemory = 0 + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("CreateProcessComponents failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.Configs.FlagsConfig.Version = "" + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) + t.Run("createFacade failure should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgsTestOnlyProcessingNode(t) + args.Configs.EpochConfig.GasSchedule.GasScheduleByEpochs = nil + node, err := NewTestOnlyProcessingNode(args) + require.Error(t, err) + require.Nil(t, node) + }) } -func TestOnlyProcessingNodeSetStateShouldError(t *testing.T) { - args := createMockArgsTestOnlyProcessingNode(t) - node, err := NewTestOnlyProcessingNode(args) - require.Nil(t, err) +func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { + t.Parallel() + + goodKeyValueMap := map[string]string{ + "01": "02", + } + node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.NoError(t, err) address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" addressBytes, _ := node.CoreComponentsHolder.AddressPubKeyConverter().Decode(address) - keyValueMap := map[string]string{ - "nonHex": "01", - } - err = node.SetKeyValueForAddress(addressBytes, keyValueMap) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), "cannot decode key")) + t.Run("should work", func(t *testing.T) { + _, err = node.StateComponentsHolder.AccountsAdapter().GetExistingAccount(addressBytes) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "account was not found")) + + err = node.SetKeyValueForAddress(addressBytes, goodKeyValueMap) + require.NoError(t, err) + + _, err = node.StateComponentsHolder.AccountsAdapter().GetExistingAccount(addressBytes) + require.NoError(t, err) + }) + t.Run("decode key failure should error", func(t *testing.T) { + keyValueMap := map[string]string{ + "nonHex": "01", + } + err = node.SetKeyValueForAddress(addressBytes, keyValueMap) + require.NotNil(t, err) + require.True(t, strings.Contains(err.Error(), "cannot decode key")) + }) + t.Run("decode value failure should error", func(t *testing.T) { + keyValueMap := map[string]string{ + "01": "nonHex", + } + err = node.SetKeyValueForAddress(addressBytes, keyValueMap) + require.NotNil(t, err) + require.True(t, strings.Contains(err.Error(), "cannot decode value")) + }) + t.Run("LoadAccount failure should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return nil, expectedErr + }, + }, + } + + err = nodeLocal.SetKeyValueForAddress(addressBytes, nil) + require.Equal(t, expectedErr, err) + }) + t.Run("account un-castable to UserAccountHandler should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return &state.PeerAccountHandlerMock{}, nil + }, + }, + } + + err = nodeLocal.SetKeyValueForAddress(addressBytes, nil) + require.Error(t, err) + require.Equal(t, "cannot cast AccountHandler to UserAccountHandler", err.Error()) + }) + t.Run("SaveKeyValue failure should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return &state.UserAccountStub{ + SaveKeyValueCalled: func(key []byte, value []byte) error { + return expectedErr + }, + }, nil + }, + }, + } + + err = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) + require.Equal(t, expectedErr, err) + }) + t.Run("SaveAccount failure should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + SaveAccountCalled: func(account vmcommon.AccountHandler) error { + return expectedErr + }, + }, + } - keyValueMap = map[string]string{ - "01": "nonHex", + err = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) + require.Equal(t, expectedErr, err) + }) +} + +func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { + t.Parallel() + + node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.NoError(t, err) + + address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" + scAddress := "erd1qqqqqqqqqqqqqpgqrchxzx5uu8sv3ceg8nx8cxc0gesezure5awqn46gtd" + addressBytes, _ := node.CoreComponentsHolder.AddressPubKeyConverter().Decode(address) + scAddressBytes, _ := node.CoreComponentsHolder.AddressPubKeyConverter().Decode(scAddress) + addressState := &dtos.AddressState{ + Address: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", + Nonce: 100, + Balance: "1000000000000000000", + Keys: map[string]string{ + "01": "02", + }, } - err = node.SetKeyValueForAddress(addressBytes, keyValueMap) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), "cannot decode value")) + + t.Run("should work", func(t *testing.T) { + _, err = node.StateComponentsHolder.AccountsAdapter().GetExistingAccount(addressBytes) + require.Error(t, err) + require.True(t, strings.Contains(err.Error(), "account was not found")) + + err = node.SetStateForAddress(addressBytes, addressState) + require.NoError(t, err) + + account, err := node.StateComponentsHolder.AccountsAdapter().GetExistingAccount(addressBytes) + require.NoError(t, err) + require.Equal(t, addressState.Nonce, account.GetNonce()) + }) + t.Run("LoadAccount failure should error", func(t *testing.T) { + t.Parallel() + + nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return nil, expectedErr + }, + }, + } + + errLocal = nodeLocal.SetStateForAddress([]byte("address"), nil) + require.Equal(t, expectedErr, errLocal) + }) + t.Run("state balance invalid should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Balance = "invalid balance" + err = node.SetStateForAddress(addressBytes, &addressStateCopy) + require.Error(t, err) + require.Equal(t, "cannot convert string balance to *big.Int", err.Error()) + }) + t.Run("AddToBalance failure should error", func(t *testing.T) { + t.Parallel() + + nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return &state.UserAccountStub{ + AddToBalanceCalled: func(value *big.Int) error { + return expectedErr + }, + }, nil + }, + }, + } + + errLocal = nodeLocal.SetStateForAddress([]byte("address"), addressState) + require.Equal(t, expectedErr, errLocal) + }) + t.Run("SaveKeyValue failure should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + LoadAccountCalled: func(container []byte) (vmcommon.AccountHandler, error) { + return &state.UserAccountStub{ + SaveKeyValueCalled: func(key []byte, value []byte) error { + return expectedErr + }, + }, nil + }, + }, + } + + errLocal = nodeLocal.SetStateForAddress(addressBytes, addressState) + require.Equal(t, expectedErr, errLocal) + }) + t.Run("invalid sc code should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Address = scAddress + addressStateCopy.Code = "invalid code" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("invalid sc code hash should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Address = scAddress + addressStateCopy.CodeHash = "invalid code hash" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("invalid sc code metadata should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Address = scAddress + addressStateCopy.CodeMetadata = "invalid code metadata" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("invalid sc owner should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Address = scAddress + addressStateCopy.Owner = "invalid owner" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("invalid sc dev rewards should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Owner = address + addressStateCopy.Address = scAddress + addressStateCopy.DeveloperRewards = "invalid dev rewards" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("invalid root hash should error", func(t *testing.T) { + addressStateCopy := *addressState + addressStateCopy.Owner = address + addressStateCopy.Address = scAddress // coverage + addressStateCopy.DeveloperRewards = "1000000" + addressStateCopy.RootHash = "invalid root hash" + + err = node.SetStateForAddress(scAddressBytes, &addressStateCopy) + require.Error(t, err) + }) + t.Run("SaveAccount failure should error", func(t *testing.T) { + t.Parallel() + + argsLocal := createMockArgsTestOnlyProcessingNode(t) + nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + require.NoError(t, errLocal) + + nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ + Accounts: &state.AccountsStub{ + SaveAccountCalled: func(account vmcommon.AccountHandler) error { + return expectedErr + }, + }, + } + + err = nodeLocal.SetStateForAddress(addressBytes, addressState) + require.Equal(t, expectedErr, err) + }) +} + +func TestTestOnlyProcessingNode_IsInterfaceNil(t *testing.T) { + t.Parallel() + + var node *testOnlyProcessingNode + require.True(t, node.IsInterfaceNil()) + + node, _ = NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.False(t, node.IsInterfaceNil()) +} + +func TestTestOnlyProcessingNode_Close(t *testing.T) { + t.Parallel() + + node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.NoError(t, err) + + require.NoError(t, node.Close()) +} + +func TestTestOnlyProcessingNode_Getters(t *testing.T) { + t.Parallel() + + node := &testOnlyProcessingNode{} + require.Nil(t, node.GetProcessComponents()) + require.Nil(t, node.GetChainHandler()) + require.Nil(t, node.GetBroadcastMessenger()) + require.Nil(t, node.GetCryptoComponents()) + require.Nil(t, node.GetCoreComponents()) + require.Nil(t, node.GetStateComponents()) + require.Nil(t, node.GetFacadeHandler()) + require.Nil(t, node.GetStatusCoreComponents()) + + node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) + require.Nil(t, err) + + require.NotNil(t, node.GetProcessComponents()) + require.NotNil(t, node.GetChainHandler()) + require.NotNil(t, node.GetBroadcastMessenger()) + require.NotNil(t, node.GetShardCoordinator()) + require.NotNil(t, node.GetCryptoComponents()) + require.NotNil(t, node.GetCoreComponents()) + require.NotNil(t, node.GetStateComponents()) + require.NotNil(t, node.GetFacadeHandler()) + require.NotNil(t, node.GetStatusCoreComponents()) } diff --git a/testscommon/state/userAccountStub.go b/testscommon/state/userAccountStub.go index 3e4278b2d38..ce54f059252 100644 --- a/testscommon/state/userAccountStub.go +++ b/testscommon/state/userAccountStub.go @@ -30,6 +30,7 @@ type UserAccountStub struct { RetrieveValueCalled func(_ []byte) ([]byte, uint32, error) SetDataTrieCalled func(dataTrie common.Trie) GetRootHashCalled func() []byte + SaveKeyValueCalled func(key []byte, value []byte) error } // HasNewCode - @@ -172,7 +173,10 @@ func (u *UserAccountStub) RetrieveValue(key []byte) ([]byte, uint32, error) { } // SaveKeyValue - -func (u *UserAccountStub) SaveKeyValue(_ []byte, _ []byte) error { +func (u *UserAccountStub) SaveKeyValue(key []byte, value []byte) error { + if u.SaveKeyValueCalled != nil { + return u.SaveKeyValueCalled(key, value) + } return nil } From b4145645237ea5bf9084cc3c52b77dc06aa04c7d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 15 Feb 2024 14:13:09 +0200 Subject: [PATCH 2/6] fixed races --- .../components/testOnlyProcessingNode_test.go | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index bb44ec5a9be..9a9714cd28c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -205,8 +205,8 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { }, } - err = nodeLocal.SetKeyValueForAddress(addressBytes, nil) - require.Equal(t, expectedErr, err) + errLocal = nodeLocal.SetKeyValueForAddress(addressBytes, nil) + require.Equal(t, expectedErr, errLocal) }) t.Run("account un-castable to UserAccountHandler should error", func(t *testing.T) { t.Parallel() @@ -223,15 +223,14 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { }, } - err = nodeLocal.SetKeyValueForAddress(addressBytes, nil) - require.Error(t, err) - require.Equal(t, "cannot cast AccountHandler to UserAccountHandler", err.Error()) + errLocal = nodeLocal.SetKeyValueForAddress(addressBytes, nil) + require.Error(t, errLocal) + require.Equal(t, "cannot cast AccountHandler to UserAccountHandler", errLocal.Error()) }) t.Run("SaveKeyValue failure should error", func(t *testing.T) { t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) - nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) + nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, errLocal) nodeLocal.StateComponentsHolder = &factory.StateComponentsMock{ @@ -246,8 +245,8 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { }, } - err = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) - require.Equal(t, expectedErr, err) + errLocal = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) + require.Equal(t, expectedErr, errLocal) }) t.Run("SaveAccount failure should error", func(t *testing.T) { t.Parallel() @@ -264,8 +263,8 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { }, } - err = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) - require.Equal(t, expectedErr, err) + errLocal = nodeLocal.SetKeyValueForAddress(addressBytes, goodKeyValueMap) + require.Equal(t, expectedErr, errLocal) }) } @@ -433,8 +432,8 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { }, } - err = nodeLocal.SetStateForAddress(addressBytes, addressState) - require.Equal(t, expectedErr, err) + errLocal = nodeLocal.SetStateForAddress(addressBytes, addressState) + require.Equal(t, expectedErr, errLocal) }) } From 19ea2fe3a180559e680f96f056327f279e4c3e99 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 15 Feb 2024 15:08:22 +0200 Subject: [PATCH 3/6] skip new tests --- .../components/testOnlyProcessingNode_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index 9a9714cd28c..10ab4ecec70 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -152,6 +152,11 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { } func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { + // TODO reinstate test after Wasm VM pointer fix + if testing.Short() { + t.Skip("cannot run with -race -short; requires Wasm VM fix") + } + t.Parallel() goodKeyValueMap := map[string]string{ @@ -269,6 +274,11 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { + // TODO reinstate test after Wasm VM pointer fix + if testing.Short() { + t.Skip("cannot run with -race -short; requires Wasm VM fix") + } + t.Parallel() node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) From 7757ae9ce8d70449958fe973088c02caf3f17958 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 16 Feb 2024 11:05:46 +0200 Subject: [PATCH 4/6] removed t.Parallel --- node/chainSimulator/components/testOnlyProcessingNode_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index 10ab4ecec70..fba412b937e 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -157,8 +157,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { t.Skip("cannot run with -race -short; requires Wasm VM fix") } - t.Parallel() - goodKeyValueMap := map[string]string{ "01": "02", } @@ -279,8 +277,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { t.Skip("cannot run with -race -short; requires Wasm VM fix") } - t.Parallel() - node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, err) From bd8c482757fdcb354b306caeb123c09b22ff33d4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 16 Feb 2024 15:48:35 +0200 Subject: [PATCH 5/6] remove t.Parallel from testOnlyProcessingNode tests --- .../components/testOnlyProcessingNode_test.go | 52 ------------------- 1 file changed, 52 deletions(-) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index fba412b937e..c2603c62441 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -46,19 +46,13 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo } func TestNewTestOnlyProcessingNode(t *testing.T) { - t.Parallel() - t.Run("should work", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) node, err := NewTestOnlyProcessingNode(args) assert.Nil(t, err) assert.NotNil(t, node) }) t.Run("try commit a block", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) node, err := NewTestOnlyProcessingNode(args) assert.Nil(t, err) @@ -86,8 +80,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { assert.Nil(t, err) }) t.Run("CreateCoreComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.Configs.GeneralConfig.Marshalizer.Type = "invalid type" node, err := NewTestOnlyProcessingNode(args) @@ -95,8 +87,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("CreateCryptoComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.Configs.GeneralConfig.PublicKeyPIDSignature.Type = "invalid type" node, err := NewTestOnlyProcessingNode(args) @@ -104,8 +94,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("CreateNetworkComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.SyncedBroadcastNetwork = nil node, err := NewTestOnlyProcessingNode(args) @@ -113,8 +101,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("CreateBootstrapComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.Configs.FlagsConfig.WorkingDir = "" node, err := NewTestOnlyProcessingNode(args) @@ -122,8 +108,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("CreateStateComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.ShardIDStr = common.MetachainShardName // coverage only args.Configs.GeneralConfig.StateTriesConfig.MaxStateTrieLevelInMemory = 0 @@ -132,8 +116,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("CreateProcessComponents failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.Configs.FlagsConfig.Version = "" node, err := NewTestOnlyProcessingNode(args) @@ -141,8 +123,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { require.Nil(t, node) }) t.Run("createFacade failure should error", func(t *testing.T) { - t.Parallel() - args := createMockArgsTestOnlyProcessingNode(t) args.Configs.EpochConfig.GasSchedule.GasScheduleByEpochs = nil node, err := NewTestOnlyProcessingNode(args) @@ -152,11 +132,6 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { } func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix - if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") - } - goodKeyValueMap := map[string]string{ "01": "02", } @@ -194,8 +169,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { require.True(t, strings.Contains(err.Error(), "cannot decode value")) }) t.Run("LoadAccount failure should error", func(t *testing.T) { - t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) require.NoError(t, errLocal) @@ -212,8 +185,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { require.Equal(t, expectedErr, errLocal) }) t.Run("account un-castable to UserAccountHandler should error", func(t *testing.T) { - t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) require.NoError(t, errLocal) @@ -231,8 +202,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { require.Equal(t, "cannot cast AccountHandler to UserAccountHandler", errLocal.Error()) }) t.Run("SaveKeyValue failure should error", func(t *testing.T) { - t.Parallel() - nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, errLocal) @@ -252,8 +221,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { require.Equal(t, expectedErr, errLocal) }) t.Run("SaveAccount failure should error", func(t *testing.T) { - t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) require.NoError(t, errLocal) @@ -272,11 +239,6 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix - if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") - } - node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, err) @@ -306,8 +268,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { require.Equal(t, addressState.Nonce, account.GetNonce()) }) t.Run("LoadAccount failure should error", func(t *testing.T) { - t.Parallel() - nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, errLocal) @@ -330,8 +290,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { require.Equal(t, "cannot convert string balance to *big.Int", err.Error()) }) t.Run("AddToBalance failure should error", func(t *testing.T) { - t.Parallel() - nodeLocal, errLocal := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, errLocal) @@ -351,8 +309,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { require.Equal(t, expectedErr, errLocal) }) t.Run("SaveKeyValue failure should error", func(t *testing.T) { - t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) require.NoError(t, errLocal) @@ -424,8 +380,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { require.Error(t, err) }) t.Run("SaveAccount failure should error", func(t *testing.T) { - t.Parallel() - argsLocal := createMockArgsTestOnlyProcessingNode(t) nodeLocal, errLocal := NewTestOnlyProcessingNode(argsLocal) require.NoError(t, errLocal) @@ -444,8 +398,6 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_IsInterfaceNil(t *testing.T) { - t.Parallel() - var node *testOnlyProcessingNode require.True(t, node.IsInterfaceNil()) @@ -454,8 +406,6 @@ func TestTestOnlyProcessingNode_IsInterfaceNil(t *testing.T) { } func TestTestOnlyProcessingNode_Close(t *testing.T) { - t.Parallel() - node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, err) @@ -463,8 +413,6 @@ func TestTestOnlyProcessingNode_Close(t *testing.T) { } func TestTestOnlyProcessingNode_Getters(t *testing.T) { - t.Parallel() - node := &testOnlyProcessingNode{} require.Nil(t, node.GetProcessComponents()) require.Nil(t, node.GetChainHandler()) From 3a90de9d8579a98b1eb32ae8e59b59125638414c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 16 Feb 2024 16:48:45 +0200 Subject: [PATCH 6/6] fix after review --- .../components/testOnlyProcessingNode_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index c2603c62441..6ee1620f888 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -132,6 +132,11 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { } func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { + // TODO reinstate test after Wasm VM pointer fix + if testing.Short() { + t.Skip("cannot run with -race -short; requires Wasm VM fix") + } + goodKeyValueMap := map[string]string{ "01": "02", } @@ -239,6 +244,11 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { + // TODO reinstate test after Wasm VM pointer fix + if testing.Short() { + t.Skip("cannot run with -race -short; requires Wasm VM fix") + } + node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) require.NoError(t, err)