Skip to content

Commit

Permalink
Merge PR CosmWasm#247: Update SDK Commit & Update CLI Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Jan 7, 2020
1 parent 434f425 commit 87a4269
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 90 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type GaiaApp struct {
// NewGaiaApp returns a reference to an initialized GaiaApp.
func NewGaiaApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool,
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp),
invCheckPeriod uint, skipUpgradeHeights map[int64]bool, baseAppOptions ...func(*bam.BaseApp),
) *GaiaApp {

cdc := MakeCodec()
Expand Down Expand Up @@ -190,7 +190,7 @@ func NewGaiaApp(
app.crisisKeeper = crisis.NewKeeper(
app.subspaces[crisis.ModuleName], invCheckPeriod, app.supplyKeeper, auth.FeeCollectorName,
)
app.upgradeKeeper = upgrade.NewKeeper(keys[upgrade.StoreKey], app.cdc)
app.upgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc)

// create evidence keeper with evidence router
evidenceKeeper := evidence.NewKeeper(
Expand Down
6 changes: 3 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import (

func TestGaiadExport(t *testing.T) {
db := db.NewMemDB()
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})
err := setGenesis(gapp)
require.NoError(t, err)

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
newGapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})
_, _, err = newGapp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}

// ensure that black listed addresses are properly set in bank keeper
func TestBlackListedAddrs(t *testing.T) {
db := db.NewMemDB()
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
gapp := NewGaiaApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{})

for acc := range maccPerms {
require.True(t, gapp.bankKeeper.BlacklistedAddr(gapp.supplyKeeper.GetModuleAddress(acc)))
Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []st
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.distrKeeper.GetValidatorOutstandingRewards(ctx, val.GetOperator())
feePool := app.distrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.distrKeeper.SetFeePool(ctx, feePool)

app.distrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
Expand Down
4 changes: 2 additions & 2 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
}
}()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, interBlockCacheOpt())
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -66,7 +66,7 @@ func BenchmarkInvariants(b *testing.B) {
}
}()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, interBlockCacheOpt())
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down
12 changes: 6 additions & 6 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestFullAppSimulation(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, fauxMerkleModeOpt)
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// run randomized simulation
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, fauxMerkleModeOpt)
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, fauxMerkleModeOpt)
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, newApp.Name())

var genesisState GenesisState
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir))
}()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, fauxMerkleModeOpt)
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())

// Run randomized simulation
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir))
}()

newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, fauxMerkleModeOpt)
newApp := NewGaiaApp(log.NewNopLogger(), newDB, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, fauxMerkleModeOpt)
require.Equal(t, appName, newApp.Name())

newApp.InitChain(abci.RequestInitChain{
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestAppStateDeterminism(t *testing.T) {

db := dbm.NewMemDB()

app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, interBlockCacheOpt())
app := NewGaiaApp(logger, db, nil, true, simapp.FlagPeriodValue, map[int64]bool{}, interBlockCacheOpt())

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
Expand Down
34 changes: 17 additions & 17 deletions cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
f.TxGovSubmitProposal(keyFoo, "Text", "Test", "test", sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)

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

// Ensure deposit was deducted
Expand Down Expand Up @@ -547,8 +547,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
deposit = f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens.Add(depositTokens), deposit.Amount.AmountOf(denom))

// Ensure tags are set on the transaction
searchResult = f.QueryTxs(1, 50, "message.action:deposit", fmt.Sprintf("message.sender:%s", fooAddr))
// Ensure events are set on the transaction
searchResult = f.QueryTxs(1, 50, "message.action=deposit", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, searchResult.Txs, 1)

// Ensure account has expected amount of funds
Expand Down Expand Up @@ -584,8 +584,8 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
require.Equal(t, uint64(1), votes[0].ProposalID)
require.Equal(t, gov.OptionYes, votes[0].Option)

// Ensure tags are applied to voting transaction properly
searchResult = f.QueryTxs(1, 50, "message.action:vote", fmt.Sprintf("message.sender:%s", fooAddr))
// Ensure events are applied to voting transaction properly
searchResult = f.QueryTxs(1, 50, "message.action=vote", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, searchResult.Txs, 1)

// Ensure no proposals in deposit period
Expand Down Expand Up @@ -647,8 +647,8 @@ func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
f.TxGovSubmitParamChangeProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)

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

// ensure deposit was deducted
Expand Down Expand Up @@ -731,8 +731,8 @@ func TestGaiaCLISubmitCommunityPoolSpendProposal(t *testing.T) {
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, "message.action:submit_proposal", fmt.Sprintf("message.sender:%s", fooAddr))
// ensure transaction events can be queried
txsPage := f.QueryTxs(1, 50, "message.action=submit_proposal", fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage.Txs, 1)

// ensure deposit was deducted
Expand Down Expand Up @@ -777,30 +777,30 @@ func TestGaiaCLIQueryTxPagination(t *testing.T) {
}

// perPage = 15, 2 pages
txsPage1 := f.QueryTxs(1, 15, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage1 := f.QueryTxs(1, 15, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage1.Txs, 15)
require.Equal(t, txsPage1.Count, 15)
txsPage2 := f.QueryTxs(2, 15, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage2 := f.QueryTxs(2, 15, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage2.Txs, 15)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)

// perPage = 16, 2 pages
txsPage1 = f.QueryTxs(1, 16, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage1 = f.QueryTxs(1, 16, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage1.Txs, 16)
txsPage2 = f.QueryTxs(2, 16, fmt.Sprintf("message.sender:%s", fooAddr))
txsPage2 = f.QueryTxs(2, 16, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPage2.Txs, 14)
require.NotEqual(t, txsPage1.Txs, txsPage2.Txs)

// perPage = 50
txsPageFull := f.QueryTxs(1, 50, fmt.Sprintf("message.sender:%s", fooAddr))
txsPageFull := f.QueryTxs(1, 50, fmt.Sprintf("message.sender=%s", fooAddr))
require.Len(t, txsPageFull.Txs, 30)
require.Equal(t, txsPageFull.Txs, append(txsPage1.Txs, txsPage2.Txs...))

// perPage = 0
f.QueryTxsInvalid(errors.New("ERROR: page must greater than 0"), 0, 50, fmt.Sprintf("message.sender:%s", fooAddr))
f.QueryTxsInvalid(errors.New("ERROR: page must greater than 0"), 0, 50, fmt.Sprintf("message.sender=%s", fooAddr))

// limit = 0
f.QueryTxsInvalid(errors.New("ERROR: limit must greater than 0"), 1, 0, fmt.Sprintf("message.sender:%s", fooAddr))
f.QueryTxsInvalid(errors.New("ERROR: limit must greater than 0"), 1, 0, fmt.Sprintf("message.sender=%s", fooAddr))

// Cleanup testing directories
f.Cleanup()
Expand Down
14 changes: 7 additions & 7 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.Ba
// gaiacli query txs

// QueryTxs is gaiacli query txs
func (f *Fixtures) QueryTxs(page, limit int, tags ...string) *sdk.SearchTxsResult {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --tags='%s' %v", f.GaiacliBinary, page, limit, queryTags(tags), f.Flags())
func (f *Fixtures) QueryTxs(page, limit int, events ...string) *sdk.SearchTxsResult {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --events='%s' %v", f.GaiacliBinary, page, limit, queryEvents(events), f.Flags())
out, _ := tests.ExecuteT(f.T, cmd, "")
var result sdk.SearchTxsResult
cdc := app.MakeCodec()
Expand All @@ -464,8 +464,8 @@ func (f *Fixtures) QueryTxs(page, limit int, tags ...string) *sdk.SearchTxsResul
}

// QueryTxsInvalid query txs with wrong parameters and compare expected error
func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, tags ...string) {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --tags='%s' %v", f.GaiacliBinary, page, limit, queryTags(tags), f.Flags())
func (f *Fixtures) QueryTxsInvalid(expectedErr error, page, limit int, events ...string) {
cmd := fmt.Sprintf("%s query txs --page=%d --limit=%d --events='%s' %v", f.GaiacliBinary, page, limit, queryEvents(events), f.Flags())
_, err := tests.ExecuteT(f.T, cmd, "")
require.EqualError(f.T, expectedErr, err)
}
Expand Down Expand Up @@ -754,9 +754,9 @@ func addFlags(cmd string, flags []string) string {
return strings.TrimSpace(cmd)
}

func queryTags(tags []string) (out string) {
for _, tag := range tags {
out += tag + "&"
func queryEvents(events []string) (out string) {
for _, event := range events {
out += event + "&"
}
return strings.TrimSuffix(out, "&")
}
Expand Down
11 changes: 8 additions & 3 deletions cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application
cache = store.NewCommitKVStoreCacheManager()
}

skipUpgradeHeights := make(map[int64]bool)
for _, h := range viper.GetIntSlice(server.FlagUnsafeSkipUpgrades) {
skipUpgradeHeights[int64(h)] = true
}

return app.NewGaiaApp(
logger, db, traceStore, true, invCheckPeriod,
logger, db, traceStore, true, invCheckPeriod, skipUpgradeHeights,
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
baseapp.SetHaltHeight(viper.GetUint64(server.FlagHaltHeight)),
Expand All @@ -98,14 +103,14 @@ func exportAppStateAndTMValidators(
) (json.RawMessage, []tmtypes.GenesisValidator, error) {

if height != -1 {
gapp := app.NewGaiaApp(logger, db, traceStore, false, uint(1))
gapp := app.NewGaiaApp(logger, db, traceStore, false, uint(1), map[int64]bool{})
err := gapp.LoadHeight(height)
if err != nil {
return nil, nil, err
}
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}

gapp := app.NewGaiaApp(logger, db, traceStore, true, uint(1))
gapp := app.NewGaiaApp(logger, db, traceStore, true, uint(1), map[int64]bool{})
return gapp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
}
2 changes: 1 addition & 1 deletion cmd/gaiad/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func replayTxs(rootDir string) error {
// Application
fmt.Fprintln(os.Stderr, "Creating application")
gapp := app.NewGaiaApp(
ctx.Logger, appDB, traceStoreWriter, true, uint(1),
ctx.Logger, appDB, traceStoreWriter, true, uint(1), map[int64]bool{},
baseapp.SetPruning(store.PruneEverything), // nothing
)

Expand Down
32 changes: 17 additions & 15 deletions docs/resources/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,41 +289,43 @@ gaiacli tx broadcast --node=<node> signedSendTx.json

### Query Transactions

#### Matching a Set of Tags
#### Matching a Set of Events

You can use the transaction search command to query for transactions that match a specific set of `tags`, which are added on every transaction.
You can use the transaction search command to query for transactions that match a
specific set of `events`, which are added on every transaction.

Each tag is conformed by a key-value pair in the form of `<tag>:<value>`. Tags can also be combined to query for a more specific result using the `&` symbol.
Each event is composed by a key-value pair in the form of `{eventType}.{eventAttribute}={value}`.
Events can also be combined to query for a more specific result using the `&` symbol.

The command for querying transactions using a `tag` is the following:
You can query transactions by `events` as follows:

```bash
gaiacli query txs --tags='<tag>:<value>'
gaiacli query txs --events='message.sender=cosmos1...'
```

And for using multiple `tags`:
And for using multiple `events`:

```bash
gaiacli query txs --tags='<tag1>:<value1>&<tag2>:<value2>'
gaiacli query txs --events='message.sender=cosmos1...&message.action=withdraw_delegator_reward'
```

The pagination is supported as well via `page` and `limit`:

```bash
gaiacli query txs --tags='<tag>:<value>' --page=1 --limit=20
gaiacli query txs --events='message.sender=cosmos1...' --page=1 --limit=20
```

::: tip Note

The action tag always equals the message type returned by the `Type()` function of the relevant message.

You can find a list of available `tags` on each of the SDK modules:
You can find a list of available `events` on each of the SDK modules:

- [Common tags](https://github.com/cosmos/cosmos-sdk/blob/d1e76221d8e28824bb4791cb4ad8662d2ae9051e/types/tags.go#L57-L63)
- [Staking tags](https://cosmos.network/docs/spec/staking/06_tags.html#tags)
- [Governance tags](https://cosmos.network/docs/spec/governance/04_tags.html#tags)
- [Slashing tags](https://cosmos.network/docs/spec/slashing/06_tags.html#tags)
- [Distribution tags](https://cosmos.network/docs/spec/distribution/06_tags.html)
- [Bank tags](https://cosmos.network/docs/spec/bank/04_tags.html#tags)
- [Staking events](https://github.com/cosmos/cosmos-sdk/blob/master/x/staking/spec/07_events.md)
- [Governance events](https://github.com/cosmos/cosmos-sdk/blob/master/x/gov/spec/04_events.md)
- [Slashing events](https://github.com/cosmos/cosmos-sdk/blob/master/x/slashing/spec/06_events.md)
- [Distribution events](https://github.com/cosmos/cosmos-sdk/blob/master/x/distribution/spec/06_events.md)
- [Bank events](https://github.com/cosmos/cosmos-sdk/blob/master/x/bank/spec/04_events.md)
:::

#### Matching a Transaction's Hash
Expand Down
Loading

0 comments on commit 87a4269

Please sign in to comment.