Skip to content

Commit

Permalink
✨ [blockchain]: Quick fix after PR merge to consolidate changes #121
Browse files Browse the repository at this point in the history
  • Loading branch information
jtse0 authored and solomondefi-dev committed Nov 22, 2021
1 parent d53f430 commit 1834516
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 97 deletions.
4 changes: 3 additions & 1 deletion apps/contracts/src/contracts/library/SlmJudgement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import "../SlmStakerManager.sol";
/// @notice Functionality for voting on chargeback/escrow events
contract SlmJudgement is Ownable {

// TODO - Add events for certain actions

uint16 public minJurorCount;
uint256[] private selectedJurors;

Expand Down Expand Up @@ -90,7 +92,7 @@ contract SlmJudgement is Ownable {
}

function setMinJurorCount(uint16 newMinJurorCount) external onlyOwner {
require(newMinJurorCount >= 0, "Invalid juror count");
require(newMinJurorCount >= 3, "Invalid juror count");
minJurorCount = newMinJurorCount;
}

Expand Down
39 changes: 25 additions & 14 deletions apps/contracts/src/tests/SLMJurors2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ describe('SLM Jurors', function () {

await token.mint(escrow.address, defaultAmount)

})

it('Checks selection and storage of jurors', async function () {
const defaultAmount = 100
const stakeAmount = 100
const endTime = Math.round(new Date().getTime() / 1000) + 259200
disputeAddress = escrow.address

await token.connect(account2).increaseAllowance(manager.address, 100)
Expand All @@ -118,6 +123,13 @@ describe('SLM Jurors', function () {
await manager.connect(account1).stake(userId1, stakeAmount)
chai.expect(await token.balanceOf(account1.address)).to.equal(0)

await jurors.setStakerPool()
await shouldRevert(
jurors.initializeDispute(disputeAddress, 1, endTime),
'Not enough stakers',
'Total stakers cannot be less than minimum juror count',
)

await token.connect(account3).increaseAllowance(manager.address, 100)
chai.expect(await token.balanceOf(account3.address)).to.equal(defaultAmount)
userId3 = 3
Expand Down Expand Up @@ -150,19 +162,27 @@ describe('SLM Jurors', function () {

await shouldRevert(
jurors.setMinJurorCount(2),
'Minimum juror count must be greater than 3',
'Invalid juror count',
'Minimum juror count must be greater than 3',
)
await jurors.setMinJurorCount(3)

await jurors.setStakerPool()
})

it('Checks voting', async function () {
const endTime = Math.round(new Date().getTime() / 1000) + 259200
await jurors.setMinJurorCount(7)
await jurors.initializeDispute(disputeAddress, 1, endTime)

const jurorList = await jurors.getJurors(disputeAddress)
chai.expect(await jurorList[0]).to.equal(userId2)
chai.expect(await jurorList[1]).to.equal(userId1)
chai.expect(await jurorList[2]).to.equal(userId3)
chai.expect(await jurorList[3]).to.equal(userId4)
chai.expect(await jurorList[4]).to.equal(userId5)
chai.expect(await jurorList[5]).to.equal(userId6)
chai.expect(await jurorList[6]).to.equal(userId7)
})

it('Checks voting', async function () {

const roleArray = [2, 1, 3, 3, 3]
const addressArray = [
account8.address,
Expand Down Expand Up @@ -205,15 +225,6 @@ describe('SLM Jurors', function () {
encryptionKeyArray,
)

const jurorList = await jurors.getJurors(disputeAddress)
chai.expect(await jurorList[0]).to.equal(userId2)
chai.expect(await jurorList[1]).to.equal(userId1)
chai.expect(await jurorList[2]).to.equal(userId3)
chai.expect(await jurorList[3]).to.equal(userId4)
chai.expect(await jurorList[4]).to.equal(userId5)
chai.expect(await jurorList[5]).to.equal(userId6)
chai.expect(await jurorList[6]).to.equal(userId7)

await jurors.connect(account1).vote(disputeAddress, fakeEncryptionKey, 1)

await jurors.voteStatus(disputeAddress)
Expand Down
160 changes: 80 additions & 80 deletions apps/contracts/src/tests/SlmJurors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,85 @@ import { shouldRevert } from './testing'

describe('SLM Jurors', function () {
it('Checks selection and storage of jurors', async function () {
const [owner, account1, account2, account3] = await ethers.getSigners()

const StorageFactory = await ethers.getContractFactory('SlmStakerStorage')
const ManagerFactory = await ethers.getContractFactory('SlmStakerManager')
const TokenFactory = await ethers.getContractFactory('SlmToken')
const JudgementFactory = await ethers.getContractFactory('SlmJudgement')

const initialSupply = ethers.utils.parseEther('100000000')
const token = await TokenFactory.deploy(
'SLMToken',
'SLM',
initialSupply,
owner.address,
)
await token.deployed()
await token.unlock()

const defaultAmount = 100
await token.mint(account1.address, defaultAmount)
await token.mint(account2.address, defaultAmount)
await token.mint(account3.address, defaultAmount)

const unstakePeriod = 1
const minimumStake = 1
const storage = await StorageFactory.deploy(
token.address,
unstakePeriod,
minimumStake,
)

const manager = await ManagerFactory.deploy(token.address, storage.address)
await storage.setStakerManager(manager.address)

const minJurorCount = 4
const jurors = await JudgementFactory.deploy(manager.address, minJurorCount)
await manager.setJudgementContract(jurors.address)

const stakeAmount = 100
const disputeAddress = token.address

await token.connect(account2).increaseAllowance(manager.address, 100)
chai.expect(await token.balanceOf(account2.address)).to.equal(defaultAmount)
const userId2 = 2
await manager.connect(account2).stake(userId2, 100)
chai.expect(await token.balanceOf(account2.address)).to.equal(0)

await token.connect(account1).increaseAllowance(manager.address, stakeAmount)
chai.expect(await token.balanceOf(account1.address)).to.equal(defaultAmount)
const userId1 = 1
await manager.connect(account1).stake(userId1, stakeAmount)
chai.expect(await token.balanceOf(account1.address)).to.equal(0)

await jurors.setStakerPool()
await shouldRevert(
jurors.setJurors(disputeAddress),
'Not enough stakers',
'Total stakers cannot be less than minimum juror count',
)

await token.connect(account3).increaseAllowance(manager.address, 100)
chai.expect(await token.balanceOf(account3.address)).to.equal(defaultAmount)
const userId3 = 3
await manager.connect(account3).stake(userId3, 100)
chai.expect(await token.balanceOf(account3.address)).to.equal(0)

await shouldRevert(
jurors.setMinJurorCount(2),
'Invalid juror count',
'Minimum juror count must be greater than 3',
)
await jurors.setMinJurorCount(3)

await jurors.setStakerPool()

await jurors.setJurors(disputeAddress)
const jurorList = await jurors.getJurors(disputeAddress)

chai.expect(await jurorList[0]).to.equal(userId2)
chai.expect(await jurorList[1]).to.equal(userId1)
chai.expect(await jurorList[2]).to.equal(userId3)
// const [owner, account1, account2, account3] = await ethers.getSigners()

// const StorageFactory = await ethers.getContractFactory('SlmStakerStorage')
// const ManagerFactory = await ethers.getContractFactory('SlmStakerManager')
// const TokenFactory = await ethers.getContractFactory('SlmToken')
// const JudgementFactory = await ethers.getContractFactory('SlmJudgement')

// const initialSupply = ethers.utils.parseEther('100000000')
// const token = await TokenFactory.deploy(
// 'SLMToken',
// 'SLM',
// initialSupply,
// owner.address,
// )
// await token.deployed()
// await token.unlock()

// const defaultAmount = 100
// await token.mint(account1.address, defaultAmount)
// await token.mint(account2.address, defaultAmount)
// await token.mint(account3.address, defaultAmount)

// const unstakePeriod = 1
// const minimumStake = 1
// const storage = await StorageFactory.deploy(
// token.address,
// unstakePeriod,
// minimumStake,
// )

// const manager = await ManagerFactory.deploy(token.address, storage.address)
// await storage.setStakerManager(manager.address)

// const minJurorCount = 4
// const jurors = await JudgementFactory.deploy(manager.address, minJurorCount)
// await manager.setJudgementContract(jurors.address)

// const stakeAmount = 100
// const disputeAddress = token.address

// await token.connect(account2).increaseAllowance(manager.address, 100)
// chai.expect(await token.balanceOf(account2.address)).to.equal(defaultAmount)
// const userId2 = 2
// await manager.connect(account2).stake(userId2, 100)
// chai.expect(await token.balanceOf(account2.address)).to.equal(0)

// await token.connect(account1).increaseAllowance(manager.address, stakeAmount)
// chai.expect(await token.balanceOf(account1.address)).to.equal(defaultAmount)
// const userId1 = 1
// await manager.connect(account1).stake(userId1, stakeAmount)
// chai.expect(await token.balanceOf(account1.address)).to.equal(0)

// await jurors.setStakerPool()
// await shouldRevert(
// jurors.setJurors(disputeAddress),
// 'Not enough stakers',
// 'Total stakers cannot be less than minimum juror count',
// )

// await token.connect(account3).increaseAllowance(manager.address, 100)
// chai.expect(await token.balanceOf(account3.address)).to.equal(defaultAmount)
// const userId3 = 3
// await manager.connect(account3).stake(userId3, 100)
// chai.expect(await token.balanceOf(account3.address)).to.equal(0)

// await shouldRevert(
// jurors.setMinJurorCount(2),
// 'Invalid juror count',
// 'Minimum juror count must be greater than 3',
// )
// await jurors.setMinJurorCount(3)

// await jurors.setStakerPool()

// await jurors.setJurors(disputeAddress)
// const jurorList = await jurors.getJurors(disputeAddress)

// chai.expect(await jurorList[0]).to.equal(userId2)
// chai.expect(await jurorList[1]).to.equal(userId1)
// chai.expect(await jurorList[2]).to.equal(userId3)
})
})
4 changes: 2 additions & 2 deletions apps/contracts/src/tests/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert'
import { ethers } from 'hardhat'

// Temporary placeholders for blockchain-utils functions
const toBN = (num) => BigInt(toSafeNumber(num))
export const toBN = (num) => BigInt(toSafeNumber(num))

const addDays = (date, days) => {
const result = new Date(date)
Expand Down Expand Up @@ -33,7 +33,7 @@ const parseSci = (value) => {
return value
}

const toSafeNumber = (value) => parseSci(value.toString())
export const toSafeNumber = (value) => parseSci(value.toString())

// End of temporary placeholders

Expand Down

0 comments on commit 1834516

Please sign in to comment.