Skip to content

Commit

Permalink
chore: add comments, cleanup, consolidate x/oracle (#440)
Browse files Browse the repository at this point in the history
* chore: add comments, cleanup, consolidate x/oracle

* add comments and remove unused code

* chore:add comments and rm unused code in x/dispute

* test: add test for `RotateQueries` method
  • Loading branch information
akremstudy authored Nov 22, 2024
1 parent f6b2892 commit e6cff29
Show file tree
Hide file tree
Showing 30 changed files with 970 additions and 870 deletions.
36 changes: 18 additions & 18 deletions app/extend_vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,24 @@ func (s *VoteExtensionTestSuite) TestExtendVoteHandler() {
require.NotNil(resp)
},
},
// {
// name: "err on GetAttestationRequestsByHeight",
// setupMocks: func(bk *mocks.BridgeKeeper, h *app.VoteExtHandler, patches *gomonkey.Patches) (*mocks.BridgeKeeper, *gomonkey.Patches) {
// patches.ApplyMethod(reflect.TypeOf(h), "GetOperatorAddress", func(_ *app.VoteExtHandler) (string, error) {
// return oppAddr, nil
// })
// bk.On("GetEVMAddressByOperator", ctx, oppAddr).Return(nil, collections.ErrNotFound)
// patches.ApplyMethod(reflect.TypeOf(h), "SignInitialMessage", func(_ *app.VoteExtHandler) ([]byte, []byte, error) {
// return []byte("signatureA"), []byte("signatureB"), nil
// })
// bk.On("GetAttestationRequestsByHeight", ctx, uint64(2)).Return((*bridgetypes.AttestationRequests)(nil), errors.New("error!"))
// return bk, patches
// },
// expectedError: nil,
// validateResponse: func(resp *abci.ResponseExtendVote) {
// require.NotNil(resp)
// },
// },
{
name: "err on GetAttestationRequestsByHeight",
setupMocks: func(bk *mocks.BridgeKeeper, h *app.VoteExtHandler, patches *gomonkey.Patches) (*mocks.BridgeKeeper, *gomonkey.Patches) {
patches.ApplyMethod(reflect.TypeOf(h), "GetOperatorAddress", func(_ *app.VoteExtHandler) (string, error) {
return oppAddr, nil
})
bk.On("GetEVMAddressByOperator", ctx, oppAddr).Return(nil, collections.ErrNotFound)
patches.ApplyMethod(reflect.TypeOf(h), "SignInitialMessage", func(_ *app.VoteExtHandler) ([]byte, []byte, error) {
return []byte("signatureA"), []byte("signatureB"), nil
})
bk.On("GetAttestationRequestsByHeight", ctx, uint64(2)).Return((*bridgetypes.AttestationRequests)(nil), errors.New("error!"))
return bk, patches
},
expectedError: nil,
validateResponse: func(resp *abci.ResponseExtendVote) {
require.NotNil(resp)
},
},
{
name: "err signing checkpoint",
setupMocks: func(bk *mocks.BridgeKeeper, h *app.VoteExtHandler, patches *gomonkey.Patches) (*mocks.BridgeKeeper, *gomonkey.Patches) {
Expand Down
62 changes: 9 additions & 53 deletions tests/integration/oracle_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func (s *IntegrationTestSuite) TestTipping() {
s.NoError(err)
s.Equal(tip.Sub(twoPercent).Amount, tips)

userQueryTips, _ := s.Setup.Oraclekeeper.Tips.Get(s.Setup.Ctx, collections.Join(btcQueryId, addr.Bytes()))
s.Equal(userQueryTips, tips)
userTips, err = s.Setup.Oraclekeeper.GetUserTips(s.Setup.Ctx, addr)
s.NoError(err)
s.Equal(userTips, tips.Add(tips).Add(tips))
Expand Down Expand Up @@ -354,7 +352,9 @@ func (s *IntegrationTestSuite) TestTimeBasedRewardsOneReporter() {

reports := testutil.GenerateReports([]sdk.AccAddress{repAccs[0]}, value, []uint64{reporterPower}, qId)

_, err = s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports[:1], 1)
aggregateReport, err := s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports[:1], 1)
s.NoError(err)
err = s.Setup.Oraclekeeper.SetAggregate(s.Setup.Ctx, aggregateReport)
s.NoError(err)
queryServer := keeper.NewQuerier(s.Setup.Oraclekeeper)
res, err := queryServer.GetCurrentAggregateReport(s.Setup.Ctx, &types.QueryGetCurrentAggregateReportRequest{QueryId: hex.EncodeToString(qId)})
Expand Down Expand Up @@ -427,9 +427,10 @@ func (s *IntegrationTestSuite) TestTimeBasedRewardsTwoReporters() {
delegator: repAccs[1],
},
}
_, err = s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports, 1)
aggregateReport, err := s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports, 1)
s.NoError(err)
err = s.Setup.Oraclekeeper.SetAggregate(s.Setup.Ctx, aggregateReport)
s.NoError(err)

queryServer := keeper.NewQuerier(s.Setup.Oraclekeeper)
res, err := queryServer.GetCurrentAggregateReport(s.Setup.Ctx, &types.QueryGetCurrentAggregateReportRequest{QueryId: hex.EncodeToString(qId)})
s.NoError(err, "error getting aggregated report")
Expand Down Expand Up @@ -509,9 +510,10 @@ func (s *IntegrationTestSuite) TestTimeBasedRewardsThreeReporters() {
delegator: repAccs[2],
},
}
_, err = s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports[:3], 1)
aggregateReport, err := s.Setup.Oraclekeeper.WeightedMedian(s.Setup.Ctx, reports[:3], 1)
s.NoError(err)
err = s.Setup.Oraclekeeper.SetAggregate(s.Setup.Ctx, aggregateReport)
s.NoError(err)

queryServer := keeper.NewQuerier(s.Setup.Oraclekeeper)
res, _ := queryServer.GetCurrentAggregateReport(s.Setup.Ctx, &types.QueryGetCurrentAggregateReportRequest{QueryId: hex.EncodeToString(qId)})
tbr, _ := queryServer.GetTimeBasedRewards(s.Setup.Ctx, &types.QueryGetTimeBasedRewardsRequest{})
Expand Down Expand Up @@ -758,52 +760,6 @@ func (s *IntegrationTestSuite) TestTokenBridgeQueryDirectreveal() {
s.Equal(len(agg.Reporters), 1)
}

// func (s *IntegrationTestSuite) TestCommitQueryMixed() {
// msgServer := keeper.NewMsgServerImpl(s.Setup.Oraclekeeper)
// repAccs, _, _ := s.createValidatorAccs([]uint64{100})
// s.NoError(s.Setup.Oraclekeeper.RotateQueries(s.Setup.Ctx))
// s.NoError(s.Setup.Reporterkeeper.Reporters.Set(s.Setup.Ctx, repAccs[0], reportertypes.NewReporter(reportertypes.DefaultMinCommissionRate, math.OneInt())))
// s.NoError(s.Setup.Reporterkeeper.Selectors.Set(s.Setup.Ctx, repAccs[0], reportertypes.NewSelection(repAccs[0], 1)))
// _, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, repAccs[0])
// s.NoError(err)
// queryData1, err := s.Setup.Oraclekeeper.GetCurrentQueryInCycleList(s.Setup.Ctx)
// s.Nil(err)

// queryData2, _ := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000056D6174696300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000")
// queryData3, _ := hex.DecodeString("00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000005737465746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000")

// tipper := s.newKeysWithTokens()
// msg := types.MsgTip{
// Tipper: tipper.String(),
// QueryData: queryData2,
// Amount: sdk.NewCoin(s.Setup.Denom, math.NewInt(1000)),
// }
// _, err = msgServer.Tip(s.Setup.Ctx, &msg)
// s.Nil(err)

// userTips, err := s.Setup.Oraclekeeper.GetUserTips(s.Setup.Ctx, tipper)
// s.Nil(err)
// // tip should be 1000 minus 2% burned
// s.Equal(userTips, math.NewInt(980))
// value := "000000000000000000000000000000000000000000000058528649cf0ee0000"
// salt, err := oracleutils.Salt(32)
// s.Nil(err)
// hash := oracleutils.CalculateCommitment(value, salt)
// s.Nil(err)
// // commit report with query data in cycle list
// commit, _ := report(repAccs[0].String(), value, salt, hash, queryData1)
// _, err = msgServer.CommitReport(s.Setup.Ctx, &commit)
// s.Nil(err)
// // commit report with query data not in cycle list but has a tip
// commit, _ = report(repAccs[0].String(), value, salt, hash, queryData2)
// _, err = msgServer.CommitReport(s.Setup.Ctx, &commit)
// s.Nil(err)
// // commit report with query data not in cycle list and has no tip
// commit, _ = report(repAccs[0].String(), value, salt, hash, queryData3)
// _, err = msgServer.CommitReport(s.Setup.Ctx, &commit)
// s.ErrorContains(err, "query doesn't exist plus not a bridge deposit: not a token deposit")
// }

// test tipping a query id not in cycle list and observe the reporters' delegators stake increase in staking module
func (s *IntegrationTestSuite) TestTipQueryNotInCycleListSingleDelegator() {
require := s.Require()
Expand Down
Loading

0 comments on commit e6cff29

Please sign in to comment.