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

Bump cosmos-sdk to v0.50.10-pio-1 (from v0.50.7-pio-1). #2175

Merged
merged 18 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e7771a3
Switch the sdk to a local version that has the 0.50.10 changes in it.
SpicyLemon Oct 8, 2024
94ac7bc
Switch to the new GetNodeHomeDirectory helper for identifying the def…
SpicyLemon Oct 8, 2024
8900c8d
Add a check that our signing context is valid. Tweak how we create ou…
SpicyLemon Oct 9, 2024
217e6c7
In the sim tests, pay attention to the new SigverifyTx flag. Also, in…
SpicyLemon Oct 9, 2024
834333b
Switch the sdk replace to a commit on our fork that has the v0.50.10 …
SpicyLemon Oct 9, 2024
85f423a
Merge branch 'main' into dwedul/bump-sdk-to-50-10
SpicyLemon Oct 9, 2024
05843b9
Fix the add-change script to call the right script when the section i…
SpicyLemon Oct 9, 2024
38f4626
Add changelog entries.
SpicyLemon Oct 9, 2024
528f682
Update linter settings to allow all of client/v2 instead of just clie…
SpicyLemon Oct 9, 2024
6031492
Update the no-now-lint.sh script to also check for the new telemetry.…
SpicyLemon Oct 10, 2024
10a5ca0
Switch all uses of time.Now() in the telemetry invocations to telemet…
SpicyLemon Oct 10, 2024
b78b62a
Update the EventsToStrings helper to put a > at the start of the firs…
SpicyLemon Oct 10, 2024
7b7b8c6
Update some of the exchange msg_server tests that broke because the e…
SpicyLemon Oct 10, 2024
d36e1f6
Fix the event assertions tests that started failing when I changed th…
SpicyLemon Oct 10, 2024
9a2f724
Switch us to the now-tagged v0.50.10-pio-1 of the SDK.
SpicyLemon Oct 10, 2024
1bac787
Merge branch 'main' into dwedul/bump-sdk-to-50-10
SpicyLemon Oct 11, 2024
a7d6d1c
Merge branch 'main' into dwedul/bump-sdk-to-50-10
SpicyLemon Oct 11, 2024
f3a48f6
Merge branch 'main' into dwedul/bump-sdk-to-50-10
SpicyLemon Oct 14, 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
2 changes: 1 addition & 1 deletion .changelog/add-change.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fi
if [[ "${#messages[@]}" -eq '0' ]]; then
if [[ "$section" == "dependencies" ]]; then
[[ -n "$verbose" ]] && printf 'Using get-dep-changes.sh for new entry.\n'
"${where_i_am}/get-valid-sections.sh" "$num_type_flag" "$num" --id "$id" --force
"${where_i_am}/get-dep-changes.sh" "$num_type_flag" "$num" --id "$id" --force
exit $?
fi
messages+=( "TODO: Write me." )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `cosmossdk.io/store` bumped to v1.1.1 (from v1.1.0) [PR 2175](https://github.com/provenance-io/provenance/pull/2175).
* `github.com/cosmos/cosmos-sdk` bumped to v0.50.10-pio-1 of `github.com/provenance-io/cosmos-sdk` (from v0.50.7-pio-1 of `github.com/provenance-io/cosmos-sdk`) [PR 2175](https://github.com/provenance-io/provenance/pull/2175).
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ linters-settings:
- github.com/armon/go-metrics

- cosmossdk.io/api
- cosmossdk.io/client/v2/autocli
- cosmossdk.io/client/v2
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
- cosmossdk.io/collections
- cosmossdk.io/core
- cosmossdk.io/errors
Expand Down
36 changes: 19 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand All @@ -22,6 +21,7 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/client/v2/autocli"
clienthelpers "cosmossdk.io/client/v2/helpers"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -308,14 +308,11 @@ type App struct {
}

func init() {
DefaultNodeHome = os.ExpandEnv("$PIO_HOME")

if strings.TrimSpace(DefaultNodeHome) == "" {
configDir, err := os.UserConfigDir()
if err != nil {
panic(err)
}
DefaultNodeHome = filepath.Join(configDir, "Provenance")
clienthelpers.EnvPrefix = EnvPrefix
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
var err error
DefaultNodeHome, err = clienthelpers.GetNodeHomeDirectory("Provenance")
if err != nil {
panic(err)
}

// 614,400 = 600 * 1024 = our wasm params maxWasmCodeSize value before it was removed in wasmd v0.27.
Expand Down Expand Up @@ -343,7 +340,14 @@ func New(
})
appCodec := codec.NewProtoCodec(interfaceRegistry)
legacyAmino := codec.NewLegacyAmino()
txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes)
txConfigOpts := authtx.ConfigOptions{
EnabledSignModes: authtx.DefaultSignModes,
SigningOptions: &signingOptions,
}
txConfig, err := authtx.NewTxConfigWithOptions(appCodec, txConfigOpts)
if err != nil {
panic(err)
}

std.RegisterLegacyAminoCodec(legacyAmino)
std.RegisterInterfaces(interfaceRegistry)
Expand Down Expand Up @@ -440,17 +444,15 @@ func New(
)

// optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
enabledSignModes := authtx.DefaultSignModes
enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := authtx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
var err error
txConfigOpts.EnabledSignModes = append(txConfigOpts.EnabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts.TextualCoinMetadataQueryFn = txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper)
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
txConfig, err = authtx.NewTxConfigWithOptions(appCodec, txConfigOpts)
if err != nil {
panic(err)
}
if err = txConfig.SigningContext().Validate(); err != nil {
panic(err)
}
app.txConfig = txConfig

app.StakingKeeper = stakingkeeper.NewKeeper(
Expand Down
3 changes: 3 additions & 0 deletions app/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const (
CoinTypeMainNet = uint32(505)
CoinTypeTestNet = uint32(1)
Purpose = 44

// EnvPrefix is the prefix added to config/flag names to get its environment variable name.
EnvPrefix = "PIO"
SpicyLemon marked this conversation as resolved.
Show resolved Hide resolved
)

var (
Expand Down
15 changes: 15 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func TestFullAppSimulation(t *testing.T) {
}
app := New(logger, db, nil, true, appOpts, baseAppOpts...)
require.Equal(t, "provenanced", app.Name())
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

fmt.Printf("running provenance full app simulation\n")

Expand Down Expand Up @@ -275,6 +278,9 @@ func TestSimple(t *testing.T) {
}
app := New(logger, db, nil, true, appOpts, baseAppOpts...)
require.Equal(t, "provenanced", app.Name())
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

// run randomized simulation
_, _, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -328,6 +334,9 @@ func TestAppImportExport(t *testing.T) {
}
app := New(logger, db, nil, true, appOpts, baseAppOpts...)
require.Equal(t, "provenanced", app.Name())
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

fmt.Printf("running provenance test import export\n")

Expand Down Expand Up @@ -457,6 +466,9 @@ func TestAppSimulationAfterImport(t *testing.T) {
baseapp.SetChainID(config.ChainID),
}
app := New(logger, db, nil, true, appOpts, baseAppOpts...)
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

// Run randomized simulation
stopEarly, lastBlockTime, simParams, simErr := simulation.SimulateFromSeedProv(
Expand Down Expand Up @@ -582,6 +594,9 @@ func TestAppStateDeterminism(t *testing.T) {

db := dbm.NewMemDB()
app := New(logger, db, nil, true, appOpts, interBlockCacheOpt(), baseapp.SetChainID(config.ChainID))
if !simcli.FlagSigverifyTxValue {
app.SetNotSigverifyTx()
}

fmt.Printf(
"running provenance non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
2 changes: 1 addition & 1 deletion cmd/provenanced/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewRootCmd(sealConfig bool) (*cobra.Command, params.EncodingConfig) {
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastSync).
WithHomeDir(app.DefaultNodeHome).
WithViper("PIO")
WithViper(app.EnvPrefix)
sdk.SetCoinDenomRegex(app.SdkCoinDenomRegex)

rootCmd := &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.4.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/store v1.1.1
cosmossdk.io/x/circuit v0.1.1
cosmossdk.io/x/evidence v0.1.1
cosmossdk.io/x/feegrant v0.1.1
Expand Down Expand Up @@ -214,7 +214,7 @@ replace (
// This is required for https://github.com/provenance-io/provenance/issues/1414
github.com/CosmWasm/wasmd => github.com/provenance-io/wasmd v0.52.0-pio-1

github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.7-pio-1
github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.10-pio-1

// Replace iavl to fix the node stop/start app hash problem. This can be removed once upstream is off v1.1.2
github.com/cosmos/iavl => github.com/cosmos/iavl v1.2.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM=
cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU=
cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE=
cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k=
cosmossdk.io/store v1.1.0 h1:LnKwgYMc9BInn9PhpTFEQVbL9UK475G2H911CGGnWHk=
cosmossdk.io/store v1.1.0/go.mod h1:oZfW/4Fc/zYqu3JmQcQdUJ3fqu5vnYTn3LZFFy8P8ng=
cosmossdk.io/store v1.1.1 h1:NA3PioJtWDVU7cHHeyvdva5J/ggyLDkyH0hGHl2804Y=
cosmossdk.io/store v1.1.1/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM=
cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ=
cosmossdk.io/x/circuit v0.1.1/go.mod h1:B6f/urRuQH8gjt4eLIXfZJucrbreuYrKh5CSjaOxr+Q=
cosmossdk.io/x/evidence v0.1.1 h1:Ks+BLTa3uftFpElLTDp9L76t2b58htjVbSZ86aoK/E4=
Expand Down Expand Up @@ -912,8 +912,8 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/provenance-io/cosmos-sdk v0.50.7-pio-1 h1:A4WC4LzcQj6jh+WdIIP4OIN3DCSW1t5qONtkYrJ77jg=
github.com/provenance-io/cosmos-sdk v0.50.7-pio-1/go.mod h1:84xDDJEHttRT7NDGwBaUOLVOMN0JNE9x7NbsYIxXs1s=
github.com/provenance-io/cosmos-sdk v0.50.10-pio-1 h1:u6FYRcCIBn9Qioo/kFWjjCLETssRG6y1CW5UHsWulNI=
github.com/provenance-io/cosmos-sdk v0.50.10-pio-1/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU=
github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1 h1:p+7pxHB0ukO2aow+M6uW9gHgeQl7YJyYGyMSKHZ5My8=
github.com/provenance-io/ibc-apps/modules/async-icq/v8 v8.0.0-prov-1/go.mod h1:tObW9uxibh5Z22CtOaHVeTDotCSMyc/2B4MrYdaViBo=
github.com/provenance-io/ibc-go/v8 v8.3.2-pio-1 h1:NOybWs/qIj0gGsOUs8xXwiAlEgtZwOtkhf0/yD0dZYA=
Expand Down
94 changes: 59 additions & 35 deletions scripts/no-now-lint.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,80 @@
#!/usr/bin/env bash
# This script looks for all uses of a time.Now() function.
# If any improper uses are found, they will be outputted and the script will exit with code 1.
# If there isn't anything of concern, nothing will be outputted, and the script will exit with code 0.
# This script looks for all uses of a .Now() function.
# If any improper uses are found, they will be printed and the script will exit with code 1.
# If there isn't anything of concern, nothing will be printed, and the script will exit with code 0.
# Providing the -v or --verbose flag (or exporting VERBOSE=1) will make this output middle-step information.

# This exists because use of time.Now() in the processing of a block (or Tx) is an easy way to halt a chain.
# All time-based validation/processing/calculations should be done against the block time.
# Doing them against time.Now() makes the outcome change depending on when it's run.
# That might sound like something desirable, but consider a chain that is starting/catching up by replaying old blocks.
# If using time.Now(), a Tx that was fine when it was run originally might now fail validation.
# If someone desides to be malicious, then could send a Tx with a time field set a few seconds in the future.
# The block creater processes the Tx and includes it in the block.
# If someone decides to be malicious, then could send a Tx with a time field set a few seconds in the future.
# The block creator processes the Tx and includes it in the block.
# Then some or none of the other validators agree as they're checking it a few seconds later.
#
# Known libraries that we know have a .Now() function that we need to worry about:
# * "time"
# * "github.com/cometbft/cometbft/types/time"
# * "github.com/cosmos/cosmos-sdk/telemetry"

# Usage: get_line_count "$var"
get_line_count () {
# Can't use a herestring here because that automatically adds an ending newline.
# That added line ending causes any string without an ending newline (even an
# empty string) to report one more line than there actually is.
# Not using wc -l for this because it won't count a line if there's no ending newline.
# Not using echo because it doesn't have a standard ending newline behavior. I.e.
# some shells will automatically add a newline, some won't, and it's flags can mean
# different things on different systems. It's just best to avoid it.
# Examples of commands that don't work like we want in here:
# wc -l <<< "" # actual = 1 (want = 0).
# wc -l <<< "something"$'\n' # actual = 2 (want = 1).
# printf '%s' "something" | wc -l # actual = 0 (want = 1).
# printf '%s' "something"$'\n'"else" | wc -l # actual = 1 (want = 2)
# grep -c '^' <<< "" # actual = 1 (want = 0).
# grep -c '^' <<< "something"$'\n' # actual = 2 (want = 1).
# But this command is Goldilocks:
printf '%s' "$1" | grep -c '^'
}

if [ "$1" == '-v' ] || [ "$1" == '--verbose' ]; then
VERBOSE='1'
fi

# Find all files that import the "time" module, and identify what they're referenced as in that file.
# There's at least one other module that has a .Now() function ("github.com/cometbft/cometbft/types/time") that we don't want used.
# So we're actually finding an import of any "time" package.
# Find all files that import a "time" or "telemetry" module, and identify what
# they're referenced as in that file. We cast a wide net here in the hopes that
# if call to a .Now() in a new library is added, there's a chance this catches it.
# So we're actually finding an import of any "time" or "telemetry" package.
# If a file has multiple such imports, there'll be a line for each import.
# The vendor directory is ignored since it's not under our control and has lots of matches (that hopefully don't cause problems).
# Output is in the format of "<file>:<alias>", e.g. "app/test_helpers.go:time".
# The vendor directory is ignored since it's not under our control and has lots
# of matches (that hopefully don't cause problems).
#
# First, find all go files of possible interest.
# Then, grep each go file looking for an import of a "time" package.
# Line format: './<file path>'
# Then, grep each go file looking for an import of a "time" or "telemetry" package.
# Line format: './<file path>:\t<import line>'
# Transform each entry into the format "<file>:<alias>" by:
# 1. Changing ': <alias> "time"' or ':import <alias> "time"' into ':<alias>'.
# 2. Changing ': "time"' or ':import "time"' into ':time'.
# 1. Changing ': <alias> "<library>"' or ':import <alias> "<library>"' into ':<alias>'.
# 2. Changing ': "<library>"' or ':import "<library>"' into ':<library's last section>'.
# 3. Removing the leading './' on the filename.
# Then sort them because I'm pedantic like that.
# Output is in the format of "<file>:<alias>", e.g. "app/test_helpers.go:time".
time_imports="$( \
find . -type f -name '*.go' -not -path '*/vendor/*' \
| xargs grep -E '^(import)?[[:space:]]+([[:alnum:]]+[[:space:]]+)?"([^"]+/)?time"' \
| sed -E -e 's/:(import)?[[:space:]]+([[:alnum:]]+)[[:space:]]+"([^"]+\/)?time".*$/:\2/' \
-e 's/:(import)?[[:space:]]+"([^"]+\/)?time".*$/:time/' \
find . -type f -name '*.go' -not -path '*/vendor/*' -print0 \
| xargs -0 grep -E '^(import)?[[:space:]]+([[:alnum:]]+[[:space:]]+)?"([^"]+/)?(time|telemetry)"' \
| sed -E -e 's/:(import)?[[:space:]]+([[:alnum:]]+)[[:space:]]+"([^"]+\/)?(time|telemetry)".*$/:\2/' \
-e 's/:(import)?[[:space:]]+"([^"]+\/)?(time|telemetry)".*$/:\3/' \
-e 's/^\.\///' \
| sort
)"
[ -n "$VERBOSE" ] && printf 'Time imports:\n%s\n\n' "$( sed 's/^/ /' <<< "$time_imports" )"
[ -n "$VERBOSE" ] && printf 'Imports of Interest (%d):\n%s\n\n' "$( get_line_count "$time_imports" )" "$( sed 's/^/ /' <<< "$time_imports" )"

# Find all uses of a time.Now() function.
# Loop through each line of time imports.
# Split the line into the file and the alias.
# Grep the file for <alias>.Now() taking care to not include entries of a different alias that ends the same.
# Then, we want to ignore the line if the only "use" of <alias>.Now() is actually in a comment.
# Find all uses of a .Now() function in a library of interest.
# Loop through each line of time_imports.
# Split the line into the <file> and the <alias>.
# Grep the <file> for <alias>.Now() taking care to not include entries of a different alias that ends the same.
# Then, we want to ignore the line if the only use of <alias>.Now() is actually just in a comment.
# But we still want the whole line in the output if it's a match.
# So we remove any comment from each matching line and re-test it. If it's still a match, include the whole line.
now_uses="$( \
Expand All @@ -63,9 +92,9 @@ now_uses="$( \
fi
done <<< "$time_imports"
)"
[ -n "$VERBOSE" ] && printf 'All uses of time.Now():\n%s\n\n' "$( sed 's/^/ /' <<< "$now_uses" )"
[ -n "$VERBOSE" ] && printf 'All uses of .Now() (%d):\n%s\n\n' "$( get_line_count "$now_uses" )" "$( sed 's/^/ /' <<< "$now_uses" )"

# Ignore known legitimate uses of time.Now().
# Ignore known legitimate uses of .Now().
# These are controlled in this script rather than through a nolint directive because:
# a) Use of time.Now() is very dangerous, and it should be harder to use it than just adding a comment on the line.
# b) This isn't a full-fledged, actual linter.
Expand All @@ -76,27 +105,22 @@ filters=()
filters+=( '^[^:]+_test\.go:' )
# It's okay to use it in the telemetry.MeasureSince and telemetry.ModuleMeasureSince functions.
filters+=( 'telemetry\.(Module)?MeasureSince\(' )
# The app/test_helpers.go file also has a legitimate use since it's only for unit tests.
# It's in the header creation for the BeginBlock.
# Since it's expected that it might move, and also that additional
# such uses might be added, allow it to be on any line number.
filters+=( '^app/test_helpers\.go:[[:digit:]]+:.*cmtproto\.Header{' )
# The x/marker/client/cli/tx.go file has two legitimate uses due to authz and feegrant grant creation.
# Since that file is not involved in any block processing, just ignore the whole file.
# Since that file is not involved in any block processing, we can just ignore the whole file.
filters+=( '^x/marker/client/cli/tx\.go:' )
# The cmd/provenanced/cmd/testnet.go file needs to use it to properly create the genesis file.
# Since it's setting a variable more specifically named than 'now',
# we can ignore the specific line, but let it be on any line number.
filters+=( '^cmd/provenanced/cmd/testnet\.go:[[:digit:]]+:[[:space:]]+genTime := [[:alnum:]]+\.Now\(\)$' )

for filters in "${filters[@]}"; do
now_uses="$( grep -vE "$filters" <<< "$now_uses" )"
[ -n "$VERBOSE" ] && printf 'After filter %s:\n%s\n\n' "'$filters'" "$( sed 's/^/ /' <<< "$now_uses" )"
for filter in "${filters[@]}"; do
now_uses="$( grep -vE "$filter" <<< "$now_uses" )"
[ -n "$VERBOSE" ] && printf 'After filter %s (%d):\n%s\n\n' "'$filter'" "$( get_line_count "$now_uses" )" "$( sed 's/^/ /' <<< "$now_uses" )"
done

# If there's anything left, it's bad.
if [ -n "$now_uses" ]; then
printf 'Improper use(s) of time.Now():\n%s\n' "$now_uses"
printf 'Improper use(s) of .Now() (%d):\n%s\n' "$( get_line_count "$now_uses" )" "$now_uses"
exit 1
fi
[ -n "$VERBOSE" ] && printf 'No improper uses of .Now().\n'
Expand Down
11 changes: 9 additions & 2 deletions testutil/assertions/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func PrependToEach(prefix string, lines []string) []string {
func EventsToStrings(events sdk.Events) []string {
var rv []string
for i, event := range events {
rv = append(rv, PrependToEach(fmt.Sprintf("[%d]", i), EventToStrings(event))...)
eventLines := PrependToEach(fmt.Sprintf(" [%d]", i), EventToStrings(event))
eventLines[0] = ">" + eventLines[0][1:]
rv = append(rv, eventLines...)
}
return rv
}
Expand Down Expand Up @@ -80,7 +82,12 @@ func AssertEqualEvents(t TB, expected, actual sdk.Events, msgAndArgs ...interfac
// This converts them to strings for the comparison so that the failure output is significantly easier to read and understand.
expectedStrs := EventsToStrings(expected)
actualStrs := EventsToStrings(actual)
return assert.Equal(t, expectedStrs, actualStrs, msgAndArgs...)
if assert.Equal(t, expectedStrs, actualStrs, msgAndArgs...) {
return true
}
// Log the actual events list for easier comparison with the pre-defined expected ones.
t.Logf("Actual events:\n%s", strings.Join(actualStrs, "\n"))
return false
}

// RequireEqualEvents asserts that the expected events equal the actual events.
Expand Down
Loading
Loading