|
| 1 | +import { expect, use } from 'chai' |
| 2 | +import { solidity } from 'ethereum-waffle' |
| 3 | + |
| 4 | +import { DisputeManager } from '../../build/typechain/contracts/DisputeManager' |
| 5 | +import { GraphToken } from '../../build/typechain/contracts/GraphToken' |
| 6 | +import { Staking } from '../../build/typechain/contracts/Staking' |
| 7 | + |
| 8 | +import { NetworkFixture } from '../lib/fixtures' |
| 9 | +import { defaults, provider, toBN } from '../lib/testHelpers' |
| 10 | + |
| 11 | +use(solidity) |
| 12 | + |
| 13 | +const MAX_PPM = 1000000 |
| 14 | + |
| 15 | +describe('DisputeManager:Config', () => { |
| 16 | + const [me, governor, slasher, arbitrator] = provider().getWallets() |
| 17 | + |
| 18 | + let fixture: NetworkFixture |
| 19 | + |
| 20 | + let disputeManager: DisputeManager |
| 21 | + let grt: GraphToken |
| 22 | + let staking: Staking |
| 23 | + |
| 24 | + before(async function () { |
| 25 | + fixture = new NetworkFixture() |
| 26 | + ;({ disputeManager, grt, staking } = await fixture.load(governor, slasher, arbitrator)) |
| 27 | + }) |
| 28 | + |
| 29 | + beforeEach(async function () { |
| 30 | + await fixture.setUp() |
| 31 | + }) |
| 32 | + |
| 33 | + afterEach(async function () { |
| 34 | + await fixture.tearDown() |
| 35 | + }) |
| 36 | + |
| 37 | + describe('configuration', () => { |
| 38 | + it('should set `governor`', async function () { |
| 39 | + // Set right in the constructor |
| 40 | + expect(await disputeManager.governor()).eq(governor.address) |
| 41 | + }) |
| 42 | + |
| 43 | + it('should set `graphToken`', async function () { |
| 44 | + // Set right in the constructor |
| 45 | + expect(await disputeManager.token()).eq(grt.address) |
| 46 | + }) |
| 47 | + |
| 48 | + describe('arbitrator', function () { |
| 49 | + it('should set `arbitrator`', async function () { |
| 50 | + // Set right in the constructor |
| 51 | + expect(await disputeManager.arbitrator()).eq(arbitrator.address) |
| 52 | + |
| 53 | + // Can set if allowed |
| 54 | + await disputeManager.connect(governor).setArbitrator(me.address) |
| 55 | + expect(await disputeManager.arbitrator()).eq(me.address) |
| 56 | + }) |
| 57 | + |
| 58 | + it('reject set `arbitrator` if not allowed', async function () { |
| 59 | + const tx = disputeManager.connect(me).setArbitrator(arbitrator.address) |
| 60 | + await expect(tx).revertedWith('Only Governor can call') |
| 61 | + }) |
| 62 | + }) |
| 63 | + |
| 64 | + describe('minimumDeposit', function () { |
| 65 | + it('should set `minimumDeposit`', async function () { |
| 66 | + const oldValue = defaults.dispute.minimumDeposit |
| 67 | + const newValue = toBN('1') |
| 68 | + |
| 69 | + // Set right in the constructor |
| 70 | + expect(await disputeManager.minimumDeposit()).eq(oldValue) |
| 71 | + |
| 72 | + // Set new value |
| 73 | + await disputeManager.connect(governor).setMinimumDeposit(newValue) |
| 74 | + expect(await disputeManager.minimumDeposit()).eq(newValue) |
| 75 | + }) |
| 76 | + |
| 77 | + it('reject set `minimumDeposit` if not allowed', async function () { |
| 78 | + const newValue = toBN('1') |
| 79 | + const tx = disputeManager.connect(me).setMinimumDeposit(newValue) |
| 80 | + await expect(tx).revertedWith('Only Governor can call') |
| 81 | + }) |
| 82 | + }) |
| 83 | + |
| 84 | + describe('fishermanRewardPercentage', function () { |
| 85 | + it('should set `fishermanRewardPercentage`', async function () { |
| 86 | + const newValue = defaults.dispute.fishermanRewardPercentage |
| 87 | + |
| 88 | + // Set right in the constructor |
| 89 | + expect(await disputeManager.fishermanRewardPercentage()).eq(newValue) |
| 90 | + |
| 91 | + // Set new value |
| 92 | + await disputeManager.connect(governor).setFishermanRewardPercentage(0) |
| 93 | + await disputeManager.connect(governor).setFishermanRewardPercentage(newValue) |
| 94 | + }) |
| 95 | + |
| 96 | + it('reject set `fishermanRewardPercentage` if out of bounds', async function () { |
| 97 | + const tx = disputeManager.connect(governor).setFishermanRewardPercentage(MAX_PPM + 1) |
| 98 | + await expect(tx).revertedWith('Reward percentage must be below or equal to MAX_PPM') |
| 99 | + }) |
| 100 | + |
| 101 | + it('reject set `fishermanRewardPercentage` if not allowed', async function () { |
| 102 | + const tx = disputeManager.connect(me).setFishermanRewardPercentage(50) |
| 103 | + await expect(tx).revertedWith('Only Governor can call') |
| 104 | + }) |
| 105 | + }) |
| 106 | + |
| 107 | + describe('slashingPercentage', function () { |
| 108 | + it('should set `slashingPercentage`', async function () { |
| 109 | + const newValue = defaults.dispute.slashingPercentage |
| 110 | + |
| 111 | + // Set right in the constructor |
| 112 | + expect(await disputeManager.slashingPercentage()).eq(newValue.toString()) |
| 113 | + |
| 114 | + // Set new value |
| 115 | + await disputeManager.connect(governor).setSlashingPercentage(0) |
| 116 | + await disputeManager.connect(governor).setSlashingPercentage(newValue) |
| 117 | + }) |
| 118 | + |
| 119 | + it('reject set `slashingPercentage` if out of bounds', async function () { |
| 120 | + const tx = disputeManager.connect(governor).setSlashingPercentage(MAX_PPM + 1) |
| 121 | + await expect(tx).revertedWith('Slashing percentage must be below or equal to MAX_PPM') |
| 122 | + }) |
| 123 | + |
| 124 | + it('reject set `slashingPercentage` if not allowed', async function () { |
| 125 | + const tx = disputeManager.connect(me).setSlashingPercentage(50) |
| 126 | + await expect(tx).revertedWith('Only Governor can call') |
| 127 | + }) |
| 128 | + }) |
| 129 | + |
| 130 | + describe('staking', function () { |
| 131 | + it('should set `staking`', async function () { |
| 132 | + // Set right in the constructor |
| 133 | + expect(await disputeManager.staking()).eq(staking.address) |
| 134 | + |
| 135 | + // Can set if allowed |
| 136 | + await disputeManager.connect(governor).setStaking(grt.address) |
| 137 | + expect(await disputeManager.staking()).eq(grt.address) |
| 138 | + }) |
| 139 | + |
| 140 | + it('reject set `staking` if not allowed', async function () { |
| 141 | + const tx = disputeManager.connect(me).setStaking(grt.address) |
| 142 | + await expect(tx).revertedWith('Only Governor can call') |
| 143 | + }) |
| 144 | + }) |
| 145 | + }) |
| 146 | +}) |
0 commit comments