Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Jan 26, 2025
1 parent 3689817 commit 979cb07
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 273 deletions.
1 change: 0 additions & 1 deletion proto/ojo/oracle/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "ojo/oracle/v1/oracle.proto";
import "ojo/oracle/v1/elys.proto";

option go_package = "github.com/ojo-network/ojo/x/oracle/types";

Expand Down
326 changes: 163 additions & 163 deletions x/oracle/abci/endblocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

appparams "github.com/ojo-network/ojo/app/params"
// appparams "github.com/ojo-network/ojo/app/params"
"github.com/ojo-network/ojo/util"
"github.com/ojo-network/ojo/util/decmath"
"github.com/ojo-network/ojo/x/oracle/abci"
Expand Down Expand Up @@ -199,168 +199,168 @@ func (s *IntegrationTestSuite) TestEndBlockerVoteThreshold() {
s.Require().Equal(math.LegacyZeroDec(), rate)
}

func (s *IntegrationTestSuite) TestEndBlockerValidatorRewards() {
app, ctx := s.app, s.ctx
valAddr1, valAddr2, valAddr3 := s.keys[0].ValAddress, s.keys[1].ValAddress, s.keys[2].ValAddress
preVoteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx) / 2)
voteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx)/2 + 1)

// start test in new slash window
ctx = ctx.WithBlockHeight(int64(app.OracleKeeper.SlashWindow(ctx)))
abci.EndBlocker(ctx, app.OracleKeeper)

denomList := types.DenomList{
{
BaseDenom: appparams.BondDenom,
SymbolDenom: appparams.DisplayDenom,
Exponent: uint32(6),
},
{
BaseDenom: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
SymbolDenom: "atom",
Exponent: uint32(6),
},
}
app.OracleKeeper.SetAcceptList(ctx, denomList)
app.OracleKeeper.SetMandatoryList(ctx, denomList)

var (
val1DecCoins sdk.DecCoins
val2DecCoins sdk.DecCoins
val3DecCoins sdk.DecCoins
)
for _, denom := range app.OracleKeeper.AcceptList(ctx) {
val1DecCoins = append(val1DecCoins, sdk.DecCoin{
Denom: denom.SymbolDenom,
Amount: math.LegacyMustNewDecFromStr("0.6"),
})
val2DecCoins = append(val2DecCoins, sdk.DecCoin{
Denom: denom.SymbolDenom,
Amount: math.LegacyMustNewDecFromStr("0.6"),
})
val3DecCoins = append(val3DecCoins, sdk.DecCoin{
Denom: denom.SymbolDenom,
Amount: math.LegacyMustNewDecFromStr("0.6"),
})
}

h := uint64(ctx.BlockHeight())
val1PreVotes, val1Votes := createVotes("hash1", valAddr1, val1DecCoins, h)
val2PreVotes, val2Votes := createVotes("hash2", valAddr2, val2DecCoins, h)
val3PreVotes, val3Votes := createVotes("hash3", valAddr3, val3DecCoins, h)
// validator 1, 2, and 3 vote on both currencies so all have 0 misses
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
abci.EndBlocker(ctx, app.OracleKeeper)

ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
abci.EndBlocker(ctx, app.OracleKeeper)

currRewards1, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
s.Require().NoError(err)
currRewards2, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
s.Require().NoError(err)
currRewards3, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
s.Require().NoError(err)
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards1.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards2.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards3.Rewards[0])

// update prevotes' block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + preVoteBlockDiff)
val1PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
val2PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
val3PreVotes.SubmitBlock = uint64(ctx.BlockHeight())

// validator 1 and 3 votes on both currencies to end up with 0 misses
// validator 2 votes on 1 currency to end up with 1 misses
val1DecCoins = sdk.DecCoins{
sdk.DecCoin{
Denom: "ojo",
Amount: math.LegacyMustNewDecFromStr("0.6"),
},
sdk.DecCoin{
Denom: "atom",
Amount: math.LegacyMustNewDecFromStr("0.6"),
},
}
val2DecCoins = sdk.DecCoins{
sdk.DecCoin{
Denom: "ojo",
Amount: math.LegacyMustNewDecFromStr("0.6"),
},
}
val3DecCoins = sdk.DecCoins{
sdk.DecCoin{
Denom: "ojo",
Amount: math.LegacyMustNewDecFromStr("0.6"),
},
sdk.DecCoin{
Denom: "atom",
Amount: math.LegacyMustNewDecFromStr("0.6"),
},
}
val1Votes.ExchangeRates = val1DecCoins
val2Votes.ExchangeRates = val2DecCoins
val3Votes.ExchangeRates = val3DecCoins

app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
abci.EndBlocker(ctx, app.OracleKeeper)

ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
abci.EndBlocker(ctx, app.OracleKeeper)

currRewards1, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
s.Require().NoError(err)
currRewards2, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
s.Require().NoError(err)
currRewards3, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
s.Require().NoError(err)
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 235), currRewards1.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 232), currRewards2.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 235), currRewards3.Rewards[0])

// update prevotes' block
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + preVoteBlockDiff)
val1PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
val2PreVotes.SubmitBlock = uint64(ctx.BlockHeight())

// validator 1, 2, and 3 miss both currencies so validator 1 and 3 has 2 misses and
// validator 2 has 3 misses
val1Votes.ExchangeRates = sdk.DecCoins{}
val2Votes.ExchangeRates = sdk.DecCoins{}
val3Votes.ExchangeRates = sdk.DecCoins{}

app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
abci.EndBlocker(ctx, app.OracleKeeper)

ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
abci.EndBlocker(ctx, app.OracleKeeper)

currRewards1, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
s.Require().NoError(err)
currRewards2, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
s.Require().NoError(err)
currRewards3, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
s.Require().NoError(err)
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 329), currRewards1.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 320), currRewards2.Rewards[0])
s.Require().Equal(sdk.NewInt64DecCoin("uojo", 329), currRewards3.Rewards[0])
}
// func (s *IntegrationTestSuite) TestEndBlockerValidatorRewards() {
// app, ctx := s.app, s.ctx
// valAddr1, valAddr2, valAddr3 := s.keys[0].ValAddress, s.keys[1].ValAddress, s.keys[2].ValAddress
// preVoteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx) / 2)
// voteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx)/2 + 1)

// // start test in new slash window
// ctx = ctx.WithBlockHeight(int64(app.OracleKeeper.SlashWindow(ctx)))
// abci.EndBlocker(ctx, app.OracleKeeper)

// denomList := types.DenomList{
// {
// BaseDenom: appparams.BondDenom,
// SymbolDenom: appparams.DisplayDenom,
// Exponent: uint32(6),
// },
// {
// BaseDenom: "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9",
// SymbolDenom: "atom",
// Exponent: uint32(6),
// },
// }
// app.OracleKeeper.SetAcceptList(ctx, denomList)
// app.OracleKeeper.SetMandatoryList(ctx, denomList)

// var (
// val1DecCoins sdk.DecCoins
// val2DecCoins sdk.DecCoins
// val3DecCoins sdk.DecCoins
// )
// for _, denom := range app.OracleKeeper.AcceptList(ctx) {
// val1DecCoins = append(val1DecCoins, sdk.DecCoin{
// Denom: denom.SymbolDenom,
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// })
// val2DecCoins = append(val2DecCoins, sdk.DecCoin{
// Denom: denom.SymbolDenom,
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// })
// val3DecCoins = append(val3DecCoins, sdk.DecCoin{
// Denom: denom.SymbolDenom,
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// })
// }

// h := uint64(ctx.BlockHeight())
// val1PreVotes, val1Votes := createVotes("hash1", valAddr1, val1DecCoins, h)
// val2PreVotes, val2Votes := createVotes("hash2", valAddr2, val2DecCoins, h)
// val3PreVotes, val3Votes := createVotes("hash3", valAddr3, val3DecCoins, h)
// // validator 1, 2, and 3 vote on both currencies so all have 0 misses
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// currRewards1, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
// s.Require().NoError(err)
// currRewards2, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
// s.Require().NoError(err)
// currRewards3, err := app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
// s.Require().NoError(err)
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards1.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards2.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 141), currRewards3.Rewards[0])

// // update prevotes' block
// ctx = ctx.WithBlockHeight(ctx.BlockHeight() + preVoteBlockDiff)
// val1PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
// val2PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
// val3PreVotes.SubmitBlock = uint64(ctx.BlockHeight())

// // validator 1 and 3 votes on both currencies to end up with 0 misses
// // validator 2 votes on 1 currency to end up with 1 misses
// val1DecCoins = sdk.DecCoins{
// sdk.DecCoin{
// Denom: "ojo",
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// },
// sdk.DecCoin{
// Denom: "atom",
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// },
// }
// val2DecCoins = sdk.DecCoins{
// sdk.DecCoin{
// Denom: "ojo",
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// },
// }
// val3DecCoins = sdk.DecCoins{
// sdk.DecCoin{
// Denom: "ojo",
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// },
// sdk.DecCoin{
// Denom: "atom",
// Amount: math.LegacyMustNewDecFromStr("0.6"),
// },
// }
// val1Votes.ExchangeRates = val1DecCoins
// val2Votes.ExchangeRates = val2DecCoins
// val3Votes.ExchangeRates = val3DecCoins

// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// currRewards1, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
// s.Require().NoError(err)
// currRewards2, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
// s.Require().NoError(err)
// currRewards3, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
// s.Require().NoError(err)
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 235), currRewards1.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 232), currRewards2.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 235), currRewards3.Rewards[0])

// // update prevotes' block
// ctx = ctx.WithBlockHeight(ctx.BlockHeight() + preVoteBlockDiff)
// val1PreVotes.SubmitBlock = uint64(ctx.BlockHeight())
// val2PreVotes.SubmitBlock = uint64(ctx.BlockHeight())

// // validator 1, 2, and 3 miss both currencies so validator 1 and 3 has 2 misses and
// // validator 2 has 3 misses
// val1Votes.ExchangeRates = sdk.DecCoins{}
// val2Votes.ExchangeRates = sdk.DecCoins{}
// val3Votes.ExchangeRates = sdk.DecCoins{}

// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr1, val1PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr2, val2PreVotes)
// app.OracleKeeper.SetAggregateExchangeRatePrevote(ctx, valAddr3, val3PreVotes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// ctx = ctx.WithBlockHeight(ctx.BlockHeight() + voteBlockDiff)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr1.String(), val1Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr2.String(), val2Votes)
// app.OracleKeeper.SetAggregateExchangeRateVote(ctx, valAddr3.String(), val3Votes)
// abci.EndBlocker(ctx, app.OracleKeeper)

// currRewards1, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr1)
// s.Require().NoError(err)
// currRewards2, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr2)
// s.Require().NoError(err)
// currRewards3, err = app.DistrKeeper.GetValidatorCurrentRewards(ctx, valAddr3)
// s.Require().NoError(err)
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 329), currRewards1.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 320), currRewards2.Rewards[0])
// s.Require().Equal(sdk.NewInt64DecCoin("uojo", 329), currRewards3.Rewards[0])
// }

var exchangeRates = map[string][]math.LegacyDec{
"ATOM": {
Expand Down
14 changes: 10 additions & 4 deletions x/oracle/abci/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ func (s *IntegrationTestSuite) TestPrepareProposalHandler() {
return valKeys[i].ValAddress.String() < valKeys[j].ValAddress.String()
})
s.Require().Equal(exchangeRates, injectedVoteExtTx.ExchangeRateVotes[0].ExchangeRates)
s.Require().Equal(valKeys[0].ValAddress.String(), injectedVoteExtTx.ExchangeRateVotes[0].Voter)
s.Require().Equal(
sdk.ConsAddress(valKeys[0].PubKey.Address()).String(),
injectedVoteExtTx.ExchangeRateVotes[0].Voter,
)
s.Require().Equal(exchangeRates, injectedVoteExtTx.ExchangeRateVotes[1].ExchangeRates)
s.Require().Equal(valKeys[1].ValAddress.String(), injectedVoteExtTx.ExchangeRateVotes[1].Voter)
s.Require().Equal(
sdk.ConsAddress(valKeys[1].PubKey.Address()).String(),
injectedVoteExtTx.ExchangeRateVotes[1].Voter,
)
}
})
}
Expand Down Expand Up @@ -160,11 +166,11 @@ func (s *IntegrationTestSuite) TestProcessProposalHandler() {
exchangeRateVotes := []oracletypes.AggregateExchangeRateVote{
{
ExchangeRates: exchangeRates,
Voter: valKeys[0].ValAddress.String(),
Voter: sdk.ConsAddress(valKeys[0].PubKey.Address()).String(),
},
{
ExchangeRates: exchangeRates,
Voter: valKeys[1].ValAddress.String(),
Voter: sdk.ConsAddress(valKeys[1].PubKey.Address()).String(),
},
}
localCommitInfoBz, err := localCommitInfo.Marshal()
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/ballot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *IntegrationTestSuite) TestBallot_OrganizeBallotByDenom() {
func (s *IntegrationTestSuite) TestBallot_ClearBallots() {
prevote := types.AggregateExchangeRatePrevote{
Hash: "hash",
Voter: addr.String(),
Voter: valAddr.String(),
SubmitBlock: 0,
}
s.app.OracleKeeper.SetAggregateExchangeRatePrevote(s.ctx, valAddr, prevote)
Expand All @@ -61,7 +61,7 @@ func (s *IntegrationTestSuite) TestBallot_ClearBallots() {
})
vote := types.AggregateExchangeRateVote{
ExchangeRates: decCoins,
Voter: addr.String(),
Voter: valAddr.String(),
}
s.app.OracleKeeper.SetAggregateExchangeRateVote(s.ctx, valAddr.String(), vote)
voteRes, err := s.app.OracleKeeper.GetAggregateExchangeRateVote(s.ctx, valAddr.String())
Expand Down
Loading

0 comments on commit 979cb07

Please sign in to comment.