Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OME Tests #91

Merged
merged 3 commits into from
Sep 5, 2018
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
2 changes: 1 addition & 1 deletion cmd/darknode/darknode.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func main() {
gen := ome.NewComputationGenerator(config.Address, store.SomerOrderFragmentStore())
matcher := ome.NewMatcher(store.SomerComputationStore(), smpcer)
confirmer := ome.NewConfirmer(store.SomerComputationStore(), &contractBinder, 5*time.Second, 2)
settler := ome.NewSettler(store.SomerComputationStore(), smpcer, &contractBinder)
settler := ome.NewSettler(store.SomerComputationStore(), smpcer, &contractBinder, 1)
ome := ome.NewOme(config.Address, gen, matcher, confirmer, settler, store.SomerComputationStore(), orderbook, smpcer, epoch)

dispatch.CoBegin(func() {
Expand Down
2 changes: 1 addition & 1 deletion ome/ome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("Ome", func() {
Expect(err).ShouldNot(HaveOccurred())
matcher = NewMatcher(storer, smpcer)
confirmer = NewConfirmer(storer, contract, PollInterval, Depth)
settler = NewSettler(storer, smpcer, contract)
settler = NewSettler(storer, smpcer, contract, 0)
})

AfterEach(func() {
Expand Down
18 changes: 10 additions & 8 deletions ome/settler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ type Settler interface {
}

type settler struct {
computationStore ComputationStorer
smpcer smpc.Smpcer
contract ContractBinder
computationStore ComputationStorer
smpcer smpc.Smpcer
contract ContractBinder
minimumSettleVolume float64
}

// NewSettler returns a Settler that settles orders by first using an
// smpc.Smpcer to join all of the composing order.Fragments, and then submits
// them to an Ethereum contract.
func NewSettler(computationStore ComputationStorer, smpcer smpc.Smpcer, contract ContractBinder) Settler {
func NewSettler(computationStore ComputationStorer, smpcer smpc.Smpcer, contract ContractBinder, minimumSettleVolume float64) Settler {
return &settler{
computationStore: computationStore,
smpcer: smpcer,
contract: contract,
computationStore: computationStore,
smpcer: smpcer,
contract: contract,
minimumSettleVolume: minimumSettleVolume,
}
}

Expand Down Expand Up @@ -125,7 +127,7 @@ func (settler *settler) settleOrderMatch(com Computation, buy, sell order.Order)
// Leave the orders if volume is too low and there is no profit for
// submitting such orders. Note: minimum volume is set to 1 ETH.
settleVolume := volumeInEth(buy, sell)
if settleVolume < 1 {
if settleVolume < settler.minimumSettleVolume {
log.Printf("[info] (settle) cannot execute settlement buy = %v, sell = %v: volume = %f ETH too low", buy.ID, sell.ID, settleVolume)
return
}
Expand Down
6 changes: 3 additions & 3 deletions ome/settler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ = Describe("Settler", func() {
storers[i] = storer.SomerComputationStore()
smpcers[i] = testutils.NewAlwaysMatchSmpc()
contracts[i] = newOmeBinder()
settles[i] = NewSettler(storers[i], smpcers[i], contracts[i])
settles[i] = NewSettler(storers[i], smpcers[i], contracts[i], 0)
}
})

Expand All @@ -40,7 +40,7 @@ var _ = Describe("Settler", func() {
}
})

/* Context("when a computation has been resolved to a match and been confirmed ", func() {
Context("when a computation has been resolved to a match and been confirmed ", func() {
It("should be able to reconstruct the order and settle it.", func() {
buyFragments, err := testutils.RandomBuyOrderFragments(int64(NumberOfNodes), int64(2*(NumberOfNodes+1)/3))
Expect(err).ShouldNot(HaveOccurred())
Expand All @@ -59,5 +59,5 @@ var _ = Describe("Settler", func() {
Expect(contracts[i].SettleCounts()).Should(Equal(1))
}
})
}) */
})
})
4 changes: 2 additions & 2 deletions smpc/joiner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Joiner", func() {
})
})

/* Context("when inserting computed joins", func() {
Context("when inserting computed joins", func() {
It("should pass the computed values to the callback", func() {
joins := generateMatchedJoins(n, k)
called := int64(0)
Expand All @@ -117,7 +117,7 @@ var _ = Describe("Joiner", func() {
}
}
})
}) */
})
})

Context("when marshaling and unmarshaling joins", func() {
Expand Down
6 changes: 4 additions & 2 deletions testutils/rand_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func RandomOrderMatch() (order.Order, order.Order) {
order.TokensDGXREN,
}[rand.Intn(4)]

buy := order.NewOrder(order.ParityBuy, order.TypeLimit, time.Now().Add(1*time.Hour), order.SettlementRenEx, tokens, rand.Uint64(), rand.Uint64(), 0, uint64(rand.Int63()))
sell := order.NewOrder(order.ParitySell, order.TypeLimit, time.Now().Add(1*time.Hour), order.SettlementRenEx, tokens, rand.Uint64(), rand.Uint64(), 0, uint64(rand.Int63()))
price := rand.Uint64()
volume := rand.Uint64()
buy := order.NewOrder(order.ParityBuy, order.TypeLimit, time.Now().Add(1*time.Hour), order.SettlementRenEx, tokens, price, volume, 0, uint64(rand.Int63()))
sell := order.NewOrder(order.ParitySell, order.TypeLimit, time.Now().Add(1*time.Hour), order.SettlementRenEx, tokens, price, volume, 0, uint64(rand.Int63()))
return buy, sell
}

Expand Down