-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ioctl] Build contract invoke command line into new ioctl (#3709)
* [ioctl] build contract invoke command line into new ioctl * build unittest to cover the modification1~ * remove stale comments Co-authored-by: huofei <[email protected]>
- Loading branch information
1 parent
de9bd7a
commit 14a7168
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
} |