Skip to content

Commit

Permalink
Fix most of the unit tests. (#1943)
Browse files Browse the repository at this point in the history
* [1760]: Stub out the registration of a couple custom GetSigners functions from the exchange module.

* [1760]: Update the exchange CLI tests to handle not having block broadcast anymore.

* [1760]: Fix the signers of the msgs in the exchange module.

* [1760]: Define and set the custom GetSigners funcs for create and accept payment.

* [1760]: Fix all of the exchange CLi tests.

* [1760]: Fix the last remaining exchange test failures.

* [1760]: Use the correct signer field for MsgAddAttributeRequest.

* [1760]: Fix the attribute module cli tests.

* [1760]: Fix the name tests.

* [1760]: Add the signer option to the oracle Msgs. Remove an error that was added to make things compile, but is no longer needed since the rest of the functionality around it has been restored.

* [1760]: Rename the testutil.Cleanup function (was CleanUp, which I kept getting wrong). Switch all uses of WaitForHeight to the testutil one.

* [1760]: Fix the oracle cli tests. Make queries.GetTxFromResponse return the one provided if the one provided doesn't have code 0.

* [1760]: Delete a couple unneeded files.

* [1760]: Create a global encoding config variable that is set in app.New so that some trigger validate basic things can get the signers of messages. Fix the trigger unit tests.

* [1760]: Fix the ibcratelimit cli tests.

* [1760]: Fix the msgfees cli tests.

* [1760]: Make AssertGetTxFromResponse return the original response if it has something in the raw log or somehow already has a Tx.

* [1760]: Create ABCIEventsToStrings (same as EventsToStrings, but with the events that come back in a txResp. Create MutateGenesisState as an easier way to update a module's genesis state during test setup. Create createQueryCmd as a helper that will create a query command for a url. Create CmdGetAllGovProps that uses createQueryCmd to get all governance proposals.

* [1760]: Add the signer option to MsgGrantAllowanceRequest and fix the marker CLI tests.

* [1760]: Add validation to marker params to fix a test.

* [1760]: Allow ValidateUnrestictedDenom to pass if the regex is blank. Fix marker keeper unit tests.

* [1760]: Fix the rest of the marker tests.

* [1760]: Fix metadata keeper tests.

* [1760]: Add signers to all the metadata Msgs.

* [1760]: Fix the metadata CLI unit tests.

* [1760]: Put the check back into the msgfees commands that makes sure the provide msgType resolves to a msg (fixes the msgfees unit tests again).

* [1760]: Create a CLITxExecutor to standarize testing of Tx commands.

* [1760]: Remove unneccesary call to ValidateBasic from GetCmdAddNetAssetValues.

* [1760]: Use ErrUnauthorized (instead of ErrorInvalidSigner) when not all required signers have sined a MsgAddNetAssetValuesRequest. The latter doesn't quite make sense for the error, and the former is what's used elsewhere in there.

* [1760]: Update all the Tx cli tests to use the new CLITxExecutor.

* [1760]: Fix the oracle TestSendQuery which I incorrectly updated when I switched to CLITxExecutor.

* [1760]: Use the cmd stdout in the auto-complete generation (instead of os stdout) so that we can hide all that output in unit tests.

* [1760]: In AddGenesisMsgFeeCmd, put back the msg type check.

* [1760]: Clean up some more tests related to the encoders. Make the cmd tests quieter so that it's easier to find test failure info in the output.

* [1760]: Fix some store loader and upgrades tests.

* [1760]: Get rid of the rest of the uses of moduletestutil.

* [1760]: Change the test workflow to put all the failing tests in one part, and split the rest among the other 3.

* [1760]: Standardize the google.golang.org/protobuf/proto as protov2. Fix some import orderings.

* [1760]: Add changelog entry.

* [1760]: In AssertGetTxFromResponse, do 4 tries before giving up, but only log the output on the last attempt.

* [1760]: In the sanction tests, make the voting period last 5 blocks.

* [1760]: In the sanction tests, bump blocks per voting period to 6 because TestSanctionValidatorImmediateUsingGovCmds keeps failing the race tests because the votes aren't coming in fast enough.
  • Loading branch information
SpicyLemon authored Apr 25, 2024
1 parent b998684 commit a2b8cae
Show file tree
Hide file tree
Showing 98 changed files with 2,962 additions and 2,752 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,28 @@ jobs:
# The next longest running is x/metadata/client/cli at 2.5ish minutes.
# So take x/marker/simulation out of the list, split the list into 3 parts and create a 4th part
# with just the x/marker/simulation test.
# Temporarily, several tests are known to still fail, so we make them all part 3, and split the rest among 0-2.
# TODO[1760]: Re-analyze how long tests tests take and change the splitting back to be based on speed.
run: |
grep -vF -e 'github.com/provenance-io/provenance/x/marker/simulation' pkgs.txt > pkgs.txt.tmp
grep -vF \
-e 'github.com/provenance-io/provenance/app' \
-e 'github.com/provenance-io/provenance/cmd/provenanced/cmd' \
-e 'github.com/provenance-io/provenance/internal/antewrapper' \
-e 'github.com/provenance-io/provenance/x/ibchooks' \
-e 'github.com/provenance-io/provenance/x/ibcratelimit/module' \
-e 'github.com/provenance-io/provenance/x/ibcratelimit/simulation' \
-e 'github.com/provenance-io/provenance/x/oracle/simulation' \
pkgs.txt > pkgs.txt.tmp
split -d -n l/3 pkgs.txt.tmp pkgs.txt.part.
printf 'github.com/provenance-io/provenance/x/marker/simulation\n' > pkgs.txt.part.03
printf '%s\n' \
'github.com/provenance-io/provenance/app' \
'github.com/provenance-io/provenance/cmd/provenanced/cmd' \
'github.com/provenance-io/provenance/internal/antewrapper' \
'github.com/provenance-io/provenance/x/ibchooks' \
'github.com/provenance-io/provenance/x/ibcratelimit/module' \
'github.com/provenance-io/provenance/x/ibcratelimit/simulation' \
'github.com/provenance-io/provenance/x/oracle/simulation' \
> pkgs.txt.part.03
- uses: actions/upload-artifact@v4
with:
name: "${{ steps.def-vars.outputs.file-prefix }}-pkgs.txt.part.00"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Use fields of the SimulationState for the encoders needed for simulations [#1931](https://github.com/provenance-io/provenance/pull/1931).
* Fix most of the failing unit tests [#1943](https://github.com/provenance-io/provenance/pull/1943)

### Dependencies

Expand Down
21 changes: 12 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,18 @@ func New(
homePath string, invCheckPeriod uint,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *App {
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
signingOptions := signing.Options{
AddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
},
ValidatorAddressCodec: address.Bech32Codec{
Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
},
}
exchange.DefineCustomGetSigners(&signingOptions)
interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signingOptions,
})
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
Expand Down Expand Up @@ -1118,6 +1120,7 @@ func New(
app.ScopedICQKeeper = scopedICQKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper

simappparams.AppEncodingConfig = app.GetEncodingConfig()
return app
}

Expand Down
19 changes: 0 additions & 19 deletions app/params/doc.go

This file was deleted.

4 changes: 4 additions & 0 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ type EncodingConfig struct {
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}

// AppEncodingConfig is a global encoding config made available for areas where we don't otherwise have access to it.
// It's set (and updated) during app.New.
var AppEncodingConfig EncodingConfig
7 changes: 0 additions & 7 deletions app/params/params.go

This file was deleted.

16 changes: 8 additions & 8 deletions app/store_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ func TestValidateWrapper(t *testing.T) {
{
name: "bad config",
appOpts: MockAppOptions{
db: "cleveldb",
pruning: "10000",
},
expLogMsgs: true,
expSleep: true,
},
{
name: "bad config no sleep",
appOpts: MockAppOptions{
db: "cleveldb",
pruning: "10000",
},
pioAckWarn: true,
expLogMsgs: true,
Expand Down Expand Up @@ -235,11 +235,11 @@ func TestIssueConfigWarnings(t *testing.T) {
name: "bad db",
appOpts: MockAppOptions{
pruning: "10",
db: "cleveldb",
db: "otherdb",
indexer: "null",
},
expLogLines: []string{
"ERR cleveldb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
"ERR otherdb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
sleepErr1,
sleepErr2,
},
Expand All @@ -249,13 +249,13 @@ func TestIssueConfigWarnings(t *testing.T) {
name: "all bad with sleep",
appOpts: MockAppOptions{
pruning: "1001",
db: "badgerdb",
db: "thisdb",
indexer: "psql",
},
expLogLines: []string{
"ERR pruning-interval 1001 EXCEEDS 999 AND IS NOT RECOMMENDED, AS IT CAN LEAD TO MISSED BLOCKS ON VALIDATORS.",
"ERR indexer \"psql\" IS NOT RECOMMENDED, AND IT IS RECOMMENDED TO USE \"null\".",
"ERR badgerdb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
"ERR thisdb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
sleepErr1,
sleepErr2,
},
Expand All @@ -265,14 +265,14 @@ func TestIssueConfigWarnings(t *testing.T) {
name: "all bad no sleep",
appOpts: MockAppOptions{
pruning: "1001",
db: "badgerdb",
db: "thatdb",
indexer: "psql",
},
pioAckWarn: "1",
expLogLines: []string{
"ERR pruning-interval 1001 EXCEEDS 999 AND IS NOT RECOMMENDED, AS IT CAN LEAD TO MISSED BLOCKS ON VALIDATORS.",
"ERR indexer \"psql\" IS NOT RECOMMENDED, AND IT IS RECOMMENDED TO USE \"null\".",
"ERR badgerdb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
"ERR thatdb IS NO LONGER SUPPORTED. MIGRATE TO goleveldb.",
},
expSleep: false,
},
Expand Down
30 changes: 13 additions & 17 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) SetupSuite() {
func (s *UpgradeTestSuite) SetupTest() {
// Alert: This function is SetupSuite. That means all tests in here
// will use the same app with the same store and data.
defer SetLoggerMaker(SetLoggerMaker(BufferedInfoLoggerMaker(&s.logBuffer)))
Expand Down Expand Up @@ -315,16 +315,6 @@ func (s *UpgradeTestSuite) TestKeysInHandlersMap() {
}
})

s.Run("two or more colors exist", func() {
// We always need the colors currently in use on mainnet and testnet.
// The ones before that shouldn't be removed until we add new ones.
// It's okay to not clean the old ones up immediately, though.
// So we always want at least 2 different colors in there.
s.Assert().GreaterOrEqual(len(colors), 2, "number of distinct colors: %q in %q", colors, handlerKeys)
// If there are more than 3, we need to do some cleanup though.
s.Assert().LessOrEqual(len(colors), 3, "number of distinct colors: %q in %q", colors, handlerKeys)
})

s.Run("no two colors start with same character", func() {
// Little tricky here. i will go from 0 to len(colors) - 2 and the color will go from the 2nd to last.
// So colors[i] in here will be the entry just before color.
Expand Down Expand Up @@ -452,7 +442,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 1, "GetAllValidators after setup")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
"INF A total of 0 inactive (unbonded) validators have had all their delegators removed.",
}
s.ExecuteAndAssertLogs(runner, expectedLogLines, nil, true, runnerName)
Expand All @@ -474,7 +465,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 2, "Setup: GetAllValidators should have: 1 bonded, 1 unbonded")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
fmt.Sprintf("INF Validator %v has been inactive (unbonded) for %d days and will be removed.", unbondedVal1.OperatorAddress, 30),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr1.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
"INF A total of 1 inactive (unbonded) validators have had all their delegators removed.",
Expand Down Expand Up @@ -510,7 +502,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 2, "Setup: GetAllValidators should have: 1 bonded, 1 unbonded")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
fmt.Sprintf("INF Validator %v has been inactive (unbonded) for %d days and will be removed.", unbondedVal1.OperatorAddress, 30),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr1.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr2.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
Expand Down Expand Up @@ -556,7 +549,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 3, "Setup: GetAllValidators should have: 1 bonded, 2 unbonded")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
fmt.Sprintf("INF Validator %v has been inactive (unbonded) for %d days and will be removed.", unbondedVal1.OperatorAddress, 30),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr1.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr2.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
Expand Down Expand Up @@ -604,7 +598,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 3, "Setup: GetAllValidators should have: 1 bonded, 1 recently unbonded, 1 old unbonded")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
fmt.Sprintf("INF Validator %v has been inactive (unbonded) for %d days and will be removed.", unbondedVal1.OperatorAddress, 30),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr1.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
fmt.Sprintf("INF Undelegate delegator %v from validator %v of all shares (%v).", addr2.String(), unbondedVal1.OperatorAddress, delegationCoinAmt),
Expand Down Expand Up @@ -640,7 +635,8 @@ func (s *UpgradeTestSuite) TestRemoveInactiveValidatorDelegations() {
s.Require().Len(validators, 3, "Setup: GetAllValidators should have: 1 bonded, 1 recently unbonded, 1 empty unbonded")

expectedLogLines := []string{
"INF Removing all delegations from validators that have been inactive (unbonded) for 21 days.",
"INF Removing inactive validator delegations.",
"INF Threshold: 21 days",
fmt.Sprintf("INF Validator %v has been inactive (unbonded) for %d days and will be removed.", unbondedVal1.OperatorAddress, 30),
"INF A total of 1 inactive (unbonded) validators have had all their delegators removed.",
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/provenanced/cmd/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (s *MetaaddressTestSuite) TestAddMetaAddressDecoder() {
command.SetArgs(tc.args)
b := bytes.NewBufferString("")
command.SetOut(b)
command.SetErr(b)
err := command.Execute()
if len(tc.err) > 0 {
require.EqualErrorf(t, err, tc.err, "%s - expected error", command.Name())
Expand Down Expand Up @@ -369,6 +370,7 @@ func (s *MetaaddressTestSuite) TestAddMetaAddressEncoder() {
command.SetArgs(tc.args)
b := bytes.NewBufferString("")
command.SetOut(b)
command.SetErr(b)
err := command.Execute()
if len(tc.err) > 0 {
require.EqualErrorf(t, err, tc.err, "%s - expected error", command.Name())
Expand Down
6 changes: 6 additions & 0 deletions cmd/provenanced/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"fmt"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -21,6 +22,8 @@ func TestInitCmd(t *testing.T) {
"simapp-test", // Moniker
fmt.Sprintf("--%s=%s", cli.FlagOverwrite, "true"), // Overwrite genesis.json, in case it already exists
})
rootCmd.SetOut(io.Discard)
rootCmd.SetErr(io.Discard)

err := cmd.Execute(rootCmd)
require.NoError(t, err)
Expand Down Expand Up @@ -73,6 +76,9 @@ func TestGenAutoCompleteCmd(t *testing.T) {

rootCmd, _ := cmd.NewRootCmd(false)
rootCmd.SetArgs(args)
rootCmd.SetOut(io.Discard)
rootCmd.SetErr(io.Discard)

err := cmd.Execute(rootCmd)
assertions.AssertErrorValue(t, err, tc.err, "should have the correct output value")
})
Expand Down
9 changes: 6 additions & 3 deletions cmd/provenanced/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/server"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"

"github.com/provenance-io/provenance/app"
simappparams "github.com/provenance-io/provenance/app/params"
"github.com/provenance-io/provenance/cmd/provenanced/cmd"
provconfig "github.com/provenance-io/provenance/cmd/provenanced/config"
"github.com/provenance-io/provenance/internal/pioconfig"
Expand All @@ -36,6 +37,8 @@ type ConfigTestSuite struct {
ServerContext *server.Context
Context *context.Context

EncodingConfig simappparams.EncodingConfig

HeaderStrApp string
HeaderStrTM string
HeaderStrClient string
Expand All @@ -51,9 +54,9 @@ func (s *ConfigTestSuite) SetupTest() {

pioconfig.SetProvenanceConfig("confcoin", 5)

encodingConfig := moduletestutil.MakeTestEncodingConfig()
s.EncodingConfig = app.MakeTestEncodingConfig(s.T())
clientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithCodec(s.EncodingConfig.Marshaler).
WithHomeDir(s.Home)
clientCtx.Viper = viper.New()
serverCtx := server.NewContext(clientCtx.Viper, provconfig.DefaultTmConfig(), log.NewNopLogger())
Expand Down
Loading

0 comments on commit a2b8cae

Please sign in to comment.