Repository: iotexproject/iotex-core (go)

Issue:
[ioctl] build contract invoke command line into new ioctl
### What would you like to be added
 - Step 1: create `contractinvoke.go` and `contractinvoke_test.go` files in `./ioctl/newcmd/contract`. create this directory if not exist. 
 - Step 2: refactor  command  https://github.com/iotexproject/iotex-core/blob/master/ioctl/cmd/contract/contractinvoke.go in `contractinvoke.go`
 - Step 3: add unit test in xx_test.go

#### Notes:
1. Use [client interface](https://github.com/iotexproject/iotex-core/blob/master/ioctl/client.go) to construct the Cobra command.
2. [Output package](https://github.com/iotexproject/iotex-core/blob/master/ioctl/output) is deprecated. `e.g.` `output.PrintError` could be replaced with `errors.Wrap`.
3. Global variables (config.ReadConfig  config.DefaultConfigFile etc.) have been wrapped into client interface. Please use [client interface](https://github.com/iotexproject/iotex-core/blob/master/ioctl/client.go) to access them if needed
4. The logic of new code should be similar to [the old one](https://github.com/iotexproject/iotex-core/blob/master/ioctl/cmd/contract/contractinvoke.go).
5. In each unit test, the results should be checked whether they are as the expected. 




#### Example:
1. https://github.com/iotexproject/iotex-core/blob/master/ioctl/newcmd/account/accountinfo.go
2. https://github.com/iotexproject/iotex-core/blob/master/ioctl/newcmd/account/accountdelete.go
3. https://github.com/iotexproject/iotex-core/blob/master/ioctl/newcmd/account/accountcreateadd.go

### Why is this needed
Unit tests couldn't be added for the old ioctl command (./ioctl/cmd) 


Pull request:
[ioctl] Build contract invoke command line into new ioctl
# Description
Build `contractinvoke` command in new `ioctl`, with the following note.

* Use [client interface](https://github.com/iotexproject/iotex-core/blob/master/ioctl/client.go) to construct the Cobra command.
* Output package is deprecated, replace it with errors package.
* Replace fmt.Println with cmd.Println
* Refactor unit test to cover the modification.

Fixes #3309  

## Type of change
Please delete options that are not relevant.
- [x] Code refactor or improvement

# How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
- [x] make test
- [x] TestNewContractInvokeCmd

**Test Configuration**:
- Firmware version: Ubuntu 21.04
- Hardware:
- Toolchain:
- SDK:

# Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules

Patch:
diff --git a/ioctl/newcmd/contract/contractinvoke.go b/ioctl/newcmd/contract/contractinvoke.go
new file mode 100644
index 000000000..97c596133
--- /dev/null
+++ b/ioctl/newcmd/contract/contractinvoke.go
@@ -0,0 +1,39 @@
+// Copyright (c) 2022 IoTeX Foundation
+// This source code is provided 'as is' and no warranties are given as to title or non-infringement,
+// merchantability or fitness for purpose and, to the extent permitted by law,
+// all liability for your use of the code is disclaimed. This source code is governed by Apache
+// License 2.0 that can be found in the LICENSE file.
+
+package contract
+
+import (
+	"github.com/spf13/cobra"
+
+	"github.com/iotexproject/iotex-core/ioctl"
+	"github.com/iotexproject/iotex-core/ioctl/config"
+)
+
+// Multi-language support
+var (
+	_invokeCmdShorts = map[config.Language]string{
+		config.English: "Invoke smart contract on IoTeX blockchain",
+		config.Chinese: "调用IoTeX区块链上的智能合约",
+	}
+)
+
+// NewContractInvokeCmd represents the contract invoke command
+func NewContractInvokeCmd(client ioctl.Client) *cobra.Command {
+	short, _ := client.SelectTranslation(_invokeCmdShorts)
+
+	cmd := &cobra.Command{
+		Use:   "invoke",
+		Short: short,
+	}
+
+	// TODO add sub commands
+	// cmd.AddCommand(NewContractInvokeFunctionCmd)
+	// cmd.AddCommand(NewContractInvokeBytecodeCmd)
+	// action.RegisterWriteCommand(NewContractInvokeFunctionCmd)
+	// action.RegisterWriteCommand(NewContractInvokeBytecodeCmd)
+	return cmd
+}


Test patch:
diff --git a/ioctl/newcmd/contract/contractinvoke_test.go b/ioctl/newcmd/contract/contractinvoke_test.go
new file mode 100644
index 000000000..aa596263e
--- /dev/null
+++ b/ioctl/newcmd/contract/contractinvoke_test.go
@@ -0,0 +1,33 @@
+// Copyright (c) 2022 IoTeX Foundation
+// This source code is provided 'as is' and no warranties are given as to title or non-infringement,
+// merchantability or fitness for purpose and, to the extent permitted by law,
+// all liability for your use of the code is disclaimed. This source code is governed by Apache
+// License 2.0 that can be found in the LICENSE file.
+
+package contract
+
+import (
+	"testing"
+
+	"github.com/golang/mock/gomock"
+	"github.com/stretchr/testify/require"
+
+	"github.com/iotexproject/iotex-core/ioctl/config"
+	"github.com/iotexproject/iotex-core/ioctl/util"
+	"github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient"
+)
+
+func TestNewContractInvokeCmd(t *testing.T) {
+	require := require.New(t)
+	ctrl := gomock.NewController(t)
+	defer ctrl.Finish()
+	client := mock_ioctlclient.NewMockClient(ctrl)
+	client.EXPECT().SelectTranslation(gomock.Any()).Return("contract", config.English).AnyTimes()
+
+	t.Run("compile contract", func(t *testing.T) {
+		cmd := NewContractInvokeCmd(client)
+		result, err := util.ExecuteCmd(cmd)
+		require.NoError(err)
+		require.Equal("contract\n\n", result)
+	})
+}