Misc, environment variables

This commit is contained in:
Christopher Goes
2018-07-18 07:37:38 +02:00
parent c61b1aa591
commit 6c61577b0b
6 changed files with 54 additions and 13 deletions
+1
View File
@@ -6,6 +6,7 @@ import (
)
// shamelessly copied from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang#31832326
// TODO we should probably move this to tendermint/libs/common/random.go
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const (
+16
View File
@@ -110,6 +110,22 @@ func (k Keeper) GetUnbondingDelegationsFromValidator(ctx sdk.Context, valAddr sd
return ubds
}
// iterate through all of the unbonding delegations
func (k Keeper) IterateUnbondingDelegations(ctx sdk.Context, fn func(index int64, ubd types.UnbondingDelegation) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, UnbondingDelegationKey)
i := int64(0)
for ; iterator.Valid(); iterator.Next() {
ubd := types.MustUnmarshalUBD(k.cdc, iterator.Key(), iterator.Value())
stop := fn(i, ubd)
if stop {
break
}
i++
}
iterator.Close()
}
// set the unbonding delegation and associated index
func (k Keeper) SetUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDelegation) {
store := ctx.KVStore(k.storeKey)
+7 -1
View File
@@ -1,6 +1,7 @@
package simulation
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
@@ -30,12 +31,17 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) sim
ctx := app.NewContext(false, abci.Header{})
pool := k.GetPool(ctx)
// Loose tokens should equal coin supply
// Loose tokens should equal coin supply plus unbonding delegations
loose := sdk.ZeroInt()
am.IterateAccounts(ctx, func(acc auth.Account) bool {
loose = loose.Add(acc.GetCoins().AmountOf("steak"))
return false
})
k.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) bool {
fmt.Printf("found ubd with balance: %v\n", ubd.Balance)
loose = loose.Add(ubd.Balance.Amount)
return false
})
require.True(t, pool.LooseTokens.RoundInt64() == loose.Int64(), "expected loose tokens to equal total steak held by accounts - pool.LooseTokens: %v, sum of account tokens: %v\nlog: %s",
pool.LooseTokens, loose, log)
// stats["stake/invariant/looseTokens"] += 1
+2 -3
View File
@@ -46,8 +46,7 @@ func TestStakeWithRandomMessages(t *testing.T) {
SimulateMsgCreateValidator(mapper, stakeKeeper),
SimulateMsgEditValidator(stakeKeeper),
SimulateMsgDelegate(mapper, stakeKeeper),
// XXX TODO
// SimulateMsgBeginUnbonding(mapper, stakeKeeper),
SimulateMsgBeginUnbonding(mapper, stakeKeeper),
SimulateMsgCompleteUnbonding(stakeKeeper),
SimulateMsgBeginRedelegate(mapper, stakeKeeper),
SimulateMsgCompleteRedelegate(stakeKeeper),
@@ -55,6 +54,6 @@ func TestStakeWithRandomMessages(t *testing.T) {
SimulationSetup(mapp, stakeKeeper),
}, []simulation.Invariant{
AllInvariants(coinKeeper, stakeKeeper, mapp.AccountMapper),
}, 10, 100, 500,
}, 10, 100, 100,
)
}