Skip to content

Commit

Permalink
address the first review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Sep 20, 2023
1 parent 929d49d commit fe010f8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
7 changes: 2 additions & 5 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ func IntegrationTestNetworkConfig() network.Config {
// execute ballot voting and thus clear out previous exchange rates, since we
// are not running a price-feeder.
oracleGenState.Params.VotePeriod = 1000
oracleGenState.ExchangeRates = append(oracleGenState.ExchangeRates, oracletypes.ExchangeRate{
Denom: params.DisplayDenom,
Rate: sdk.MustNewDecFromStr("34.21"),
Timestamp: time.Now(),
})
oracleGenState.ExchangeRates = append(oracleGenState.ExchangeRates, oracletypes.NewExchangeRate(
params.DisplayDenom, sdk.MustNewDecFromStr("34.21"), time.Now()))
// Set mock historic medians to satisfy leverage module's 24 median requirement
for i := 1; i <= 24; i++ {
median := oracletypes.Price{
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CalcPrices(ctx sdk.Context, params types.Params, k keeper.Keeper) error {
return err
}
// save the exchange rate to store with denom and timestamp
k.SetExchangeRateWithEvent(ctx, denom, exchangeRate, ctx.BlockTime())
k.SetExchangeRateWithEvent(ctx, denom, exchangeRate)

if k.IsPeriodLastBlock(ctx, params.HistoricStampPeriod) {
k.AddHistoricPrice(ctx, denom, exchangeRate)
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (k Keeper) SetExchangeRate(ctx sdk.Context, denom string, rate sdk.Dec, t t

// SetExchangeRateWithEvent sets an consensus
// exchange rate to the store with ABCI event
func (k Keeper) SetExchangeRateWithEvent(ctx sdk.Context, denom string, rate sdk.Dec, t time.Time) {
k.SetExchangeRate(ctx, denom, rate, t)
func (k Keeper) SetExchangeRateWithEvent(ctx sdk.Context, denom string, rate sdk.Dec) {
k.SetExchangeRate(ctx, denom, rate, ctx.BlockTime())
sdkutil.Emit(&ctx, &types.EventSetFxRate{
Denom: denom, Rate: rate,
})
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (s *IntegrationTestSuite) TestAggregateExchangeRateVoteError() {

func (s *IntegrationTestSuite) TestSetExchangeRateWithEvent() {
v := sdk.OneDec()
s.app.OracleKeeper.SetExchangeRateWithEvent(s.ctx, displayDenom, v, s.ctx.BlockTime())
s.app.OracleKeeper.SetExchangeRateWithEvent(s.ctx, displayDenom, v)
rate, err := s.app.OracleKeeper.GetExchangeRate(s.ctx, displayDenom)
s.Require().NoError(err)
s.Require().Equal(rate, types.ExchangeRate{Rate: v, Timestamp: s.ctx.BlockTime(), Denom: displayDenom})
Expand Down
16 changes: 16 additions & 0 deletions x/oracle/types/exchange_rates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package types

import (
time "time"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// NewExchangeRate creates a ExchangeRate instance
func NewExchangeRate(denom string, exchangeRate sdk.Dec, t time.Time) ExchangeRate {
return ExchangeRate{
Denom: denom,
Rate: exchangeRate,
Timestamp: t,
}
}

0 comments on commit fe010f8

Please sign in to comment.