-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e3a28c
commit 30c7ccc
Showing
16 changed files
with
235 additions
and
249 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
package cli_test | ||
package cli_test | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
"github.com/stretchr/testify/suite" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/gov" | ||
// "github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" | ||
"io" | ||
"testing" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/gov" | ||
"github.com/stretchr/testify/suite" | ||
// "github.com/cosmos/cosmos-sdk/x/gov/client/cli" | ||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
) | ||
|
||
type CLITestSuite struct { | ||
suite.Suite | ||
suite.Suite | ||
|
||
kr keyring.Keyring | ||
encCfg testutilmod.TestEncodingConfig //This holds the encoding configuration, which is crucial for marshaling and unmarshaling data for transactions and messages. | ||
baseCtx client.Context //This is a base context used for all operations in the test suite. | ||
kr keyring.Keyring | ||
encCfg testutilmod.TestEncodingConfig // This holds the encoding configuration, which is crucial for marshaling and unmarshaling data for transactions and messages. | ||
baseCtx client.Context // This is a base context used for all operations in the test suite. | ||
} | ||
|
||
func TestCLITestSuite(t *testing.T) { | ||
suite.Run(t, new(CLITestSuite)) | ||
suite.Run(t, new(CLITestSuite)) | ||
} | ||
//run once before any tests in the suite | ||
|
||
// run once before any tests in the suite | ||
func (s *CLITestSuite) SetupSuite() { | ||
//It initializes the necessary components, such as the codec, which is used for marshaling and unmarshaling data. | ||
s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModuleBasic{}) | ||
s.kr = keyring.NewInMemory(s.encCfg.Codec) | ||
s.baseCtx = client.Context{}. | ||
WithKeyring(s.kr). | ||
WithTxConfig(s.encCfg.TxConfig). | ||
WithCodec(s.encCfg.Codec). | ||
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). | ||
WithAccountRetriever(client.MockAccountRetriever{}). | ||
WithOutput(io.Discard). | ||
WithChainID("test-chain") | ||
s.encCfg = testutilmod.MakeTestEncodingConfig(gov.AppModuleBasic{}) | ||
s.kr = keyring.NewInMemory(s.encCfg.Codec) | ||
s.baseCtx = client.Context{}. | ||
WithKeyring(s.kr). | ||
WithTxConfig(s.encCfg.TxConfig). | ||
WithCodec(s.encCfg.Codec). | ||
WithClient(clitestutil.MockTendermintRPC{Client: rpcclientmock.Client{}}). | ||
WithAccountRetriever(client.MockAccountRetriever{}). | ||
WithOutput(io.Discard). | ||
WithChainID("test-chain") | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,40 +1,41 @@ | ||
package cli_test | ||
package cli_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
v2lunc1cli "github.com/classic-terra/core/v3/custom/gov/client/cli" | ||
"fmt" | ||
"strings" | ||
|
||
v2lunc1cli "github.com/classic-terra/core/v3/custom/gov/client/cli" | ||
) | ||
|
||
func (s *CLITestSuite) TestGetCmdQueryMinimalDeposit() { | ||
testCases := []struct { | ||
name string | ||
args []string | ||
expCmdOutput string | ||
}{ | ||
{ | ||
"proposal with id", | ||
[]string{ | ||
"1", | ||
}, | ||
"1", | ||
}, | ||
{ | ||
"proposal with no id", | ||
[]string{ | ||
"", | ||
}, | ||
"", | ||
}, | ||
} | ||
testCases := []struct { | ||
name string | ||
args []string | ||
expCmdOutput string | ||
}{ | ||
{ | ||
"proposal with id", | ||
[]string{ | ||
"1", | ||
}, | ||
"1", | ||
}, | ||
{ | ||
"proposal with no id", | ||
[]string{ | ||
"", | ||
}, | ||
"", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(tc.name, func() { | ||
cmd := v2lunc1cli.GetCmdQueryMinimalDeposit() | ||
cmd.SetArgs(tc.args) | ||
s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) | ||
}) | ||
} | ||
} | ||
s.Run(tc.name, func() { | ||
cmd := v2lunc1cli.GetCmdQueryMinimalDeposit() | ||
cmd.SetArgs(tc.args) | ||
s.Require().Contains(fmt.Sprint(cmd), strings.TrimSpace(tc.expCmdOutput)) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,52 +1,52 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// proposal defines the new Msg-based proposal. | ||
type proposal struct { | ||
// Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. | ||
Messages []json.RawMessage `json:"messages,omitempty"` | ||
Metadata string `json:"metadata"` | ||
Deposit string `json:"deposit"` | ||
Title string `json:"title"` | ||
Summary string `json:"summary"` | ||
} | ||
|
||
// parseSubmitProposal reads and parses the proposal. | ||
func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, string, string, string, sdk.Coins, error) { | ||
var proposal proposal | ||
|
||
contents, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, "", "", "", nil, err | ||
} | ||
|
||
err = json.Unmarshal(contents, &proposal) | ||
if err != nil { | ||
return nil, "", "", "", nil, err | ||
} | ||
|
||
msgs := make([]sdk.Msg, len(proposal.Messages)) | ||
for i, anyJSON := range proposal.Messages { | ||
var msg sdk.Msg | ||
err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) | ||
if err != nil { | ||
return nil, "", "", "", nil, err | ||
} | ||
|
||
msgs[i] = msg | ||
} | ||
|
||
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) | ||
if err != nil { | ||
return nil, "", "", "", nil, err | ||
} | ||
|
||
return msgs, proposal.Metadata, proposal.Title, proposal.Summary, deposit, nil | ||
} | ||
// import ( | ||
// "encoding/json" | ||
// "os" | ||
|
||
// "github.com/cosmos/cosmos-sdk/codec" | ||
// sdk "github.com/cosmos/cosmos-sdk/types" | ||
// ) | ||
|
||
// // proposal defines the new Msg-based proposal. | ||
// type proposal struct { | ||
// // Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. | ||
// Messages []json.RawMessage `json:"messages,omitempty"` | ||
// Metadata string `json:"metadata"` | ||
// Deposit string `json:"deposit"` | ||
// Title string `json:"title"` | ||
// Summary string `json:"summary"` | ||
// } | ||
|
||
// // parseSubmitProposal reads and parses the proposal. | ||
// func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, string, string, string, sdk.Coins, error) { | ||
// var proposal proposal | ||
|
||
// contents, err := os.ReadFile(path) | ||
// if err != nil { | ||
// return nil, "", "", "", nil, err | ||
// } | ||
|
||
// err = json.Unmarshal(contents, &proposal) | ||
// if err != nil { | ||
// return nil, "", "", "", nil, err | ||
// } | ||
|
||
// msgs := make([]sdk.Msg, len(proposal.Messages)) | ||
// for i, anyJSON := range proposal.Messages { | ||
// var msg sdk.Msg | ||
// err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) | ||
// if err != nil { | ||
// return nil, "", "", "", nil, err | ||
// } | ||
|
||
// msgs[i] = msg | ||
// } | ||
|
||
// deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) | ||
// if err != nil { | ||
// return nil, "", "", "", nil, err | ||
// } | ||
|
||
// return msgs, proposal.Metadata, proposal.Title, proposal.Summary, deposit, nil | ||
// } |
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
Oops, something went wrong.