-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First cut. Fixing integration and deployment code next
- Loading branch information
Showing
4 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
pragma solidity 0.4.20; | ||
|
||
import 'trading/IOrders.sol'; | ||
import 'reporting/IMarket.sol'; | ||
|
||
|
||
contract OrdersFinder { | ||
IOrders public orders; | ||
|
||
function OrdersFinder(IOrders _orders) { | ||
orders = _orders; | ||
} | ||
|
||
function getExistingOrders5(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[5] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders10(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[10] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders20(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[20] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders50(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[50] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders100(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[100] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders200(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[200] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders500(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[500] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
|
||
function getExistingOrders1000(Order.Types _type, IMarket _market, uint256 _outcome) external view returns (bytes32[1000] _results) { | ||
bytes32 _orderId = orders.getBestOrderId(_type, _market, _outcome); | ||
uint256 _index = 0; | ||
while (_orderId != 0) { | ||
_results[_index] = _orderId; | ||
_index++; | ||
_orderId = orders.getWorseOrderId(_orderId); | ||
} | ||
return _results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
|
||
from ethereum.tools import tester | ||
from ethereum.tools.tester import TransactionFailed | ||
from utils import longTo32Bytes, longToHexString, bytesToHexString, fix, AssertLog, stringToBytes, EtherDelta, PrintGasUsed | ||
from constants import ASK, BID, YES, NO | ||
from pytest import raises, fixture, mark | ||
from pprint import pprint | ||
|
||
def test_case_1(contractsFixture, cash, market, universe): | ||
createOrder = contractsFixture.contracts['CreateOrder'] | ||
orders = contractsFixture.contracts['Orders'] | ||
ordersFinder = contractsFixture.contracts['OrdersFinder'] | ||
tradeGroupID = "42" | ||
nullAddress = longTo32Bytes(0) | ||
|
||
# Orphaned order due to early exit logic from bad data caused by Orders worst order setting bug | ||
assert orders.getBestOrderId(BID, market.address, 1) == nullAddress | ||
orderID1 = createOrder.publicCreateOrder(BID, fix(1), 3000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '3000')) | ||
orderID2 = createOrder.publicCreateOrder(BID, fix(2), 3000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('2', '3000')) | ||
orderID3 = createOrder.publicCreateOrder(BID, fix(3), 2999, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('3', '2999')) | ||
assert orders.getWorseOrderId(orderID1) == orderID3 | ||
assert orders.getWorseOrderId(orderID3) == longTo32Bytes(0) # order 2 orphaned | ||
|
||
orderIds = ordersFinder.getExistingOrders5(BID, market.address, 1) | ||
|
||
assert orderID1 in orderIds | ||
assert orderID3 in orderIds | ||
assert orderID2 not in orderIds | ||
|
||
def test_case_2(contractsFixture, cash, market, universe): | ||
createOrder = contractsFixture.contracts['CreateOrder'] | ||
cancelOrder = contractsFixture.contracts['CancelOrder'] | ||
orders = contractsFixture.contracts['Orders'] | ||
ordersFinder = contractsFixture.contracts['OrdersFinder'] | ||
tradeGroupID = "42" | ||
nullAddress = longTo32Bytes(0) | ||
|
||
# create orders | ||
assert orders.getBestOrderId(BID, market.address, 1) == nullAddress | ||
orderID1 = createOrder.publicCreateOrder(BID, fix(1), 3000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '3000')) | ||
orderID2 = createOrder.publicCreateOrder(BID, fix(2), 3000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('2', '3000')) | ||
assert cancelOrder.cancelOrder(orderID1) | ||
orderID3 = createOrder.publicCreateOrder(BID, fix(3), 4000, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('3', '4000')) | ||
assert orders.getBestOrderId(BID, market.address, 1) == orderID3 | ||
assert orders.getWorseOrderId(orderID3) == nullAddress # order 2 orphaned | ||
|
||
orderIds = ordersFinder.getExistingOrders5(BID, market.address, 1) | ||
|
||
assert orderID1 not in orderIds | ||
assert orderID2 not in orderIds | ||
assert orderID3 in orderIds | ||
|
||
def test_overflow(contractsFixture, cash, market, universe): | ||
createOrder = contractsFixture.contracts['CreateOrder'] | ||
ordersFinder = contractsFixture.contracts['OrdersFinder'] | ||
tradeGroupID = "42" | ||
nullAddress = longTo32Bytes(0) | ||
|
||
# create orders | ||
orderID1 = createOrder.publicCreateOrder(BID, fix(1), 1, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '1')) | ||
orderID2 = createOrder.publicCreateOrder(BID, fix(1), 2, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '2')) | ||
orderID3 = createOrder.publicCreateOrder(BID, fix(1), 3, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '3')) | ||
orderID4 = createOrder.publicCreateOrder(BID, fix(1), 4, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '4')) | ||
orderID5 = createOrder.publicCreateOrder(BID, fix(1), 5, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '5')) | ||
orderID6 = createOrder.publicCreateOrder(BID, fix(1), 6, market.address, YES, longTo32Bytes(0), longTo32Bytes(0), tradeGroupID, value=fix('1', '6')) | ||
|
||
with raises(TransactionFailed): | ||
orderIds = ordersFinder.getExistingOrders5(BID, market.address, 1) | ||
|
||
orderIds = ordersFinder.getExistingOrders10(BID, market.address, 1) |