-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sudo): CLI fns + tests. Also, switches testutil to use secp256k1 (…
…#1317) * golang structs for the contract binding types * feat(wasm): implement custom queries: Reserves, AllMarkets * refactor: make request type names more obvious * Wire in the WasmKeeper to the app with []wasm.Option set for the bindings * add FundAccount fn to x/common/testutil * rm fund.go. These functions were defined in the recent x/inflation PR * refactor: test genesis setup to testutil/genesis so other modules can import th functions * fix: add json serialization info to cw_query.go * test(wasmbin): add perp bindings contract and add correctness tests * test(wasm/binding): successful integration test using the real contract * update CHANGELOG and include marshal.go * fix: linter * (wasm): impl and test base price query * add utils * impl and test BasePrice, Metrics, and PremiumFraction queries * add remaining integration tests for the PR * test,fix(wasm): all integration tests working on a real contract * test,fix(wasm): all integration tests working on a real contract * comment * refactor(wasm): small rename to query_responses.json * refactor,docs: PR comments * test(cw_struct): test compatibility with rust binding types for execute msgs * feat(wasm): add execute msg bindings for open pos, add & remove margin, close pos * (wasm.go): wire the execute msg as a wasm.Option * test(wasm): unit + integration tests for perp transactions * changelog * changelog * test(wasm): check for position in state after it's open * golangci-lint * (wasm): new bindings contract * feat(wasm): peg shift bindings + unit test + integration test * changelog * build: new contract with String types for sdk.Dec values that can be negative * impl Position query with unit test * test: integration test for Position query * impl and test multiple position query * test(wasm): verify correctness of fields in positions query * checkpoint #wip sudo core business logic * checkpoint #wip: implement all business logic with full test coverage * test: add integration tests of the sudo contracts in x/wasm * changelog * changelog * more docs * refactor(sudo): run msg.ValidateBasic before the main handler * refactor: small cleanup * doc comment * feat(sudo): cli commands + tests for tx and query * feat(sample.go): secp256k1 usage for #1316 * chore: changelog + linter * test(sudo): slice order can change when written into state * test(sudo): fix boolean checks * chore: linter * chore: linter * changelog * remove ed25519Algo support in sample.go --------- Co-authored-by: Matthias <[email protected]>
- Loading branch information
1 parent
9661bf1
commit 8b0ebbd
Showing
9 changed files
with
482 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package genesis | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/app" | ||
|
||
"github.com/NibiruChain/nibiru/x/sudo" | ||
sudotypes "github.com/NibiruChain/nibiru/x/sudo/pb" | ||
|
||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
|
||
"github.com/NibiruChain/nibiru/x/common/testutil" | ||
) | ||
|
||
func AddSudoGenesis(gen app.GenesisState) ( | ||
genState app.GenesisState, | ||
rootPrivKey cryptotypes.PrivKey, | ||
rootAddr sdk.AccAddress, | ||
) { | ||
sudoGenesis, rootPrivKey, rootAddr := SudoGenesis() | ||
gen[sudotypes.ModuleName] = TEST_ENCODING_CONFIG.Marshaler. | ||
MustMarshalJSON(sudoGenesis) | ||
return gen, rootPrivKey, rootAddr | ||
} | ||
|
||
func SudoGenesis() ( | ||
genState *sudotypes.GenesisState, | ||
rootPrivKey cryptotypes.PrivKey, | ||
rootAddr sdk.AccAddress, | ||
) { | ||
sudoGenesis := sudo.DefaultGenesis() | ||
|
||
// Set the root user | ||
privKeys, addrs := testutil.PrivKeyAddressPairs(1) | ||
rootPrivKey = privKeys[0] | ||
rootAddr = addrs[0] | ||
sudoGenesis.Sudoers.Root = rootAddr.String() | ||
|
||
return sudoGenesis, rootPrivKey, rootAddr | ||
} |
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,143 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/version" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/NibiruChain/nibiru/x/sudo/pb" | ||
) | ||
|
||
// GetTxCmd returns a cli command for this module's transactions | ||
func GetTxCmd() *cobra.Command { | ||
txCmd := &cobra.Command{ | ||
Use: pb.ModuleName, | ||
Short: fmt.Sprintf("x/%s transaction subcommands", pb.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
// Add subcommands | ||
txCmd.AddCommand( | ||
CmdEditSudoers(), | ||
) | ||
|
||
return txCmd | ||
} | ||
|
||
// GetQueryCmd returns a cli command for this module's queries | ||
func GetQueryCmd() *cobra.Command { | ||
moduleQueryCmd := &cobra.Command{ | ||
Use: pb.ModuleName, | ||
Short: fmt.Sprintf( | ||
"Query commands for the x/%s module", pb.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
// Add subcommands | ||
cmds := []*cobra.Command{ | ||
CmdQuerySudoers(), | ||
} | ||
for _, cmd := range cmds { | ||
moduleQueryCmd.AddCommand(cmd) | ||
} | ||
|
||
return moduleQueryCmd | ||
} | ||
|
||
// CmdEditSudoers is a terminal command corresponding to the EditSudoers | ||
// function of the sdk.Msg handler for x/sudo. | ||
func CmdEditSudoers() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "edit [edit-json]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "Edit the x/sudo state (sudoers) by adding or removing contracts", | ||
Example: strings.TrimSpace(fmt.Sprintf(` | ||
Example: | ||
$ %s tx sudo edit <path/to/edit.json> --from=<key_or_address> | ||
`, version.AppName)), | ||
Long: strings.TrimSpace( | ||
`Adds or removes contracts from the x/sudo state, giving the | ||
contracts permissioned access to certain bindings in x/wasm. | ||
The edit.json for 'EditSudoers' is of the form: | ||
{ | ||
"action": "add_contracts", | ||
"contracts": "..." | ||
} | ||
- Valid action types: "add_contracts", "remove_contracts" | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := new(pb.MsgEditSudoers) | ||
|
||
// marshals contents into the proto.Message to which 'msg' points. | ||
contents, err := os.ReadFile(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
if err = clientCtx.Codec.UnmarshalJSON(contents, msg); err != nil { | ||
return err | ||
} | ||
|
||
// Parse the message sender | ||
from := clientCtx.GetFromAddress() | ||
msg.Sender = from.String() | ||
|
||
if err = msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func CmdQuerySudoers() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "state", | ||
Short: "displays the internal state (sudoers) of the x/sudo module", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := pb.NewQueryClient(clientCtx) | ||
|
||
req := new(pb.QuerySudoersRequest) | ||
resp, err := queryClient.QuerySudoers( | ||
cmd.Context(), req, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(resp) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
Oops, something went wrong.