Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Updates for upstream PR (community pool spend proposal) #10

Merged
merged 16 commits into from
May 21, 2019
1 change: 1 addition & 0 deletions .pending/features/gaiad/Update-Gaia-for-comm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Gaia for community pool spend proposals per Cosmos Hub governance proposal #7 "Activate the Community Pool"
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
// register the proposal types
govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper))
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper))
app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.paramsKeeper, govSubspace,
app.bankKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter)

Expand Down
1 change: 1 addition & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func testAndRunTxs(app *GaiaApp) []simulation.WeightedOperation {
{50, distrsim.SimulateMsgWithdrawValidatorCommission(app.accountKeeper, app.distrKeeper)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, govsim.SimulateTextProposalContent)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent)},
{5, govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, distrsim.SimulateCommunityPoolSpendProposalContent(app.distrKeeper))},
{100, govsim.SimulateMsgDeposit(app.govKeeper)},
{100, stakingsim.SimulateMsgCreateValidator(app.accountKeeper, app.stakingKeeper)},
{5, stakingsim.SimulateMsgEditValidator(app.stakingKeeper)},
Expand Down
64 changes: 64 additions & 0 deletions cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,70 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
f.Cleanup()
}

func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

proc := f.GDStart()
defer proc.Stop(false)

fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))

// write proposal to file
proposalTokens := sdk.TokensFromTendermintPower(5)
proposal := fmt.Sprintf(`{
"title": "Community Pool Spend",
"description": "Spend from community pool",
"recipient": "%s",
"amount": [
{
"denom": "stake",
"amount": "%s"
}
],
"deposit": [
{
"denom": "stake",
"amount": "%s"
}
]
}
`, fooAddr, proposalTokens.String(), proposalTokens.String())

proposalFile := WriteToNewTempFile(t, proposal)

// create the param change proposal
f.TxGovSubmitCommunityPoolSpendProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)

// ensure transaction tags can be queried
txsPage := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("sender:%s", fooAddr))
require.Len(t, txsPage.Txs, 1)

// ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens).String(), fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom).String())

// ensure proposal is directly queryable
proposal1 := f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status)

// ensure correct query proposals result
proposalsQuery := f.QueryGovProposals()
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)

// ensure the correct deposit amount on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))

// Cleanup testing directories
f.Cleanup()
}

func TestGaiaCLIQueryTxPagination(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
Expand Down
14 changes: 14 additions & 0 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@ func (f *Fixtures) TxGovSubmitParamChangeProposal(
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
}

// TxGovSubmitCommunityPoolSpendProposal executes a CLI community pool spend proposal
// submission.
func (f *Fixtures) TxGovSubmitCommunityPoolSpendProposal(
from, proposalPath string, deposit sdk.Coin, flags ...string,
) (bool, string, string) {

cmd := fmt.Sprintf(
"%s tx gov submit-proposal community-pool-spend %s --from=%s %v",
f.GaiacliBinary, proposalPath, from, f.Flags(),
)

return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
}

//___________________________________________________________________________________
// gaiacli query account

Expand Down
5 changes: 3 additions & 2 deletions cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
mintclient "github.com/cosmos/cosmos-sdk/x/mint/client"
mintrest "github.com/cosmos/cosmos-sdk/x/mint/client/rest"
distrcli "github.com/cosmos/cosmos-sdk/x/params/client/cli"
cwgoes marked this conversation as resolved.
Show resolved Hide resolved
paramcli "github.com/cosmos/cosmos-sdk/x/params/client/cli"
paramsrest "github.com/cosmos/cosmos-sdk/x/params/client/rest"
sl "github.com/cosmos/cosmos-sdk/x/slashing"
Expand Down Expand Up @@ -70,7 +71,7 @@ func main() {
// Module clients hold cli commnads (tx,query) and lcd routes
// TODO: Make the lcd command take a list of ModuleClient
mc := []sdk.ModuleClient{
govClient.NewModuleClient(gv.StoreKey, cdc, paramcli.GetCmdSubmitProposal(cdc)),
govClient.NewModuleClient(gv.StoreKey, cdc, paramcli.GetCmdSubmitProposal(cdc), distrcli.GetCmdSubmitProposal(cdc)),
distClient.NewModuleClient(distcmd.StoreKey, cdc),
stakingclient.NewModuleClient(st.StoreKey, cdc),
mintclient.NewModuleClient(mint.StoreKey, cdc),
Expand Down Expand Up @@ -175,7 +176,7 @@ func registerRoutes(rs *lcd.RestServer) {
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
staking.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc), dist.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/btcsuite/btcd v0.0.0-20190427004231-96897255fd17 // indirect
github.com/cosmos/cosmos-sdk v0.28.2-0.20190520151953-4b872d2eb4bb
github.com/cosmos/cosmos-sdk v0.28.2-0.20190521100210-dd89c329516e
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/google/gofuzz v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cosmos/cosmos-sdk v0.28.2-0.20190520151953-4b872d2eb4bb h1:njT3ur+sTKBaNvQOaWVvFr1mqczrqB3gaLd2BTCgXlQ=
github.com/cosmos/cosmos-sdk v0.28.2-0.20190520151953-4b872d2eb4bb/go.mod h1:asKfALbDgAL4BGwQdoYwEyfRIPHL20mA2Esan1ELVB4=
github.com/cosmos/cosmos-sdk v0.28.2-0.20190521100210-dd89c329516e h1:sey/szRUq+qpsaWP3TxNzT8MmFMQT/6QFhqD6xeLF9o=
github.com/cosmos/cosmos-sdk v0.28.2-0.20190521100210-dd89c329516e/go.mod h1:asKfALbDgAL4BGwQdoYwEyfRIPHL20mA2Esan1ELVB4=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 h1:Iwin12wRQtyZhH6FV3ykFcdGNlYEzoeR0jN8Vn+JWsI=
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
Expand Down
48 changes: 47 additions & 1 deletion lcd_test/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
accs = append(accs, acc)
}

// distr data
distrDataBz := genesisState[distr.ModuleName]
var distrData distr.GenesisState
cdc.MustUnmarshalJSON(distrDataBz, &distrData)
distrData.FeePool.CommunityPool = sdk.DecCoins{sdk.DecCoin{"test", sdk.NewDecFromInt(sdk.NewInt(10))}}
distrDataBz = cdc.MustMarshalJSON(distrData)
genesisState[distr.ModuleName] = distrDataBz

// now add the account tokens to the non-bonded pool
for _, acc := range accs {
accTokens := acc.Coins.AmountOf(sdk.DefaultBondDenom)
Expand Down Expand Up @@ -438,7 +446,7 @@ func registerRoutes(rs *lcd.RestServer) {
distrrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distr.StoreKey)
stakingrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashingrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
govrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
govrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc), distrrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
}

Expand Down Expand Up @@ -1221,6 +1229,44 @@ func doSubmitParamChangeProposal(
return txResp
}

func doSubmitCommunityPoolSpendProposal(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
amount sdk.Int, fees sdk.Coins,
) sdk.TxResponse {

acc := getAccount(t, port, proposerAddr)
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
from := acc.GetAddress().String()

baseReq := rest.NewBaseReq(from, "", chainID, "", "", accnum, sequence, fees, nil, false)
pr := distrrest.CommunityPoolSpendProposalReq{
BaseReq: baseReq,
Title: "Test",
Description: "test",
Proposer: proposerAddr,
Recipient: proposerAddr,
Deposit: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, amount)},
Amount: sdk.Coins{sdk.NewCoin("test", sdk.NewInt(5))},
}

req, err := cdc.MarshalJSON(pr)
require.NoError(t, err)

resp, body := Request(t, port, "POST", "/gov/proposals/community_pool_spend", req)
require.Equal(t, http.StatusOK, resp.StatusCode, body)

resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
require.Equal(t, http.StatusOK, resp.StatusCode, body)

var txResp sdk.TxResponse
err = cdc.UnmarshalJSON([]byte(body), &txResp)
require.NoError(t, err)

return txResp
}

// GET /gov/proposals Query proposals
func getProposalsAll(t *testing.T, port string) []gov.Proposal {
res, body := Request(t, port, "GET", "/gov/proposals", nil)
Expand Down
37 changes: 37 additions & 0 deletions lcd_test/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,43 @@ func TestSubmitProposal(t *testing.T) {
require.Equal(t, proposalID, proposer.ProposalID)
}

func TestSubmitCommunityPoolSpendProposal(t *testing.T) {
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
require.NoError(t, err)
addr, seed := CreateAddr(t, name1, pw, kb)
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, true)
defer cleanup()

acc := getAccount(t, port, addr)
initialBalance := acc.GetCoins()

// create proposal tx
proposalTokens := sdk.TokensFromTendermintPower(5)
resultTx := doSubmitCommunityPoolSpendProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was committed
require.Equal(t, uint32(0), resultTx.Code)

var proposalID uint64
bz, err := hex.DecodeString(resultTx.Data)
require.NoError(t, err)
cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID)

// verify balance
acc = getAccount(t, port, addr)
expectedBalance := initialBalance[0].Sub(fees[0])
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom))

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.GetTitle())

proposer := getProposer(t, port, proposalID)
require.Equal(t, addr.String(), proposer.Proposer)
require.Equal(t, proposalID, proposer.ProposalID)
}

func TestSubmitParamChangeProposal(t *testing.T) {
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
require.NoError(t, err)
Expand Down