Restructure contd.
This commit is contained in:
parent
a49f9d6314
commit
cbcd0f0828
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
|
||||||
gaia "github.com/cosmos/cosmos-sdk/cmd/gaia/app"
|
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 (
|
const (
|
||||||
|
@ -26,11 +26,11 @@ func TestFullGaiaSimulation(t *testing.T) {
|
||||||
require.Equal(t, "GaiaApp", app.Name())
|
require.Equal(t, "GaiaApp", app.Name())
|
||||||
|
|
||||||
// Run randomized simulation
|
// Run randomized simulation
|
||||||
mock.RandomizedTesting(
|
simulation.RandomizedTesting(
|
||||||
t, app.BaseApp,
|
t, app.BaseApp,
|
||||||
[]mock.TestAndRunTx{},
|
[]simulation.TestAndRunTx{},
|
||||||
[]mock.RandSetup{},
|
[]simulation.RandSetup{},
|
||||||
[]mock.Invariant{},
|
[]simulation.Invariant{},
|
||||||
NumKeys,
|
NumKeys,
|
||||||
NumBlocks,
|
NumBlocks,
|
||||||
BlockSize,
|
BlockSize,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package mock
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/mock"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
@ -27,7 +28,7 @@ func RandomizedTestingFromSeed(
|
||||||
invariants []Invariant, numKeys int, numBlocks int, blockSize int,
|
invariants []Invariant, numKeys int, numBlocks int, blockSize int,
|
||||||
) {
|
) {
|
||||||
log := fmt.Sprintf("Starting SingleModuleTest with randomness created with seed %d", int(seed))
|
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))
|
r := rand.New(rand.NewSource(seed))
|
||||||
|
|
||||||
// XXX TODO
|
// XXX TODO
|
|
@ -1,4 +1,4 @@
|
||||||
package mock
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
|
@ -1,38 +1,9 @@
|
||||||
package mock
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
|
||||||
"math/rand"
|
"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
|
// shamelessly copied from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang#31832326
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
@ -1,6 +1,8 @@
|
||||||
package mock
|
package mock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
|
@ -10,6 +12,32 @@ import (
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"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.
|
// CheckBalance checks the balance of an account.
|
||||||
func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins) {
|
func CheckBalance(t *testing.T, app *App, addr sdk.AccAddress, exp sdk.Coins) {
|
||||||
ctxCheck := app.BaseApp.NewContext(true, abci.Header{})
|
ctxCheck := app.BaseApp.NewContext(true, abci.Header{})
|
||||||
|
|
Loading…
Reference in New Issue