Skip to content

Commit

Permalink
Merge pull request #79 from neutron-org/feat/update-interchain-query-…
Browse files Browse the repository at this point in the history
…add-check

feat: do not update key for tx query
  • Loading branch information
Andrew Zavgorodny authored Oct 19, 2022
2 parents 3096999 + 11bbcd3 commit c412c51
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 109 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ require (
github.com/dvsekhvalnov/jose2go v0.0.0-20200901110807-248326c1351b // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
Expand All @@ -71,7 +69,6 @@ require (
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand Down Expand Up @@ -379,8 +378,6 @@ github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2V
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188/go.mod h1:vXjM/+wXQnTPR4KqTKDgJukSZ6amVRtWMPEjE6sQoK8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -500,8 +497,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gtank/merlin v0.1.1-0.20191105220539-8318aed1a79f/go.mod h1:T86dnYJhcGOh5BjZFCJWTDeTK7XW8uE+E21Cy/bIQ+s=
Expand Down
3 changes: 2 additions & 1 deletion proto/interchainqueries/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ message MsgUpdateInterchainQueryRequest {
uint64 query_id = 1;
repeated KVKey new_keys = 2;
uint64 new_update_period = 3;
string sender = 4; // is the signer of the message
string new_transactions_filter = 4;
string sender = 5; // is the signer of the message
}
message MsgUpdateInterchainQueryResponse {}
80 changes: 62 additions & 18 deletions x/interchainqueries/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainQuery() {

func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
var msg iqtypes.MsgUpdateInterchainQueryRequest
originalQuery := iqtypes.MsgRegisterInterchainQuery{
originalKVQuery := iqtypes.MsgRegisterInterchainQuery{
QueryType: string(iqtypes.InterchainQueryTypeKV),
Keys: []*iqtypes.KVKey{
{
Expand All @@ -142,12 +142,23 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
Sender: "",
}

originalTXQuery := iqtypes.MsgRegisterInterchainQuery{
QueryType: string(iqtypes.InterchainQueryTypeTX),
Keys: nil,
TransactionsFilter: "someFilter",
ConnectionId: suite.Path.EndpointA.ConnectionID,
UpdatePeriod: 1,
Sender: "",
}

tests := []struct {
name string
malleate func(sender string)
expectedErr error
expectedPeriod uint64
expectedQueryKeys []*iqtypes.KVKey
name string
malleate func(sender string)
expectedErr error
expectedPeriod uint64
expectedQueryKeys []*iqtypes.KVKey
expectedQueryTXFilter string
query iqtypes.MsgRegisterInterchainQuery
}{
{
"valid update period",
Expand All @@ -161,7 +172,9 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
},
nil,
2,
originalQuery.Keys,
originalKVQuery.Keys,
"",
originalKVQuery,
},
{
"valid query data",
Expand All @@ -179,16 +192,18 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
}
},
nil,
originalQuery.UpdatePeriod,
originalKVQuery.UpdatePeriod,
[]*iqtypes.KVKey{
{
Path: "newpath",
Key: []byte("newdata"),
},
},
"",
originalKVQuery,
},
{
"valid query both query keys and update period",
"valid query both query keys and update period and ignore tx filter",
func(sender string) {
msg = iqtypes.MsgUpdateInterchainQueryRequest{
QueryId: 1,
Expand All @@ -198,8 +213,9 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
Key: []byte("newdata"),
},
},
NewUpdatePeriod: 2,
Sender: sender,
NewTransactionsFilter: "newFilter",
NewUpdatePeriod: 2,
Sender: sender,
}
},
nil,
Expand All @@ -210,9 +226,33 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
Key: []byte("newdata"),
},
},
"",
originalKVQuery,
},
{
"must not update keys for a tx query but update filter",
func(sender string) {
msg = iqtypes.MsgUpdateInterchainQueryRequest{
QueryId: 1,
NewKeys: []*iqtypes.KVKey{
{
Path: "newpath",
Key: []byte("newdata"),
},
},
NewUpdatePeriod: 2,
NewTransactionsFilter: "newFilter",
Sender: sender,
}
},
nil,
2,
nil,
"newFilter",
originalTXQuery,
},
{
"invavid query id",
"invalid query id",
func(sender string) {
msg = iqtypes.MsgUpdateInterchainQueryRequest{
QueryId: 2,
Expand All @@ -227,8 +267,10 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
}
},
iqtypes.ErrInvalidQueryID,
originalQuery.UpdatePeriod,
originalQuery.Keys,
originalKVQuery.UpdatePeriod,
originalKVQuery.Keys,
"",
originalKVQuery,
},
{
"failed due to auth error",
Expand All @@ -248,8 +290,10 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {
}
},
sdkerrors.ErrUnauthorized,
originalQuery.UpdatePeriod,
originalQuery.Keys,
originalKVQuery.UpdatePeriod,
originalKVQuery.Keys,
"",
originalKVQuery,
},
}

Expand Down Expand Up @@ -280,8 +324,8 @@ func (suite *KeeperTestSuite) TestUpdateInterchainQuery() {

msgSrv := keeper.NewMsgServerImpl(iqkeeper)

originalQuery.Sender = contractAddress.String()
resRegister, err := msgSrv.RegisterInterchainQuery(sdktypes.WrapSDKContext(ctx), &originalQuery)
tt.query.Sender = contractAddress.String()
resRegister, err := msgSrv.RegisterInterchainQuery(sdktypes.WrapSDKContext(ctx), &tt.query)
suite.Require().NoError(err)
suite.Require().NotNil(resRegister)

Expand Down
5 changes: 4 additions & 1 deletion x/interchainqueries/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ func (k msgServer) UpdateInterchainQuery(goCtx context.Context, msg *types.MsgUp
if msg.GetNewUpdatePeriod() > 0 {
query.UpdatePeriod = msg.GetNewUpdatePeriod()
}
if len(msg.GetNewKeys()) > 0 {
if len(msg.GetNewKeys()) > 0 && types.InterchainQueryType(query.GetQueryType()).IsKV() {
query.Keys = msg.GetNewKeys()
}
if len(msg.NewTransactionsFilter) > 0 && types.InterchainQueryType(query.GetQueryType()).IsTX() {
query.TransactionsFilter = msg.NewTransactionsFilter
}

err = k.SaveQuery(ctx, *query)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion x/interchainqueries/types/genesis.pb.go

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

3 changes: 2 additions & 1 deletion x/interchainqueries/types/params.pb.go

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

Loading

0 comments on commit c412c51

Please sign in to comment.