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: fix tx search #2842

Merged
merged 26 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4de3aee
fixed tx search
Nov 16, 2018
e65d186
test empty response
Nov 16, 2018
1a7f9da
update unit tests
Nov 16, 2018
15d98cc
update lcd tests
Nov 16, 2018
f42363b
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into f…
Nov 16, 2018
1755993
PENDING
Nov 16, 2018
8a95de4
updated swagger.yaml
Nov 16, 2018
ee4c51b
update cli tests
Nov 20, 2018
b7301b5
Merge branch 'develop' into fedekunze/2819-fix-tx-search
fedekunze Nov 20, 2018
60fc7c7
Merge develop
Nov 26, 2018
198b27b
Merge branch 'fedekunze/2819-fix-tx-search' of https://github.com/cos…
Nov 26, 2018
9fdd430
update cli tx search
Nov 26, 2018
a2189bc
fix tx search CLI
Nov 27, 2018
666fafb
add other tests and update docs
Nov 27, 2018
9bf2041
delete comments on lcd tests
fedekunze Nov 27, 2018
cd812c7
fix comments and cmd description
Nov 27, 2018
1dab1f7
Merge branch 'fedekunze/2819-fix-tx-search' of https://github.com/cos…
Nov 27, 2018
f97b934
few more tx search tests
Nov 27, 2018
9c85e93
Merge branch 'develop' of https://github.com/cosmos/cosmos-sdk into f…
Nov 27, 2018
2d9ce31
updated tests
Nov 27, 2018
d8683fe
Update client/tx/search.go
alexanderbez Nov 27, 2018
ebaac49
minor changes from review
Nov 27, 2018
14154f7
deleted unnecessary function
Nov 27, 2018
9751a61
Merge branch 'develop' into fedekunze/2819-fix-tx-search
fedekunze Nov 27, 2018
7cf5da2
address Chris' comments
Nov 27, 2018
8414c34
Merge branch 'fedekunze/2819-fix-tx-search' of https://github.com/cos…
Nov 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BREAKING CHANGES

* Gaia REST API (`gaiacli advanced rest-server`)
* [gaia-lite] [\#2819](https://github.com/cosmos/cosmos-sdk/pull/2819) Txs query param format is now: `/txs?tag=value` (removed '' wrapping the query parameter `value`)

* Gaia CLI (`gaiacli`)
* [cli] [\#2728](https://github.com/cosmos/cosmos-sdk/pull/2728) Seperate `tx` and `query` subcommands by module
Expand Down Expand Up @@ -56,10 +57,12 @@ FEATURES
IMPROVEMENTS

* Gaia REST API (`gaiacli advanced rest-server`)
* [gaia-lite] [\#2819](https://github.com/cosmos/cosmos-sdk/pull/2819) Tx search now supports multiple tags as query parameters
* [\#2836](https://github.com/cosmos/cosmos-sdk/pull/2836) Expose LCD router to allow users to register routes there.

* Gaia CLI (`gaiacli`)
* [\#2749](https://github.com/cosmos/cosmos-sdk/pull/2749) Add --chain-id flag to gaiad testnet
* [\#2819](https://github.com/cosmos/cosmos-sdk/pull/2819) Tx search now supports multiple tags as query parameters

* Gaia
- #2772 Update BaseApp to not persist state when the ante handler fails on DeliverTx.
Expand All @@ -78,7 +81,7 @@ IMPROVEMENTS
- #2779 Introduce `ValidateBasic` to the `Tx` interface and call it in the ante
handler.
- #2825 More staking and distribution invariants
* #2912 Print commit ID in hex when commit is synced.
- #2912 Print commit ID in hex when commit is synced.

* Tendermint
- #2796 Update to go-amino 0.14.1
Expand All @@ -94,7 +97,7 @@ BUG FIXES
* Gaia
* [\#2723] Use `cosmosvalcons` Bech32 prefix in `tendermint show-address`
* [\#2742](https://github.com/cosmos/cosmos-sdk/issues/2742) Fix time format of TimeoutCommit override
* [\#2898](https://github.com/cosmos/cosmos-sdk/issues/2898) Remove redundant '$' in docker-compose.yml
* [\#2898](https://github.com/cosmos/cosmos-sdk/issues/2898) Remove redundant '$' in docker-compose.yml

* SDK

Expand Down
150 changes: 108 additions & 42 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -399,57 +400,39 @@ func TestTxs(t *testing.T) {
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
defer cleanup()

// query wrong
res, body := Request(t, port, "GET", "/txs", nil)
require.Equal(t, http.StatusBadRequest, res.StatusCode, body)
var emptyTxs []tx.Info
txs := getTransactions(t, port)
require.Equal(t, emptyTxs, txs)

// query empty
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32='%s'", "cosmos1jawd35d9aq4u76sr3fjalmcqc8hqygs90d0g0v"), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.Equal(t, "[]", body)
txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String()))
require.Equal(t, emptyTxs, txs)

// create TX
receiveAddr, resultTx := doSend(t, port, seed, name, password, addr)

tests.WaitForHeight(resultTx.Height+1, port)
// also tests url decoding
txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String()))
require.Equal(t, emptyTxs, txs)

// check if tx is findable
res, body = Request(t, port, "GET", fmt.Sprintf("/txs/%s", resultTx.Hash), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
txs = getTransactions(t, port, fmt.Sprintf("action=submit%%20proposal&proposer=%s", addr.String()))
require.Equal(t, emptyTxs, txs)

var indexedTxs []tx.Info
// create tx
receiveAddr, resultTx := doSend(t, port, seed, name, password, addr)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx is queryable
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=tx.hash='%s'", resultTx.Hash), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
require.NotEqual(t, "[]", body)

err := cdc.UnmarshalJSON([]byte(body), &indexedTxs)
require.NoError(t, err)
require.Equal(t, 1, len(indexedTxs))

// XXX should this move into some other testfile for txs in general?
// test if created TX hash is the correct hash
require.Equal(t, resultTx.Hash, indexedTxs[0].Hash)
txs = getTransactions(t, port, fmt.Sprintf("tx.hash=%s", resultTx.Hash))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Hash, txs[0].Hash)

// query sender
// also tests url decoding
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=sender_bech32=%%27%s%%27", addr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
require.NoError(t, err)
require.Equal(t, 1, len(indexedTxs), "%v", indexedTxs) // there are 2 txs created with doSend
require.Equal(t, resultTx.Height, indexedTxs[0].Height)
txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String()))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

// query recipient
res, body = Request(t, port, "GET", fmt.Sprintf("/txs?tag=recipient_bech32='%s'", receiveAddr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

err = cdc.UnmarshalJSON([]byte(body), &indexedTxs)
require.NoError(t, err)
require.Equal(t, 1, len(indexedTxs))
require.Equal(t, resultTx.Height, indexedTxs[0].Height)
txs = getTransactions(t, port, fmt.Sprintf("recipient=%s", receiveAddr.String()))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)
}

func TestPoolParamsQuery(t *testing.T) {
Expand Down Expand Up @@ -534,6 +517,14 @@ func TestBonding(t *testing.T) {
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
require.Equal(t, uint32(0), resultTx.DeliverTx.Code)

// query tx
txs := getTransactions(t, port,
fmt.Sprintf("action=delegate&delegator=%s", addr),
fmt.Sprintf("destination-validator=%s", operAddrs[0]),
)
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

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

Expand Down Expand Up @@ -571,6 +562,14 @@ func TestBonding(t *testing.T) {
coins = acc.GetCoins()
require.Equal(t, int64(40), coins.AmountOf(stakeTypes.DefaultBondDenom).Int64())

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin-unbonding&delegator=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
)
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

unbonding := getUndelegation(t, port, addr, operAddrs[0])
require.Equal(t, "30", unbonding.Balance.Amount.String())

Expand All @@ -581,6 +580,15 @@ func TestBonding(t *testing.T) {
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
require.Equal(t, uint32(0), resultTx.DeliverTx.Code)

// query tx
txs = getTransactions(t, port,
fmt.Sprintf("action=begin-redelegation&delegator=%s", addr),
fmt.Sprintf("source-validator=%s", operAddrs[0]),
fmt.Sprintf("destination-validator=%s", operAddrs[1]),
)
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

// query delegations, unbondings and redelegations from validator and delegator
delegatorDels = getDelegatorDelegations(t, port, addr)
require.Len(t, delegatorDels, 1)
Expand All @@ -606,7 +614,7 @@ func TestBonding(t *testing.T) {
// require.Equal(t, sdk.Unbonding, bondedValidators[0].Status)

// query txs
txs := getBondingTxs(t, port, addr, "")
txs = getBondingTxs(t, port, addr, "")
require.Len(t, txs, 3, "All Txs found")

txs = getBondingTxs(t, port, addr, "bond")
Expand Down Expand Up @@ -639,6 +647,11 @@ func TestSubmitProposal(t *testing.T) {
// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.GetTitle())

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=submit-proposal&proposer=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)
}

func TestDeposit(t *testing.T) {
Expand Down Expand Up @@ -666,6 +679,11 @@ func TestDeposit(t *testing.T) {
resultTx = doDeposit(t, port, seed, name, password, addr, proposalID, 5)
tests.WaitForHeight(resultTx.Height+1, port)

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=deposit&depositor=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

// query proposal
proposal = getProposal(t, port, proposalID)
require.True(t, proposal.GetTotalDeposit().IsEqual(sdk.Coins{sdk.NewInt64Coin(stakeTypes.DefaultBondDenom, 10)}))
Expand Down Expand Up @@ -708,6 +726,11 @@ func TestVote(t *testing.T) {
resultTx = doVote(t, port, seed, name, password, addr, proposalID)
tests.WaitForHeight(resultTx.Height+1, port)

// query tx
txs := getTransactions(t, port, fmt.Sprintf("action=vote&voter=%s", addr))
require.Len(t, txs, 1)
require.Equal(t, resultTx.Height, txs[0].Height)

vote := getVote(t, port, proposalID, addr)
require.Equal(t, proposalID, vote.ProposalID)
require.Equal(t, gov.OptionYes, vote.Option)
Expand Down Expand Up @@ -866,7 +889,7 @@ func TestProposalsQuery(t *testing.T) {
//_____________________________________________________________________________
// get the account to get the sequence
func getAccount(t *testing.T, port string, addr sdk.AccAddress) auth.Account {
res, body := Request(t, port, "GET", fmt.Sprintf("/auth/accounts/%s", addr), nil)
res, body := Request(t, port, "GET", fmt.Sprintf("/auth/accounts/%s", addr.String()), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
var acc auth.Account
err := cdc.UnmarshalJSON([]byte(body), &acc)
Expand Down Expand Up @@ -944,6 +967,22 @@ func doSend(t *testing.T, port, seed, name, password string, addr sdk.AccAddress
return receiveAddr, resultTx
}

func getTransactions(t *testing.T, port string, tags ...string) []tx.Info {
var txs []tx.Info
if len(tags) == 0 {
return txs
}
queryStr := strings.Join(tags, "&")
res, body := Request(t, port, "GET", fmt.Sprintf("/txs?%s", queryStr), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)

err := cdc.UnmarshalJSON([]byte(body), &txs)
require.NoError(t, err)
return txs
}

// ============= IBC Module ================

func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.AccAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
// create receive address
kb := client.MockKeyBase()
Expand Down Expand Up @@ -984,6 +1023,8 @@ func doIBCTransfer(t *testing.T, port, seed, name, password string, addr sdk.Acc
return resultTx
}

// ============= Slashing Module ================

func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing.ValidatorSigningInfo {
res, body := Request(t, port, "GET", fmt.Sprintf("/slashing/validators/%s/signing_info", validatorPubKey), nil)
require.Equal(t, http.StatusOK, res.StatusCode, body)
Expand All @@ -995,6 +1036,31 @@ func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing.
return signingInfo
}

func doUnjail(t *testing.T, port, seed, name, password string,
valAddr sdk.ValAddress) (resultTx ctypes.ResultBroadcastTxCommit) {
chainID := viper.GetString(client.FlagChainID)

jsonStr := []byte(fmt.Sprintf(`{
"base_req": {
"name": "%s",
"password": "%s",
"chain_id": "%s",
"account_number":"1",
"sequence":"1"
}
}`, name, password, chainID))

res, body := Request(t, port, "POST", fmt.Sprintf("/slashing/validators/%s/unjail", valAddr.String()), jsonStr)
// TODO : fails with "401 must use own validator address"
require.Equal(t, http.StatusOK, res.StatusCode, body)

var results []ctypes.ResultBroadcastTxCommit
err := cdc.UnmarshalJSON([]byte(body), &results)
require.Nil(t, err)

return results[0]
}

// ============= Stake Module ================

func getDelegation(t *testing.T, port string, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress) stake.Delegation {
Expand Down
6 changes: 3 additions & 3 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ paths:
tags:
- ICS0
summary: Search transactions
description: Search transactions by tag
description: Search transactions by tag(s).
produces:
- application/json
parameters:
- in: query
name: tag
type: string
description: "transaction tag, for instance: sender_bech32=`'cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'`"
description: "transaction tags such as 'action=submit-proposal' and 'proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc' which results in the following endpoint: 'GET /txs?action=submit-proposal&proposer=cosmos1g9ahr6xhht5rmqven628nklxluzyv8z9jqjcmc'"
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
required: true
- in: query
name: page
Expand All @@ -228,7 +228,7 @@ paths:
type: integer
responses:
200:
description: All Tx matching the provided tags
description: All txs matching the provided tags
schema:
type: array
items:
Expand Down
Loading