[sales] Use Clock instead of getTime()
This commit is contained in:
parent
1e44ed5fd3
commit
3a8ce485e4
|
@ -35,7 +35,7 @@ proc new*(_: type ContractInteractions,
|
||||||
let clock = OnChainClock.new(signer.provider)
|
let clock = OnChainClock.new(signer.provider)
|
||||||
some ContractInteractions(
|
some ContractInteractions(
|
||||||
purchasing: Purchasing.new(market, clock),
|
purchasing: Purchasing.new(market, clock),
|
||||||
sales: Sales.new(market),
|
sales: Sales.new(market, clock),
|
||||||
proving: Proving.new(proofs, clock),
|
proving: Proving.new(proofs, clock),
|
||||||
clock: clock
|
clock: clock
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import std/times
|
|
||||||
import std/sequtils
|
import std/sequtils
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import pkg/upraises
|
import pkg/upraises
|
||||||
|
@ -6,6 +5,7 @@ import pkg/stint
|
||||||
import pkg/nimcrypto
|
import pkg/nimcrypto
|
||||||
import pkg/chronicles
|
import pkg/chronicles
|
||||||
import ./market
|
import ./market
|
||||||
|
import ./clock
|
||||||
|
|
||||||
export stint
|
export stint
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ const DefaultOfferExpiryInterval = (10 * 60).u256
|
||||||
type
|
type
|
||||||
Sales* = ref object
|
Sales* = ref object
|
||||||
market: Market
|
market: Market
|
||||||
|
clock: Clock
|
||||||
subscription: ?Subscription
|
subscription: ?Subscription
|
||||||
available*: seq[Availability]
|
available*: seq[Availability]
|
||||||
offerExpiryInterval*: UInt256
|
offerExpiryInterval*: UInt256
|
||||||
|
@ -34,8 +35,12 @@ type
|
||||||
finished: bool
|
finished: bool
|
||||||
OnSale = proc(offer: StorageOffer) {.gcsafe, upraises: [].}
|
OnSale = proc(offer: StorageOffer) {.gcsafe, upraises: [].}
|
||||||
|
|
||||||
func new*(_: type Sales, market: Market): Sales =
|
func new*(_: type Sales, market: Market, clock: Clock): Sales =
|
||||||
Sales(market: market, offerExpiryInterval: DefaultOfferExpiryInterval)
|
Sales(
|
||||||
|
market: market,
|
||||||
|
clock: clock,
|
||||||
|
offerExpiryInterval: DefaultOfferExpiryInterval
|
||||||
|
)
|
||||||
|
|
||||||
proc init*(_: type Availability,
|
proc init*(_: type Availability,
|
||||||
size: UInt256,
|
size: UInt256,
|
||||||
|
@ -62,10 +67,11 @@ func findAvailability(sales: Sales, ask: StorageAsk): ?Availability =
|
||||||
return some availability
|
return some availability
|
||||||
|
|
||||||
proc createOffer(negotiation: Negotiation): StorageOffer =
|
proc createOffer(negotiation: Negotiation): StorageOffer =
|
||||||
|
let sales = negotiation.sales
|
||||||
StorageOffer(
|
StorageOffer(
|
||||||
requestId: negotiation.requestId,
|
requestId: negotiation.requestId,
|
||||||
price: negotiation.ask.maxPrice,
|
price: negotiation.ask.maxPrice,
|
||||||
expiry: getTime().toUnix().u256 + negotiation.sales.offerExpiryInterval
|
expiry: sales.clock.now().u256 + sales.offerExpiryInterval
|
||||||
)
|
)
|
||||||
|
|
||||||
proc sendOffer(negotiation: Negotiation) {.async.} =
|
proc sendOffer(negotiation: Negotiation) {.async.} =
|
||||||
|
|
|
@ -3,6 +3,7 @@ import pkg/asynctest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/dagger/sales
|
import pkg/dagger/sales
|
||||||
import ./helpers/mockmarket
|
import ./helpers/mockmarket
|
||||||
|
import ./helpers/mockclock
|
||||||
import ./examples
|
import ./examples
|
||||||
|
|
||||||
suite "Sales":
|
suite "Sales":
|
||||||
|
@ -20,10 +21,12 @@ suite "Sales":
|
||||||
|
|
||||||
var sales: Sales
|
var sales: Sales
|
||||||
var market: MockMarket
|
var market: MockMarket
|
||||||
|
var clock: MockClock
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
market = MockMarket.new()
|
market = MockMarket.new()
|
||||||
sales = Sales.new(market)
|
clock = MockClock.new()
|
||||||
|
sales = Sales.new(market, clock)
|
||||||
await sales.start()
|
await sales.start()
|
||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
|
|
Loading…
Reference in New Issue