diff --git a/Gopkg.lock b/Gopkg.lock index dcc57cab3..37a32820c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -13,51 +13,6 @@ packages = ["btcec"] revision = "1432d294a5b055c297457c25434efbf13384cc46" -[[projects]] - name = "github.com/cosmos/cosmos-sdk" - packages = [ - "baseapp", - "client", - "client/context", - "client/keys", - "client/lcd", - "client/rpc", - "client/tx", - "cmd/gaia/app", - "examples/basecoin/app", - "examples/basecoin/types", - "examples/democoin/app", - "examples/democoin/types", - "examples/democoin/x/cool", - "examples/democoin/x/cool/client/cli", - "examples/democoin/x/pow", - "examples/democoin/x/pow/client/cli", - "examples/democoin/x/simplestake", - "examples/democoin/x/simplestake/client/cli", - "examples/democoin/x/sketchy", - "mock", - "server", - "store", - "tests", - "types", - "version", - "wire", - "x/auth", - "x/auth/client/cli", - "x/auth/client/rest", - "x/bank", - "x/bank/client", - "x/bank/client/cli", - "x/bank/client/rest", - "x/ibc", - "x/ibc/client/cli", - "x/ibc/client/rest", - "x/stake", - "x/stake/client/cli" - ] - revision = "187be1a5df81de1fd71da9053102d3a4868ec979" - version = "v0.17.2" - [[projects]] name = "github.com/davecgh/go-spew" packages = ["spew"] @@ -502,6 +457,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "9b6ee069da61cf1815c332c5624e8af99b51ea72e2e9b91d780db92299598dcc" + inputs-digest = "7540d2ecdb5d7d5084ab4e6132e929bbd501bd6add3006d8f08a6b2c127e0c7d" solver-name = "gps-cdcl" solver-version = 1 diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 7d1dab676..5108279ac 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -36,16 +36,18 @@ import ( gapp "github.com/cosmos/cosmos-sdk/cmd/gaia/app" tests "github.com/cosmos/cosmos-sdk/tests" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/wire" + "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/stake" ) var ( - coinDenom = "mycoin" + coinDenom = "steak" coinAmount = int64(10000000) stakeDenom = "steak" - candidateAddr1 = "" - candidateAddr2 = "" + validatorAddr1 = "" + validatorAddr2 = "" // XXX bad globals name = "test" @@ -222,6 +224,7 @@ func TestValidators(t *testing.T) { func TestCoinSend(t *testing.T) { // query empty + //res, body := request(t, port, "GET", "/accounts/8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6", nil) res, body := request(t, port, "GET", "/accounts/8FA6AB57AD6870F6B5B2E57735F38F2F30E73CB6", nil) require.Equal(t, http.StatusNoContent, res.StatusCode, body) @@ -327,7 +330,7 @@ func TestBond(t *testing.T) { assert.Equal(t, int64(9999900), coins.AmountOf(stakeDenom)) // query candidate - bond := getDelegation(t, sendAddr, candidateAddr1) + bond := getDelegation(t, sendAddr, validatorAddr1) assert.Equal(t, "100/1", bond.Shares.String()) } @@ -347,7 +350,7 @@ func TestUnbond(t *testing.T) { assert.Equal(t, int64(9999911), coins.AmountOf(stakeDenom)) // query candidate - bond := getDelegation(t, sendAddr, candidateAddr1) + bond := getDelegation(t, sendAddr, validatorAddr1) assert.Equal(t, "99/1", bond.Shares.String()) } @@ -366,14 +369,6 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) { if err != nil { return nil, nil, err } - var info cryptoKeys.Info - info, seed, err = kb.Create(name, password, cryptoKeys.AlgoEd25519) // XXX global seed - if err != nil { - return nil, nil, err - } - - pubKey := info.PubKey - sendAddr = pubKey.Address().String() // XXX global config := GetConfig() config.Consensus.TimeoutCommit = 1000 @@ -400,59 +395,46 @@ func startTMAndLCD() (*nm.Node, net.Listener, error) { Name: "val", }, ) - candidateAddr1 = hex.EncodeToString(genDoc.Validators[0].PubKey.Address()) - candidateAddr2 = hex.EncodeToString(genDoc.Validators[1].PubKey.Address()) - coins := sdk.Coins{ - {coinDenom, coinAmount}, - {stakeDenom, coinAmount}, - } - appState := gapp.GenesisState{ - Accounts: []gapp.GenesisAccount{ - { - Address: pubKey.Address(), - Coins: coins, - }, - }, - StakeData: stake.GenesisState{ - Pool: stake.Pool{ - BondedShares: sdk.NewRat(200, 1), - UnbondedShares: sdk.ZeroRat(), - Inflation: sdk.NewRat(7, 100), - PrevBondedShares: sdk.ZeroRat(), - }, - Params: stake.Params{ - InflationRateChange: sdk.NewRat(13, 100), - InflationMax: sdk.NewRat(1, 5), - InflationMin: sdk.NewRat(7, 100), - GoalBonded: sdk.NewRat(67, 100), - MaxValidators: 100, - BondDenom: stakeDenom, - }, - Validators: []stake.Validator{ - { - Owner: genDoc.Validators[0].PubKey.Address(), - PubKey: genDoc.Validators[0].PubKey, - Description: stake.Description{ - Moniker: "validator1", - }, - }, - { - Owner: genDoc.Validators[1].PubKey.Address(), - PubKey: genDoc.Validators[1].PubKey, - Description: stake.Description{ - Moniker: "validator2", - }, - }, - }, - }, - } + pk1 := genDoc.Validators[0].PubKey + pk2 := genDoc.Validators[1].PubKey + validatorAddr1 = hex.EncodeToString(pk1.Address()) + validatorAddr2 = hex.EncodeToString(pk2.Address()) - stateBytes, err := cdc.MarshalJSONIndent(appState, "", " ") + // NOTE it's bad practice to reuse pk address for the owner address but doing in the + // test for simplicity + var appGenTxs [2]json.RawMessage + appGenTxs[0], _, _, err = gapp.GaiaAppGenTxNF(cdc, pk1, pk1.Address(), "test_val1", true) if err != nil { return nil, nil, err } - genDoc.AppStateJSON = stateBytes + appGenTxs[1], _, _, err = gapp.GaiaAppGenTxNF(cdc, pk2, pk2.Address(), "test_val2", true) + if err != nil { + return nil, nil, err + } + + genesisState, err := gapp.GaiaAppGenState(cdc, appGenTxs[:]) + if err != nil { + return nil, nil, err + } + + // add the sendAddr to genesis + var info cryptoKeys.Info + info, seed, err = kb.Create(name, password, cryptoKeys.AlgoEd25519) // XXX global seed + if err != nil { + return nil, nil, err + } + sendAddr = info.PubKey.Address().String() // XXX global + accAuth := auth.NewBaseAccountWithAddress(info.PubKey.Address()) + accAuth.Coins = sdk.Coins{{"steak", 100}} + acc := gapp.NewGenesisAccount(&accAuth) + genesisState.Accounts = append(genesisState.Accounts, acc) + + appState, err := wire.MarshalJSONIndent(cdc, genesisState) + if err != nil { + return nil, nil, err + } + genDoc.AppStateJSON = appState // LCD listen address port = fmt.Sprintf("%d", 17377) // XXX @@ -609,7 +591,7 @@ func doBond(t *testing.T, port, seed string) (resultTx ctypes.ResultBroadcastTxC } ], "unbond": [] - }`, name, password, sequence, candidateAddr1, stakeDenom)) + }`, name, password, sequence, validatorAddr1, stakeDenom)) res, body := request(t, port, "POST", "/stake/bondunbond", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -637,7 +619,7 @@ func doUnbond(t *testing.T, port, seed string) (resultTx ctypes.ResultBroadcastT "shares": "1" } ] - }`, name, password, sequence, candidateAddr1)) + }`, name, password, sequence, validatorAddr1)) res, body := request(t, port, "POST", "/stake/bondunbond", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -674,7 +656,7 @@ func doMultiBond(t *testing.T, port, seed string) (resultTx ctypes.ResultBroadca "shares": "1" } ] - }`, name, password, sequence, candidateAddr1, stakeDenom, candidateAddr2, stakeDenom, candidateAddr1)) + }`, name, password, sequence, validatorAddr1, stakeDenom, validatorAddr2, stakeDenom, validatorAddr1)) res, body := request(t, port, "POST", "/stake/bondunbond", jsonStr) require.Equal(t, http.StatusOK, res.StatusCode, body) diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 525fe8ab0..64db33543 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -74,7 +74,7 @@ func GaiaAppInit() server.AppInit { FlagsAppGenState: fsAppGenState, FlagsAppGenTx: fsAppGenTx, AppGenTx: GaiaAppGenTx, - AppGenState: GaiaAppGenState, + AppGenState: GaiaAppGenStateJSON, } } @@ -85,19 +85,31 @@ type GaiaGenTx struct { PubKey crypto.PubKey `json:"pub_key"` } -// Generate a gaia genesis transaction +// Generate a gaia genesis transaction with flags func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { - - var addr sdk.Address - var secret string clientRoot := viper.GetString(flagClientHome) overwrite := viper.GetBool(flagOWK) name := viper.GetString(flagName) + var addr sdk.Address + var secret string addr, secret, err = server.GenerateSaveCoinKey(clientRoot, name, "1234567890", overwrite) if err != nil { return } + mm := map[string]string{"secret": secret} + var bz []byte + bz, err = cdc.MarshalJSON(mm) + if err != nil { + return + } + cliPrint = json.RawMessage(bz) + return GaiaAppGenTxNF(cdc, pk, addr, name, overwrite) +} + +// Generate a gaia genesis transaction without flags +func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.Address, name string, overwrite bool) ( + appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { var bz []byte gaiaGenTx := GaiaGenTx{ @@ -111,13 +123,6 @@ func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey) ( } appGenTx = json.RawMessage(bz) - mm := map[string]string{"secret": secret} - bz, err = cdc.MarshalJSON(mm) - if err != nil { - return - } - cliPrint = json.RawMessage(bz) - validator = tmtypes.GenesisValidator{ PubKey: pk, Power: freeFermionVal, @@ -127,7 +132,7 @@ func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey) ( // Create the core parameters for genesis initialization for gaia // note that the pubkey input is this machines pubkey -func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { +func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState GenesisState, err error) { if len(appGenTxs) == 0 { err = errors.New("must provide at least genesis transaction") @@ -171,10 +176,21 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState jso } // create the final app state - genesisState := GenesisState{ + genesisState = GenesisState{ Accounts: genaccs, StakeData: stakeData, } + return +} + +// GaiaAppGenState but with JSON +func GaiaAppGenStateJSON(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { + + // create the final app state + genesisState, err := GaiaAppGenState(cdc, appGenTxs) + if err != nil { + return nil, err + } appState, err = wire.MarshalJSONIndent(cdc, genesisState) return } diff --git a/x/stake/genesis.go b/x/stake/genesis.go index d45adc3d7..be8d0dbe4 100644 --- a/x/stake/genesis.go +++ b/x/stake/genesis.go @@ -22,8 +22,8 @@ func NewGenesisState(pool Pool, params Params, validators []Validator, bonds []D // get raw genesis raw message for testing func DefaultGenesisState() GenesisState { return GenesisState{ - Pool: initialPool(), - Params: defaultParams(), + Pool: InitialPool(), + Params: DefaultParams(), } } diff --git a/x/stake/keeper_test.go b/x/stake/keeper_test.go index f28a2cf68..01d4434e8 100644 --- a/x/stake/keeper_test.go +++ b/x/stake/keeper_test.go @@ -586,7 +586,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) { func TestGetTendermintUpdatesNotValidatorCliff(t *testing.T) { ctx, _, keeper := createTestInput(t, false, 0) - params := defaultParams() + params := DefaultParams() params.MaxValidators = 2 keeper.setParams(ctx, params) @@ -721,7 +721,7 @@ func TestBond(t *testing.T) { func TestParams(t *testing.T) { ctx, _, keeper := createTestInput(t, false, 0) - expParams := defaultParams() + expParams := DefaultParams() //check that the empty keeper loads the default resParams := keeper.GetParams(ctx) @@ -736,7 +736,7 @@ func TestParams(t *testing.T) { func TestPool(t *testing.T) { ctx, _, keeper := createTestInput(t, false, 0) - expPool := initialPool() + expPool := InitialPool() //check that the empty keeper loads the default resPool := keeper.GetPool(ctx) diff --git a/x/stake/params.go b/x/stake/params.go index 32b8c0ae8..ace39935c 100644 --- a/x/stake/params.go +++ b/x/stake/params.go @@ -23,7 +23,8 @@ func (p Params) equal(p2 Params) bool { return bytes.Equal(bz1, bz2) } -func defaultParams() Params { +// default params +func DefaultParams() Params { return Params{ InflationRateChange: sdk.NewRat(13, 100), InflationMax: sdk.NewRat(20, 100), diff --git a/x/stake/pool.go b/x/stake/pool.go index e2547b050..0b320432e 100644 --- a/x/stake/pool.go +++ b/x/stake/pool.go @@ -31,7 +31,7 @@ func (p Pool) equal(p2 Pool) bool { } // initial pool for testing -func initialPool() Pool { +func InitialPool() Pool { return Pool{ LooseUnbondedTokens: 0, BondedTokens: 0, diff --git a/x/stake/test_common.go b/x/stake/test_common.go index 2dac36069..a0aca4a57 100644 --- a/x/stake/test_common.go +++ b/x/stake/test_common.go @@ -111,8 +111,8 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context ) ck := bank.NewKeeper(accountMapper) keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace) - keeper.setPool(ctx, initialPool()) - keeper.setNewParams(ctx, defaultParams()) + keeper.setPool(ctx, InitialPool()) + keeper.setNewParams(ctx, DefaultParams()) // fill all the addresses with some coins for _, addr := range addrs { diff --git a/x/stake/tick_test.go b/x/stake/tick_test.go index 4f0f6dc06..438b678f1 100644 --- a/x/stake/tick_test.go +++ b/x/stake/tick_test.go @@ -61,7 +61,7 @@ func TestGetInflation(t *testing.T) { func TestProcessProvisions(t *testing.T) { ctx, _, keeper := createTestInput(t, false, 0) - params := defaultParams() + params := DefaultParams() params.MaxValidators = 2 keeper.setParams(ctx, params) pool := keeper.GetPool(ctx) diff --git a/x/stake/validator_test.go b/x/stake/validator_test.go index 1ca5ba2f7..db6ab6f4c 100644 --- a/x/stake/validator_test.go +++ b/x/stake/validator_test.go @@ -169,7 +169,7 @@ func randomValidator(r *rand.Rand) Validator { // generate a random staking state func randomSetup(r *rand.Rand, numValidators int) (Pool, Validators) { - pool := initialPool() + pool := InitialPool() validators := make([]Validator, numValidators) for i := 0; i < numValidators; i++ {