Skip to content

Commit

Permalink
Add query id arg to ReporterStake (#437)
Browse files Browse the repository at this point in the history
* make queryId part of key to report collections

* fix and cleanup test

* remove unnecessary arg on `SlashAndJailReporter`
  • Loading branch information
akremstudy authored Nov 18, 2024
1 parent 8d186c5 commit a200b38
Show file tree
Hide file tree
Showing 31 changed files with 706 additions and 589 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
18 changes: 9 additions & 9 deletions tests/e2e/dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *E2ETestSuite) TestDisputes() {
require.Equal(reporter.Jailed, false)
freeFloatingBalanceBefore := s.Setup.Bankkeeper.GetBalance(s.Setup.Ctx, reporterAccount, s.Setup.Denom)

balBeforeDispute, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount)
balBeforeDispute, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount, []byte{})
require.NoError(err)
onePercent := balBeforeDispute.Mul(math.NewInt(1)).Quo(math.NewInt(100))
disputeFee := sdk.NewCoin(s.Setup.Denom, onePercent) // warning should be 1% of bonded tokens
Expand Down Expand Up @@ -370,7 +370,7 @@ func (s *E2ETestSuite) TestDisputes() {
_, err = s.Setup.App.BeginBlocker(s.Setup.Ctx)
require.NoError(err)

balBeforeDispute, err = s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount)
balBeforeDispute, err = s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount, queryId)
fmt.Println("Balance before dispute: ", balBeforeDispute)
require.NoError(err)
fivePercent := balBeforeDispute.Mul(math.NewInt(5)).Quo(math.NewInt(100))
Expand Down Expand Up @@ -551,7 +551,7 @@ func (s *E2ETestSuite) TestDisputes() {
require.NoError(err)
require.Equal(reporter.Jailed, false)

oneHundredPercent, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount)
oneHundredPercent, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, reporterAccount, queryId)
require.NoError(err)
disputeFee = sdk.NewCoin(s.Setup.Denom, oneHundredPercent)

Expand Down Expand Up @@ -853,7 +853,7 @@ func (s *E2ETestSuite) TestDisputeFromDelegatorPayFromBond() {
_, err = s.Setup.App.BeginBlocker(s.Setup.Ctx)
require.NoError(err)

rickyReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, rickyAccAddr)
rickyReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, rickyAccAddr, queryId)
require.NoError(err)

report := oracletypes.MicroReport{
Expand Down Expand Up @@ -926,15 +926,15 @@ func (s *E2ETestSuite) TestOpenDisputePrecision() {
_, err = s.Setup.CreateReporter(ctx, annaAccAddr, reportertypes.DefaultMinCommissionRate, math.NewInt(1*1e6))
require.NoError(err)
// verify anna's reporter power
annaReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(ctx, annaAccAddr)
annaReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(ctx, annaAccAddr, []byte{})
require.NoError(err)
require.Equal(math.NewInt(annaInitialStake).String(), annaReporterStake.String())

// bob becomes a reporter
_, err = s.Setup.CreateReporter(ctx, bobAccAddr, reportertypes.DefaultMinCommissionRate, math.NewInt(1*1e6))
require.NoError(err)
// verify bobs reporter power
bobReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(ctx, bobAccAddr)
bobReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(ctx, bobAccAddr, []byte{})
require.NoError(err)
require.Equal(math.NewInt(bobInitialStake).String(), bobReporterStake.String())

Expand Down Expand Up @@ -974,7 +974,7 @@ func (s *E2ETestSuite) TestOpenDisputePrecision() {
require.NoError(err)
require.Equal(randomAmountLoya, chrisDelegation.GetShares().TruncateInt64())
// check on selection from chris to anna reporter
annaReporterStake, err = s.Setup.Reporterkeeper.ReporterStake(ctx, annaAccAddr)
annaReporterStake, err = s.Setup.Reporterkeeper.ReporterStake(ctx, annaAccAddr, []byte{})
require.NoError(err)
expectedAnnaPower := math.NewInt(randomAmountLoya).Add(math.NewInt(annaInitialStake))
require.Equal(expectedAnnaPower.String(), annaReporterStake.String())
Expand Down Expand Up @@ -1169,7 +1169,7 @@ func (s *E2ETestSuite) TestDisputes2() {

val, err := s.Setup.Stakingkeeper.GetValidator(s.Setup.Ctx, valsValAddrs[0])
require.NoError(err)
repTokens, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, badReporter)
repTokens, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, badReporter, []byte{})
require.NoError(err)
require.Equal(repTokens, val.Tokens)

Expand Down Expand Up @@ -1341,7 +1341,7 @@ func (s *E2ETestSuite) TestDisputes2() {
report = oracletypes.MicroReport{
Reporter: repsAccs[0].String(),
Power: repTokens.Quo(sdk.DefaultPowerReduction).Uint64(),
QueryId: queryId,
QueryId: utils.QueryIDFromData(reveal.QueryData),
Value: value,
Timestamp: revealTime,
BlockNumber: uint64(revealBlock),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (s *E2ETestSuite) TestSetUpValidatorAndReporter() {
require.NoError(err)
val, err := s.Setup.Stakingkeeper.GetValidator(s.Setup.Ctx, valAddr)
require.NoError(err)
oracleReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, valAddr.Bytes())
oracleReporterStake, err := s.Setup.Reporterkeeper.ReporterStake(s.Setup.Ctx, valAddr.Bytes(), []byte{})
require.NoError(err)
require.Equal(oracleReporterStake, val.Tokens)
require.Equal(oracleReporter.Jailed, false)
Expand Down
Loading

0 comments on commit a200b38

Please sign in to comment.