Skip to content

Commit

Permalink
fix: QueryGetSecondarySpStorePriceByTime return data of other SPs in …
Browse files Browse the repository at this point in the history
…some cases (#263)
  • Loading branch information
owen-reorg authored May 25, 2023
1 parent 102ed9a commit 3cb644a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions e2e/tests/sp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ func (s *StorageProviderTestSuite) TestSpStoragePrice() {
s.Require().Equal(newReadPrice, spStoragePrice2.SpStoragePrice.ReadPrice)
s.Require().Equal(newStorePrice, spStoragePrice2.SpStoragePrice.StorePrice)
s.CheckSecondarySpPrice()
// query sp storage price by time before it exists, expect error
_, err = s.Client.QueryGetSecondarySpStorePriceByTime(ctx, &sptypes.QueryGetSecondarySpStorePriceByTimeRequest{
Timestamp: 1,
})
s.Require().Error(err)
_, err = s.Client.QueryGetSpStoragePriceByTime(ctx, &sptypes.QueryGetSpStoragePriceByTimeRequest{
SpAddr: spAddr,
Timestamp: 1,
})
s.Require().Error(err)
}

func (s *StorageProviderTestSuite) CheckSecondarySpPrice() {
Expand Down
5 changes: 4 additions & 1 deletion x/sp/keeper/sp_storage_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ func (k Keeper) GetSpStoragePriceByTime(
return val, fmt.Errorf("no price found")
}

spAddrRes, UpdateTimeSec := types.ParseSpStoragePriceKey(iterator.Key())
if !spAddrRes.Equals(spAddr) {
return val, fmt.Errorf("no price found")
}
k.cdc.MustUnmarshal(iterator.Value(), &val)
_, UpdateTimeSec := types.ParseSpStoragePriceKey(iterator.Key())
val.SpAddress = spAddr.String()
val.UpdateTimeSec = UpdateTimeSec

Expand Down

0 comments on commit 3cb644a

Please sign in to comment.