Skip to content

Commit

Permalink
Merge pull request #68 from gnosis/upgrade-coverage-tool
Browse files Browse the repository at this point in the history
Upgrade coverage tool
  • Loading branch information
cag authored Jan 5, 2018
2 parents 8c72d7e + 9e260ee commit 362a2f3
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 135 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lodash": "^4.17.4",
"npm-prepublish": "^1.2.3",
"run-with-testrpc": "^0.3.0",
"solidity-coverage": "^0.3.5",
"solidity-coverage": "^0.4.2",
"truffle": "^3.4.11"
},
"repository": {
Expand Down
96 changes: 48 additions & 48 deletions test/javascript/test_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,50 @@ contract('Event', function (accounts) {
const buyer = 0
const collateralTokenCount = 10
await etherToken.deposit({ value: collateralTokenCount, from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)

await etherToken.approve(event.address, collateralTokenCount, { from: accounts[buyer] })
await event.buyAllOutcomes(collateralTokenCount, { from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), 0)

const outcomeToken1 = Token.at(await event.outcomeTokens(0))
const outcomeToken2 = Token.at(await event.outcomeTokens(1))
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), collateralTokenCount)
const outcomeToken1 = Token.at(await event.outcomeTokens.call(0))
const outcomeToken2 = Token.at(await event.outcomeTokens.call(1))
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), collateralTokenCount)

// Sell all outcomes
await event.sellAllOutcomes(collateralTokenCount, { from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf(event.address), 0)
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), 0)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(event.address), 0)
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), 0)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), 0)
})

it('should buy and verify outcomes', async () => {
// Buy all outcomes
const buyer = 1
const collateralTokenCount = 10
await etherToken.deposit({ value: collateralTokenCount, from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)

await etherToken.approve(event.address, collateralTokenCount, { from: accounts[buyer] })
await event.buyAllOutcomes(collateralTokenCount, { from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), 0)

const outcomeToken1 = Token.at(await event.outcomeTokens(0))
const outcomeToken2 = Token.at(await event.outcomeTokens(1))
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), collateralTokenCount)
const outcomeToken1 = Token.at(await event.outcomeTokens.call(0))
const outcomeToken2 = Token.at(await event.outcomeTokens.call(1))
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), collateralTokenCount)

// Validate getters
assert.equal(await event.getOutcomeCount(), 2)
assert.deepEqual(await event.getOutcomeTokens(), [await event.outcomeTokens(0), await event.outcomeTokens(1)])
assert.equal(await event.getOutcomeCount.call(), 2)
assert.deepEqual(await event.getOutcomeTokens.call(), [await event.outcomeTokens.call(0), await event.outcomeTokens.call(1)])
//using parseInt and .valueOf because of strictEqual comparison in arrays.deepEqual()
const outcomeTokenDistribution = await event.getOutcomeTokenDistribution(accounts[buyer])
const outcomeTokenDistribution = await event.getOutcomeTokenDistribution.call(accounts[buyer])
assert.deepEqual(
[parseInt(outcomeTokenDistribution[0].valueOf(), 10), parseInt(outcomeTokenDistribution[1].valueOf(),10)],
[parseInt(outcomeTokenDistribution[0].valueOf(), 10), parseInt(outcomeTokenDistribution[1].valueOf(), 10)],
[collateralTokenCount, collateralTokenCount])
})

Expand All @@ -92,35 +92,35 @@ contract('Event', function (accounts) {
const buyer = 2
const collateralTokenCount = 10
await etherToken.deposit({ value: collateralTokenCount, from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)

await etherToken.approve(event.address, collateralTokenCount, { from: accounts[buyer] })
await event.buyAllOutcomes(collateralTokenCount, { from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(event.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), 0)

const outcomeToken1 = Token.at(await event.outcomeTokens(0))
const outcomeToken2 = Token.at(await event.outcomeTokens(1))
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), collateralTokenCount)
const outcomeToken1 = Token.at(await event.outcomeTokens.call(0))
const outcomeToken2 = Token.at(await event.outcomeTokens.call(1))
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), collateralTokenCount)

//Set outcome in oracle contract
await oracle.setOutcome(1)
assert.equal(await oracle.getOutcome(), 1)
assert.equal(await oracle.isOutcomeSet(), true)
assert.equal(await oracle.getOutcome.call(), 1)
assert.equal(await oracle.isOutcomeSet.call(), true)

//Set outcome in event
await event.setOutcome()
assert.equal(await event.outcome(), 1)
assert.equal(await event.isOutcomeSet(),true)
assert.equal(await event.outcome.call(), 1)
assert.equal(await event.isOutcomeSet.call(),true)

//Redeem winnings for buyer account
const buyerWinnings = utils.getParamFromTxEvent(
await event.redeemWinnings({ from: accounts[buyer] }), 'winnings')
assert.equal(buyerWinnings.valueOf(), collateralTokenCount)
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)
})

it('should buy, set, and redeem outcomes for scalar event', async () => {
Expand All @@ -132,34 +132,34 @@ contract('Event', function (accounts) {
const buyer = 3
const collateralTokenCount = 10
await etherToken.deposit({ value: collateralTokenCount, from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)

await etherToken.approve(scalarEvent.address, collateralTokenCount, { from: accounts[buyer] })
await scalarEvent.buyAllOutcomes(collateralTokenCount, { from: accounts[buyer] })
assert.equal(await etherToken.balanceOf(scalarEvent.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(scalarEvent.address), collateralTokenCount)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), 0)

const outcomeToken1 = Token.at(await scalarEvent.outcomeTokens(0))
const outcomeToken2 = Token.at(await scalarEvent.outcomeTokens(1))
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), collateralTokenCount)

//Set outcome in oracle contract
await oracle.setOutcome(0)
assert.equal(await oracle.getOutcome(), 0)
assert.equal(await oracle.isOutcomeSet(), true)
assert.equal(await oracle.getOutcome.call(), 0)
assert.equal(await oracle.isOutcomeSet.call(), true)

//Set outcome in event
await scalarEvent.setOutcome()
assert.equal(await scalarEvent.outcome(), 0)
assert.equal(await scalarEvent.isOutcomeSet(), true)
assert.equal(await scalarEvent.outcome.call(), 0)
assert.equal(await scalarEvent.isOutcomeSet.call(), true)

//Redeem winnings for buyer account
const buyerWinnings = utils.getParamFromTxEvent(
await scalarEvent.redeemWinnings({ from: accounts[buyer] }), 'winnings')
assert.equal(buyerWinnings.valueOf(), collateralTokenCount)
assert.equal(await outcomeToken1.balanceOf(accounts[buyer]), 0)
assert.equal(await outcomeToken2.balanceOf(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf(accounts[buyer]), collateralTokenCount)
assert.equal(await outcomeToken1.balanceOf.call(accounts[buyer]), 0)
assert.equal(await outcomeToken2.balanceOf.call(accounts[buyer]), 0)
assert.equal(await etherToken.balanceOf.call(accounts[buyer]), collateralTokenCount)
})
})
24 changes: 12 additions & 12 deletions test/javascript/test_market_makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract('MarketMaker', function(accounts) {
eventFactory = await EventFactory.deployed()
centralizedOracleFactory = await CentralizedOracleFactory.deployed()
standardMarketFactory = await StandardMarketFactory.deployed()
lmsrMarketMaker = await LMSRMarketMaker.deployed()
lmsrMarketMaker = await LMSRMarketMaker.deployed.call()
etherToken = await EtherToken.deployed()
})

Expand Down Expand Up @@ -56,16 +56,16 @@ contract('MarketMaker', function(accounts) {
const funding = 1e17

await etherToken.deposit({ value: funding, from: accounts[investor] })
assert.equal(await etherToken.balanceOf(accounts[investor]), funding)
assert.equal(await etherToken.balanceOf.call(accounts[investor]), funding)

await etherToken.approve(market.address, funding, { from: accounts[investor] })
await market.fund(funding, { from: accounts[investor] })
assert.equal(await etherToken.balanceOf(accounts[investor]), 0)
assert.equal(await etherToken.balanceOf.call(accounts[investor]), 0)

// User buys all outcomes
const trader = 1
const outcome = 1
const outcomeToken = Token.at(await event.outcomeTokens(outcome))
const outcomeToken = Token.at(await event.outcomeTokens.call(outcome))
const tokenCount = 1e18
const loopCount = 10

Expand All @@ -74,11 +74,11 @@ contract('MarketMaker', function(accounts) {
await event.buyAllOutcomes(tokenCount * loopCount, { from: accounts[trader] })

// User sells tokens
const buyerBalance = await etherToken.balanceOf(accounts[trader])
const buyerBalance = await etherToken.balanceOf.call(accounts[trader])
let profit
for(let i of _.range(loopCount)) {
// Calculate profit for selling tokens
profit = await lmsrMarketMaker.calcProfit(market.address, outcome, tokenCount)
profit = await lmsrMarketMaker.calcProfit.call(market.address, outcome, tokenCount)
if(profit == 0)
break

Expand All @@ -90,7 +90,7 @@ contract('MarketMaker', function(accounts) {

let netOutcomeTokensSold = await Promise.all(_.range(numOutcomes).map((j) => market.netOutcomeTokensSold(j)))
let expected = lmsrMarginalPrice(funding, netOutcomeTokensSold, outcome)
let actual = (await lmsrMarketMaker.calcMarginalPrice(market.address, outcome)).div(ONE)
let actual = (await lmsrMarketMaker.calcMarginalPrice.call(market.address, outcome)).div(ONE)
assert(
isClose(actual, expected),
`Marginal price calculation is off for iteration ${i}:\n` +
Expand All @@ -103,7 +103,7 @@ contract('MarketMaker', function(accounts) {
// Selling of tokens is worth less than 1 Wei
assert.equal(profit, 0)
// User's Ether balance increased
assert.isAbove(await etherToken.balanceOf(accounts[trader]), buyerBalance)
assert.isAbove(await etherToken.balanceOf.call(accounts[trader]), buyerBalance)
})

it('should move price of an outcome to 1 after participants buy lots of that outcome from market maker', async () => {
Expand Down Expand Up @@ -131,11 +131,11 @@ contract('MarketMaker', function(accounts) {

// Fund market
await etherToken.deposit({ value: funding, from: accounts[investor] })
assert.equal(await etherToken.balanceOf(accounts[investor]), funding)
assert.equal(await etherToken.balanceOf.call(accounts[investor]), funding)

await etherToken.approve(market.address, funding, { from: accounts[investor] })
await market.fund(funding, { from: accounts[investor] })
assert.equal(await etherToken.balanceOf(accounts[investor]), 0)
assert.equal(await etherToken.balanceOf.call(accounts[investor]), 0)

// User buys ether tokens
const trader = 1
Expand All @@ -147,7 +147,7 @@ contract('MarketMaker', function(accounts) {
let cost
for(let i of _.range(loopCount)) {
// Calculate profit for selling tokens
cost = await lmsrMarketMaker.calcCost(market.address, outcome, tokenCount)
cost = await lmsrMarketMaker.calcCost.call(market.address, outcome, tokenCount)

// Buying tokens
await etherToken.approve(market.address, tokenCount, { from: accounts[trader] })
Expand All @@ -157,7 +157,7 @@ contract('MarketMaker', function(accounts) {

let netOutcomeTokensSold = await Promise.all(_.range(numOutcomes).map((j) => market.netOutcomeTokensSold(j)))
let expected = lmsrMarginalPrice(funding, netOutcomeTokensSold, outcome)
let actual = (await lmsrMarketMaker.calcMarginalPrice(market.address, outcome)).div(ONE)
let actual = (await lmsrMarketMaker.calcMarginalPrice.call(market.address, outcome)).div(ONE)
assert(
isClose(actual, expected) || expected.toString() == 'NaN',
`Marginal price calculation is off for iteration ${i}:\n` +
Expand Down
Loading

0 comments on commit 362a2f3

Please sign in to comment.