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

Check for distinct claims in JobsManager.doubleClaimSegmentSlash() #297

Merged
merged 1 commit into from Jul 29, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -496,6 +496,9 @@ contract JobsManager is ManagerProxyTarget, IVerifiable, IJobsManager {
whenSystemNotPaused
jobExists(_jobId)
{
// The provided claims must be different (i.e different IDs)
require(_claimId1 != _claimId2);

Job storage job = jobs[_jobId];
Claim storage claim1 = job.claims[_claimId1];
Claim storage claim2 = job.claims[_claimId2];
@@ -4,6 +4,7 @@ import MerkleTree from "../../utils/merkleTree"
import {createTranscodingOptions} from "../../utils/videoProfile"
import Segment from "../../utils/segment"
import BigNumber from "bignumber.js"
import expectThrow from "../helpers/expectThrow";

const Controller = artifacts.require("Controller")
const BondingManager = artifacts.require("BondingManager")
@@ -123,6 +124,11 @@ contract("DoubleClaimSegmentSlashing", accounts => {
// Wait for claims to be mined
await roundsManager.mineBlocks(2)

// Watcher fails to slash transcoder by specifying the same claim twice
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, 0, 0, 0, {from: watcher}))
// Watcher fails to slash transcoder by specifying the same claim twice
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, 1, 1, 0, {from: watcher}))

// Watcher slashes transcoder for double claiming segments
// Transcoder claimed segments 0 through 3 twice
await jobsManager.doubleClaimSegmentSlash(0, 0, 1, 0, {from: watcher})
@@ -988,15 +988,26 @@ contract("JobsManager", accounts => {
})

it("should fail if claim 0 does not exist", async () => {
const invalidClaimId0 = 5
let invalidClaimId0 = 5
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, invalidClaimId0, 1, 0, {from: watcher}))

invalidClaimId0 = -1
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, invalidClaimId0, 1, 0, {from: watcher}))
})

it("should fail if claim 1 does not exist", async () => {
const invalidClaimId1 = 5
let invalidClaimId1 = 5
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, 0, invalidClaimId1, 0, {from: watcher}))

invalidClaimId1 = -1
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, 0, invalidClaimId1, 0, {from: watcher}))
})

it("should fail if claim 0 == claim 1", async () => {
const claimId = 0
await expectThrow(jobsManager.doubleClaimSegmentSlash(0, claimId, claimId, 0, {from: watcher}))
})

it("should fail if claim 0 is slashed", async () => {
// Fast forward through verification period
const endVerificationBlock = (await jobsManager.getClaim(0, 0))[3]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.