-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into panic_no_space
- Loading branch information
Showing
15 changed files
with
467 additions
and
29 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
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
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
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
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
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,5 @@ | ||
#!/bin/sh | ||
|
||
/usr/sbin/crond | ||
|
||
exec "$@" |
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
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,79 @@ | ||
// Copyright (c) 2022 IoTeX Foundation | ||
// This is an alpha (internal) release and is not suitable for production. 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 did | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
"github.com/iotexproject/iotex-address/address" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl" | ||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/newcmd/action" | ||
"github.com/iotexproject/iotex-core/ioctl/util" | ||
) | ||
|
||
// Multi-language support | ||
var ( | ||
_getHashCmdUses = map[config.Language]string{ | ||
config.English: "gethash (CONTRACT_ADDRESS|ALIAS) DID", | ||
config.Chinese: "gethash (合约地址|别名) DID", | ||
} | ||
_getHashCmdShorts = map[config.Language]string{ | ||
config.English: "Gethash get DID doc's hash on IoTeX blockchain", | ||
config.Chinese: "Gethash 在IoTeX链上获取相应DID的doc hash", | ||
} | ||
) | ||
|
||
// NewDidGetHash represents the did get hash command | ||
func NewDidGetHash(client ioctl.Client) *cobra.Command { | ||
use, _ := client.SelectTranslation(_getHashCmdUses) | ||
short, _ := client.SelectTranslation(_getHashCmdShorts) | ||
|
||
cmd := &cobra.Command{ | ||
Use: use, | ||
Short: short, | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
contract, err := client.Address(args[0]) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to get contract address") | ||
} | ||
addr, err := address.FromString(contract) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid contract address") | ||
} | ||
bytecode, err := _didABI.Pack(_getHashName, []byte(args[1])) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid bytecode") | ||
} | ||
|
||
result, err := action.Read(client, addr, "0", bytecode, contract, 20000000) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to read contract") | ||
} | ||
ret, err := hex.DecodeString(result) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to decode contract") | ||
} | ||
res, err := _didABI.Unpack(_getHashName, ret) | ||
if err != nil { | ||
return errors.New("DID does not exist") | ||
} | ||
out, err := util.To32Bytes(res[0]) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to convert hash to bytes") | ||
} | ||
cmd.Println(hex.EncodeToString(out[:])) | ||
return nil | ||
}, | ||
} | ||
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,91 @@ | ||
// Copyright (c) 2022 IoTeX Foundation | ||
// This is an alpha (internal) release and is not suitable for production. 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 did | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/iotexproject/iotex-proto/golang/iotexapi" | ||
"github.com/iotexproject/iotex-proto/golang/iotexapi/mock_iotexapi" | ||
"github.com/pkg/errors" | ||
"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/identityset" | ||
"github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" | ||
) | ||
|
||
func TestNewDidGetHashCmd(t *testing.T) { | ||
require := require.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
client := mock_ioctlclient.NewMockClient(ctrl) | ||
apiServiceClient := mock_iotexapi.NewMockAPIServiceClient(ctrl) | ||
accAddr := identityset.Address(0).String() | ||
did := "did:io:0x11111111111111111" | ||
|
||
client.EXPECT().SelectTranslation(gomock.Any()).Return("did", config.English).Times(12) | ||
client.EXPECT().Address(gomock.Any()).Return(accAddr, nil).Times(4) | ||
client.EXPECT().AddressWithDefaultIfNotExist(gomock.Any()).Return(accAddr, nil).Times(4) | ||
client.EXPECT().APIServiceClient().Return(apiServiceClient, nil).Times(4) | ||
|
||
t.Run("get did hash", func(t *testing.T) { | ||
apiServiceClient.EXPECT().ReadContract(gomock.Any(), gomock.Any()).Return(&iotexapi.ReadContractResponse{ | ||
Data: hex.EncodeToString([]byte("60fe47b100000000000000000000000000000000000000000000000000000000")), | ||
}, nil) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, accAddr, did) | ||
require.NoError(err) | ||
}) | ||
|
||
t.Run("failed to decode contract", func(t *testing.T) { | ||
expectedErr := errors.New("failed to decode contract") | ||
apiServiceClient.EXPECT().ReadContract(gomock.Any(), gomock.Any()).Return(&iotexapi.ReadContractResponse{ | ||
Data: "test", | ||
}, nil) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, "test", did) | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
|
||
t.Run("DID does not exist", func(t *testing.T) { | ||
expectedErr := errors.New("DID does not exist") | ||
apiServiceClient.EXPECT().ReadContract(gomock.Any(), gomock.Any()).Return(&iotexapi.ReadContractResponse{ | ||
Data: hex.EncodeToString([]byte("test")), | ||
}, nil) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, accAddr, did) | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
|
||
t.Run("failed to read contract", func(t *testing.T) { | ||
expectedErr := errors.New("failed to read contract") | ||
apiServiceClient.EXPECT().ReadContract(gomock.Any(), gomock.Any()).Return(nil, expectedErr) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, accAddr, did) | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
|
||
t.Run("invalid contract address", func(t *testing.T) { | ||
expectedErr := errors.New("invalid contract address") | ||
client.EXPECT().Address(gomock.Any()).Return("test", nil) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, "test", did) | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
|
||
t.Run("failed to get contract address", func(t *testing.T) { | ||
expectedErr := errors.New("failed to get contract address") | ||
client.EXPECT().Address(gomock.Any()).Return("", expectedErr) | ||
cmd := NewDidGetHash(client) | ||
_, err := util.ExecuteCmd(cmd, "test", did) | ||
require.Contains(err.Error(), expectedErr.Error()) | ||
}) | ||
} |
Oops, something went wrong.