Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

cidgravity: adjust to new api change #104

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions service/pricing/cid_gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type rawRules struct {
DealRateLimit int
CurrentDealRate int
PricingRules []struct {
Verified bool
Verified string
MinSize uint64 // bytes
MaxSize uint64 // bytes
MinDuration uint64 // epoches
Expand Down Expand Up @@ -119,9 +119,9 @@ func (cg *clientRules) PricesFor(auction *pb.Auction) (prices ResolvedPrices, va
for _, r := range rules.PricingRules {
if auction.DealSize >= r.MinSize && auction.DealSize <= r.MaxSize &&
auction.DealDuration >= r.MinDuration && auction.DealDuration <= r.MaxDuration {
if r.Verified && !prices.VerifiedPriceValid {
if (r.Verified == "true" || r.Verified == "any") && !prices.VerifiedPriceValid {
prices.VerifiedPriceValid, prices.VerifiedPrice = true, r.Price
} else if !prices.UnverifiedPriceValid {
} else if (r.Verified == "false" || r.Verified == "any") && !prices.UnverifiedPriceValid {
prices.UnverifiedPriceValid, prices.UnverifiedPrice = true, r.Price
}
if prices.VerifiedPriceValid && prices.UnverifiedPriceValid {
Expand Down
16 changes: 8 additions & 8 deletions service/pricing/cid_gravity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ func TestPriceFor(t *testing.T) {
cidGravityCachePeriod = time.Second
rules := &rawRules{
PricingRules: []struct {
Verified bool
Verified string
MinSize uint64
MaxSize uint64
MinDuration uint64
MaxDuration uint64
Price int64
}{
{
Verified: false, Price: 100,
Verified: "false", Price: 100,
MinSize: 2 << 20, MaxSize: 2<<30 - 1,
MinDuration: 1, MaxDuration: 2 << 10,
},
{
Verified: false, Price: 10,
Verified: "false", Price: 10,
MinSize: 2 << 30, MaxSize: 2<<40 - 1,
MinDuration: 1, MaxDuration: 2 << 10,
},
{
Verified: false, Price: 1000,
Verified: "false", Price: 1000,
MinSize: 2 << 30, MaxSize: 2<<40 - 1,
MinDuration: 2 >> 10, MaxDuration: 2 << 30,
},
{
Verified: true, Price: 1,
Verified: "true", Price: 1,
MinSize: 1, MaxSize: 2<<30 - 1,
MinDuration: 1, MaxDuration: 2 << 10,
},
{
Verified: true, Price: 0,
Verified: "true", Price: 0,
MinSize: 2 << 30, MaxSize: 2<<40 - 1,
MinDuration: 1, MaxDuration: 2 << 10,
},
{
Verified: true, Price: 100,
Verified: "true", Price: 100,
MinSize: 2 << 30, MaxSize: 2<<40 - 1,
MinDuration: 2 >> 10, MaxDuration: 2 << 30,
},
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestMaybeReloadRules(t *testing.T) {
apiResponse := []byte(`{
"pricingRules": [
{
"verified": false,
"verified": "false",
"minSize": 1,
"maxSize": 2,
"minDuration": 1,
Expand Down