2021-04-20 21:40:47 +00:00
|
|
|
import { ethers } from "hardhat";
|
2021-04-22 18:30:51 +00:00
|
|
|
import { Contract } from "ethers";
|
2021-04-20 21:40:47 +00:00
|
|
|
import { expect } from "chai";
|
|
|
|
import { soliditySha3 } from "web3-utils";
|
2021-04-22 18:30:51 +00:00
|
|
|
import deploy from "../common/deployment";
|
2021-04-20 21:40:47 +00:00
|
|
|
|
|
|
|
describe("DioneDispute", function () {
|
|
|
|
let dioneDispute: Contract;
|
|
|
|
let dioneStaking: Contract;
|
|
|
|
|
|
|
|
beforeEach(async function () {
|
2021-04-22 18:30:51 +00:00
|
|
|
const contracts = await deploy({
|
|
|
|
reward: 100,
|
|
|
|
minStake: 5000,
|
|
|
|
voteWindowTime: 2,
|
|
|
|
randomizeStake: false,
|
|
|
|
maxStake: 0, // don't use this deployment feature
|
|
|
|
actualStake: 9000,
|
|
|
|
nodeCount: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
dioneDispute = contracts.dioneDispute;
|
|
|
|
dioneStaking = contracts.dioneStaking;
|
2021-04-20 21:40:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should create dispute, vote it by various eth addresses and then finish it after 2 secs", async function () {
|
|
|
|
const [owner, addr1, addr2, addr3] = await ethers.getSigners();
|
|
|
|
|
|
|
|
const dhash = soliditySha3(addr1.address, 1);
|
|
|
|
|
|
|
|
await expect(dioneDispute.beginDispute(addr1.address, 1))
|
|
|
|
.to.emit(dioneDispute, 'NewDispute')
|
|
|
|
.withArgs(dhash, 1, addr1.address, owner.address);
|
|
|
|
|
|
|
|
await expect(dioneDispute.connect(addr2).vote(dhash, true))
|
|
|
|
.to.emit(dioneDispute, 'NewVote')
|
|
|
|
.withArgs(dhash, addr2.address);
|
|
|
|
|
|
|
|
await expect(dioneDispute.connect(addr3).vote(dhash, true))
|
|
|
|
.to.emit(dioneDispute, 'NewVote')
|
|
|
|
.withArgs(dhash, addr3.address);
|
|
|
|
|
|
|
|
await delay(2000);
|
|
|
|
|
|
|
|
await expect(dioneDispute.finishDispute(dhash))
|
|
|
|
.to.emit(dioneDispute, 'DisputeFinished')
|
|
|
|
.withArgs(dhash, true);
|
|
|
|
|
|
|
|
expect(await dioneStaking.minerStake(addr1.address))
|
|
|
|
.to.equal(0);
|
|
|
|
|
|
|
|
expect(await dioneStaking.minerStake(addr2.address))
|
|
|
|
.to.equal(ethers.constants.WeiPerEther.mul(12000));
|
|
|
|
|
|
|
|
expect(await dioneStaking.minerStake(addr3.address))
|
|
|
|
.to.equal(ethers.constants.WeiPerEther.mul(12000));
|
|
|
|
|
|
|
|
expect(await dioneStaking.minerStake(owner.address))
|
|
|
|
.to.equal(ethers.constants.WeiPerEther.mul(12000));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function delay(ms: number): Promise<void> {
|
|
|
|
return new Promise( resolve => setTimeout(resolve, ms) );
|
|
|
|
}
|