From e7771a3598aaa0c684343f352f1ca1c29089216d Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 8 Oct 2024 17:16:08 -0600 Subject: [PATCH 01/14] Switch the sdk to a local version that has the 0.50.10 changes in it. --- go.mod | 5 +++-- go.sum | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 4ca8a197f..734f68e0b 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -214,7 +214,8 @@ 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.7-pio-1 + github.com/cosmos/cosmos-sdk => ../prov-cosmos-sdk // 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 diff --git a/go.sum b/go.sum index 76b7098c6..2e8edcf89 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -912,8 +912,6 @@ 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/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= From 94ac7bc2099f36a0ad2b3f5c87b938c5030f1502 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 8 Oct 2024 17:24:52 -0600 Subject: [PATCH 02/14] Switch to the new GetNodeHomeDirectory helper for identifying the default node home directory. --- app/app.go | 15 ++++++--------- app/prefix.go | 3 +++ cmd/provenanced/cmd/root.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/app.go b/app/app.go index ce7c4a132..73d674e06 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -23,6 +22,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" @@ -309,14 +309,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 + 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. diff --git a/app/prefix.go b/app/prefix.go index 536bf57c7..de1416b41 100644 --- a/app/prefix.go +++ b/app/prefix.go @@ -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" ) var ( diff --git a/cmd/provenanced/cmd/root.go b/cmd/provenanced/cmd/root.go index 2e4bc0947..2744a7dc2 100644 --- a/cmd/provenanced/cmd/root.go +++ b/cmd/provenanced/cmd/root.go @@ -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{ From 8900c8df396c10340cf8472a2b97026789dabd1b Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Tue, 8 Oct 2024 19:31:52 -0600 Subject: [PATCH 03/14] Add a check that our signing context is valid. Tweak how we create our signing context because the validation was failing because the custom msg signers funcs aren't getting propagated from the interface registry to the signing context. --- app/app.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index 73d674e06..84bd891a2 100644 --- a/app/app.go +++ b/app/app.go @@ -341,7 +341,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) @@ -440,17 +447,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) 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( From 217e6c7b8694e1a8b9011ec2e8f41d8832b6b8de Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 16:12:42 -0600 Subject: [PATCH 04/14] In the sim tests, pay attention to the new SigverifyTx flag. Also, in the previous commit, I also updated how we set the default node home directory to match the SDK's example (using one of their helpers). --- app/sim_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/sim_test.go b/app/sim_test.go index 4e0f58c18..c07477b10 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -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") @@ -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( @@ -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") @@ -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( @@ -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", From 834333b47f2ece4f61d8d6fdb29fe6713b0a824f Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 16:41:55 -0600 Subject: [PATCH 05/14] Switch the sdk replace to a commit on our fork that has the v0.50.10 stuff applied (and will hopefully get merged and become v0.50.10-pio-1). --- go.mod | 3 +-- go.sum | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 734f68e0b..54fb763e2 100644 --- a/go.mod +++ b/go.mod @@ -214,8 +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 => ../prov-cosmos-sdk + github.com/cosmos/cosmos-sdk => github.com/provenance-io/cosmos-sdk v0.50.7-pio-1.0.20241009215832-692cc7b414fc // 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 diff --git a/go.sum b/go.sum index 2e8edcf89..0bc221e29 100644 --- a/go.sum +++ b/go.sum @@ -912,6 +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.0.20241009215832-692cc7b414fc h1:x4ILzMtxlyJZVJGPEnhn+VGmJH/VSSLemxBL6oCRWxc= +github.com/provenance-io/cosmos-sdk v0.50.7-pio-1.0.20241009215832-692cc7b414fc/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= From 05843b9576018561f130ef88fe8a7383b500dea8 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 16:59:53 -0600 Subject: [PATCH 06/14] Fix the add-change script to call the right script when the section is dependencies and there's no messages. --- .changelog/add-change.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/add-change.sh b/.changelog/add-change.sh index fb17fbd23..d184d221b 100755 --- a/.changelog/add-change.sh +++ b/.changelog/add-change.sh @@ -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." ) From 38f4626d467e19dd8aac1a3fb3a8d803e7458bbf Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 17:03:08 -0600 Subject: [PATCH 07/14] Add changelog entries. --- .changelog/unreleased/dependencies/2175-bump-sdk-to-50-10.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/dependencies/2175-bump-sdk-to-50-10.md diff --git a/.changelog/unreleased/dependencies/2175-bump-sdk-to-50-10.md b/.changelog/unreleased/dependencies/2175-bump-sdk-to-50-10.md new file mode 100644 index 000000000..55aef1119 --- /dev/null +++ b/.changelog/unreleased/dependencies/2175-bump-sdk-to-50-10.md @@ -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). From 528f682645969b210652cc4fa8ed6a683a530b8d Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 17:11:53 -0600 Subject: [PATCH 08/14] Update linter settings to allow all of client/v2 instead of just client/v2/autocli. --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 5cf123f1a..ca18dfdd7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -84,7 +84,7 @@ linters-settings: - github.com/armon/go-metrics - cosmossdk.io/api - - cosmossdk.io/client/v2/autocli + - cosmossdk.io/client/v2 - cosmossdk.io/collections - cosmossdk.io/core - cosmossdk.io/errors From 603149247637baa751fbcef6ca854243b434b32c Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 19:10:09 -0600 Subject: [PATCH 09/14] Update the no-now-lint.sh script to also check for the new telemetry.Now and add line counts to the outputs. Also, remove the app/test_helpers.go filter since that file doesn't use .Now anymore. --- scripts/no-now-lint.sh | 94 ++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/scripts/no-now-lint.sh b/scripts/no-now-lint.sh index f82e8cd6b..dde294d17 100755 --- a/scripts/no-now-lint.sh +++ b/scripts/no-now-lint.sh @@ -1,7 +1,7 @@ #!/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. @@ -9,43 +9,72 @@ # 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 ":", 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: './' +# Then, grep each go file looking for an import of a "time" or "telemetry" package. +# Line format: './:\t' # Transform each entry into the format ":" by: -# 1. Changing ': "time"' or ':import "time"' into ':'. -# 2. Changing ': "time"' or ':import "time"' into ':time'. +# 1. Changing ': ""' or ':import ""' into ':'. +# 2. Changing ': ""' or ':import ""' into ':'. # 3. Removing the leading './' on the filename. # Then sort them because I'm pedantic like that. +# Output is in the format of ":", 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 .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 .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 and the . +# Grep the for .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 .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="$( \ @@ -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. @@ -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' From 10a5ca04290cb6b498ab47b4a772b6192f9d9095 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 19:12:22 -0600 Subject: [PATCH 10/14] Switch all uses of time.Now() in the telemetry invocations to telemetry.Now(). The telemetry verision returns an empty Time if telemetry isn't enabled which is supposed to save on a bit a processing. --- x/attribute/keeper/keeper.go | 15 +++++------ x/marker/abci.go | 3 +-- x/marker/keeper/marker.go | 33 +++++++++++------------ x/metadata/keeper/msg_server.go | 45 +++++++++++++++---------------- x/metadata/keeper/query_server.go | 45 +++++++++++++++---------------- 5 files changed, 68 insertions(+), 73 deletions(-) diff --git a/x/attribute/keeper/keeper.go b/x/attribute/keeper/keeper.go index 1cb465cb6..736e96a27 100644 --- a/x/attribute/keeper/keeper.go +++ b/x/attribute/keeper/keeper.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "fmt" "strings" - "time" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -87,7 +86,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // GetAllAttributes gets all attributes for an address. func (k Keeper) GetAllAttributes(ctx sdk.Context, addr string) ([]types.Attribute, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "get_all") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "get_all") pred := func(string) bool { return true } return k.prefixScan(ctx, types.AddrStrAttributesKeyPrefix(addr), pred) @@ -95,7 +94,7 @@ func (k Keeper) GetAllAttributes(ctx sdk.Context, addr string) ([]types.Attribut // GetAllAttributesAddr gets all attributes for an AccAddress or MetadataAddress. func (k Keeper) GetAllAttributesAddr(ctx sdk.Context, addr []byte) ([]types.Attribute, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "get_all") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "get_all") pred := func(string) bool { return true } return k.prefixScan(ctx, types.AddrAttributesKeyPrefix(addr), pred) @@ -103,7 +102,7 @@ func (k Keeper) GetAllAttributesAddr(ctx sdk.Context, addr []byte) ([]types.Attr // GetAttributes gets all attributes with the given name from an account. func (k Keeper) GetAttributes(ctx sdk.Context, addr string, name string) ([]types.Attribute, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "get") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "get") name = strings.ToLower(strings.TrimSpace(name)) if _, err := k.nameKeeper.GetRecordByName(ctx, name); err != nil { // Ensure name exists (ie was bound to an address) @@ -137,7 +136,7 @@ func (k Keeper) IterateRecords(ctx sdk.Context, prefix []byte, handle Handler) e func (k Keeper) SetAttribute( ctx sdk.Context, attr types.Attribute, owner sdk.AccAddress, ) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "set") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "set") if err := k.ValidateExpirationDate(ctx, attr); err != nil { return err @@ -216,7 +215,7 @@ func (k Keeper) DecAttrNameAddressLookup(ctx sdk.Context, name string, addrBytes // UpdateAttribute updates an attribute under the given account. The attribute name must resolve to the given owner address and value must resolve to an existing attribute. func (k Keeper) UpdateAttribute(ctx sdk.Context, originalAttribute types.Attribute, updateAttribute types.Attribute, owner sdk.AccAddress, ) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "update") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "update") var err error @@ -299,7 +298,7 @@ func (k Keeper) UpdateAttribute(ctx sdk.Context, originalAttribute types.Attribu // UpdateAttributeExpiration updates the expiration date on an attribute. func (k Keeper) UpdateAttributeExpiration(ctx sdk.Context, updateAttribute types.Attribute, owner sdk.AccAddress, ) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "update_expiration") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "update_expiration") if err := k.ValidateExpirationDate(ctx, updateAttribute); err != nil { return err @@ -372,7 +371,7 @@ func (k Keeper) AccountsByAttribute(ctx sdk.Context, name string) (addresses []s // DeleteAttribute removes attributes under the given account from the state store. func (k Keeper) DeleteAttribute(ctx sdk.Context, addr string, name string, value *[]byte, owner sdk.AccAddress) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "keeper_method", "delete") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "keeper_method", "delete") var deleteDistinct bool if value != nil { diff --git a/x/marker/abci.go b/x/marker/abci.go index a0a2a3998..a8e749f89 100644 --- a/x/marker/abci.go +++ b/x/marker/abci.go @@ -2,7 +2,6 @@ package marker import ( "fmt" - "time" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,7 +13,7 @@ import ( // BeginBlocker returns the begin blocker for the marker module. func BeginBlocker(ctx sdk.Context, k keeper.Keeper, bk bankkeeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // Iterate through all marker accounts and check for supply above or below expected targets. var err error k.IterateMarkers(ctx, func(record types.MarkerAccountI) bool { diff --git a/x/marker/keeper/marker.go b/x/marker/keeper/marker.go index 89650b6f4..560c1093b 100644 --- a/x/marker/keeper/marker.go +++ b/x/marker/keeper/marker.go @@ -2,7 +2,6 @@ package keeper import ( "fmt" - "time" sdkmath "cosmossdk.io/math" @@ -18,7 +17,7 @@ import ( // GetMarkerByDenom looks up marker with the given denom func (k Keeper) GetMarkerByDenom(ctx sdk.Context, denom string) (types.MarkerAccountI, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "get_marker_by_denom") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "get_marker_by_denom") addr, err := types.MarkerAddress(denom) if err != nil { @@ -36,7 +35,7 @@ func (k Keeper) GetMarkerByDenom(ctx sdk.Context, denom string) (types.MarkerAcc // AddMarkerAccount persists marker to the account keeper store. func (k Keeper) AddMarkerAccount(ctx sdk.Context, marker types.MarkerAccountI) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "add_marker_account") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "add_marker_account") if err := marker.Validate(); err != nil { return err @@ -83,7 +82,7 @@ func (k Keeper) AddMarkerAccount(ctx sdk.Context, marker types.MarkerAccountI) e func (k Keeper) AddAccess( ctx sdk.Context, caller sdk.AccAddress, denom string, grant types.AccessGrantI, ) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "add_access") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "add_access") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, denom) @@ -125,7 +124,7 @@ func (k Keeper) AddAccess( // RemoveAccess delete the AccessGrant for the specified user from the marker if the caller is allowed to make changes func (k Keeper) RemoveAccess(ctx sdk.Context, caller sdk.AccAddress, denom string, remove sdk.AccAddress) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "remove_access") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "remove_access") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, denom) @@ -170,7 +169,7 @@ func (k Keeper) RemoveAccess(ctx sdk.Context, caller sdk.AccAddress, denom strin func (k Keeper) WithdrawCoins( ctx sdk.Context, caller sdk.AccAddress, recipient sdk.AccAddress, denom string, coins sdk.Coins, ) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "withdraw_coins") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "withdraw_coins") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, denom) @@ -213,7 +212,7 @@ func (k Keeper) WithdrawCoins( // updating the marker's record of expected total supply, and transferring the created coin to the MarkerAccount // for holding pending further action. func (k Keeper) MintCoin(ctx sdk.Context, caller sdk.AccAddress, coin sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "mint_coin") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "mint_coin") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, coin.Denom) @@ -253,7 +252,7 @@ func (k Keeper) MintCoin(ctx sdk.Context, caller sdk.AccAddress, coin sdk.Coin) // BurnCoin removes supply from the marker by burning coins held within the marker acccount. func (k Keeper) BurnCoin(ctx sdk.Context, caller sdk.AccAddress, coin sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "burn_coin") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "burn_coin") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, coin.Denom) @@ -302,7 +301,7 @@ func (k Keeper) CurrentEscrow(ctx sdk.Context, marker types.MarkerAccountI) sdk. // AdjustCirculation will mint/burn coin if required to ensure desired supply matches amount in circulation func (k Keeper) AdjustCirculation(ctx sdk.Context, marker types.MarkerAccountI, desiredSupply sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "adjust_circulation") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "adjust_circulation") currentSupply := k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount if desiredSupply.Denom != marker.GetDenom() { @@ -342,7 +341,7 @@ func (k Keeper) AdjustCirculation(ctx sdk.Context, marker types.MarkerAccountI, // IncreaseSupply will mint coins to the marker module coin pool account, then send these to the marker account func (k Keeper) IncreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coin sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "increase_supply") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "increase_supply") inCirculation := sdk.NewCoin(marker.GetDenom(), k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount) total := inCirculation.Add(coin) @@ -368,7 +367,7 @@ func (k Keeper) IncreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coi // DecreaseSupply will move a given amount of coin from the marker to the markermodule coin pool account then burn it. func (k Keeper) DecreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coin sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "decrease_supply") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "decrease_supply") inCirculation := sdk.NewCoin(marker.GetDenom(), k.bankKeeper.GetSupply(ctx, marker.GetDenom()).Amount) @@ -405,7 +404,7 @@ func (k Keeper) DecreaseSupply(ctx sdk.Context, marker types.MarkerAccountI, coi // FinalizeMarker sets the state of the marker to finalized, mints the associated supply, assigns the minted coin to // the marker accounts, and if successful emits an EventMarkerFinalize event to transition the state to active func (k Keeper) FinalizeMarker(ctx sdk.Context, caller sdk.Address, denom string) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "finalize") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "finalize") // (if marker does not exist then fail) m, err := k.GetMarkerByDenom(ctx, denom) @@ -466,7 +465,7 @@ func (k Keeper) FinalizeMarker(ctx sdk.Context, caller sdk.Address, denom string // ActivateMarker transitions a marker into the active status, enforcing permissions, supply constraints, and minting // any supply as required. func (k Keeper) ActivateMarker(ctx sdk.Context, caller sdk.Address, denom string) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "activate") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "activate") m, err := k.GetMarkerByDenom(ctx, denom) if err != nil { @@ -517,7 +516,7 @@ func (k Keeper) ActivateMarker(ctx sdk.Context, caller sdk.Address, denom string // CancelMarker prepares transition to deleted state. func (k Keeper) CancelMarker(ctx sdk.Context, caller sdk.AccAddress, denom string) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "cancel") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "cancel") m, err := k.GetMarkerByDenom(ctx, denom) if err != nil { @@ -565,7 +564,7 @@ func (k Keeper) CancelMarker(ctx sdk.Context, caller sdk.AccAddress, denom strin // DeleteMarker burns the entire coin supply, ensure no assets are pooled, and marks the current instance of the // marker as destroyed. func (k Keeper) DeleteMarker(ctx sdk.Context, caller sdk.AccAddress, denom string) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "delete") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "delete") m, err := k.GetMarkerByDenom(ctx, denom) if err != nil { @@ -623,7 +622,7 @@ func (k Keeper) DeleteMarker(ctx sdk.Context, caller sdk.AccAddress, denom strin // TransferCoin transfers restricted coins between to accounts when the administrator account holds the transfer // access right and the marker type is restricted_coin func (k Keeper) TransferCoin(ctx sdk.Context, from, to, admin sdk.AccAddress, amount sdk.Coin) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "transfer_coin") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "transfer_coin") m, err := k.GetMarkerByDenom(ctx, amount.Denom) if err != nil { @@ -810,7 +809,7 @@ func (k Keeper) authzHandler(ctx sdk.Context, admin, from, to sdk.AccAddress, am // SetMarkerDenomMetadata updates the denom metadata records for the current marker. func (k Keeper) SetMarkerDenomMetadata(ctx sdk.Context, metadata banktypes.Metadata, caller sdk.AccAddress) error { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "set_marker_denom_metadata") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "set_marker_denom_metadata") if metadata.Base == "" { return fmt.Errorf("invalid metadata request, base denom must match existing marker") diff --git a/x/metadata/keeper/msg_server.go b/x/metadata/keeper/msg_server.go index 8230753d7..409f5485b 100644 --- a/x/metadata/keeper/msg_server.go +++ b/x/metadata/keeper/msg_server.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "strings" - "time" sdkmath "cosmossdk.io/math" @@ -33,7 +32,7 @@ func (k msgServer) WriteScope( goCtx context.Context, msg *types.MsgWriteScopeRequest, ) (*types.MsgWriteScopeResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteScope") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteScope") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -70,7 +69,7 @@ func (k msgServer) DeleteScope( goCtx context.Context, msg *types.MsgDeleteScopeRequest, ) (*types.MsgDeleteScopeResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteScope") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteScope") ctx := UnwrapMetadataContext(goCtx) transferAgents, err := k.ValidateDeleteScope(ctx, msg) @@ -94,7 +93,7 @@ func (k msgServer) AddScopeDataAccess( goCtx context.Context, msg *types.MsgAddScopeDataAccessRequest, ) (*types.MsgAddScopeDataAccessResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "AddScopeDataAccess") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "AddScopeDataAccess") ctx := UnwrapMetadataContext(goCtx) existing, found := k.GetScope(ctx, msg.ScopeId) @@ -122,7 +121,7 @@ func (k msgServer) DeleteScopeDataAccess( goCtx context.Context, msg *types.MsgDeleteScopeDataAccessRequest, ) (*types.MsgDeleteScopeDataAccessResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteScopeDataAccess") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteScopeDataAccess") ctx := UnwrapMetadataContext(goCtx) existing, found := k.GetScope(ctx, msg.ScopeId) @@ -150,7 +149,7 @@ func (k msgServer) AddScopeOwner( goCtx context.Context, msg *types.MsgAddScopeOwnerRequest, ) (*types.MsgAddScopeOwnerResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "AddScopeOwner") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "AddScopeOwner") ctx := UnwrapMetadataContext(goCtx) if err := msg.ValidateBasic(); err != nil { @@ -186,7 +185,7 @@ func (k msgServer) DeleteScopeOwner( goCtx context.Context, msg *types.MsgDeleteScopeOwnerRequest, ) (*types.MsgDeleteScopeOwnerResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteScopeOwner") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteScopeOwner") ctx := UnwrapMetadataContext(goCtx) if err := msg.ValidateBasic(); err != nil { @@ -222,7 +221,7 @@ func (k msgServer) UpdateValueOwners( goCtx context.Context, msg *types.MsgUpdateValueOwnersRequest, ) (*types.MsgUpdateValueOwnersResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "UpdateValueOwners") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "UpdateValueOwners") ctx := UnwrapMetadataContext(goCtx) links, err := k.GetScopeValueOwners(ctx, msg.ScopeIds) @@ -249,7 +248,7 @@ func (k msgServer) MigrateValueOwner( goCtx context.Context, msg *types.MsgMigrateValueOwnerRequest, ) (*types.MsgMigrateValueOwnerResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "MigrateValueOwner") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "MigrateValueOwner") ctx := UnwrapMetadataContext(goCtx) addr, err := sdk.AccAddressFromBech32(msg.Existing) @@ -284,7 +283,7 @@ func (k msgServer) WriteSession( goCtx context.Context, msg *types.MsgWriteSessionRequest, ) (*types.MsgWriteSessionResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteSession") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteSession") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -313,7 +312,7 @@ func (k msgServer) WriteRecord( goCtx context.Context, msg *types.MsgWriteRecordRequest, ) (*types.MsgWriteRecordResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteRecord") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteRecord") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -351,7 +350,7 @@ func (k msgServer) DeleteRecord( goCtx context.Context, msg *types.MsgDeleteRecordRequest, ) (*types.MsgDeleteRecordResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteRecord") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteRecord") ctx := UnwrapMetadataContext(goCtx) if err := k.ValidateDeleteRecord(ctx, msg.RecordId, msg); err != nil { @@ -369,7 +368,7 @@ func (k msgServer) WriteScopeSpecification( goCtx context.Context, msg *types.MsgWriteScopeSpecificationRequest, ) (*types.MsgWriteScopeSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteScopeSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteScopeSpecification") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -397,7 +396,7 @@ func (k msgServer) DeleteScopeSpecification( goCtx context.Context, msg *types.MsgDeleteScopeSpecificationRequest, ) (*types.MsgDeleteScopeSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteScopeSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteScopeSpecification") ctx := UnwrapMetadataContext(goCtx) existing, found := k.GetScopeSpecification(ctx, msg.SpecificationId) @@ -421,7 +420,7 @@ func (k msgServer) WriteContractSpecification( goCtx context.Context, msg *types.MsgWriteContractSpecificationRequest, ) (*types.MsgWriteContractSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteContractSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteContractSpecification") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -449,7 +448,7 @@ func (k msgServer) DeleteContractSpecification( goCtx context.Context, msg *types.MsgDeleteContractSpecificationRequest, ) (*types.MsgDeleteContractSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteContractSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteContractSpecification") ctx := UnwrapMetadataContext(goCtx) existing, found := k.GetContractSpecification(ctx, msg.SpecificationId) @@ -498,7 +497,7 @@ func (k msgServer) AddContractSpecToScopeSpec( goCtx context.Context, msg *types.MsgAddContractSpecToScopeSpecRequest, ) (*types.MsgAddContractSpecToScopeSpecResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "AddContractSpecToScopeSpec") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "AddContractSpecToScopeSpec") ctx := UnwrapMetadataContext(goCtx) _, found := k.GetContractSpecification(ctx, msg.ContractSpecificationId) if !found { @@ -531,7 +530,7 @@ func (k msgServer) DeleteContractSpecFromScopeSpec( goCtx context.Context, msg *types.MsgDeleteContractSpecFromScopeSpecRequest, ) (*types.MsgDeleteContractSpecFromScopeSpecResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteContractSpecFromScopeSpec") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteContractSpecFromScopeSpec") ctx := UnwrapMetadataContext(goCtx) scopeSpec, found := k.GetScopeSpecification(ctx, msg.ScopeSpecificationId) if !found { @@ -567,7 +566,7 @@ func (k msgServer) WriteRecordSpecification( goCtx context.Context, msg *types.MsgWriteRecordSpecificationRequest, ) (*types.MsgWriteRecordSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "WriteRecordSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "WriteRecordSpecification") ctx := UnwrapMetadataContext(goCtx) //nolint:errcheck // the error was checked when msg.ValidateBasic was called before getting here. @@ -606,7 +605,7 @@ func (k msgServer) DeleteRecordSpecification( goCtx context.Context, msg *types.MsgDeleteRecordSpecificationRequest, ) (*types.MsgDeleteRecordSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteRecordSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteRecordSpecification") ctx := UnwrapMetadataContext(goCtx) _, found := k.GetRecordSpecification(ctx, msg.SpecificationId) @@ -639,7 +638,7 @@ func (k msgServer) BindOSLocator( goCtx context.Context, msg *types.MsgBindOSLocatorRequest, ) (*types.MsgBindOSLocatorResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "BindOSLocator") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "BindOSLocator") ctx := UnwrapMetadataContext(goCtx) // Validate if err := msg.ValidateBasic(); err != nil { @@ -673,7 +672,7 @@ func (k msgServer) DeleteOSLocator( goCtx context.Context, msg *types.MsgDeleteOSLocatorRequest, ) (*types.MsgDeleteOSLocatorResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "DeleteOSLocator") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "DeleteOSLocator") ctx := UnwrapMetadataContext(goCtx) // Validate if err := msg.ValidateBasic(); err != nil { @@ -709,7 +708,7 @@ func (k msgServer) ModifyOSLocator( goCtx context.Context, msg *types.MsgModifyOSLocatorRequest, ) (*types.MsgModifyOSLocatorResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "tx", "ModifyOSLocator") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "tx", "ModifyOSLocator") ctx := UnwrapMetadataContext(goCtx) // Validate if err := msg.ValidateBasic(); err != nil { diff --git a/x/metadata/keeper/query_server.go b/x/metadata/keeper/query_server.go index e2611424c..20215051f 100644 --- a/x/metadata/keeper/query_server.go +++ b/x/metadata/keeper/query_server.go @@ -5,7 +5,6 @@ import ( b64 "encoding/base64" "fmt" "net/url" - "time" "github.com/google/uuid" @@ -25,7 +24,7 @@ var _ types.QueryServer = Keeper{} // Params queries params of metadata module. func (k Keeper) Params(_ context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Params") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "Params") resp := &types.QueryParamsResponse{Params: types.Params{}} if req != nil && req.IncludeRequest { resp.Request = req @@ -36,7 +35,7 @@ func (k Keeper) Params(_ context.Context, req *types.QueryParamsRequest) (*types // Scope returns a specific scope by id. func (k Keeper) Scope(c context.Context, req *types.ScopeRequest) (*types.ScopeResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Scope") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "Scope") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -142,7 +141,7 @@ func (k Keeper) Scope(c context.Context, req *types.ScopeRequest) (*types.ScopeR // ScopesAll returns all scopes (limited by pagination). func (k Keeper) ScopesAll(c context.Context, req *types.ScopesAllRequest) (*types.ScopesAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ScopesAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ScopesAll") retval := types.ScopesAllResponse{} incInfo := false if req != nil { @@ -188,7 +187,7 @@ func (k Keeper) ScopesAll(c context.Context, req *types.ScopesAllRequest) (*type // Sessions returns sessions based on the provided request. func (k Keeper) Sessions(c context.Context, req *types.SessionsRequest) (*types.SessionsResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Sessions") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "Sessions") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -340,7 +339,7 @@ func (k Keeper) Sessions(c context.Context, req *types.SessionsRequest) (*types. // SessionsAll returns all sessions (limited by pagination). func (k Keeper) SessionsAll(c context.Context, req *types.SessionsAllRequest) (*types.SessionsAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "SessionsAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "SessionsAll") retval := types.SessionsAllResponse{} incInfo := false if req != nil { @@ -386,7 +385,7 @@ func (k Keeper) SessionsAll(c context.Context, req *types.SessionsAllRequest) (* // Records returns records based on the provided request. func (k Keeper) Records(c context.Context, req *types.RecordsRequest) (*types.RecordsResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Records") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "Records") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -526,7 +525,7 @@ func (k Keeper) Records(c context.Context, req *types.RecordsRequest) (*types.Re // RecordsAll returns all records (limited by pagination). func (k Keeper) RecordsAll(c context.Context, req *types.RecordsAllRequest) (*types.RecordsAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "RecordsAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "RecordsAll") retval := types.RecordsAllResponse{} incInfo := false if req != nil { @@ -572,7 +571,7 @@ func (k Keeper) RecordsAll(c context.Context, req *types.RecordsAllRequest) (*ty // Ownership returns a list of scope identifiers that list the given address as a data or value owner. func (k Keeper) Ownership(c context.Context, req *types.OwnershipRequest) (*types.OwnershipResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "Ownership") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "Ownership") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -617,7 +616,7 @@ func (k Keeper) Ownership(c context.Context, req *types.OwnershipRequest) (*type // ValueOwnership returns a list of scope identifiers that list the given address as a value owner. func (k Keeper) ValueOwnership(c context.Context, req *types.ValueOwnershipRequest) (*types.ValueOwnershipResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ValueOwnership") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ValueOwnership") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -650,7 +649,7 @@ func (k Keeper) ValueOwnership(c context.Context, req *types.ValueOwnershipReque // ScopeSpecification returns a specific scope specification by id. func (k Keeper) ScopeSpecification(c context.Context, req *types.ScopeSpecificationRequest) (*types.ScopeSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ScopeSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ScopeSpecification") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -712,7 +711,7 @@ func (k Keeper) ScopeSpecification(c context.Context, req *types.ScopeSpecificat // ScopeSpecificationsAll returns all scope specifications (limited by pagination). func (k Keeper) ScopeSpecificationsAll(c context.Context, req *types.ScopeSpecificationsAllRequest) (*types.ScopeSpecificationsAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ScopeSpecificationsAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ScopeSpecificationsAll") retval := types.ScopeSpecificationsAllResponse{} incInfo := false if req != nil { @@ -758,7 +757,7 @@ func (k Keeper) ScopeSpecificationsAll(c context.Context, req *types.ScopeSpecif // ContractSpecification returns a specific contract specification by id. func (k Keeper) ContractSpecification(c context.Context, req *types.ContractSpecificationRequest) (*types.ContractSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ContractSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ContractSpecification") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -799,7 +798,7 @@ func (k Keeper) ContractSpecification(c context.Context, req *types.ContractSpec // ContractSpecificationsAll returns all contract specifications (limited by pagination). func (k Keeper) ContractSpecificationsAll(c context.Context, req *types.ContractSpecificationsAllRequest) (*types.ContractSpecificationsAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "ContractSpecificationsAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "ContractSpecificationsAll") retval := types.ContractSpecificationsAllResponse{} incInfo := false if req != nil { @@ -848,7 +847,7 @@ func (k Keeper) RecordSpecificationsForContractSpecification( c context.Context, req *types.RecordSpecificationsForContractSpecificationRequest, ) (*types.RecordSpecificationsForContractSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "RecordSpecificationsForContractSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "RecordSpecificationsForContractSpecification") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -887,7 +886,7 @@ func (k Keeper) RecordSpecificationsForContractSpecification( // RecordSpecification returns a specific record specification. func (k Keeper) RecordSpecification(c context.Context, req *types.RecordSpecificationRequest) (*types.RecordSpecificationResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "RecordSpecification") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "RecordSpecification") if req == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -919,7 +918,7 @@ func (k Keeper) RecordSpecification(c context.Context, req *types.RecordSpecific // RecordSpecificationsAll returns all record specifications (limited by pagination). func (k Keeper) RecordSpecificationsAll(c context.Context, req *types.RecordSpecificationsAllRequest) (*types.RecordSpecificationsAllResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "RecordSpecificationsAll") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "RecordSpecificationsAll") retval := types.RecordSpecificationsAllResponse{} incInfo := false if req != nil { @@ -965,7 +964,7 @@ func (k Keeper) RecordSpecificationsAll(c context.Context, req *types.RecordSpec // GetByAddr retrieves metadata given any address(es). func (k Keeper) GetByAddr(c context.Context, req *types.GetByAddrRequest) (*types.GetByAddrResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "GetByAddr") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "GetByAddr") if req == nil || len(req.Addrs) == 0 { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -1030,7 +1029,7 @@ func (k Keeper) GetByAddr(c context.Context, req *types.GetByAddrRequest) (*type } func (k Keeper) OSLocatorParams(c context.Context, request *types.OSLocatorParamsRequest) (*types.OSLocatorParamsResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSLocatorParams") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "OSLocatorParams") ctx := sdk.UnwrapSDKContext(c) params := k.GetOSLocatorParams(ctx) resp := &types.OSLocatorParamsResponse{Params: params} @@ -1041,7 +1040,7 @@ func (k Keeper) OSLocatorParams(c context.Context, request *types.OSLocatorParam } func (k Keeper) OSLocator(c context.Context, request *types.OSLocatorRequest) (*types.OSLocatorResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSLocator") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "OSLocator") if request == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -1067,7 +1066,7 @@ func (k Keeper) OSLocator(c context.Context, request *types.OSLocatorRequest) (* } func (k Keeper) OSLocatorsByURI(ctx context.Context, request *types.OSLocatorsByURIRequest) (*types.OSLocatorsByURIResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSLocatorsByURI") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "OSLocatorsByURI") retval := types.OSLocatorsByURIResponse{} if request == nil { return &retval, sdkerrors.ErrInvalidRequest.Wrap("empty request") @@ -1113,7 +1112,7 @@ func (k Keeper) OSLocatorsByURI(ctx context.Context, request *types.OSLocatorsBy } func (k Keeper) OSLocatorsByScope(ctx context.Context, request *types.OSLocatorsByScopeRequest) (*types.OSLocatorsByScopeResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSLocatorsByScope") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "OSLocatorsByScope") if request == nil { return nil, sdkerrors.ErrInvalidRequest.Wrap("empty request") } @@ -1138,7 +1137,7 @@ func (k Keeper) OSLocatorsByScope(ctx context.Context, request *types.OSLocators } func (k Keeper) OSAllLocators(ctx context.Context, request *types.OSAllLocatorsRequest) (*types.OSAllLocatorsResponse, error) { - defer telemetry.MeasureSince(time.Now(), types.ModuleName, "query", "OSAllLocators") + defer telemetry.MeasureSince(telemetry.Now(), types.ModuleName, "query", "OSAllLocators") retval := types.OSAllLocatorsResponse{} if request == nil { return &retval, sdkerrors.ErrInvalidRequest.Wrap("empty request") From b78b62a36051b52e426428e0946be1511ad07bc4 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 19:58:48 -0600 Subject: [PATCH 11/14] Update the EventsToStrings helper to put a > at the start of the first line for an event, and a space on the rest. This makes it easier to identify where one event starts and another ends. Also, update AssertEqualEvents to output the actual events when the check fails. --- testutil/assertions/events.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/testutil/assertions/events.go b/testutil/assertions/events.go index 0a55d6330..5d8073f1c 100644 --- a/testutil/assertions/events.go +++ b/testutil/assertions/events.go @@ -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 } @@ -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. From 7b7b8c68ef7b5c5bf556642cdf33f90a77507dfa Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 20:00:45 -0600 Subject: [PATCH 12/14] Update some of the exchange msg_server tests that broke because the events that the bank module emits changed a little bit (for the better). --- x/exchange/keeper/msg_server_test.go | 84 ++++++++++++++++------------ 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/x/exchange/keeper/msg_server_test.go b/x/exchange/keeper/msg_server_test.go index 526f47921..242e97f24 100644 --- a/x/exchange/keeper/msg_server_test.go +++ b/x/exchange/keeper/msg_server_test.go @@ -1621,9 +1621,9 @@ func (s *TestSuite) TestMsgServer_FillBids() { s.eventCoinSpent(s.addr1, "13apple"), s.eventMessageSender(s.addr1), s.eventCoinReceived(s.addr2, "10apple"), - s.eventTransfer(s.addr2, nil, "10apple"), s.eventCoinReceived(s.addr3, "3apple"), - s.eventTransfer(s.addr3, nil, "3apple"), + s.eventTransfer(s.addr2, s.addr1, "10apple"), + s.eventTransfer(s.addr3, s.addr1, "3apple"), // Price transfer events. s.eventCoinSpent(s.addr2, "50pear"), @@ -1631,7 +1631,8 @@ func (s *TestSuite) TestMsgServer_FillBids() { s.eventCoinSpent(s.addr3, "20pear"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr1, "70pear"), - s.eventTransfer(s.addr1, nil, "70pear"), + s.eventTransfer(s.addr1, s.addr2, "50pear"), + s.eventTransfer(s.addr1, s.addr3, "20pear"), // Settlement fee transfer events. s.eventCoinSpent(s.addr2, "35fig"), @@ -1641,7 +1642,9 @@ func (s *TestSuite) TestMsgServer_FillBids() { s.eventCoinSpent(s.addr1, "9pear"), s.eventMessageSender(s.addr1), s.eventCoinReceived(s.marketAddr1, "67fig,9pear"), - s.eventTransfer(s.marketAddr1, nil, "67fig,9pear"), + s.eventTransfer(s.marketAddr1, s.addr2, "35fig"), + s.eventTransfer(s.marketAddr1, s.addr3, "32fig"), + s.eventTransfer(s.marketAddr1, s.addr1, "9pear"), // Transfer of exchange portion of settlement fee. s.eventCoinSpent(s.marketAddr1, "4fig,1pear"), @@ -2109,15 +2112,16 @@ func (s *TestSuite) TestMsgServer_FillAsks() { s.eventCoinSpent(s.addr3, "3apple"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr1, "13apple"), - s.eventTransfer(s.addr1, nil, "13apple"), + s.eventTransfer(s.addr1, s.addr2, "10apple"), + s.eventTransfer(s.addr1, s.addr3, "3apple"), // Price transfer events. s.eventCoinSpent(s.addr1, "70pear"), s.eventMessageSender(s.addr1), s.eventCoinReceived(s.addr2, "50pear"), - s.eventTransfer(s.addr2, nil, "50pear"), s.eventCoinReceived(s.addr3, "20pear"), - s.eventTransfer(s.addr3, nil, "20pear"), + s.eventTransfer(s.addr2, s.addr1, "50pear"), + s.eventTransfer(s.addr3, s.addr1, "20pear"), // Settlement fee transfer events. s.eventCoinSpent(s.addr2, "8pear"), @@ -2127,7 +2131,9 @@ func (s *TestSuite) TestMsgServer_FillAsks() { s.eventCoinSpent(s.addr1, "37fig"), s.eventMessageSender(s.addr1), s.eventCoinReceived(s.marketAddr1, "49fig,10pear"), - s.eventTransfer(s.marketAddr1, nil, "49fig,10pear"), + s.eventTransfer(s.marketAddr1, s.addr2, "8pear"), + s.eventTransfer(s.marketAddr1, s.addr3, "12fig,2pear"), + s.eventTransfer(s.marketAddr1, s.addr1, "37fig"), // Transfer of exchange portion of settlement fee. s.eventCoinSpent(s.marketAddr1, "3fig,1pear"), @@ -2397,9 +2403,9 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinSpent(s.addr3, "11apple"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr2, "10apple"), - s.eventTransfer(s.addr2, nil, "10apple"), s.eventCoinReceived(s.addr4, "1apple"), - s.eventTransfer(s.addr4, nil, "1apple"), + s.eventTransfer(s.addr2, s.addr3, "10apple"), + s.eventTransfer(s.addr4, s.addr3, "1apple"), s.eventCoinSpent(s.addr1, "7apple"), s.eventCoinReceived(s.addr4, "7apple"), @@ -2415,9 +2421,9 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinSpent(s.addr4, "85pear"), s.eventMessageSender(s.addr4), s.eventCoinReceived(s.addr3, "9pear"), - s.eventTransfer(s.addr3, nil, "9pear"), s.eventCoinReceived(s.addr1, "76pear"), - s.eventTransfer(s.addr1, nil, "76pear"), + s.eventTransfer(s.addr3, s.addr4, "9pear"), + s.eventTransfer(s.addr1, s.addr4, "76pear"), // Orders filled (24-27) s.untypeEvent(&exchange.EventOrderFilled{ @@ -2571,9 +2577,9 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinSpent(s.addr3, "11apple"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr2, "10apple"), - s.eventTransfer(s.addr2, nil, "10apple"), s.eventCoinReceived(s.addr4, "1apple"), - s.eventTransfer(s.addr4, nil, "1apple"), + s.eventTransfer(s.addr2, s.addr3, "10apple"), + s.eventTransfer(s.addr4, s.addr3, "1apple"), s.eventCoinSpent(s.addr1, "7apple"), s.eventCoinReceived(s.addr4, "7apple"), @@ -2589,9 +2595,9 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinSpent(s.addr4, "85pear"), s.eventMessageSender(s.addr4), s.eventCoinReceived(s.addr3, "9pear"), - s.eventTransfer(s.addr3, nil, "9pear"), s.eventCoinReceived(s.addr1, "76pear"), - s.eventTransfer(s.addr1, nil, "76pear"), + s.eventTransfer(s.addr3, s.addr4, "9pear"), + s.eventTransfer(s.addr1, s.addr4, "76pear"), // Orders filled (24-27) s.untypeEvent(&exchange.EventOrderFilled{ @@ -2689,26 +2695,28 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinReceived(s.addr4, "7apple"), s.eventTransfer(s.addr4, s.addr1, "7apple"), s.eventMessageSender(s.addr1), + s.eventCoinSpent(s.addr3, "11apple"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr4, "1apple"), - s.eventTransfer(s.addr4, nil, "1apple"), s.eventCoinReceived(s.addr2, "10apple"), - s.eventTransfer(s.addr2, nil, "10apple"), + s.eventTransfer(s.addr4, s.addr3, "1apple"), + s.eventTransfer(s.addr2, s.addr3, "10apple"), // Price transfers s.eventCoinSpent(s.addr4, "85pear"), s.eventMessageSender(s.addr4), s.eventCoinReceived(s.addr1, "75pear"), - s.eventTransfer(s.addr1, nil, "75pear"), s.eventCoinReceived(s.addr3, "10pear"), - s.eventTransfer(s.addr3, nil, "10pear"), + s.eventTransfer(s.addr1, s.addr4, "75pear"), + s.eventTransfer(s.addr3, s.addr4, "10pear"), + s.eventCoinSpent(s.addr2, "100pear"), s.eventMessageSender(s.addr2), s.eventCoinReceived(s.addr3, "98pear"), - s.eventTransfer(s.addr3, nil, "98pear"), s.eventCoinReceived(s.addr1, "2pear"), - s.eventTransfer(s.addr1, nil, "2pear"), + s.eventTransfer(s.addr3, s.addr2, "98pear"), + s.eventTransfer(s.addr1, s.addr2, "2pear"), // Orders filled s.untypeEvent(&exchange.EventOrderFilled{ @@ -3031,26 +3039,28 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinReceived(s.addr2, "7apple"), s.eventTransfer(s.addr2, s.addr1, "7apple"), s.eventMessageSender(s.addr1), + s.eventCoinSpent(s.addr3, "11apple"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr2, "3apple"), - s.eventTransfer(s.addr2, nil, "3apple"), s.eventCoinReceived(s.addr4, "8apple"), - s.eventTransfer(s.addr4, nil, "8apple"), + s.eventTransfer(s.addr2, s.addr3, "3apple"), + s.eventTransfer(s.addr4, s.addr3, "8apple"), // Price transfers s.eventCoinSpent(s.addr2, "100pear"), s.eventMessageSender(s.addr2), s.eventCoinReceived(s.addr1, "75pear"), - s.eventTransfer(s.addr1, nil, "75pear"), s.eventCoinReceived(s.addr3, "25pear"), - s.eventTransfer(s.addr3, nil, "25pear"), + s.eventTransfer(s.addr1, s.addr2, "75pear"), + s.eventTransfer(s.addr3, s.addr2, "25pear"), + s.eventCoinSpent(s.addr4, "85pear"), s.eventMessageSender(s.addr4), s.eventCoinReceived(s.addr3, "83pear"), - s.eventTransfer(s.addr3, nil, "83pear"), s.eventCoinReceived(s.addr1, "2pear"), - s.eventTransfer(s.addr1, nil, "2pear"), + s.eventTransfer(s.addr3, s.addr4, "83pear"), + s.eventTransfer(s.addr1, s.addr4, "2pear"), // Fee transfers to market s.eventCoinSpent(s.addr1, "10fig,8pear"), @@ -3062,7 +3072,10 @@ func (s *TestSuite) TestMsgServer_MarketSettle() { s.eventCoinSpent(s.addr4, "10pear"), s.eventMessageSender(s.addr4), s.eventCoinReceived(s.marketAddr2, "30fig,34pear"), - s.eventTransfer(s.marketAddr2, nil, "30fig,34pear"), + s.eventTransfer(s.marketAddr2, s.addr1, "10fig,8pear"), + s.eventTransfer(s.marketAddr2, s.addr3, "16pear"), + s.eventTransfer(s.marketAddr2, s.addr2, "20fig"), + s.eventTransfer(s.marketAddr2, s.addr4, "10pear"), // Transfers of exchange portion of fees s.eventCoinSpent(s.marketAddr2, "2fig,2pear"), @@ -3219,11 +3232,11 @@ func (s *TestSuite) TestMsgServer_MarketCommitmentSettle() { s.eventCoinSpent(s.addr1, "95apple"), s.eventMessageSender(s.addr1), s.eventCoinReceived(s.addr2, "57apple"), - s.eventTransfer(s.addr2, nil, "57apple"), s.eventCoinReceived(s.addr3, "12apple"), - s.eventTransfer(s.addr3, nil, "12apple"), s.eventCoinReceived(s.addr4, "26apple"), - s.eventTransfer(s.addr4, nil, "26apple"), + s.eventTransfer(s.addr2, s.addr1, "57apple"), + s.eventTransfer(s.addr3, s.addr1, "12apple"), + s.eventTransfer(s.addr4, s.addr1, "26apple"), // Transfer from addr2 s.eventCoinSpent(s.addr2, "50plum"), @@ -3235,9 +3248,9 @@ func (s *TestSuite) TestMsgServer_MarketCommitmentSettle() { s.eventCoinSpent(s.addr3, "77plum"), s.eventMessageSender(s.addr3), s.eventCoinReceived(s.addr1, "40plum"), - s.eventTransfer(s.addr1, nil, "40plum"), s.eventCoinReceived(s.addr4, "37plum"), - s.eventTransfer(s.addr4, nil, "37plum"), + s.eventTransfer(s.addr1, s.addr3, "40plum"), + s.eventTransfer(s.addr4, s.addr3, "37plum"), // Fee Transfer s.eventCoinSpent(s.addr1, "2cherry"), @@ -3245,7 +3258,8 @@ func (s *TestSuite) TestMsgServer_MarketCommitmentSettle() { s.eventCoinSpent(s.addr2, "3cherry"), s.eventMessageSender(s.addr2), s.eventCoinReceived(s.marketAddr3, "5cherry"), - s.eventTransfer(s.marketAddr3, nil, "5cherry"), + s.eventTransfer(s.marketAddr3, s.addr1, "2cherry"), + s.eventTransfer(s.marketAddr3, s.addr2, "3cherry"), // re-commits s.eventHoldAddedCommitment(s.addr1, "90plum", 3), From d36e1f6dfab070a24f1219f1da1becdec5bae55d Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Wed, 9 Oct 2024 20:19:30 -0600 Subject: [PATCH 13/14] Fix the event assertions tests that started failing when I changed the output of EventsToStrings. --- testutil/assertions/events_test.go | 157 ++++++++++++++-------------- testutil/assertions/general_test.go | 4 +- 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/testutil/assertions/events_test.go b/testutil/assertions/events_test.go index bd4f4a8e8..7d022950b 100644 --- a/testutil/assertions/events_test.go +++ b/testutil/assertions/events_test.go @@ -113,20 +113,20 @@ func TestEventsToStrings(t *testing.T) { name: "one event", events: sdk.Events{eventRel}, exp: []string{ - fmt.Sprintf("[0]provenance.hold.v1.EventHoldReleased[0]: \"address\" = \"\\\"%s\\\"\"", addrRel), - fmt.Sprintf("[0]provenance.hold.v1.EventHoldReleased[1]: \"amount\" = \"\\\"%s\\\"\"", coinsRel), + fmt.Sprintf(">[0]provenance.hold.v1.EventHoldReleased[0]: \"address\" = \"\\\"%s\\\"\"", addrRel), + fmt.Sprintf(" [0]provenance.hold.v1.EventHoldReleased[1]: \"amount\" = \"\\\"%s\\\"\"", coinsRel), }, }, { name: "three events", events: sdk.Events{eventAdd, sdk.Event{Type: "weird.entry"}, eventRel}, exp: []string{ - fmt.Sprintf("[0]provenance.hold.v1.EventHoldAdded[0]: \"address\" = \"\\\"%s\\\"\" (indexed)", addrAdd), - fmt.Sprintf("[0]provenance.hold.v1.EventHoldAdded[1]: \"amount\" = \"\\\"%s\\\"\"", coinsAdd), - fmt.Sprintf("[0]provenance.hold.v1.EventHoldAdded[2]: \"reason\" = \"\\\"%s\\\"\"", reason), - "[1]weird.entry: (no attributes)", - fmt.Sprintf("[2]provenance.hold.v1.EventHoldReleased[0]: \"address\" = \"\\\"%s\\\"\"", addrRel), - fmt.Sprintf("[2]provenance.hold.v1.EventHoldReleased[1]: \"amount\" = \"\\\"%s\\\"\"", coinsRel), + fmt.Sprintf(">[0]provenance.hold.v1.EventHoldAdded[0]: \"address\" = \"\\\"%s\\\"\" (indexed)", addrAdd), + fmt.Sprintf(" [0]provenance.hold.v1.EventHoldAdded[1]: \"amount\" = \"\\\"%s\\\"\"", coinsAdd), + fmt.Sprintf(" [0]provenance.hold.v1.EventHoldAdded[2]: \"reason\" = \"\\\"%s\\\"\"", reason), + ">[1]weird.entry: (no attributes)", + fmt.Sprintf(">[2]provenance.hold.v1.EventHoldReleased[0]: \"address\" = \"\\\"%s\\\"\"", addrRel), + fmt.Sprintf(" [2]provenance.hold.v1.EventHoldReleased[1]: \"amount\" = \"\\\"%s\\\"\"", coinsRel), }, }, } @@ -325,8 +325,8 @@ func getEqualEventsTestCases() []equalEventsTestCase { expOutput: []string{ errorLead + "Not equal:", blankLead + "expected: []string(nil)", - blankLead + "actual : []string{\"[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"}", - "+ (string) (len=26) \"[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"", + blankLead + "actual : []string{\">[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"}", + "+ (string) (len=27) \">[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"", }, }, { @@ -335,9 +335,9 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: nil, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"}", + blankLead + "expected: []string{\">[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"}", blankLead + "actual : []string(nil)", - "- (string) (len=26) \"[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"", + "- (string) (len=27) \">[0]missing[0]: \\\"mk\\\" = \\\"mv\\\"\"", }, }, { @@ -352,10 +352,10 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key2", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key2\\\" = \\\"value1\\\"\"}", - "- (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", - "+ (string) (len=30) \"[0]found[0]: \\\"key2\\\" = \\\"value1\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key2\\\" = \\\"value1\\\"\"}", + "- (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", + "+ (string) (len=31) \">[0]found[0]: \\\"key2\\\" = \\\"value1\\\"\"", }, }, { @@ -364,10 +364,10 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key1", "value2"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value2\\\"\"}", - "- (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", - "+ (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value2\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value2\\\"\"}", + "- (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", + "+ (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value2\\\"\"", }, }, { @@ -376,10 +376,10 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key1", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - "- (string) (len=40) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"", - "+ (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + "- (string) (len=41) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"", + "+ (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", }, }, { @@ -388,10 +388,10 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attri("key1", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"}", - "- (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", - "+ (string) (len=40) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"}", + "- (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", + "+ (string) (len=41) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\" (indexed)\"", }, }, { @@ -400,9 +400,9 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key1", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - "- (string) (len=30) \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + "- (string) (len=31) \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", }, }, { @@ -411,9 +411,9 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key1", "value1"), attr("key2", "value2"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", - "+ (string) (len=30) \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", + "+ (string) (len=31) \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", }, }, { @@ -422,12 +422,12 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key2", "value2"), attr("key1", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key2\\\" = \\\"value2\\\"\", \"[0]found[1]: \\\"key1\\\" = \\\"value1\\\"\"}", - "- (string) (len=30) \"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", - "- (string) (len=30) \"[0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", - "+ (string) (len=30) \"[0]found[0]: \\\"key2\\\" = \\\"value2\\\"\"", - "+ (string) (len=30) \"[0]found[1]: \\\"key1\\\" = \\\"value1\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key2\\\" = \\\"value2\\\"\", \" [0]found[1]: \\\"key1\\\" = \\\"value1\\\"\"}", + "- (string) (len=31) \">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"", + "- (string) (len=31) \" [0]found[1]: \\\"key2\\\" = \\\"value2\\\"\"", + "+ (string) (len=31) \">[0]found[0]: \\\"key2\\\" = \\\"value2\\\"\"", + "+ (string) (len=31) \" [0]found[1]: \\\"key1\\\" = \\\"value1\\\"\"", }, }, { @@ -439,9 +439,9 @@ func getEqualEventsTestCases() []equalEventsTestCase { actual: sdk.Events{event("found", attr("key1", "value1"))}, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - "- (string) (len=32) \"[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \">[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + "- (string) (len=33) \">[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"", }, }, { @@ -453,9 +453,9 @@ func getEqualEventsTestCases() []equalEventsTestCase { }, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - blankLead + "actual : []string{\"[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"}", - "+ (string) (len=32) \"[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"", + blankLead + "expected: []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + blankLead + "actual : []string{\">[0]found[0]: \\\"key1\\\" = \\\"value1\\\"\", \">[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"}", + "+ (string) (len=33) \">[1]missing[0]: \\\"key2\\\" = \\\"value2\\\"\"", }, }, { @@ -482,12 +482,12 @@ func getEqualEventsTestCases() []equalEventsTestCase { }, expOutput: []string{ errorLead + "Not equal:", - blankLead + "expected: []string{\"[0]first[0]: \\\"key1\\\" = \\\"value1\\\"\", \"[1]second[0]: \\\"key2\\\" = \\\"value2\\\"\"}", - blankLead + "actual : []string{\"[0]second[0]: \\\"key2\\\" = \\\"value2\\\"\", \"[1]first[0]: \\\"key1\\\" = \\\"value1\\\"\"}", - "- (string) (len=30) \"[0]first[0]: \\\"key1\\\" = \\\"value1\\\"\"", - "- (string) (len=31) \"[1]second[0]: \\\"key2\\\" = \\\"value2\\\"\"", - "+ (string) (len=31) \"[0]second[0]: \\\"key2\\\" = \\\"value2\\\"\"", - "+ (string) (len=30) \"[1]first[0]: \\\"key1\\\" = \\\"value1\\\"\"", + blankLead + "expected: []string{\">[0]first[0]: \\\"key1\\\" = \\\"value1\\\"\", \">[1]second[0]: \\\"key2\\\" = \\\"value2\\\"\"}", + blankLead + "actual : []string{\">[0]second[0]: \\\"key2\\\" = \\\"value2\\\"\", \">[1]first[0]: \\\"key1\\\" = \\\"value1\\\"\"}", + "- (string) (len=31) \">[0]first[0]: \\\"key1\\\" = \\\"value1\\\"\"", + "- (string) (len=32) \">[1]second[0]: \\\"key2\\\" = \\\"value2\\\"\"", + "+ (string) (len=32) \">[0]second[0]: \\\"key2\\\" = \\\"value2\\\"\"", + "+ (string) (len=31) \">[1]first[0]: \\\"key1\\\" = \\\"value1\\\"\"", }, }, } @@ -641,11 +641,11 @@ func getEventsContainsTestCases() []eventsContainsTestCase { expOutput: []string{ "1 (of 1) expected events missing from 3 actual events", "Actual:", - "\t[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", - "\t[0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", - "\t[1]eventblank: (no attributes)", - "\t[2]event2[0]: \"name\" = \"kelly\"", - "\t[2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", + "\t>[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", + "\t [0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", + "\t>[1]eventblank: (no attributes)", + "\t>[2]event2[0]: \"name\" = \"kelly\"", + "\t [2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", "Missing:", "\t0: event2[0]: \"name\" = \"kelly\"", "\t0: event2[1]: \"amount\" = \"\\\"101banana\\\"\"", @@ -674,7 +674,8 @@ func getEventsContainsTestCases() []eventsContainsTestCase { newEvent("event2", attr("name", "kelly"), attr("amount", `"100banana"`)), }, expOutput: nil, - }, { + }, + { name: "one exp three act third", expected: sdk.Events{ newEvent("event2", attr("name", "kelly"), attr("amount", `"100banana"`)), @@ -753,11 +754,11 @@ func getEventsContainsTestCases() []eventsContainsTestCase { expOutput: []string{ "1 (of 3) expected events missing from 3 actual events", "Actual:", - "\t[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", - "\t[0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", - "\t[1]eventblank: (no attributes)", - "\t[2]event2[0]: \"name\" = \"kelly\"", - "\t[2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", + "\t>[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", + "\t [0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", + "\t>[1]eventblank: (no attributes)", + "\t>[2]event2[0]: \"name\" = \"kelly\"", + "\t [2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", "Missing:", "\t0: event0[0]: \"crazy\" = \"indexedval\" (indexed)", }, @@ -777,11 +778,11 @@ func getEventsContainsTestCases() []eventsContainsTestCase { expOutput: []string{ "1 (of 3) expected events missing from 3 actual events", "Actual:", - "\t[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", - "\t[0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", - "\t[1]eventblank: (no attributes)", - "\t[2]event2[0]: \"name\" = \"kelly\"", - "\t[2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", + "\t>[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", + "\t [0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", + "\t>[1]eventblank: (no attributes)", + "\t>[2]event2[0]: \"name\" = \"kelly\"", + "\t [2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", "Missing:", "\t0: eventblank[0]: \"oops\" = \"toomuch\"", }, @@ -801,11 +802,11 @@ func getEventsContainsTestCases() []eventsContainsTestCase { expOutput: []string{ "1 (of 3) expected events missing from 3 actual events", "Actual:", - "\t[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", - "\t[0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", - "\t[1]eventblank: (no attributes)", - "\t[2]event2[0]: \"name\" = \"kelly\"", - "\t[2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", + "\t>[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", + "\t [0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", + "\t>[1]eventblank: (no attributes)", + "\t>[2]event2[0]: \"name\" = \"kelly\"", + "\t [2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", "Missing:", "\t0: event3[0]: \"name\" = \"kelly\"", "\t0: event3[1]: \"amount\" = \"\\\"100banana\\\"\"", @@ -826,11 +827,11 @@ func getEventsContainsTestCases() []eventsContainsTestCase { expOutput: []string{ "3 (of 3) expected events missing from 3 actual events", "Actual:", - "\t[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", - "\t[0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", - "\t[1]eventblank: (no attributes)", - "\t[2]event2[0]: \"name\" = \"kelly\"", - "\t[2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", + "\t>[0]event0[0]: \"something\" = \"\\\"quotedval\\\"\"", + "\t [0]event0[1]: \"crazy\" = \"indexedval\" (indexed)", + "\t>[1]eventblank: (no attributes)", + "\t>[2]event2[0]: \"name\" = \"kelly\"", + "\t [2]event2[1]: \"amount\" = \"\\\"100banana\\\"\"", "Missing:", "\t0: event0[0]: \"something\" = \"\\\"quotedval\\\"\"", "\t0: event0[1]: \"crazy\" = \"indexedval\"", diff --git a/testutil/assertions/general_test.go b/testutil/assertions/general_test.go index 5c83987ba..7a75a9a4c 100644 --- a/testutil/assertions/general_test.go +++ b/testutil/assertions/general_test.go @@ -80,7 +80,7 @@ func assertMockRunAssertResult(t *testing.T, funcName string, tb *mockTB, succes assert.False(t, success, "%s result", funcName) assert.True(t, tb.isFailed, "%s is failed", funcName) for _, exp := range expOutput { - assert.Contains(t, tb.output, exp, "%s output", funcName) + assert.Contains(t, tb.output, exp, "%s output, looking for %q", funcName, exp) } assert.Contains(t, tb.output, expMsgAndArgs, "%s output has msgAndArgs", funcName) } else { @@ -95,7 +95,7 @@ func assertMockRunRequireResult(t *testing.T, funcName string, tb *mockTB, exite if len(expOutput) > 0 { assert.True(t, tb.isFailed, "%s is failed", funcName) for _, exp := range expOutput { - assert.Contains(t, tb.output, exp, "%s output", funcName) + assert.Contains(t, tb.output, exp, "%s output, looking for %q", funcName, exp) } assert.Contains(t, tb.output, expMsgAndArgs, "%s output has msgAndArgs", funcName) assert.True(t, exited, "%s exited", funcName) From 9a2f7243b2f0d8ca01d1942bbdf203e6b8e70296 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 10 Oct 2024 16:33:23 -0600 Subject: [PATCH 14/14] Switch us to the now-tagged v0.50.10-pio-1 of the SDK. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 54fb763e2..993b6679f 100644 --- a/go.mod +++ b/go.mod @@ -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.0.20241009215832-692cc7b414fc + 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 diff --git a/go.sum b/go.sum index 0bc221e29..722928904 100644 --- a/go.sum +++ b/go.sum @@ -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.0.20241009215832-692cc7b414fc h1:x4ILzMtxlyJZVJGPEnhn+VGmJH/VSSLemxBL6oCRWxc= -github.com/provenance-io/cosmos-sdk v0.50.7-pio-1.0.20241009215832-692cc7b414fc/go.mod h1:6Eesrx3ZE7vxBZWpK++30H+Uc7Q4ahQWCL7JKU/LEdU= +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=