Skip to content

Commit

Permalink
Coverage ignore large test (#486)
Browse files Browse the repository at this point in the history
* Skip Large example on coverage report.
* Move large example into separate file and test with truffle independently
* reduce to 5.5M gas limit
  • Loading branch information
bh2smith committed Jan 22, 2020
1 parent bef1d00 commit c6e4ec4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 69 deletions.
4 changes: 4 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ module.exports = {
providerOptions: {
default_balance_ether: 500000000,
},
mocha: {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true, // Run the grep's inverse set.
},
}
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ before_install:
- yarn --version
- npm install -g ganache-cli@latest
- ganache-cli --version
before_script:
- ganache-cli -l 8e6 > /dev/null &
script:
- yarn run lint
- yarn run solhint
- yarn run pretty-check
- solium -d contracts/
- yarn run coverage && cat ./coverage/lcov.info | coveralls
- yarn run test ./test/stablex/stablex_large_example.js
before_deploy:
- export PACKAGE_VERSION=$(jq -r '.version' package.json)
- test "v$PACKAGE_VERSION" = "$TRAVIS_TAG"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "truffle test",
"test-stablex": "truffle test test/stablex/*",
"test-snapp": "truffle test test/snapp/*",
"coverage": "truffle run coverage --network development",
"coverage": "truffle run coverage --network coverage",
"networks-extract": "CONF_FILE=$(pwd)'/migration_conf.js' node node_modules/@gnosis.pm/util-contracts/src/extract_network_info.js",
"networks-inject": "CONF_FILE=$(pwd)'/migration_conf.js' node node_modules/@gnosis.pm/util-contracts/src/inject_network_info.js",
"networks-reset": "mkdir -p build/contracts && truffle networks --clean && yarn run networks-inject",
Expand Down
68 changes: 0 additions & 68 deletions test/stablex/batch_exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
smallExample,
marginalTrade,
exampleOrderWithUnlimitedAmount,
largeRing30,
} = require("../resources/examples")
const { makeDeposits, placeOrders, setupGenericStableX } = require("./stablex_utils")

Expand Down Expand Up @@ -2040,71 +2039,4 @@ contract("BatchExchange", async accounts => {
assert.equal(await batchExchange.hasToken.call(erc20_1.address), true)
})
})
describe("Large Examples", () => {
it("ensures hard gas limit on largest possible ring trade ", async () => {
const batchExchange = await setupGenericStableX(30)
const sixPointFiveMillion = 6500000

const tradeExample = largeRing30
// Deposit double sufficient amount and immediately request withdraw for half
await makeDeposits(batchExchange, accounts, tradeExample.deposits)
for (const order of tradeExample.orders) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
await batchExchange.requestWithdraw(tokenAddress, order.buyAmount, { from: accounts[order.user] })
}
await closeAuction(batchExchange)

const batchId = (await batchExchange.getCurrentBatchId.call()).toNumber()
const orderIds = await placeOrders(batchExchange, accounts, tradeExample.orders, batchId + 1)
await closeAuction(batchExchange)

// Ensure that first 30 orders have valid withdraw requests.
for (const order of tradeExample.orders.slice(0, 30)) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
assert(
await batchExchange.hasValidWithdrawRequest.call(accounts[order.user], tokenAddress),
true,
"Expected valid withdraw requests before first solution submission."
)
}

const solution = solutionSubmissionParams(tradeExample.solutions[0], accounts, orderIds)
const firstSubmissionTX = await batchExchange.submitSolution(
batchId,
solution.objectiveValue,
solution.owners,
solution.touchedorderIds,
solution.volumes,
solution.prices,
solution.tokenIdsForPrice,
{ from: solver }
)
assert(
firstSubmissionTX.receipt.gasUsed < sixPointFiveMillion,
`Solution submission exceeded 6.5 million gas at ${firstSubmissionTX.receipt.gasUsed}`
)

// Ensure second 30 order's users valid withdraw requests.
for (const order of tradeExample.orders.slice(30)) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
assert(await batchExchange.hasValidWithdrawRequest.call(accounts[order.user], tokenAddress), true)
}

const solution2 = solutionSubmissionParams(tradeExample.solutions[1], accounts, orderIds)
const secondSubmissionTX = await batchExchange.submitSolution(
batchId,
solution2.objectiveValue,
solution2.owners,
solution2.touchedorderIds,
solution2.volumes,
solution2.prices,
solution2.tokenIdsForPrice,
{ from: competingSolver }
)
assert(
secondSubmissionTX.receipt.gasUsed < sixPointFiveMillion,
`Competing solution submission exceeded 6.5 million gas at ${secondSubmissionTX.receipt.gasUsed}`
)
})
})
})
76 changes: 76 additions & 0 deletions test/stablex/stablex_large_example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { closeAuction } = require("../../scripts/stablex/utilities.js")
const { solutionSubmissionParams, largeRing30 } = require("../resources/examples")
const { makeDeposits, placeOrders, setupGenericStableX } = require("./stablex_utils")

contract("BatchExchange", async accounts => {
const solver = accounts.pop()
const competingSolver = accounts.pop()

describe("Large Examples [ @skip-on-coverage ]", () => {
it("ensures hard gas limit on largest possible ring trade ", async () => {
const batchExchange = await setupGenericStableX(30)
const fivePointFiveMillion = 5500000

const tradeExample = largeRing30
// Deposit double sufficient amount and immediately request withdraw for half
await makeDeposits(batchExchange, accounts, tradeExample.deposits)
for (const order of tradeExample.orders) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
await batchExchange.requestWithdraw(tokenAddress, order.buyAmount, { from: accounts[order.user] })
}
await closeAuction(batchExchange)

const batchId = (await batchExchange.getCurrentBatchId.call()).toNumber()
const orderIds = await placeOrders(batchExchange, accounts, tradeExample.orders, batchId + 1)
await closeAuction(batchExchange)

// Ensure that first 30 orders have valid withdraw requests.
for (const order of tradeExample.orders.slice(0, 30)) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
assert(
await batchExchange.hasValidWithdrawRequest.call(accounts[order.user], tokenAddress),
true,
"Expected valid withdraw requests before first solution submission."
)
}

const solution = solutionSubmissionParams(tradeExample.solutions[0], accounts, orderIds)
const firstSubmissionTX = await batchExchange.submitSolution(
batchId,
solution.objectiveValue,
solution.owners,
solution.touchedorderIds,
solution.volumes,
solution.prices,
solution.tokenIdsForPrice,
{ from: solver }
)
assert(
firstSubmissionTX.receipt.gasUsed < fivePointFiveMillion,
`Solution submission exceeded 6.5 million gas at ${firstSubmissionTX.receipt.gasUsed}`
)

// Ensure second 30 order's users valid withdraw requests.
for (const order of tradeExample.orders.slice(30)) {
const tokenAddress = await batchExchange.tokenIdToAddressMap.call(order.buyToken)
assert(await batchExchange.hasValidWithdrawRequest.call(accounts[order.user], tokenAddress), true)
}

const solution2 = solutionSubmissionParams(tradeExample.solutions[1], accounts, orderIds)
const secondSubmissionTX = await batchExchange.submitSolution(
batchId,
solution2.objectiveValue,
solution2.owners,
solution2.touchedorderIds,
solution2.volumes,
solution2.prices,
solution2.tokenIdsForPrice,
{ from: competingSolver }
)
assert(
secondSubmissionTX.receipt.gasUsed < fivePointFiveMillion,
`Competing solution submission exceeded 6.5 million gas at ${secondSubmissionTX.receipt.gasUsed}`
)
})
})
})

0 comments on commit c6e4ec4

Please sign in to comment.