Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
  • Loading branch information
shrenujb committed May 3, 2024
1 parent a9ea773 commit 76094e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
5 changes: 2 additions & 3 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -275,9 +274,9 @@ func CmdModuleNameToAddress() *cobra.Command {
Use: "module-name-to-address [module-name]",
Short: "module name to address",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
address := authtypes.NewModuleAddress(args[0])
fmt.Println(address.String())
return nil
return clientCtx.PrintString(address.String())
},
}

Expand Down
24 changes: 24 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package cmd_test

import (
"fmt"
"testing"

clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"

"github.com/cosmos/cosmos-sdk/client"

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/dydxprotocol/v4-chain/protocol/app/config"
"github.com/dydxprotocol/v4-chain/protocol/app/constants"
Expand Down Expand Up @@ -46,3 +51,22 @@ func TestNewRootCmd_UsesClientConfig(t *testing.T) {
rootCmd.SetArgs([]string{"query", "auth", "params"})
require.ErrorContains(t, svrcmd.Execute(rootCmd, constants.AppDaemonName, tempDir), "fakeTestAddress")
}

func TestCmdModuleNameToAddress(t *testing.T) {
expectedModuleNameAddress := map[string]string{
"subaccounts": "dydx1v88c3xv9xyv3eetdx0tvcmq7ung3dywp5upwc6",
"subaccounts:37": "dydx16lwrx54mh9aru9ulzpknd429wldkhdwekhlswf",
"insurance_fund": "dydx1c7ptc87hkd54e3r7zjy92q29xkq7t79w64slrq",
"insurance_fund:37": "dydx10mlrxmaquwjwsj59ywp8xttc8rfxn9jfvzswtn",
}
for moduleName, expectedAddress := range expectedModuleNameAddress {
t.Run(
fmt.Sprintf("ModuleNameToAddress %s", moduleName), func(t *testing.T) {
ctx := client.Context{}
out, err := clitestutil.ExecTestCLICmd(ctx, cmd.CmdModuleNameToAddress(), []string{moduleName})
require.NoError(t, err)
require.Equal(t, expectedAddress, out.String())
},
)
}
}
14 changes: 0 additions & 14 deletions protocol/x/perpetuals/client/cli/query_perpetual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,3 @@ func TestListPerpetual(t *testing.T) {
}
})
}

func TestCmdModuleNameToAddress(t *testing.T) {
expectedModuleNameAddress := map[string]string{
"subaccounts": "dydx1v88c3xv9xyv3eetdx0tvcmq7ung3dywp5upwc6",
"subaccounts:37": "dydx16lwrx54mh9aru9ulzpknd429wldkhdwekhlswf",
"insurance_fund": "dydx1c7ptc87hkd54e3r7zjy92q29xkq7t79w64slrq",
"insurance_fund:37": "dydx10mlrxmaquwjwsj59ywp8xttc8rfxn9jfvzswtn",
}
for moduleName, expectedAddress := range expectedModuleNameAddress {
args := []string{
moduleName,
fmt.Sprintf("--%s=json", tmcli.OutputFlag),

}

0 comments on commit 76094e3

Please sign in to comment.