Skip to content

Commit

Permalink
refactor(x/data): remove unique constraint on resolver url (#1128)
Browse files Browse the repository at this point in the history
* refactor(x/data): remove unique constraint on resolver url

* remove pagination check and expected items
  • Loading branch information
ryanchristo authored May 26, 2022
1 parent 94034cc commit 643fb97
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 389 deletions.
178 changes: 89 additions & 89 deletions api/regen/data/v1/query.pulsar.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/regen/data/v1/query_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions api/regen/data/v1/state.cosmos_orm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions api/regen/data/v1/state.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions proto/regen/data/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ message QueryResolversByHashResponse {

// QueryResolverInfoRequest is the Query/ResolverInfo request type.
message QueryResolverInfoRequest {
// url is the resolver URL that has been registered.
string url = 1;
// id is the id of the resolver.
uint64 id = 1;
}

// QueryResolverInfoResponse is the Query/ResolverInfo response type.
message QueryResolverInfoResponse {
// id is the id of the resolver which can be used in Msg/RegisterResolver.
uint64 id = 1;
// url is the resolver URL that has been registered.
string url = 1;

// manager is the bech32 account address of the resolver manager.
string manager = 2;
Expand Down
4 changes: 2 additions & 2 deletions proto/regen/data/v1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ message ResolverInfo {
option (cosmos.orm.v1alpha1.table) = {
id : 4
primary_key : {fields : "id", auto_increment : true}
index : {id : 1, fields : "url", unique : true}
index : {id : 1, fields : "url"}
index : {id : 2, fields : "manager"}
};

// id is the ID of the resolver.
uint64 id = 1;

// url is the unique URL of the resolver.
// url is the URL of the resolver.
string url = 2;

// manager is the bytes address of the resolver manager who is allowed
Expand Down
10 changes: 8 additions & 2 deletions x/data/client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"fmt"
"io/ioutil"
"strconv"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -218,7 +219,7 @@ func QueryAttestorsCmd() *cobra.Command {
// QueryResolverInfoCmd creates a CLI command for Query/ResolverInfo.
func QueryResolverInfoCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "resolver-info [url]",
Use: "resolver-info [id]",
Short: "Query for resolver information",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -227,8 +228,13 @@ func QueryResolverInfoCmd() *cobra.Command {
return err
}

id, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid resolver id: %s", err)
}

res, err := c.ResolverInfo(cmd.Context(), &data.QueryResolverInfoRequest{
Url: args[0],
Id: id,
})

return print(ctx, res, err)
Expand Down
28 changes: 8 additions & 20 deletions x/data/client/testsuite/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,35 +464,23 @@ func (s *IntegrationTestSuite) TestQueryAttestors() {
func (s *IntegrationTestSuite) TestQueryResolverInfo() {
val := s.network.Validators[0]

url := "https://foo.bar"

testCases := []struct {
name string
url string
expErr bool
errMsg string
expItems int
name string
url string
expErr bool
errMsg string
}{
{
"invalid url",
fmt.Sprintf("%s/regen/data/v1/resolver?url=%s", val.APIAddress, "foo"),
"invalid id",
fmt.Sprintf("%s/regen/data/v1/resolver?id=%d", val.APIAddress, 404),
true,
"not found",
0,
},
{
"valid request",
fmt.Sprintf("%s/regen/data/v1/resolver?url=%s", val.APIAddress, url),
fmt.Sprintf("%s/regen/data/v1/resolver?id=%d", val.APIAddress, s.resolverID),
false,
"",
2,
},
{
"valid request pagination",
fmt.Sprintf("%s/regen/data/v1/resolver?url=%s&pagination.limit=1", val.APIAddress, url),
false,
"",
1,
},
}

Expand All @@ -511,7 +499,7 @@ func (s *IntegrationTestSuite) TestQueryResolverInfo() {
require.Contains(string(resp), tc.errMsg)
} else {
require.NoError(err)
require.NotNil(resolver.Id)
require.NotNil(resolver.Url)
require.NotNil(resolver.Manager)
}
})
Expand Down
10 changes: 8 additions & 2 deletions x/data/client/testsuite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,20 @@ func (s *IntegrationTestSuite) TestQueryResolverInfoCmd() {
expErrMsg: "Error: accepts 1 arg(s), received 2",
},
{
name: "invalid url",
name: "invalid id",
args: []string{"abcd"},
expErr: true,
expErrMsg: "invalid syntax",
},
{
name: "id not found",
args: []string{"404"},
expErr: true,
expErrMsg: "not found",
},
{
name: "valid",
args: []string{"https://foo.bar"},
args: []string{"1"},
expErr: false,
},
}
Expand Down
43 changes: 15 additions & 28 deletions x/data/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package testsuite

import (
"fmt"
"strconv"
"strings"

"github.com/stretchr/testify/suite"

tmcli "github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand Down Expand Up @@ -119,7 +119,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.Require().NoError(err)
}

_, err = cli.ExecTestCLICmd(val1.ClientCtx, client.MsgDefineResolverCmd(),
out, err := cli.ExecTestCLICmd(val1.ClientCtx, client.MsgDefineResolverCmd(),
append(
[]string{
"https://foo.bar",
Expand All @@ -130,19 +130,12 @@ func (s *IntegrationTestSuite) SetupSuite() {
)
s.Require().NoError(err)

out, err := cli.ExecTestCLICmd(val1.ClientCtx, client.QueryResolverInfoCmd(),
append(
[]string{
"https://foo.bar",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
),
)
s.Require().NoError(err)
var res sdk.TxResponse
s.Require().NoError(val1.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))

var resolverInfo data.QueryResolverInfoResponse
s.Require().NoError(val1.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &resolverInfo))
s.resolverID = resolverInfo.Id
id := strings.Trim(res.Logs[0].Events[1].Attributes[0].Value, "\"")
s.resolverID, err = strconv.ParseUint(id, 10, 64)
s.Require().NoError(err)

_, ch := s.createIRIAndGraphHash([]byte("abcdefg"))

Expand All @@ -164,7 +157,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
))
s.Require().NoError(err)

_, err = cli.ExecTestCLICmd(val1.ClientCtx, client.MsgDefineResolverCmd(),
out2, err := cli.ExecTestCLICmd(val1.ClientCtx, client.MsgDefineResolverCmd(),
append(
[]string{
"https://bar.baz",
Expand All @@ -175,22 +168,16 @@ func (s *IntegrationTestSuite) SetupSuite() {
)
s.Require().NoError(err)

out2, err := cli.ExecTestCLICmd(val1.ClientCtx, client.QueryResolverInfoCmd(),
append(
[]string{
"https://bar.baz",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
),
)
s.Require().NoError(err)
var res2 sdk.TxResponse
s.Require().NoError(val1.ClientCtx.Codec.UnmarshalJSON(out2.Bytes(), &res2))

var resolverInfo2 data.QueryResolverInfoResponse
s.Require().NoError(val1.ClientCtx.Codec.UnmarshalJSON(out2.Bytes(), &resolverInfo2))
id2 := strings.Trim(res2.Logs[0].Events[1].Attributes[0].Value, "\"")
resolverId2, err := strconv.ParseUint(id2, 10, 64)
s.Require().NoError(err)

_, err = cli.ExecTestCLICmd(val1.ClientCtx, client.MsgRegisterResolverCmd(), append(
[]string{
fmt.Sprintf("%d", resolverInfo2.Id),
fmt.Sprintf("%d", resolverId2),
filePath,
fmt.Sprintf("--%s=%s", flags.FlagFrom, account1.String()),
},
Expand Down
Loading

0 comments on commit 643fb97

Please sign in to comment.