Skip to content

Commit

Permalink
Fixed wrong protobuf type reference in simulations
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed May 31, 2021
1 parent 51c643c commit 5cedac1
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 98 deletions.
19 changes: 0 additions & 19 deletions x/node/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
28 changes: 28 additions & 0 deletions x/node/simulation/rand.go
Original file line number Diff line number Diff line change
@@ -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)
}

2 changes: 1 addition & 1 deletion x/plan/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 0 additions & 24 deletions x/provider/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions x/provider/simulation/rand.go
Original file line number Diff line number Diff line change
@@ -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
}

8 changes: 4 additions & 4 deletions x/session/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 0 additions & 30 deletions x/session/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
38 changes: 38 additions & 0 deletions x/session/simulation/rand.go
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 0 additions & 20 deletions x/swap/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions x/swap/simulation/rand.go
Original file line number Diff line number Diff line change
@@ -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
}

2 changes: 2 additions & 0 deletions x/vpn/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}

0 comments on commit 5cedac1

Please sign in to comment.