diff --git a/x/node/simulation/genesis.go b/x/node/simulation/genesis.go index 1b0738a0..17ef0d08 100644 --- a/x/node/simulation/genesis.go +++ b/x/node/simulation/genesis.go @@ -7,29 +7,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/types/simulation" hubtypes "github.com/sentinel-official/hub/types" "github.com/sentinel-official/hub/x/node/types" ) -func getRandomDeposit(r *rand.Rand) int64 { - return int64(r.Intn(100) + 1) -} - -func getRandomInactiveDuration(r *rand.Rand) time.Duration { - return time.Duration(simulation.RandIntBetween(r, 60, 60<<13)) -} - -func getNodeAddress() hubtypes.NodeAddress { - bz := make([]byte, 20) - _, err := rand.Read(bz) - if err != nil { - panic(err) - } - - return hubtypes.NodeAddress(bz) -} - func RandomizedGenState(simState *module.SimulationState) *types.GenesisState { var ( diff --git a/x/node/simulation/rand.go b/x/node/simulation/rand.go new file mode 100644 index 00000000..e879f123 --- /dev/null +++ b/x/node/simulation/rand.go @@ -0,0 +1,28 @@ +package simulation + +import ( + "math/rand" + "time" + + "github.com/cosmos/cosmos-sdk/types/simulation" + hubtypes "github.com/sentinel-official/hub/types" +) + +func getRandomDeposit(r *rand.Rand) int64 { + return int64(r.Intn(100) + 1) +} + +func getRandomInactiveDuration(r *rand.Rand) time.Duration { + return time.Duration(simulation.RandIntBetween(r, 60, 60<<13)) +} + +func getNodeAddress() hubtypes.NodeAddress { + bz := make([]byte, 20) + _, err := rand.Read(bz) + if err != nil { + panic(err) + } + + return hubtypes.NodeAddress(bz) +} + diff --git a/x/plan/simulation/decoder.go b/x/plan/simulation/decoder.go index 828dbb70..eeac3ea6 100644 --- a/x/plan/simulation/decoder.go +++ b/x/plan/simulation/decoder.go @@ -38,7 +38,7 @@ func NewDecoderStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("%s\n%s", &inacivePlanA, &inactivePlanB) case bytes.Equal(kvA.Key[:1], types.CountForNodeByProviderKeyPrefix): - var countForNodeByProviderA, countForNodeByProviderB protobuf.Int64Value + var countForNodeByProviderA, countForNodeByProviderB protobuf.UInt64Value cdc.MustUnmarshalBinaryBare(kvA.Value, &countForNodeByProviderA) cdc.MustUnmarshalBinaryBare(kvB.Value, &countForNodeByProviderB) return fmt.Sprintf("%s\n%s", &countForNodeByProviderA, &countForNodeByProviderB) diff --git a/x/provider/simulation/genesis.go b/x/provider/simulation/genesis.go index 72688b2c..761f5ee5 100644 --- a/x/provider/simulation/genesis.go +++ b/x/provider/simulation/genesis.go @@ -5,33 +5,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sentinel-official/hub/x/provider/types" ) -func getRandomDeposit(r *rand.Rand) sdk.Coin { - denom := simulation.RandStringOfLength(r, r.Intn(125)+3) - amount := sdk.NewInt(r.Int63n(10<<12)) - - return sdk.NewCoin(denom, amount) -} - -func getRandomProviders(r *rand.Rand) types.Providers { - var providers types.Providers - - for _, acc := range simulation.RandomAccounts(r, r.Intn(20)+4) { - providers = append(providers, types.Provider{ - Address: acc.Address.String(), - Name: simulation.RandStringOfLength(r, r.Intn(60)+4), - Identity: simulation.RandStringOfLength(r, r.Intn(60)+4), - Website: simulation.RandStringOfLength(r, r.Intn(60)+4), - Description: simulation.RandStringOfLength(r, r.Intn(250)+6), - }) - } - - return providers -} - func RandomizedGenesisState(simState *module.SimulationState) *types.GenesisState { var deposit sdk.Coin diff --git a/x/provider/simulation/rand.go b/x/provider/simulation/rand.go new file mode 100644 index 00000000..f4bf7f84 --- /dev/null +++ b/x/provider/simulation/rand.go @@ -0,0 +1,33 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/sentinel-official/hub/x/provider/types" +) + +func getRandomDeposit(r *rand.Rand) sdk.Coin { + denom := simulation.RandStringOfLength(r, r.Intn(125)+3) + amount := sdk.NewInt(r.Int63n(10<<12)) + + return sdk.NewCoin(denom, amount) +} + +func getRandomProviders(r *rand.Rand) types.Providers { + var providers types.Providers + + for _, acc := range simulation.RandomAccounts(r, r.Intn(20)+4) { + providers = append(providers, types.Provider{ + Address: acc.Address.String(), + Name: simulation.RandStringOfLength(r, r.Intn(60)+4), + Identity: simulation.RandStringOfLength(r, r.Intn(60)+4), + Website: simulation.RandStringOfLength(r, r.Intn(60)+4), + Description: simulation.RandStringOfLength(r, r.Intn(250)+6), + }) + } + + return providers +} + diff --git a/x/session/simulation/decoder.go b/x/session/simulation/decoder.go index 12165099..f28b69e8 100644 --- a/x/session/simulation/decoder.go +++ b/x/session/simulation/decoder.go @@ -26,10 +26,10 @@ func NewDecoderStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("%s\n%s", &sessionA, &sessionB) case bytes.Equal(kvA.Key[:1], types.SessionForSubscriptionKeyPrefix): - var sessionA, sessionB types.Session - cdc.MustUnmarshalBinaryBare(kvA.Value, &sessionA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &sessionB) - return fmt.Sprintf("%s\n%s", &sessionA, &sessionB) + var valueA, valueB protobuf.BoolValue + cdc.MustUnmarshalBinaryBare(kvA.Value, &valueA) + cdc.MustUnmarshalBinaryBare(kvB.Value, &valueB) + return fmt.Sprintf("%s\n%s", &valueA, &valueB) case bytes.Equal(kvA.Key[:1], types.SessionForNodeKeyPrefix): var sessionForNodeA, sessionForNodeB protobuf.BoolValue diff --git a/x/session/simulation/genesis.go b/x/session/simulation/genesis.go index 95cd64fa..745c76e4 100644 --- a/x/session/simulation/genesis.go +++ b/x/session/simulation/genesis.go @@ -5,21 +5,10 @@ import ( "math/rand" "time" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - sdksimulation "github.com/cosmos/cosmos-sdk/types/simulation" - hubtypes "github.com/sentinel-official/hub/types" "github.com/sentinel-official/hub/x/session/types" ) -func getRandomInactiveDuration(r *rand.Rand) time.Duration { - return time.Duration(sdksimulation.RandIntBetween(r, 60, 60<<13)) -} - -func getRandomProofVerificationEnabled(r *rand.Rand) bool { - return rand.Int31n(2) == int32(0) -} - func RandomizedGenState(simState *module.SimulationState) *types.GenesisState { var ( @@ -47,22 +36,3 @@ func RandomizedGenState(simState *module.SimulationState) *types.GenesisState { fmt.Printf("selected randomly generated sessions parameters: %s\n", bz) return state } - -func getRandomSessions(r *rand.Rand) types.Sessions { - sessions := make(types.Sessions, r.Int31n(28)+4) - - for range sessions { - sessions = append(sessions, types.Session{ - Id: rand.Uint64(), - Subscription: 0, - Node: hubtypes.NodeAddress("node-address").String(), - Address: sdk.AccAddress("address").String(), - Duration: time.Duration(r.Int31n(1800)+1800), - Bandwidth: hubtypes.NewBandwidthFromInt64(int64(1024<<20 * r.Intn(10)), int64(1024<<20 * r.Intn(10))), - Status: hubtypes.Status(r.Int31n(3)), - StatusAt: sdksimulation.RandTimestamp(r), - }) - } - - return sessions -} diff --git a/x/session/simulation/rand.go b/x/session/simulation/rand.go new file mode 100644 index 00000000..b96191a1 --- /dev/null +++ b/x/session/simulation/rand.go @@ -0,0 +1,38 @@ +package simulation + +import ( + "math/rand" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdksimulation "github.com/cosmos/cosmos-sdk/types/simulation" + hubtypes "github.com/sentinel-official/hub/types" + "github.com/sentinel-official/hub/x/session/types" +) + +func getRandomSessions(r *rand.Rand) types.Sessions { + sessions := make(types.Sessions, r.Int31n(28)+4) + + for range sessions { + sessions = append(sessions, types.Session{ + Id: rand.Uint64(), + Subscription: 0, + Node: hubtypes.NodeAddress("node-address").String(), + Address: sdk.AccAddress("address").String(), + Duration: time.Duration(r.Int31n(1800)+1800), + Bandwidth: hubtypes.NewBandwidthFromInt64(int64(1024<<20 * r.Intn(10)), int64(1024<<20 * r.Intn(10))), + Status: hubtypes.Status(r.Int31n(3)), + StatusAt: sdksimulation.RandTimestamp(r), + }) + } + + return sessions +} + +func getRandomInactiveDuration(r *rand.Rand) time.Duration { + return time.Duration(sdksimulation.RandIntBetween(r, 60, 60<<13)) +} + +func getRandomProofVerificationEnabled(r *rand.Rand) bool { + return rand.Int31n(2) == int32(0) +} diff --git a/x/swap/simulation/genesis.go b/x/swap/simulation/genesis.go index 1050624b..9deeb099 100644 --- a/x/swap/simulation/genesis.go +++ b/x/swap/simulation/genesis.go @@ -7,29 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/sentinel-official/hub/x/swap/types" ) -func GetRandomSwapDenom(r *rand.Rand) string { - // denom length should be between 3-128 - return simulation.RandStringOfLength(r, r.Intn(125)+3) -} - -func GetRandomApproveBy(r *rand.Rand) string { - bz := make([]byte, 20) - _, err := r.Read(bz) - if err != nil { - panic(err) - } - - return sdk.AccAddress(bz).String() -} - -func GetRandomSwapEnabled(r *rand.Rand) bool { - return r.Intn(2) == 1 -} - func RandomizedGenesisState(simState *module.SimulationState) { var ( swapEnabled bool diff --git a/x/swap/simulation/rand.go b/x/swap/simulation/rand.go new file mode 100644 index 00000000..06535ea4 --- /dev/null +++ b/x/swap/simulation/rand.go @@ -0,0 +1,28 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/simulation" +) + +func GetRandomSwapDenom(r *rand.Rand) string { + // denom length should be between 3-128 + return simulation.RandStringOfLength(r, r.Intn(125)+3) +} + +func GetRandomApproveBy(r *rand.Rand) string { + bz := make([]byte, 20) + _, err := r.Read(bz) + if err != nil { + panic(err) + } + + return sdk.AccAddress(bz).String() +} + +func GetRandomSwapEnabled(r *rand.Rand) bool { + return r.Intn(2) == 1 +} + diff --git a/x/vpn/simulation/params.go b/x/vpn/simulation/params.go index 91846c37..c3f0a850 100644 --- a/x/vpn/simulation/params.go +++ b/x/vpn/simulation/params.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/simulation" nodesim "github.com/sentinel-official/hub/x/node/simulation" + providersim "github.com/sentinel-official/hub/x/provider/simulation" sessionsim "github.com/sentinel-official/hub/x/session/simulation" subscriptionsim "github.com/sentinel-official/hub/x/subscription/simulation" ) @@ -15,6 +16,7 @@ func RandomizedParams(r *rand.Rand) []simulation.ParamChange { params = append(params, nodesim.ParamChanges(r)...) params = append(params, subscriptionsim.ParamChanges(r)...) params = append(params, sessionsim.ParamChanges(r)...) + params = append(params, providersim.ParamChanges(r)...) return params }