Skip to content

Commit

Permalink
Increase Report Window Time (#352) (#354)
Browse files Browse the repository at this point in the history
* changed submit window offset from 3s to 6s. Changed SpotPrice ReportBufferWindow from 3s to 6s

* commented out failing tests so that github actions will pass and we can test out the changes

* test: report buffer window change test fixes (#353)

* e2e dispute test fix

* e2e report test fix

* fix integration tests

---------

Co-authored-by: Dan F <[email protected]>
(cherry picked from commit 5e5d3ab)

Co-authored-by: CJPotter10 <[email protected]>
  • Loading branch information
github-actions[bot] and CJPotter10 authored Sep 26, 2024
1 parent 8664aaa commit 08920de
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
6 changes: 3 additions & 3 deletions tests/e2e/basic_dispute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *E2ETestSuite) TestDisputes() {
require.NoError(err)
require.NotNil(revealResponse)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, err = s.Setup.App.EndBlocker(s.Setup.Ctx)
require.NoError(err)
// get queryId for GetAggregatedReportRequest
Expand Down Expand Up @@ -279,7 +279,7 @@ func (s *E2ETestSuite) TestDisputes() {
require.NoError(err)
require.NotNil(revealResponse)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, err = s.Setup.App.EndBlocker(s.Setup.Ctx)
require.NoError(err)
// get queryId for GetAggregatedReportRequest
Expand Down Expand Up @@ -450,7 +450,7 @@ func (s *E2ETestSuite) TestDisputes() {
require.NoError(err)
require.NotNil(revealResponse)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, err = s.Setup.App.EndBlocker(s.Setup.Ctx)
require.NoError(err)
// get queryId for GetAggregatedReportRequest
Expand Down
17 changes: 9 additions & 8 deletions tests/e2e/basic_reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (s *E2ETestSuite) TestBasicReporting() {
require.NoError(err)
require.NotNil(revealResponse1)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
s.NoError(s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx))

Expand Down Expand Up @@ -241,8 +241,8 @@ func (s *E2ETestSuite) TestBasicReporting() {

// check that 8 sec of tbr has been minted
tbrModuleAccountBalance = s.Setup.Bankkeeper.GetBalance(s.Setup.Ctx, tbrModuleAccount, s.Setup.Denom)
expectedBlockProvision = int64(146940000 * (8 * time.Second) / (24 * 60 * 60 * 1000))
expectedTbr = sdk.NewCoin(s.Setup.Denom, math.NewInt((expectedBlockProvision)).MulRaw(75).QuoRaw(100).Quo(sdk.DefaultPowerReduction))
expectedBlockProvision = int64(146940000 * (22 * time.Second) / (24 * 60 * 60 * 1000))
expectedTbr = sdk.NewCoin(s.Setup.Denom, (math.NewInt((expectedBlockProvision)).MulRaw(75).QuoRaw(100).Quo(sdk.DefaultPowerReduction)).Add(math.NewInt(1)))

require.Equal(expectedTbr, tbrModuleAccountBalance)

Expand All @@ -264,7 +264,7 @@ func (s *E2ETestSuite) TestBasicReporting() {
require.NoError(err)
require.NotNil(revealResponse2)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
s.NoError(s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx))

Expand Down Expand Up @@ -382,7 +382,7 @@ func (s *E2ETestSuite) TestBasicReporting() {
require.NotNil(revealResponse1)

// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
s.NoError(s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx))

Expand Down Expand Up @@ -417,7 +417,8 @@ func (s *E2ETestSuite) TestBasicReporting() {
// check that reporter now has more bonded tokens
deleAfter, err := s.Setup.Stakingkeeper.Delegation(s.Setup.Ctx, reporterAccount.Bytes(), valBz)
require.NoError(err)
require.Equal(deleBeforeReport.GetShares().Add(math.LegacyNewDec(98+8928)), deleAfter.GetShares())
tipPlusTbr := math.NewInt(98 + 26786)
require.Equal(deleBeforeReport.GetShares().Add(math.LegacyNewDecFromInt(tipPlusTbr)), deleAfter.GetShares())

_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
s.NoError(s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx))
Expand All @@ -433,7 +434,7 @@ func (s *E2ETestSuite) TestBasicReporting() {
// check reporter starting shares
deleBeforeReport2, err := s.Setup.Stakingkeeper.Delegation(s.Setup.Ctx, reporterAccount.Bytes(), valBz)
require.NoError(err)
tipPlusTbr := math.NewInt(98 + 8928)

twoPercentTip := sdk.NewCoin(s.Setup.Denom, tipAmount.Amount.Mul(math.NewInt(2)).Quo(math.NewInt(100)))
twoPercentTipPlusTbr := sdk.NewCoin(s.Setup.Denom, tipAmount.Amount.Mul(math.NewInt(2)).Quo(math.NewInt(tipPlusTbr.Int64())))
expectedShares := math.LegacyNewDecFromInt(deleBeforeReport.GetShares().TruncateInt().Add(tipPlusTbr)) // 8928 is the tbr that was earned
Expand Down Expand Up @@ -464,7 +465,7 @@ func (s *E2ETestSuite) TestBasicReporting() {
require.NoError(err)
require.NotNil(revealTrb)
// advance time and block height to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(7 * time.Second))
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(21 * time.Second))
_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
s.NoError(s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx))
// create get aggregated report query
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/oracle_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *IntegrationTestSuite) TestTippingReporting() {
_, err = msgServer.SubmitValue(s.Setup.Ctx, &reveal)
s.Nil(err)
// advance time to expire the query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 7)) // bypassing offset that expires time to commit/reveal
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 17)) // bypassing offset that expires time to commit/reveal
err = s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx)
s.Nil(err)

Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *IntegrationTestSuite) TestMedianReports() {
})
}
// advance time to expire query and aggregate report
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 7)) // bypass time to expire query so it can be aggregated
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 17)) // bypass time to expire query so it can be aggregated
_, err = s.Setup.App.BeginBlocker(s.Setup.Ctx)
s.Nil(err)
_, _ = s.Setup.App.EndBlocker(s.Setup.Ctx)
Expand Down Expand Up @@ -672,7 +672,7 @@ func (s *IntegrationTestSuite) TestTokenBridgeQuery() {
_, _ = app.EndBlocker(ctx)

// time plus offset
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Second * 4)})
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Second * 11)})
_, err = app.BeginBlocker(ctx)
s.NoError(err)
_, _ = app.EndBlocker(ctx)
Expand All @@ -699,7 +699,7 @@ func (s *IntegrationTestSuite) TestTokenBridgeQuery() {
s.NoError(err)
_, _ = app.EndBlocker(ctx)

ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Hour + time.Second*4)})
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Hour + time.Second*11)})

_, err = app.BeginBlocker(ctx)
s.NoError(err)
Expand Down Expand Up @@ -790,7 +790,7 @@ func (s *IntegrationTestSuite) TestTokenBridgeQueryDirectreveal() {
_, _ = app.EndBlocker(ctx)

// time plus offset
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Second * 4)})
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Second * 11)})
_, err = app.BeginBlocker(ctx)
s.NoError(err)
_, _ = app.EndBlocker(ctx)
Expand All @@ -808,7 +808,7 @@ func (s *IntegrationTestSuite) TestTokenBridgeQueryDirectreveal() {
s.NoError(err)
_, _ = app.EndBlocker(ctx)

ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Hour + time.Second*4)})
ctx = ctx.WithBlockHeader(cmtproto.Header{Height: ctx.BlockHeight() + 1, Time: ctx.BlockTime().Add(time.Hour + time.Second*11)})

_, err = app.BeginBlocker(ctx)
s.NoError(err)
Expand Down Expand Up @@ -907,7 +907,7 @@ func (s *IntegrationTestSuite) TestTipQueryNotInCycleListSingleDelegator() {
s.Nil(s.Setup.Oraclekeeper.Query.Set(s.Setup.Ctx, collections.Join(queryId, query.Id), query))
err = s.Setup.Oraclekeeper.Reports.Set(s.Setup.Ctx, collections.Join3(queryId, repAccs[0].Bytes(), query.Id), reports[0])
s.Nil(err)
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 7)) // bypassing offset that expires time to commit/reveal
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 17)) // bypassing offset that expires time to commit/reveal
err = s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx)
s.Nil(err)

Expand Down Expand Up @@ -987,7 +987,7 @@ func (s *IntegrationTestSuite) TestTipQueryNotInCycleListTwoDelegators() {
s.Nil(err)
err = s.Setup.Oraclekeeper.Reports.Set(s.Setup.Ctx, collections.Join3(queryId, repAccs[1].Bytes(), query.Id), reports[1])
s.Nil(err)
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 7)) // bypassing offset that expires time to commit/reveal
s.Setup.Ctx = s.Setup.Ctx.WithBlockTime(s.Setup.Ctx.BlockTime().Add(time.Second * 17)) // bypassing offset that expires time to commit/reveal
err = s.Setup.Oraclekeeper.SetAggregatedReport(s.Setup.Ctx)
s.Nil(err)

Expand Down
10 changes: 5 additions & 5 deletions tests/integration/tipping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ func (s *IntegrationTestSuite) TestTipQueryInCycle() {
// get query
query, err = okpr.CurrentQuery(ctx, utils.QueryIDFromData(btcQueryData))
s.NoError(err)
s.Equal(math.NewInt(980_000), query.Amount) // 2% burn
s.True(query.Expiration.After(ctx.BlockTime()))
s.Equal(math.NewInt(980_000), query.Amount) // 2% burn
s.True(query.Expiration.After(ctx.BlockTime())) // not expired
s.Equal(expiration, query.Expiration)

// ----------------
// next block
ctx, err = simtestutil.NextBlock(app, ctx, time.Second+1) // eth query data
ctx, err = simtestutil.NextBlock(app, ctx, ((time.Second * 10) + 1)) // eth query data
s.NoError(err)
// assert height is 3
s.Equal(int64(3), ctx.BlockHeight())

// check query
query, err = okpr.CurrentQuery(ctx, utils.QueryIDFromData(btcQueryData))
s.NoError(err)
Expand All @@ -97,5 +97,5 @@ func (s *IntegrationTestSuite) TestTipQueryInCycle() {
query, err = okpr.CurrentQuery(ctx, utils.QueryIDFromData(btcQueryData))
s.NoError(err)
s.Equal(math.NewInt(980_000), query.Amount) // 2% burn
s.True(query.Expiration.Before(ctx.BlockTime())) // expired commit time window but still has 3 seconds left in reveal time window
s.True(query.Expiration.Before(ctx.BlockTime())) // expired commit time window
}
2 changes: 1 addition & 1 deletion x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var offset = time.Second * 3
var offset = time.Second * 6

type (
Keeper struct {
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/submit_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *KeeperTestSuite) TestGetDataSpec() {
require.Equal(spec.DocumentHash, "")
require.Equal(spec.AggregationMethod, "weighted-median")
require.Equal(spec.Registrar, "genesis")
require.Equal(spec.ReportBufferWindow, time.Second*2)
require.Equal(spec.ReportBufferWindow, time.Second*10)
require.Equal(spec.ResponseValueType, "uint256")

regK.On("GetSpec", ctx, "BadQueryType").Return(regtypes.GenesisDataSpec(), errors.New("not found")).Once()
Expand Down
2 changes: 1 addition & 1 deletion x/registry/types/dataspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GenesisDataSpec() DataSpec {
},
AggregationMethod: "weighted-median",
Registrar: "genesis",
ReportBufferWindow: time.Second * 2,
ReportBufferWindow: time.Second * 10,
}
}

Expand Down

0 comments on commit 08920de

Please sign in to comment.