From 3cb644a217311f12772d9fd332c4e99f765d93c4 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 25 May 2023 19:28:40 +0800 Subject: [PATCH] fix: QueryGetSecondarySpStorePriceByTime return data of other SPs in some cases (#263) --- e2e/tests/sp_test.go | 10 ++++++++++ x/sp/keeper/sp_storage_price.go | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/e2e/tests/sp_test.go b/e2e/tests/sp_test.go index 0d350d9ac..e1513a663 100644 --- a/e2e/tests/sp_test.go +++ b/e2e/tests/sp_test.go @@ -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() { diff --git a/x/sp/keeper/sp_storage_price.go b/x/sp/keeper/sp_storage_price.go index 570ac4ac7..ee1d03165 100644 --- a/x/sp/keeper/sp_storage_price.go +++ b/x/sp/keeper/sp_storage_price.go @@ -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