Skip to content

Commit

Permalink
fix(x/oracle): rename creation_time to creation_time_unix_ms
Browse files Browse the repository at this point in the history
  • Loading branch information
pyncz committed Nov 20, 2024
1 parent 39683cc commit 2b01f69
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 104 deletions.
9 changes: 5 additions & 4 deletions proto/archway/oracle/v1/oracle.proto
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ message DatedPrice {
(gogoproto.nullable) = false
];

/// creation_height defines the block height when price record was created
// creation_height defines the block height when price record was created
int64 creation_height = 2
[ (gogoproto.moretags) = "yaml:\"creation_height\"" ];

/// creation_time defines the block time when price record was created
uint64 creation_time = 3
[ (gogoproto.moretags) = "yaml:\"creation_time\"" ];
// creation_time_unix_ms defines the block time in milliseconds since unix epoch,
// when price record was created
uint64 creation_time_unix_ms = 3
[ (gogoproto.moretags) = "yaml:\"creation_time_unix_ms\"" ];
}

// Rewards defines a credit object towards validators
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestExportInitGenesis(t *testing.T) {
require.NoError(t, keepers.OracleKeeper.Params.Set(ctx, types.DefaultParams()))
require.NoError(t, keepers.OracleKeeper.FeederDelegations.Set(ctx, ValAddrs[0], AccAddrs[1]))
require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, "pair1:pair2", types.DatedPrice{
ExchangeRate: math.LegacyNewDec(123),
CreationHeight: 0,
CreationTime: 0,
ExchangeRate: math.LegacyNewDec(123),
CreationHeight: 0,
CreationTimeUnixMs: 0,
}))
require.NoError(t, keepers.OracleKeeper.Prevotes.Set(ctx, ValAddrs[0], types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{123}, ValAddrs[0], uint64(2))))
require.NoError(t, keepers.OracleKeeper.Votes.Set(ctx, ValAddrs[0], types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{Pair: "foo", ExchangeRate: math.LegacyNewDec(123)}}, ValAddrs[0])))
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func (k Keeper) GetExchangeRate(ctx sdk.Context, pair asset.Pair) (price math.Le
// SetPrice sets the price for a pair as well as the price snapshot.
func (k Keeper) SetPrice(ctx sdk.Context, pair asset.Pair, price math.LegacyDec) {
if err := k.ExchangeRates.Set(ctx, pair, types.DatedPrice{
ExchangeRate: price,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: price,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}); err != nil {
ctx.Logger().Error("failed to set DatedPrice", "pair", pair, "error", err)
}
Expand Down
36 changes: 18 additions & 18 deletions x/oracle/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ func TestQueryExchangeRate(t *testing.T) {

rate := math.LegacyNewDec(1700)
require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))

// empty request
Expand Down Expand Up @@ -91,14 +91,14 @@ func TestQueryExchangeRates(t *testing.T) {

rate := math.LegacyNewDec(1700)
require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))
require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))

res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{})
Expand Down Expand Up @@ -233,21 +233,21 @@ func TestQueryActives(t *testing.T) {
rate := math.LegacyNewDec(1700)

require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))

require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))

require.NoError(t, keepers.OracleKeeper.ExchangeRates.Set(ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), types.DatedPrice{
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTime: uint64(ctx.BlockTime().UnixMilli()),
ExchangeRate: rate,
CreationHeight: ctx.BlockHeight(),
CreationTimeUnixMs: uint64(ctx.BlockTime().UnixMilli()),
}))

res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{})
Expand Down
Loading

0 comments on commit 2b01f69

Please sign in to comment.