Skip to content

Commit

Permalink
Merge branch 'main' into dwedul/fix-docs-sanct-brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon authored Jun 3, 2024
2 parents 04da9dc + c9f8d39 commit c32ee59
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 158 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Add the Quarantine module back in [#1926](https://github.com/provenance-io/provenance/pull/1926).
* Bump wasmd to `v0.50.0` [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Update stargate queries for Attribute, Exchange, Marker, IBCRateLimit, Metadata, Msgfees, and Oracle modules [#1760](https://github.com/provenance-io/provenance/issues/1760).
* Update stargate queries for Quarantine and Sanction modules [#2016](https://github.com/provenance-io/provenance/pull/2016).

### Improvements

Expand Down Expand Up @@ -99,6 +100,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* `name` add `UpdateParams` endpoint and cli [#2004](https://github.com/provenance-io/provenance/pull/2004).
* Update the exchange `commitment-settlement-fee-calc` cli query to utilize the keyring [#2001](https://github.com/provenance-io/provenance/pull/2001).
* Implement the ProposalMsgs module interface for the internal/provwasm, ibcratelimit, oracle, and sanction modules [#1993](https://github.com/provenance-io/provenance/pull/1993.)
* Breakdown internal/helpers into multiple internal packages [#2019](https://github.com/provenance-io/provenance/pull/2019).

### Client Breaking

Expand Down Expand Up @@ -136,6 +138,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- Bump `docker/setup-qemu-action` from 2 to 3 ([#1983](https://github.com/provenance-io/provenance/pull/1983))
- Update `github.com/cosmos/ibc-go/v8` to our forked tag v8.2.1-pio-1 ([#1998](https://github.com/provenance-io/provenance/pull/1998))
- Bump `github.com/rs/zerolog` from 1.32.0 to 1.33.0 ([#1994](https://github.com/provenance-io/provenance/pull/1994))
- Bump `github.com/spf13/viper` from 1.18.2 to 1.19.0 ([#2020](https://github.com/provenance-io/provenance/pull/2020))

---

Expand Down
8 changes: 4 additions & 4 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/provenance-io/provenance/internal/helpers"
internalsdk "github.com/provenance-io/provenance/internal/sdk"
markertypes "github.com/provenance-io/provenance/x/marker/types"
)

Expand Down Expand Up @@ -100,7 +100,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str

// withdraw all validator commission
ierr := app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, helpers.MustGetOperatorAddr(val))
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, internalsdk.MustGetOperatorAddr(val))
return false
})
if ierr != nil {
Expand Down Expand Up @@ -136,7 +136,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
// reinitialize all validators
ierr = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, helpers.MustGetOperatorAddr(val))
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, internalsdk.MustGetOperatorAddr(val))
if err != nil {
panic(err)
}
Expand All @@ -150,7 +150,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
panic(err)
}

if err = app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, helpers.MustGetOperatorAddr(val)); err != nil {
if err = app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, internalsdk.MustGetOperatorAddr(val)); err != nil {
panic(err)
}
return false
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/provenance-io/provenance/internal/helpers"
internalsdk "github.com/provenance-io/provenance/internal/sdk"
)

type UpgradeTestSuite struct {
Expand Down Expand Up @@ -265,7 +265,7 @@ func (s *UpgradeTestSuite) DelegateToValidator(valAddress sdk.ValAddress, delega
}

func (s *UpgradeTestSuite) GetOperatorAddr(val stakingtypes.ValidatorI) sdk.ValAddress {
addr, err := helpers.GetOperatorAddr(val)
addr, err := internalsdk.GetOperatorAddr(val)
s.Require().NoError(err, "GetOperatorAddr(%q)", val.GetOperator())
return addr
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/text v0.15.0
Expand Down Expand Up @@ -116,7 +116,7 @@ require (
github.com/google/orderedcode v0.0.1 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
Expand Down Expand Up @@ -156,7 +156,7 @@ require (
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -195,7 +195,7 @@ require (
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99
github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqEF02fYlzkUCyo=
github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY=
github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA=
github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc=
github.com/googleapis/gax-go/v2 v2.12.3 h1:5/zPPDvw8Q1SuXjrqrZslrqT7dL/uJT2CQii/cLCKqA=
github.com/googleapis/gax-go/v2 v2.12.3/go.mod h1:AKloxT6GtNbaLm8QTNSidHUVsHYcBHwWRvkNFJUQcS4=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
Expand Down Expand Up @@ -854,8 +854,8 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/petermattis/goid v0.0.0-20230904192822-1876fd5063bc h1:8bQZVK1X6BJR/6nYUPxQEP+ReTsceJTKizeuwjWOPUA=
Expand Down Expand Up @@ -976,8 +976,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down Expand Up @@ -1496,8 +1496,8 @@ google.golang.org/api v0.96.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ
google.golang.org/api v0.97.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ13s=
google.golang.org/api v0.98.0/go.mod h1:w7wJQLTM+wvQpNf5JyEcBoxK0RH7EDrh/L4qfsuJ13s=
google.golang.org/api v0.100.0/go.mod h1:ZE3Z2+ZOr87Rx7dqFsdRQkRBk36kDtp/h+QpHbB7a70=
google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY=
google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg=
google.golang.org/api v0.171.0 h1:w174hnBPqut76FzW5Qaupt7zY8Kql6fiVjgys4f58sU=
google.golang.org/api v0.171.0/go.mod h1:Hnq5AHm4OTMt2BUVjael2CWZFD6vksJdWCWiUAmjC9o=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers/maps.go → internal/collections/maps.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package collections

// This file houses functions that are in "golang.org/x/exp/maps" but not "maps", but that we want to use.
// If any show up in "maps", delete them from here and switch uses to the official ones.
Expand Down
4 changes: 2 additions & 2 deletions internal/handlers/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/cosmos/gogoproto/proto"

"github.com/provenance-io/provenance/internal/antewrapper"
"github.com/provenance-io/provenance/internal/helpers"
"github.com/provenance-io/provenance/internal/protocompat"
internalsdk "github.com/provenance-io/provenance/internal/sdk"
msgfeeskeeper "github.com/provenance-io/provenance/x/msgfees/keeper"
)

Expand Down Expand Up @@ -169,7 +169,7 @@ func (msr *PioMsgServiceRouter) registerMsgServiceHandler(sd *grpc.ServiceDesc,
return handler(goCtx, req)
}

if err = helpers.ValidateBasic(req); err != nil {
if err = internalsdk.ValidateBasic(req); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/provwasm/message_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/provenance-io/provenance/internal/helpers"
internalsdk "github.com/provenance-io/provenance/internal/sdk"
)

// Encoder describes behavior for provenance smart contract message encoding.
Expand Down Expand Up @@ -65,7 +65,7 @@ func customEncoders(registry *EncoderRegistry, logger log.Logger) wasmkeeper.Cus
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
for _, msg := range msgs {
if err := helpers.ValidateBasic(msg); err != nil {
if err := internalsdk.ValidateBasic(msg); err != nil {
logger.Error("message validation failed", "err", err)
return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}
Expand Down
13 changes: 13 additions & 0 deletions internal/provwasm/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types"
nametypes "github.com/provenance-io/provenance/x/name/types"
oracletypes "github.com/provenance-io/provenance/x/oracle/types"
"github.com/provenance-io/provenance/x/quarantine"
"github.com/provenance-io/provenance/x/sanction"
triggertypes "github.com/provenance-io/provenance/x/trigger/types"
)

Expand Down Expand Up @@ -65,6 +67,17 @@ func init() {
setWhitelistedQuery("/cosmos.gov.v1beta1.Query/Params", &govtypes.QueryParamsResponse{})
setWhitelistedQuery("/cosmos.gov.v1beta1.Query/Vote", &govtypes.QueryVoteResponse{})

// quarantine
setWhitelistedQuery("/cosmos.quarantine.v1beta1.Query/IsQuarantined", &quarantine.QueryIsQuarantinedResponse{})
setWhitelistedQuery("/cosmos.quarantine.v1beta1.Query/QuarantinedFunds", &quarantine.QueryQuarantinedFundsResponse{})
setWhitelistedQuery("/cosmos.quarantine.v1beta1.Query/AutoResponses", &quarantine.QueryAutoResponsesResponse{})

// sanction
setWhitelistedQuery("/cosmos.sanction.v1beta1.Query/IsSanctioned", &sanction.QueryIsSanctionedResponse{})
setWhitelistedQuery("/cosmos.sanction.v1beta1.Query/SanctionedAddresses", &sanction.QuerySanctionedAddressesResponse{})
setWhitelistedQuery("/cosmos.sanction.v1beta1.Query/TemporaryEntries", &sanction.QueryTemporaryEntriesResponse{})
setWhitelistedQuery("/cosmos.sanction.v1beta1.Query/Params", &sanction.QueryParamsResponse{})

// slashing
setWhitelistedQuery("/cosmos.slashing.v1beta1.Query/Params", &slashingtypes.QueryParamsResponse{})
setWhitelistedQuery("/cosmos.slashing.v1beta1.Query/SigningInfo", &slashingtypes.QuerySigningInfoResponse{})
Expand Down
12 changes: 12 additions & 0 deletions internal/rand/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package rand

import (
"math/rand"

simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)

// SelectAccounts selects count accounts from the ones provided.
func SelectAccounts(r *rand.Rand, accs []simtypes.Account, count int) ([]simtypes.Account, error) {
return SelectEntries(r, accs, count, "accounts")
}
8 changes: 8 additions & 0 deletions internal/rand/int.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package rand

import "math/rand"

// IntBetween generates a random number between min and max inclusive.
func IntBetween(r *rand.Rand, min, max int) int {
return r.Intn(max-min+1) + min
}
94 changes: 94 additions & 0 deletions internal/rand/int_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package rand

import (
"fmt"
"math/rand"
"slices"
"testing"

internalcollections "github.com/provenance-io/provenance/internal/collections"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIntBetween(t *testing.T) {
tests := []struct {
min int
max int
expPanic bool
}{
{min: 0, max: 0},
{min: 0, max: 10},
{min: 1, max: 1},
{min: -1, max: -1},
{min: 1, max: 0, expPanic: true},
{min: 0, max: -1, expPanic: true},
{min: 1, max: -1, expPanic: true},
{min: 10, max: -20, expPanic: true},
{min: 10, max: -11, expPanic: true},
{min: 10, max: -10, expPanic: true},
{min: 10, max: -9, expPanic: true},
{min: 10, max: 9, expPanic: true},
{min: 10, max: 10},
{min: 10, max: 11},
{min: 10, max: 20},
{min: -10, max: -11, expPanic: true},
{min: -10, max: -10},
{min: -10, max: -9},
{min: -10, max: 9},
{min: -10, max: 10},
{min: -10, max: 11},
{min: -20, max: -1},
{min: -20, max: 0},
{min: -20, max: 1},
{min: 1001, max: 1100},
{min: -1778, max: -1670},
}

for _, tc := range tests {
name := fmt.Sprintf("RandIntBetween(%d, %d)", tc.min, tc.max)
if tc.expPanic {
name += " panics"
}

t.Run(name, func(t *testing.T) {
r := rand.New(rand.NewSource(1))
// Check for panic for the first try.
seen := make(map[int]bool)
testFunc := func() {
val := IntBetween(r, tc.min, tc.max)
seen[val] = true
}
if tc.expPanic {
require.PanicsWithValue(t, "invalid argument to Intn", testFunc)
return
}
require.NotPanics(t, testFunc)

count := tc.max - tc.min + 1
expected := make([]int, 0, count)
for i := tc.min; i <= tc.max; i++ {
expected = append(expected, i)
}

// Run it a bunch of times, trying to get it to return all possible values.
// I chose count*100 to essentially give each value 100 chances to be chosen, but be
// low enough to still finish pretty quickly if one or more values never gets returned.
for i := 0; i < count*100 && len(seen) < count; i++ {
testFunc()
}
// Make sure both the min and max were returned at some point.
assert.True(t, seen[tc.min], "minimum value %d in seen map", tc.min)
assert.True(t, seen[tc.max], "maximum value %d in seen map", tc.max)

seenVals := internalcollections.Keys(seen)
slices.Sort(seenVals)
// Make sure the smallest and largest are as expected.
assert.Equal(t, tc.min, seenVals[0], "smallest number generated")
assert.Equal(t, tc.max, seenVals[len(seenVals)-1], "largest number generated")
// Make sure all values were generated. This check technically covers the previous ones,
// but I've got them split out like this for friendlier test failure messages.
assert.Equal(t, expected, seenVals, "values generated")
})
}
}
18 changes: 3 additions & 15 deletions internal/helpers/rand.go → internal/rand/slices.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package helpers
package rand

import (
"fmt"
"math/rand"

simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)

// RandIntBetween generates a random number between min and max inclusive.
func RandIntBetween(r *rand.Rand, min, max int) int {
return r.Intn(max-min+1) + min
}

// SelectRandomEntries selects count entries from the ones provided.
// SelectEntries selects count entries from the ones provided.
// The entriesType string is used in the error message to describe the entries slice.
func SelectRandomEntries[E any](r *rand.Rand, entries []E, count int, entriesType string) ([]E, error) {
func SelectEntries[E any](r *rand.Rand, entries []E, count int, entriesType string) ([]E, error) {
if count == 0 {
return nil, nil
}
Expand All @@ -36,8 +29,3 @@ func SelectRandomEntries[E any](r *rand.Rand, entries []E, count int, entriesTyp
})
return randomized[:count], nil
}

// SelectRandomAccounts selects count accounts from the ones provided.
func SelectRandomAccounts(r *rand.Rand, accs []simtypes.Account, count int) ([]simtypes.Account, error) {
return SelectRandomEntries(r, accs, count, "accounts")
}
Loading

0 comments on commit c32ee59

Please sign in to comment.