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

[WIP] claimant and challenger tested together #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 client/primitives/defend.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = async (cmd, api, claim) => {

const computeStep = require('./computeStep')
const claimantConvictedEvent = api.scryptVerifier.ClaimantConvicted({ claimant: claim.claimant })
const queryEvent = api.scryptVerifier.NewQuery({ claimant: claim.claimant })
const queryEvent = api.scryptVerifier.NewQuery({ claimant: claim.claimant, sessionId: sessionId })

await Promise.race([

Expand Down
86 changes: 86 additions & 0 deletions test/integration/challengerAndClaimant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
This tests the client's functionality on the challenger side of things. Code is meant to simulate the claimant by proxy.
*/

require('dotenv').config()
require('../helpers/chai').should()
web3.eth.defaultAccount = web3.eth.accounts[0]

const miner = require('../helpers/miner')(web3)
const getAllEvents = require('../helpers/events').getAllEvents
const getContracts = require('../../client/util/getContracts')

const {
serializedBlockHeader,
scryptHash,
fakeTestScryptHash,
} = require('../helpers/blockheader')

describe('Challenger Client Integration Tests', function () {
// set max timeout to 5 minutes
this.timeout(300000)

let bridge, claimant, challenger, otherClaimant
let monitor, stopMonitor

before(async () => {
const contracts = await (await getContracts(web3)).deploy()
bridge = await require('../../client')(web3, contracts)

claimant = web3.eth.accounts[1]
challenger = web3.eth.accounts[2]
})

after(async () => {
// teardown processes
stopMonitor()
await monitor
})

describe('Challenger reacting to verification game', () => {
it('should start monitoring claims', async () => {
// eslint-disable-next-line
const stopper = new Promise((resolve) => stopMonitor = resolve)
await bridge.api.makeDeposit({ from: challenger, value: 2 })
monitor = bridge.monitorClaims(console, challenger, stopper, true)
})

it('should let claimant make a deposit and create real claim', async () => {
// early indicator if contract deployment is correct
await bridge.api.makeDeposit({ from: claimant, value: 1 })

let deposit = await bridge.api.getDeposit(claimant)
deposit.should.be.bignumber.equal(1)

const stopper = new Promise((resolve) => stopMonitor = resolve)

const claim = {
claimant: claimant,
input: serializedBlockHeader,
hash: scryptHash,
proposalID: 'foobar',
}

bridge.submitClaim(console, claim, stopper)
})

it('should let claimant make a deposit and create real claim', async () => {
// early indicator if contract deployment is correct
await bridge.api.makeDeposit({ from: claimant, value: 1 })

let deposit = await bridge.api.getDeposit(claimant)
deposit.should.be.bignumber.equal(1)

const stopper = new Promise((resolve) => stopMonitor = resolve)

const claim = {
claimant: claimant,
input: serializedBlockHeader,
hash: fakeTestScryptHash,
proposalID: 'barbar',
}

bridge.submitClaim(console, claim, stopper)
})
})
})