Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix most of the unit tests. #1943

Merged
merged 46 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7b9cc24
[1760]: Stub out the registration of a couple custom GetSigners funct…
SpicyLemon Apr 16, 2024
2146d84
[1760]: Update the exchange CLI tests to handle not having block broa…
SpicyLemon Apr 16, 2024
3311f79
[1760]: Fix the signers of the msgs in the exchange module.
SpicyLemon Apr 17, 2024
72a9860
[1760]: Define and set the custom GetSigners funcs for create and acc…
SpicyLemon Apr 17, 2024
a012c2f
[1760]: Fix all of the exchange CLi tests.
SpicyLemon Apr 17, 2024
b64829a
[1760]: Fix the last remaining exchange test failures.
SpicyLemon Apr 17, 2024
6ea9d4f
[1760]: Use the correct signer field for MsgAddAttributeRequest.
SpicyLemon Apr 18, 2024
450b67b
[1760]: Fix the attribute module cli tests.
SpicyLemon Apr 18, 2024
f2971a3
[1760]: Fix the name tests.
SpicyLemon Apr 18, 2024
981c11b
[1760]: Add the signer option to the oracle Msgs. Remove an error tha…
SpicyLemon Apr 18, 2024
82486f6
[1760]: Rename the testutil.Cleanup function (was CleanUp, which I ke…
SpicyLemon Apr 18, 2024
63564de
[1760]: Fix the oracle cli tests. Make queries.GetTxFromResponse retu…
SpicyLemon Apr 18, 2024
2935133
[1760]: Delete a couple unneeded files.
SpicyLemon Apr 18, 2024
8e806f1
[1760]: Create a global encoding config variable that is set in app.N…
SpicyLemon Apr 18, 2024
229ef84
[1760]: Fix the ibcratelimit cli tests.
SpicyLemon Apr 18, 2024
e8f616f
[1760]: Fix the msgfees cli tests.
SpicyLemon Apr 19, 2024
a0ee1f1
[1760]: Make AssertGetTxFromResponse return the original response if …
SpicyLemon Apr 19, 2024
f72ae06
Merge branch 'main' into dwedul/1760-broadcast
SpicyLemon Apr 19, 2024
d8c1d10
[1760]: Create ABCIEventsToStrings (same as EventsToStrings, but with…
SpicyLemon Apr 19, 2024
e5f6504
[1760]: Add the signer option to MsgGrantAllowanceRequest and fix the…
SpicyLemon Apr 19, 2024
0a87878
[1760]: Add validation to marker params to fix a test.
SpicyLemon Apr 19, 2024
1fd3429
[1760]: Allow ValidateUnrestictedDenom to pass if the regex is blank.…
SpicyLemon Apr 19, 2024
17ac8a6
[1760]: Fix the rest of the marker tests.
SpicyLemon Apr 19, 2024
0eab2a2
[1760]: Fix metadata keeper tests.
SpicyLemon Apr 19, 2024
2a751c8
[1760]: Add signers to all the metadata Msgs.
SpicyLemon Apr 19, 2024
3e3bd28
[1760]: Fix the metadata CLI unit tests.
SpicyLemon Apr 22, 2024
8142654
[1760]: Put the check back into the msgfees commands that makes sure …
SpicyLemon Apr 22, 2024
94f4df9
[1760]: Create a CLITxExecutor to standarize testing of Tx commands.
SpicyLemon Apr 23, 2024
2674721
[1760]: Remove unneccesary call to ValidateBasic from GetCmdAddNetAss…
SpicyLemon Apr 23, 2024
1874058
[1760]: Use ErrUnauthorized (instead of ErrorInvalidSigner) when not …
SpicyLemon Apr 23, 2024
108e5d3
[1760]: Update all the Tx cli tests to use the new CLITxExecutor.
SpicyLemon Apr 23, 2024
de45ca7
[1760]: Fix the oracle TestSendQuery which I incorrectly updated when…
SpicyLemon Apr 23, 2024
4a3befc
[1760]: Use the cmd stdout in the auto-complete generation (instead o…
SpicyLemon Apr 23, 2024
ea506ab
[1760]: In AddGenesisMsgFeeCmd, put back the msg type check.
SpicyLemon Apr 23, 2024
1888f8f
[1760]: Clean up some more tests related to the encoders. Make the cm…
SpicyLemon Apr 23, 2024
e7b979f
[1760]: Fix some store loader and upgrades tests.
SpicyLemon Apr 23, 2024
ac7b00a
[1760]: Get rid of the rest of the uses of moduletestutil.
SpicyLemon Apr 24, 2024
1a3b18c
Merge branch 'main' into dwedul/1760-broadcast
SpicyLemon Apr 24, 2024
5ed6a82
[1760]: Change the test workflow to put all the failing tests in one …
SpicyLemon Apr 24, 2024
517db05
[1760]: Standardize the google.golang.org/protobuf/proto as protov2. …
SpicyLemon Apr 24, 2024
3d6b97e
[1760]: Add changelog entry.
SpicyLemon Apr 24, 2024
f339848
[1760]: In AssertGetTxFromResponse, do 4 tries before giving up, but …
SpicyLemon Apr 24, 2024
0f54784
[1760]: In the sanction tests, make the voting period last 5 blocks.
SpicyLemon Apr 24, 2024
5e81ee5
[1760]: In the sanction tests, bump blocks per voting period to 6 bec…
SpicyLemon Apr 24, 2024
dd523f4
Merge branch 'main' into dwedul/1760-broadcast
SpicyLemon Apr 24, 2024
f6ddf0c
Merge branch 'main' into dwedul/1760-broadcast
Taztingo Apr 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading