Restructure contd.

This commit is contained in:
Christopher Goes 2018-07-17 03:25:15 +02:00
parent a49f9d6314
commit cbcd0f0828
5 changed files with 38 additions and 38 deletions

View File

@ -9,7 +9,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
gaia "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
"github.com/cosmos/cosmos-sdk/x/mock"
"github.com/cosmos/cosmos-sdk/x/mock/simulation"
)
const (
@ -26,11 +26,11 @@ func TestFullGaiaSimulation(t *testing.T) {
require.Equal(t, "GaiaApp", app.Name())
// Run randomized simulation
mock.RandomizedTesting(
simulation.RandomizedTesting(
t, app.BaseApp,
[]mock.TestAndRunTx{},
[]mock.RandSetup{},
[]mock.Invariant{},
[]simulation.TestAndRunTx{},
[]simulation.RandSetup{},
[]simulation.Invariant{},
NumKeys,
NumBlocks,
BlockSize,

View File

@ -1,4 +1,4 @@
package mock
package simulation
import (
"fmt"
@ -7,6 +7,7 @@ import (
"time"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/x/mock"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)
@ -27,7 +28,7 @@ func RandomizedTestingFromSeed(
invariants []Invariant, numKeys int, numBlocks int, blockSize int,
) {
log := fmt.Sprintf("Starting SingleModuleTest with randomness created with seed %d", int(seed))
keys, _ := GeneratePrivKeyAddressPairs(numKeys)
keys, _ := mock.GeneratePrivKeyAddressPairs(numKeys)
r := rand.New(rand.NewSource(seed))
// XXX TODO

View File

@ -1,4 +1,4 @@
package mock
package simulation
import (
"math/rand"

View File

@ -1,38 +1,9 @@
package mock
package simulation
import (
"math/big"
"math/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BigInterval is a representation of the interval [lo, hi), where
// lo and hi are both of type sdk.Int
type BigInterval struct {
lo sdk.Int
hi sdk.Int
}
// RandFromBigInterval chooses an interval uniformly from the provided list of
// BigIntervals, and then chooses an element from an interval uniformly at random.
func RandFromBigInterval(r *rand.Rand, intervals []BigInterval) sdk.Int {
if len(intervals) == 0 {
return sdk.ZeroInt()
}
interval := intervals[r.Intn(len(intervals))]
lo := interval.lo
hi := interval.hi
diff := hi.Sub(lo)
result := sdk.NewIntFromBigInt(new(big.Int).Rand(r, diff.BigInt()))
result = result.Add(lo)
return result
}
// shamelessly copied from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang#31832326
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

View File

@ -1,6 +1,8 @@
package mock
import (
"math/big"
"math/rand"
"testing"
"github.com/cosmos/cosmos-sdk/baseapp"
@ -10,6 +12,32 @@ import (
"github.com/tendermint/tendermint/crypto"
)
// BigInterval is a representation of the interval [lo, hi), where
// lo and hi are both of type sdk.Int
type BigInterval struct {
lo sdk.Int
hi sdk.Int
}
// RandFromBigInterval chooses an interval uniformly from the provided list of
// BigIntervals, and then chooses an element from an interval uniformly at random.
func RandFromBigInterval(r *rand.Rand, intervals []BigInterval) sdk.Int {
if len(intervals) == 0 {
return sdk.ZeroInt()
}
interval := intervals[r.Intn(len(intervals))]
lo := interval.lo
hi := interval.hi
diff := hi.Sub(lo)
result := sdk.NewIntFromBigInt(new(big.Int).Rand(r, diff.BigInt()))
result = result.Add(lo)
return result
}
// CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins) {
ctxCheck := app.BaseApp.NewContext(true, abci.Header{})