-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E: Increase masterchef coverage (#976)
* add more tests * query tests * add more tests * remove as we will switch to autocli * add msg server tests * add tests
- Loading branch information
1 parent
79379d5
commit d974e53
Showing
8 changed files
with
647 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package cli_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
"github.com/cosmos/gogoproto/proto" | ||
"github.com/elys-network/elys/x/masterchef/client/cli" | ||
"github.com/elys-network/elys/x/masterchef/types" | ||
) | ||
|
||
func (s *CLITestSuite) TestAprs() { | ||
cmd := cli.CmdAprs() | ||
cmd.SetOutput(io.Discard) | ||
|
||
testCases := []struct { | ||
name string | ||
ctxGen func() client.Context | ||
args []string | ||
expectResult proto.Message | ||
expectErr bool | ||
}{ | ||
{ | ||
"valid query", | ||
func() client.Context { | ||
bz, _ := s.encCfg.Codec.Marshal(&types.QueryAprsResponse{ | ||
UsdcAprUsdc: sdkmath.LegacyOneDec(), | ||
EdenAprUsdc: sdkmath.LegacyOneDec(), | ||
UsdcAprEdenb: sdkmath.LegacyOneDec(), | ||
EdenAprEdenb: sdkmath.LegacyOneDec(), | ||
}) | ||
c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ | ||
Value: bz, | ||
}) | ||
return s.baseCtx.WithClient(c) | ||
}, | ||
[]string{ | ||
fmt.Sprintf("--%s=json", flags.FlagOutput), | ||
}, | ||
&types.QueryAprsResponse{ | ||
UsdcAprUsdc: sdkmath.LegacyOneDec(), | ||
EdenAprUsdc: sdkmath.LegacyOneDec(), | ||
UsdcAprEdenb: sdkmath.LegacyOneDec(), | ||
EdenAprEdenb: sdkmath.LegacyOneDec(), | ||
}, | ||
false, | ||
}, | ||
{ | ||
"invalid query", | ||
func() client.Context { | ||
bz, _ := s.encCfg.Codec.Marshal(&types.QueryAprsResponse{}) | ||
c := clitestutil.NewMockCometRPC(abci.ResponseQuery{ | ||
Value: bz, | ||
}) | ||
return s.baseCtx.WithClient(c) | ||
}, | ||
[]string{ | ||
"-1", | ||
fmt.Sprintf("--%s=json", flags.FlagOutput), | ||
}, | ||
&types.QueryAprsResponse{}, | ||
true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(tc.name, func() { | ||
var outBuf bytes.Buffer | ||
|
||
clientCtx := tc.ctxGen().WithOutput(&outBuf) | ||
ctx := svrcmd.CreateExecuteContext(context.Background()) | ||
|
||
cmd.SetContext(ctx) | ||
cmd.SetArgs(tc.args) | ||
|
||
s.Require().NoError(client.SetCmdClientContextHandler(clientCtx, cmd)) | ||
|
||
err := cmd.Execute() | ||
if tc.expectErr { | ||
s.Require().Error(err) | ||
} else { | ||
s.Require().NoError(s.encCfg.Codec.UnmarshalJSON(outBuf.Bytes(), tc.expectResult)) | ||
s.Require().NoError(err) | ||
} | ||
}) | ||
} | ||
} |
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,39 @@ | ||
package cli_test | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" | ||
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil" | ||
"github.com/cosmos/cosmos-sdk/x/bank" | ||
) | ||
|
||
type CLITestSuite struct { | ||
suite.Suite | ||
|
||
kr keyring.Keyring | ||
encCfg testutilmod.TestEncodingConfig | ||
baseCtx client.Context | ||
} | ||
|
||
func TestMigrateTestSuite(t *testing.T) { | ||
suite.Run(t, new(CLITestSuite)) | ||
} | ||
|
||
func (s *CLITestSuite) SetupSuite() { | ||
s.encCfg = testutilmod.MakeTestEncodingConfig(bank.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.MockCometRPC{Client: rpcclientmock.Client{}}). | ||
WithAccountRetriever(client.MockAccountRetriever{}). | ||
WithOutput(io.Discard) | ||
} |
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
Oops, something went wrong.