Skip to content

Commit

Permalink
more gas cost data about trading (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuevoalex authored and adrake33 committed Jul 13, 2018
1 parent 7bb06e2 commit f296da5
Showing 1 changed file with 160 additions and 5 deletions.
165 changes: 160 additions & 5 deletions tests/test_trade_gas_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
from trading.test_claimTradingProceeds import acquireLongShares, finalizeMarket
from reporting_utils import proceedToNextRound, proceedToFork, finalizeFork, proceedToDesignatedReporting

pytestmark = mark.skip(reason="Just for testing gas cost")

# Trading Max Costs

CREATE_ORDER_BEST_CASE = [
547694,
562138,
576582,
591026,
605470,
619914,
634358,
]

CREATE_ORDER_MAXES = [
695034,
794664,
Expand All @@ -29,7 +41,27 @@
825440,
]

FILL_ORDER_MAXES = [
FILL_ORDER_TAKE_SHARES = [
464780,
479514,
494248,
508981,
523715,
538449,
553183,
]

FILL_ORDER_BOTH_ETH = [
839050,
1029970,
1220890,
1411809,
1602729,
1793649,
1984569,
]

FILL_ORDER_MAKER_REVERSE_POSITION = [
933495,
1172245,
1410995,
Expand All @@ -39,10 +71,46 @@
2365994,
]

pytestmark = mark.skip(reason="Just for testing gas cost")
FILL_ORDER_TAKER_REVERSE_POSITION = [
939239,
1115159,
1291079,
1466998,
1642918,
1818838,
1994758,
]

FILL_ORDER_DOUBLE_REVERSE_POSITION = [
2134777,
2455117,
2775457,
3095796,
3416136,
3736476,
4056816,
]

tester.STARTGAS = long(6.7 * 10**6)

@mark.parametrize('numOutcomes', range(2,9))
def test_order_creation_best_case(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
marketIndex = numOutcomes - 2
market = markets[marketIndex]

maxGas = 0
cost = fix('1', '5000')

outcome = 0

startGas = localFixture.chain.head_state.gas_used
orderID = createOrder.publicCreateOrder(BID, fix(1), 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = fix(1, 5000))
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == CREATE_ORDER_BEST_CASE[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_orderCreationMax(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
Expand Down Expand Up @@ -86,7 +154,48 @@ def test_orderCancelationMax(numOutcomes, localFixture, markets):
assert maxGas == CANCEL_ORDER_MAXES[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_orderFilling(numOutcomes, localFixture, markets):
def test_order_filling_take_shares(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
fillOrder = localFixture.contracts['FillOrder']
tradeGroupID = "42"
marketIndex = numOutcomes - 2
market = markets[marketIndex]

cost = 500000

assert completeSets.publicBuyCompleteSets(market.address, 100, value=1000000)
outcome = 0
orderID = createOrder.publicCreateOrder(ASK, 100, 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = cost)

startGas = localFixture.chain.head_state.gas_used
fillOrder.publicFillOrder(orderID, fix(1), tradeGroupID, sender = tester.k1, value=cost)
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == FILL_ORDER_TAKE_SHARES[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_order_filling_both_eth(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
fillOrder = localFixture.contracts['FillOrder']
tradeGroupID = "42"
marketIndex = numOutcomes - 2
market = markets[marketIndex]

cost = fix('1', '5000')

outcome = 0
orderID = createOrder.publicCreateOrder(BID, fix(1), 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = fix(1, 5000))

startGas = localFixture.chain.head_state.gas_used
fillOrder.publicFillOrder(orderID, fix(1), tradeGroupID, sender = tester.k1, value=cost)
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == FILL_ORDER_BOTH_ETH[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_order_filling_maker_reverse(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
fillOrder = localFixture.contracts['FillOrder']
Expand All @@ -99,14 +208,60 @@ def test_orderFilling(numOutcomes, localFixture, markets):
assert completeSets.publicBuyCompleteSets(market.address, 100, value=1000000)
outcome = 0
shareToken = localFixture.applySignature('ShareToken', market.getShareToken(outcome))
shareToken.transfer(tester.a7, 100)
shareToken.transfer(tester.a2, 100)
orderID = createOrder.publicCreateOrder(BID, fix(1), 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = fix(1, 5000))

startGas = localFixture.chain.head_state.gas_used
fillOrder.publicFillOrder(orderID, fix(1), tradeGroupID, sender = tester.k1, value=cost)
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == FILL_ORDER_MAKER_REVERSE_POSITION[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_order_filling_taker_reverse(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
fillOrder = localFixture.contracts['FillOrder']
tradeGroupID = "42"
marketIndex = numOutcomes - 2
market = markets[marketIndex]

cost = fix('1', '5000')

assert completeSets.publicBuyCompleteSets(market.address, 100, value=1000000, sender = tester.k2)
outcome = 0
shareToken = localFixture.applySignature('ShareToken', market.getShareToken(outcome))
shareToken.transfer(tester.a1, 100, sender = tester.k2)
orderID = createOrder.publicCreateOrder(BID, fix(1), 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = fix(1, 5000))

startGas = localFixture.chain.head_state.gas_used
fillOrder.publicFillOrder(orderID, fix(1), tradeGroupID, sender = tester.k1, value=cost)
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == FILL_ORDER_TAKER_REVERSE_POSITION[marketIndex]

@mark.parametrize('numOutcomes', range(2,9))
def test_order_filling_double_reverse(numOutcomes, localFixture, markets):
createOrder = localFixture.contracts['CreateOrder']
completeSets = localFixture.contracts['CompleteSets']
fillOrder = localFixture.contracts['FillOrder']
tradeGroupID = "42"
marketIndex = numOutcomes - 2
market = markets[marketIndex]

cost = fix('1', '5000')

assert completeSets.publicBuyCompleteSets(market.address, 100, value=1000000)
outcome = 0
shareToken = localFixture.applySignature('ShareToken', market.getShareToken(outcome))
shareToken.transfer(tester.a1, 100)
orderID = createOrder.publicCreateOrder(BID, fix(1), 5000, market.address, outcome, longTo32Bytes(0), longTo32Bytes(0), "7", value = fix(1, 5000))

startGas = localFixture.chain.head_state.gas_used
fillOrder.publicFillOrder(orderID, fix(1), tradeGroupID, sender = tester.k1, value=cost)
maxGas = localFixture.chain.head_state.gas_used - startGas

assert maxGas == FILL_ORDER_MAXES[marketIndex]
assert maxGas == FILL_ORDER_DOUBLE_REVERSE_POSITION[marketIndex]


@fixture(scope="session")
Expand Down

0 comments on commit f296da5

Please sign in to comment.