Event stats
This commit is contained in:
parent
5918ab18fd
commit
c61b1aa591
4
Makefile
4
Makefile
|
@ -114,8 +114,10 @@ test_race:
|
||||||
@go test -race $(PACKAGES_NOCLITEST)
|
@go test -race $(PACKAGES_NOCLITEST)
|
||||||
|
|
||||||
test_sim:
|
test_sim:
|
||||||
|
@echo "Running individual module simulations..."
|
||||||
|
@go test $(PACKAGES_SIMTEST) -v
|
||||||
|
@echo "Running full Gaia simulation..."
|
||||||
@ENABLE_GAIA_SIMULATION=1 go test ./cmd/gaia/app -run TestFullGaiaSimulation -v
|
@ENABLE_GAIA_SIMULATION=1 go test ./cmd/gaia/app -run TestFullGaiaSimulation -v
|
||||||
@go test $(PACKAGES_SIMTEST)
|
|
||||||
|
|
||||||
test_cover:
|
test_cover:
|
||||||
@bash tests/test_cover.sh
|
@bash tests/test_cover.sh
|
||||||
|
|
|
@ -33,6 +33,12 @@ func SimulateFromSeed(
|
||||||
keys, addrs := mock.GeneratePrivKeyAddressPairs(numKeys)
|
keys, addrs := mock.GeneratePrivKeyAddressPairs(numKeys)
|
||||||
r := rand.New(rand.NewSource(seed))
|
r := rand.New(rand.NewSource(seed))
|
||||||
|
|
||||||
|
// Setup event stats
|
||||||
|
events := make(map[string]uint)
|
||||||
|
event := func(what string) {
|
||||||
|
events[what] += 1
|
||||||
|
}
|
||||||
|
|
||||||
app.InitChain(abci.RequestInitChain{AppStateBytes: appStateFn(r, addrs)})
|
app.InitChain(abci.RequestInitChain{AppStateBytes: appStateFn(r, addrs)})
|
||||||
for i := 0; i < len(setups); i++ {
|
for i := 0; i < len(setups); i++ {
|
||||||
setups[i](r, keys)
|
setups[i](r, keys)
|
||||||
|
@ -53,7 +59,7 @@ func SimulateFromSeed(
|
||||||
// TODO: Add modes to simulate "no load", "medium load", and
|
// TODO: Add modes to simulate "no load", "medium load", and
|
||||||
// "high load" blocks.
|
// "high load" blocks.
|
||||||
for j := 0; j < blockSize; j++ {
|
for j := 0; j < blockSize; j++ {
|
||||||
logUpdate, err := ops[r.Intn(len(ops))](t, r, app, ctx, keys, log)
|
logUpdate, err := ops[r.Intn(len(ops))](t, r, app, ctx, keys, log, event)
|
||||||
log += "\n" + logUpdate
|
log += "\n" + logUpdate
|
||||||
|
|
||||||
require.Nil(t, err, log)
|
require.Nil(t, err, log)
|
||||||
|
@ -63,6 +69,8 @@ func SimulateFromSeed(
|
||||||
app.EndBlock(abci.RequestEndBlock{})
|
app.EndBlock(abci.RequestEndBlock{})
|
||||||
header.Height++
|
header.Height++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisplayEvents(events)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssertAllInvariants asserts a list of provided invariants against application state
|
// AssertAllInvariants asserts a list of provided invariants against application state
|
||||||
|
|
|
@ -15,7 +15,7 @@ type (
|
||||||
// about what this fuzzed tx actually did, for ease of debugging.
|
// about what this fuzzed tx actually did, for ease of debugging.
|
||||||
TestAndRunTx func(
|
TestAndRunTx func(
|
||||||
t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context,
|
||||||
privKeys []crypto.PrivKey, log string,
|
privKeys []crypto.PrivKey, log string, event func(string),
|
||||||
) (action string, err sdk.Error)
|
) (action string, err sdk.Error)
|
||||||
|
|
||||||
// RandSetup performs the random setup the mock module needs.
|
// RandSetup performs the random setup the mock module needs.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package simulation
|
package simulation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,3 +30,8 @@ func RandStringOfLength(r *rand.Rand, n int) string {
|
||||||
}
|
}
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DisplayEvents(events map[string]uint) {
|
||||||
|
// TODO
|
||||||
|
fmt.Printf("Events: %v\n", events)
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
|
|
||||||
// SimulateMsgCreateValidator
|
// SimulateMsgCreateValidator
|
||||||
func SimulateMsgCreateValidator(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgCreateValidator(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
denom := k.GetParams(ctx).BondDenom
|
denom := k.GetParams(ctx).BondDenom
|
||||||
description := stake.Description{
|
description := stake.Description{
|
||||||
Moniker: simulation.RandStringOfLength(r, 10),
|
Moniker: simulation.RandStringOfLength(r, 10),
|
||||||
|
@ -47,6 +47,7 @@ func SimulateMsgCreateValidator(m auth.AccountMapper, k stake.Keeper) simulation
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgCreateValidator/%v", result.IsOK()))
|
||||||
// require.True(t, result.IsOK(), "expected OK result but instead got %v", result)
|
// require.True(t, result.IsOK(), "expected OK result but instead got %v", result)
|
||||||
action = fmt.Sprintf("TestMsgCreateValidator: %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgCreateValidator: %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
|
@ -55,7 +56,7 @@ func SimulateMsgCreateValidator(m auth.AccountMapper, k stake.Keeper) simulation
|
||||||
|
|
||||||
// SimulateMsgEditValidator
|
// SimulateMsgEditValidator
|
||||||
func SimulateMsgEditValidator(k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgEditValidator(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
description := stake.Description{
|
description := stake.Description{
|
||||||
Moniker: simulation.RandStringOfLength(r, 10),
|
Moniker: simulation.RandStringOfLength(r, 10),
|
||||||
Identity: simulation.RandStringOfLength(r, 10),
|
Identity: simulation.RandStringOfLength(r, 10),
|
||||||
|
@ -75,6 +76,7 @@ func SimulateMsgEditValidator(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgEditValidator/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgEditValidator: %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgEditValidator: %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
@ -82,7 +84,7 @@ func SimulateMsgEditValidator(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
|
|
||||||
// SimulateMsgDelegate
|
// SimulateMsgDelegate
|
||||||
func SimulateMsgDelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgDelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
denom := k.GetParams(ctx).BondDenom
|
denom := k.GetParams(ctx).BondDenom
|
||||||
validatorKey := keys[r.Intn(len(keys))]
|
validatorKey := keys[r.Intn(len(keys))]
|
||||||
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
||||||
|
@ -106,6 +108,7 @@ func SimulateMsgDelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAn
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgDelegate/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgDelegate: %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgDelegate: %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
@ -113,7 +116,7 @@ func SimulateMsgDelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAn
|
||||||
|
|
||||||
// SimulateMsgBeginUnbonding
|
// SimulateMsgBeginUnbonding
|
||||||
func SimulateMsgBeginUnbonding(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgBeginUnbonding(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
denom := k.GetParams(ctx).BondDenom
|
denom := k.GetParams(ctx).BondDenom
|
||||||
validatorKey := keys[r.Intn(len(keys))]
|
validatorKey := keys[r.Intn(len(keys))]
|
||||||
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
||||||
|
@ -137,6 +140,7 @@ func SimulateMsgBeginUnbonding(m auth.AccountMapper, k stake.Keeper) simulation.
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgBeginUnbonding/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgBeginUnbonding: %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgBeginUnbonding: %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
@ -144,7 +148,7 @@ func SimulateMsgBeginUnbonding(m auth.AccountMapper, k stake.Keeper) simulation.
|
||||||
|
|
||||||
// SimulateMsgCompleteUnbonding
|
// SimulateMsgCompleteUnbonding
|
||||||
func SimulateMsgCompleteUnbonding(k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgCompleteUnbonding(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
validatorKey := keys[r.Intn(len(keys))]
|
validatorKey := keys[r.Intn(len(keys))]
|
||||||
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
validatorAddress := sdk.AccAddress(validatorKey.PubKey().Address())
|
||||||
delegatorKey := keys[r.Intn(len(keys))]
|
delegatorKey := keys[r.Intn(len(keys))]
|
||||||
|
@ -159,6 +163,7 @@ func SimulateMsgCompleteUnbonding(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgCompleteUnbonding/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgCompleteUnbonding with %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgCompleteUnbonding with %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
@ -166,7 +171,7 @@ func SimulateMsgCompleteUnbonding(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
|
|
||||||
// SimulateMsgBeginRedelegate
|
// SimulateMsgBeginRedelegate
|
||||||
func SimulateMsgBeginRedelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgBeginRedelegate(m auth.AccountMapper, k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
denom := k.GetParams(ctx).BondDenom
|
denom := k.GetParams(ctx).BondDenom
|
||||||
sourceValidatorKey := keys[r.Intn(len(keys))]
|
sourceValidatorKey := keys[r.Intn(len(keys))]
|
||||||
sourceValidatorAddress := sdk.AccAddress(sourceValidatorKey.PubKey().Address())
|
sourceValidatorAddress := sdk.AccAddress(sourceValidatorKey.PubKey().Address())
|
||||||
|
@ -194,6 +199,7 @@ func SimulateMsgBeginRedelegate(m auth.AccountMapper, k stake.Keeper) simulation
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgBeginRedelegate/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgBeginRedelegate: %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgBeginRedelegate: %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
@ -201,7 +207,7 @@ func SimulateMsgBeginRedelegate(m auth.AccountMapper, k stake.Keeper) simulation
|
||||||
|
|
||||||
// SimulateMsgCompleteRedelegate
|
// SimulateMsgCompleteRedelegate
|
||||||
func SimulateMsgCompleteRedelegate(k stake.Keeper) simulation.TestAndRunTx {
|
func SimulateMsgCompleteRedelegate(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string) (action string, err sdk.Error) {
|
return func(t *testing.T, r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, keys []crypto.PrivKey, log string, event func(string)) (action string, err sdk.Error) {
|
||||||
validatorSrcKey := keys[r.Intn(len(keys))]
|
validatorSrcKey := keys[r.Intn(len(keys))]
|
||||||
validatorSrcAddress := sdk.AccAddress(validatorSrcKey.PubKey().Address())
|
validatorSrcAddress := sdk.AccAddress(validatorSrcKey.PubKey().Address())
|
||||||
validatorDstKey := keys[r.Intn(len(keys))]
|
validatorDstKey := keys[r.Intn(len(keys))]
|
||||||
|
@ -219,6 +225,7 @@ func SimulateMsgCompleteRedelegate(k stake.Keeper) simulation.TestAndRunTx {
|
||||||
if result.IsOK() {
|
if result.IsOK() {
|
||||||
write()
|
write()
|
||||||
}
|
}
|
||||||
|
event(fmt.Sprintf("stake/MsgCompleteRedelegate/%v", result.IsOK()))
|
||||||
action = fmt.Sprintf("TestMsgCompleteRedelegate with %s", msg.GetSignBytes())
|
action = fmt.Sprintf("TestMsgCompleteRedelegate with %s", msg.GetSignBytes())
|
||||||
return action, nil
|
return action, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue