Implement NewTestGaiaAppGenState and update LCD test bonding
This commit is contained in:
parent
9f67e8af20
commit
2527e1fa3b
|
@ -518,9 +518,12 @@ func TestBonding(t *testing.T) {
|
||||||
name, password, denom := "test", "1234567890", "steak"
|
name, password, denom := "test", "1234567890", "steak"
|
||||||
addr, seed := CreateAddr(t, name, password, GetKeyBase(t))
|
addr, seed := CreateAddr(t, name, password, GetKeyBase(t))
|
||||||
|
|
||||||
cleanup, _, operAddrs, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
cleanup, valPubKeys, operAddrs, port := InitializeTestLCD(t, 2, []sdk.AccAddress{addr})
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
|
require.Equal(t, 2, len(valPubKeys))
|
||||||
|
require.Equal(t, 2, len(operAddrs))
|
||||||
|
|
||||||
amt := sdk.NewDec(60)
|
amt := sdk.NewDec(60)
|
||||||
validator := getValidator(t, port, operAddrs[0])
|
validator := getValidator(t, port, operAddrs[0])
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,6 @@ func GaiaAppGenTxNF(cdc *codec.Codec, pk crypto.PubKey, addr sdk.AccAddress, nam
|
||||||
// Create the core parameters for genesis initialization for gaia
|
// Create the core parameters for genesis initialization for gaia
|
||||||
// note that the pubkey input is this machines pubkey
|
// note that the pubkey input is this machines pubkey
|
||||||
func GaiaAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (genesisState GenesisState, err error) {
|
func GaiaAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (genesisState GenesisState, err error) {
|
||||||
|
|
||||||
if len(appGenTxs) == 0 {
|
if len(appGenTxs) == 0 {
|
||||||
err = errors.New("must provide at least genesis transaction")
|
err = errors.New("must provide at least genesis transaction")
|
||||||
return
|
return
|
||||||
|
@ -196,6 +195,7 @@ func GaiaAppGenState(cdc *codec.Codec, appGenTxs []json.RawMessage) (genesisStat
|
||||||
StakeData: stakeData,
|
StakeData: stakeData,
|
||||||
GovData: gov.DefaultGenesisState(),
|
GovData: gov.DefaultGenesisState(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewTestGaiaAppGenState creates the core parameters for a test genesis
|
||||||
|
// initialization given a set of genesis txs, TM validators and their respective
|
||||||
|
// operating addresses.
|
||||||
|
func NewTestGaiaAppGenState(
|
||||||
|
cdc *codec.Codec, appGenTxs []json.RawMessage, tmVals []tmtypes.GenesisValidator, valOperAddrs []sdk.ValAddress,
|
||||||
|
) (GenesisState, error) {
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case len(appGenTxs) == 0:
|
||||||
|
return GenesisState{}, errors.New("must provide at least genesis transaction")
|
||||||
|
case len(tmVals) != len(valOperAddrs):
|
||||||
|
return GenesisState{}, errors.New("number of TM validators does not match number of operator addresses")
|
||||||
|
}
|
||||||
|
|
||||||
|
// start with the default staking genesis state
|
||||||
|
stakeData := stake.DefaultGenesisState()
|
||||||
|
|
||||||
|
// get genesis account information
|
||||||
|
genAccs := make([]GenesisAccount, len(appGenTxs))
|
||||||
|
for i, appGenTx := range appGenTxs {
|
||||||
|
|
||||||
|
var genTx GaiaGenTx
|
||||||
|
if err := cdc.UnmarshalJSON(appGenTx, &genTx); err != nil {
|
||||||
|
return GenesisState{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the genesis account for the given genesis tx
|
||||||
|
genAccs[i] = genesisAccountFromGenTx(genTx)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tmVal := range tmVals {
|
||||||
|
var issuedDelShares sdk.Dec
|
||||||
|
|
||||||
|
// increase total supply by validator's power
|
||||||
|
power := sdk.NewInt(tmVal.Power)
|
||||||
|
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(power))
|
||||||
|
|
||||||
|
// add the validator
|
||||||
|
desc := stake.NewDescription(tmVal.Name, "", "", "")
|
||||||
|
validator := stake.NewValidator(sdk.ValAddress(valOperAddrs[i]), tmVal.PubKey, desc)
|
||||||
|
|
||||||
|
validator, stakeData.Pool, issuedDelShares = validator.AddTokensFromDel(stakeData.Pool, power)
|
||||||
|
stakeData.Validators = append(stakeData.Validators, validator)
|
||||||
|
|
||||||
|
// create the self-delegation from the issuedDelShares
|
||||||
|
selfDel := stake.Delegation{
|
||||||
|
DelegatorAddr: sdk.AccAddress(validator.OperatorAddr),
|
||||||
|
ValidatorAddr: validator.OperatorAddr,
|
||||||
|
Shares: issuedDelShares,
|
||||||
|
Height: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
stakeData.Bonds = append(stakeData.Bonds, selfDel)
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenesisState{
|
||||||
|
Accounts: genAccs,
|
||||||
|
StakeData: stakeData,
|
||||||
|
GovData: gov.DefaultGenesisState(),
|
||||||
|
}, nil
|
||||||
|
}
|
Loading…
Reference in New Issue