-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* utd * add command * typo * add test * changelog * format * Update ignite/cmd/network_request_param_change.go Co-authored-by: Lucas Bertrand <[email protected]> * Update changelog.md Co-authored-by: Lucas Bertrand <[email protected]> Co-authored-by: Lucas Bertrand <[email protected]>
- Loading branch information
Showing
6 changed files
with
177 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ignite/cli/ignite/pkg/cliui" | ||
"github.com/ignite/cli/ignite/services/network" | ||
) | ||
|
||
// NewNetworkRequestParamChange creates a new command to send param change request | ||
func NewNetworkRequestParamChange() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "param-change [launch-id] [module-name] [param-name] [value (json, string, number)]", | ||
Short: "Send request to change param", | ||
RunE: networkRequestParamChangeHandler, | ||
Args: cobra.ExactArgs(4), | ||
} | ||
|
||
flagSetClearCache(c) | ||
c.Flags().AddFlagSet(flagNetworkFrom()) | ||
c.Flags().AddFlagSet(flagSetHome()) | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagSetKeyringDir()) | ||
return c | ||
} | ||
|
||
func networkRequestParamChangeHandler(cmd *cobra.Command, args []string) error { | ||
session := cliui.New(cliui.StartSpinner()) | ||
defer session.End() | ||
|
||
nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// parse launch ID | ||
launchID, err := network.ParseID(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
module := args[1] | ||
param := args[2] | ||
value := []byte(args[3]) | ||
|
||
n, err := nb.Network() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return n.SendParamChangeRequest( | ||
cmd.Context(), | ||
launchID, | ||
module, | ||
param, | ||
value, | ||
) | ||
} |
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,53 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
launchtypes "github.com/tendermint/spn/x/launch/types" | ||
|
||
"github.com/ignite/cli/ignite/services/network/networktypes" | ||
"github.com/ignite/cli/ignite/services/network/testutil" | ||
) | ||
|
||
func TestRequestParamChange(t *testing.T) { | ||
t.Run("successfully send request", func(t *testing.T) { | ||
var ( | ||
account = testutil.NewTestAccount(t, testutil.TestAccountName) | ||
suite, network = newSuite(account) | ||
module = "module" | ||
param = "param" | ||
value = []byte("value") | ||
) | ||
|
||
addr, err := account.Address(networktypes.SPN) | ||
require.NoError(t, err) | ||
|
||
suite.CosmosClientMock. | ||
On( | ||
"BroadcastTx", | ||
context.Background(), | ||
account, | ||
launchtypes.NewMsgSendRequest( | ||
addr, | ||
testutil.LaunchID, | ||
launchtypes.NewParamChange( | ||
testutil.LaunchID, | ||
module, | ||
param, | ||
value, | ||
), | ||
), | ||
). | ||
Return(testutil.NewResponse(&launchtypes.MsgSendRequestResponse{ | ||
RequestID: 0, | ||
AutoApproved: false, | ||
}), nil). | ||
Once() | ||
|
||
sendRequestError := network.SendParamChangeRequest(context.Background(), testutil.LaunchID, module, param, value) | ||
require.NoError(t, sendRequestError) | ||
suite.AssertAllMocks(t) | ||
}) | ||
} |
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