Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuguen committed Dec 7, 2022
1 parent 47341c7 commit 272e2ea
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
2 changes: 1 addition & 1 deletion proto/panacea/oracle/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ service Query {

// OracleRegistrations returns a list of OracleRegistration.
rpc OracleRegistrations(QueryOracleRegistrationsRequest) returns (QueryOracleRegistrationsResponse) {
option (google.api.http).get = "/panacea/oracle/v2/oracle_registrations";
option (google.api.http).get = "/panacea/oracle/v2/oracle_registrations/{unique_id}";
}

// OracleRegistration returns a OracleRegistration details.
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/grpc_query_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (k Keeper) OracleRegistrations(goCtx context.Context, request *types.QueryO
ctx := sdk.UnwrapSDKContext(goCtx)

store := ctx.KVStore(k.storeKey)
oracleRegistrationStore := prefix.NewStore(store, types.OracleRegistrationKey)
oracleRegistrationStore := prefix.NewStore(store, append(types.OracleRegistrationKey, []byte(request.UniqueId)...))

var oracleRegistrations []*types.OracleRegistration
pageRes, err := query.Paginate(oracleRegistrationStore, request.Pagination, func(_, value []byte) error {
Expand Down
106 changes: 106 additions & 0 deletions x/oracle/keeper/grpc_query_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,116 @@ func (suite *queryOracleTestSuite) TestOracleRegistrations() {
OracleCommissionRate: suite.oracle2CommissionRate,
}

anotherUniqueID := "uniqueID2"
oracleRegistration3 := &types.OracleRegistration{
UniqueId: anotherUniqueID,
OracleAddress: suite.oracle2AccAddr.String(),
NodePubKey: suite.nodePubKey.SerializeCompressed(),
NodePubKeyRemoteReport: remoteReport,
TrustedBlockHeight: 10,
TrustedBlockHash: trustedBlockHash,
Endpoint: suite.oracle2Endpoint,
OracleCommissionRate: suite.oracle2CommissionRate,
}

err := oracleKeeper.SetOracleRegistration(ctx, oracleRegistration)
suite.Require().NoError(err)
err = oracleKeeper.SetOracleRegistration(ctx, oracleRegistration2)
suite.Require().NoError(err)
err = oracleKeeper.SetOracleRegistration(ctx, oracleRegistration3)
suite.Require().NoError(err)

req := types.QueryOracleRegistrationsRequest{
UniqueId: suite.uniqueID,
Pagination: &query.PageRequest{},
}
res, err := oracleKeeper.OracleRegistrations(sdk.WrapSDKContext(ctx), &req)
suite.Require().NoError(err)
suite.Require().Equal(2, len(res.OracleRegistrations))
for _, oracleRegistration := range res.OracleRegistrations {
switch oracleRegistration.OracleAddress {
case suite.oracleAccAddr.String():
suite.Require().Equal(suite.uniqueID, oracleRegistration.UniqueId)
suite.Require().Equal(suite.nodePubKey.SerializeCompressed(), oracleRegistration.NodePubKey)
suite.Require().Equal(remoteReport, oracleRegistration.NodePubKeyRemoteReport)
suite.Require().Equal(int64(10), oracleRegistration.TrustedBlockHeight)
suite.Require().Equal(trustedBlockHash, oracleRegistration.TrustedBlockHash)
suite.Require().Equal(suite.oracleEndpoint, oracleRegistration.Endpoint)
suite.Require().Equal(suite.oracleCommissionRate, oracleRegistration.OracleCommissionRate)
case suite.oracle2AccAddr.String():
suite.Require().Equal(suite.uniqueID, oracleRegistration.UniqueId)
suite.Require().Equal(suite.nodePubKey.SerializeCompressed(), oracleRegistration.NodePubKey)
suite.Require().Equal(remoteReport, oracleRegistration.NodePubKeyRemoteReport)
suite.Require().Equal(int64(10), oracleRegistration.TrustedBlockHeight)
suite.Require().Equal(trustedBlockHash, oracleRegistration.TrustedBlockHash)
suite.Require().Equal(suite.oracle2Endpoint, oracleRegistration.Endpoint)
suite.Require().Equal(suite.oracle2CommissionRate, oracleRegistration.OracleCommissionRate)
default:
panic("not found oracle address. address: " + oracleRegistration.OracleAddress)
}
}

req.UniqueId = anotherUniqueID
res, err = oracleKeeper.OracleRegistrations(sdk.WrapSDKContext(ctx), &req)
suite.Require().NoError(err)
suite.Require().Equal(1, len(res.OracleRegistrations))

suite.Require().Equal(suite.oracle2AccAddr.String(), res.OracleRegistrations[0].OracleAddress)
suite.Require().Equal(anotherUniqueID, res.OracleRegistrations[0].UniqueId)
suite.Require().Equal(suite.nodePubKey.SerializeCompressed(), res.OracleRegistrations[0].NodePubKey)
suite.Require().Equal(remoteReport, res.OracleRegistrations[0].NodePubKeyRemoteReport)
suite.Require().Equal(int64(10), res.OracleRegistrations[0].TrustedBlockHeight)
suite.Require().Equal(trustedBlockHash, res.OracleRegistrations[0].TrustedBlockHash)
suite.Require().Equal(suite.oracle2Endpoint, res.OracleRegistrations[0].Endpoint)
suite.Require().Equal(suite.oracle2CommissionRate, res.OracleRegistrations[0].OracleCommissionRate)
}

func (suite *queryOracleTestSuite) TestOracleRegistrationsDifferentUniqueID() {
ctx := suite.Ctx
oracleKeeper := suite.OracleKeeper

remoteReport := []byte("nodePubKeyRemoteReport")
trustedBlockHash := []byte("hash")

oracleRegistration := &types.OracleRegistration{
UniqueId: suite.uniqueID,
OracleAddress: suite.oracleAccAddr.String(),
NodePubKey: suite.nodePubKey.SerializeCompressed(),
NodePubKeyRemoteReport: remoteReport,
TrustedBlockHeight: 10,
TrustedBlockHash: trustedBlockHash,
Endpoint: suite.oracleEndpoint,
OracleCommissionRate: suite.oracleCommissionRate,
}

oracleRegistration2 := &types.OracleRegistration{
UniqueId: suite.uniqueID,
OracleAddress: suite.oracle2AccAddr.String(),
NodePubKey: suite.nodePubKey.SerializeCompressed(),
NodePubKeyRemoteReport: remoteReport,
TrustedBlockHeight: 10,
TrustedBlockHash: trustedBlockHash,
Endpoint: suite.oracle2Endpoint,
OracleCommissionRate: suite.oracle2CommissionRate,
}

oracleRegistration3 := &types.OracleRegistration{
UniqueId: "uniqueID2",
OracleAddress: suite.oracle2AccAddr.String(),
NodePubKey: suite.nodePubKey.SerializeCompressed(),
NodePubKeyRemoteReport: remoteReport,
TrustedBlockHeight: 10,
TrustedBlockHash: trustedBlockHash,
Endpoint: suite.oracle2Endpoint,
OracleCommissionRate: suite.oracle2CommissionRate,
}

err := oracleKeeper.SetOracleRegistration(ctx, oracleRegistration)
suite.Require().NoError(err)
err = oracleKeeper.SetOracleRegistration(ctx, oracleRegistration2)
suite.Require().NoError(err)
err = oracleKeeper.SetOracleRegistration(ctx, oracleRegistration3)
suite.Require().NoError(err)

req := types.QueryOracleRegistrationsRequest{
UniqueId: suite.uniqueID,
Expand Down

0 comments on commit 272e2ea

Please sign in to comment.