Skip to content

Commit

Permalink
chore: apply review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: zemyblue <[email protected]>
  • Loading branch information
zemyblue committed Aug 11, 2022
1 parent ba04319 commit 4f303d7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 46 deletions.
18 changes: 9 additions & 9 deletions x/wasm/client/testutil/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCodeInfo() {

codeID, err := strconv.ParseUint(s.codeID, 10, 64)
s.Require().NoError(err)
dataHash, err := hex.DecodeString("470C5B703A682F778B8B088D48169B8D6E43F7F44AC70316692CDBE69E6605E3")
expectedDataHash, err := hex.DecodeString("470C5B703A682F778B8B088D48169B8D6E43F7F44AC70316692CDBE69E6605E3")
s.Require().NoError(err)

testCases := map[string]struct {
Expand All @@ -94,7 +94,7 @@ func (s *IntegrationTestSuite) TestGetCmdQueryCodeInfo() {
&types.CodeInfoResponse{
CodeID: codeID,
Creator: val.Address.String(),
DataHash: dataHash,
DataHash: expectedDataHash,
InstantiatePermission: types.AllowEverybody,
},
},
Expand Down Expand Up @@ -223,7 +223,7 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractStateAll() {
},
"no exist bech32_address": {
[]string{
"link1hmayw7vv0p3gzeh3jzwmw9xj8fy8a3kmpqgjrysljdnecqkps02qrq5rvm",
s.nonExistValidAddress,
},
false,
nil,
Expand Down Expand Up @@ -260,7 +260,7 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractStateRaw() {
"valid query": {
[]string{
s.contractAddress,
"636F6E666967", // hex.EncodeToString([]byte("config")),
hex.EncodeToString([]byte("config")), // "636F6E666967"
},
true,
&types.QueryRawContractStateResponse{
Expand All @@ -270,23 +270,23 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractStateRaw() {
"no exist key": {
[]string{
s.contractAddress,
hex.EncodeToString([]byte("verifier")),
hex.EncodeToString([]byte("verifier")), // "7665726966696572",
},
true,
&types.QueryRawContractStateResponse{Data: nil},
},
"wrong bech32_address": {
[]string{
"xxx",
"636F6E666967",
hex.EncodeToString([]byte("config")), // "636F6E666967"
},
false,
nil,
},
"no exist bech32_address": {
[]string{
"link1hmayw7vv0p3gzeh3jzwmw9xj8fy8a3kmpqgjrysljdnecqkps02qrq5rvm",
"636F6E666967",
s.nonExistValidAddress,
hex.EncodeToString([]byte("config")), // "636F6E666967"
},
false,
nil,
Expand Down Expand Up @@ -356,7 +356,7 @@ func (s *IntegrationTestSuite) TestGetCmdGetContractStateSmart() {
},
"no exist bech32_address": {
[]string{
"link1hmayw7vv0p3gzeh3jzwmw9xj8fy8a3kmpqgjrysljdnecqkps02qrq5rvm",
s.nonExistValidAddress,
"{\"verifier\":{}}",
},
false,
Expand Down
22 changes: 13 additions & 9 deletions x/wasm/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/wasm/client/cli"
"github.com/line/lbm-sdk/x/wasm/keeper"
"github.com/line/lbm-sdk/x/wasm/types"
ostcli "github.com/line/ostracon/libs/cli"
"github.com/stretchr/testify/suite"
)
Expand All @@ -23,8 +24,9 @@ type IntegrationTestSuite struct {

setupHeight int64

codeID string
contractAddress string
codeID string
contractAddress string
nonExistValidAddress string

// for hackatom contract
verifier string
Expand Down Expand Up @@ -60,6 +62,8 @@ func (s *IntegrationTestSuite) SetupSuite() {
params := fmt.Sprintf("{\"verifier\": \"%s\", \"beneficiary\": \"%s\"}", s.verifier, s.beneficiary)
s.contractAddress = s.instantiate(s.codeID, params)

s.nonExistValidAddress = keeper.RandomAccountAddress(s.T()).String()

s.setupHeight, err = s.network.LatestHeight()
s.Require().NoError(err)
s.Require().NoError(s.network.WaitForNextBlock())
Expand All @@ -86,8 +90,8 @@ func (s *IntegrationTestSuite) deployContract() string {

args := append([]string{
wasmPath,
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%v", flags.FlagGas, 1500000),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%d", flags.FlagGas, 1500000),
}, commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.StoreCodeCmd(), args)
Expand All @@ -99,7 +103,7 @@ func (s *IntegrationTestSuite) deployContract() string {

// parse codeID
for _, v := range res.Events {
if v.Type == "store_code" {
if v.Type == types.EventTypeStoreCode {
return string(v.Attributes[0].Value)
}
}
Expand All @@ -114,9 +118,9 @@ func (s *IntegrationTestSuite) instantiate(codeID, params string) string {
args := append([]string{
codeID,
params,
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
}, commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.InstantiateContractCmd(), args)
Expand All @@ -128,7 +132,7 @@ func (s *IntegrationTestSuite) instantiate(codeID, params string) string {

// parse contractAddress
for _, v := range res.Events {
if v.Type == "instantiate" {
if v.Type == types.EventTypeInstantiate {
return string(v.Attributes[0].Value)
}
}
Expand Down
46 changes: 23 additions & 23 deletions x/wasm/client/testutil/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func (s *IntegrationTestSuite) TestInstantiateContractCmd() {
[]string{
s.codeID,
fmt.Sprintf("{\"verifier\": \"%s\", \"beneficiary\": \"%s\"}", owner, keeper.RandomAccountAddress(s.T())),
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
true,
},
Expand All @@ -44,35 +44,35 @@ func (s *IntegrationTestSuite) TestInstantiateContractCmd() {
[]string{
s.codeID,
fmt.Sprintf("{\"verifier\": \"%s\", \"beneficiary\": \"%s\"}", owner, keeper.RandomAccountAddress(s.T())),
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--label=%s", "TestContract"),
},
false,
},
"no sender error": {
[]string{
s.codeID,
fmt.Sprintf("{\"verifier\": \"%s\", \"beneficiary\": \"%s\"}", owner, keeper.RandomAccountAddress(s.T())),
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
},
false,
},
"no instantiate params error": {
[]string{
s.codeID,
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
false,
},
"no exist codeID error": {
[]string{
"0",
fmt.Sprintf("{\"verifier\": \"%s\", \"beneficiary\": \"%s\"}", owner, keeper.RandomAccountAddress(s.T())),
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
false,
},
Expand Down Expand Up @@ -111,30 +111,30 @@ func (s *IntegrationTestSuite) TestExecuteContractCmd() {
[]string{
contractAddr,
"{\"release\":{}}",
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
true,
},
"wrong amount": {
[]string{
contractAddr,
"{\"release\":{}}",
fmt.Sprintf("--%s=%v", "amount", "100"),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", "amount", "100"),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
false,
},
"wrong param": {
[]string{
contractAddr,
"{release:{}}",
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
false,
},
"no contract address": {
[]string{
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
},
false,
},
Expand Down Expand Up @@ -184,10 +184,10 @@ func (s *IntegrationTestSuite) TestStoreCodeAndInstantiateContractCmd() {
[]string{
wasmPath,
params,
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--%s=%v", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%v", flags.FlagGas, 1600000),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=%d", flags.FlagGas, 1600000),
},
true,
},
Expand All @@ -206,8 +206,8 @@ func (s *IntegrationTestSuite) TestStoreCodeAndInstantiateContractCmd() {
[]string{
wasmPath,
params,
fmt.Sprintf("--label=%v", "TestContract"),
fmt.Sprintf("--admin=%v", owner),
fmt.Sprintf("--label=%s", "TestContract"),
fmt.Sprintf("--admin=%s", owner),
},
false,
},
Expand Down
5 changes: 1 addition & 4 deletions x/wasm/lbm/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ func (msg MsgStoreCodeAndInstantiateContract) GetSignBytes() []byte {
}

func (msg MsgStoreCodeAndInstantiateContract) GetSigners() []sdk.AccAddress {
senderAddr, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil { // should never happen as valid basic rejects invalid addresses
panic(err.Error())
}
senderAddr, _ := sdk.AccAddressFromBech32(msg.Sender)
return []sdk.AccAddress{senderAddr}
}
2 changes: 1 addition & 1 deletion x/wasm/lbm/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func validateLabel(label string) error {
return sdkerrors.Wrap(wasmtypes.ErrEmpty, "is required")
}
if len(label) > wasmtypes.MaxLabelSize {
return sdkerrors.Wrap(wasmtypes.ErrLimit, "cannot be longer than 128 characters")
return sdkerrors.Wrapf(wasmtypes.ErrLimit, "cannot be longer than %d characters", wasmtypes.MaxWasmSize)
}
return nil
}

0 comments on commit 4f303d7

Please sign in to comment.