From 75a296553c79848a7b31a02392fb6382bbe3e5ca Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Mon, 11 Mar 2024 15:42:14 -0500 Subject: [PATCH] slight test refactor --- ethereum/test/Work1.js | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/ethereum/test/Work1.js b/ethereum/test/Work1.js index aba7aed..9afd934 100644 --- a/ethereum/test/Work1.js +++ b/ethereum/test/Work1.js @@ -136,49 +136,41 @@ describe('Work1', () => { }); describe('Work evidence and approval/disapproval', () => { + let dao; + let work1; + let account2; + + beforeEach(async () => { + const setup = await loadFixture(deploy); + dao = setup.dao; + work1 = setup.work1; + account2 = setup.account2; + await dao.stakeAvailability(work1.target, 50, STAKE_DURATION); + }); + it('should be able to submit work evidence', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await expect(work1.submitWorkEvidence(0)).to.emit(work1, 'WorkEvidenceSubmitted').withArgs(0); }); it('should not be able to submit work evidence twice', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await expect(work1.submitWorkEvidence(0)).to.emit(work1, 'WorkEvidenceSubmitted').withArgs(0); await expect(work1.submitWorkEvidence(0)).to.be.revertedWith('Status must be Requested'); }); it('should not be able to submit work evidence for a different worker', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await expect(work1.connect(account2).submitWorkEvidence(0)).to.be.revertedWith('Worker can only submit evidence for work they are assigned'); }); it('should be able to submit work approval', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await work1.submitWorkEvidence(0); await expect(work1.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); }); it('should not be able to submit work approval/disapproval twice', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await work1.submitWorkEvidence(0); await expect(work1.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); @@ -186,10 +178,6 @@ describe('Work1', () => { }); it('should not be able to submit work evidence after work approval', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await work1.submitWorkEvidence(0); await expect(work1.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); @@ -197,10 +185,6 @@ describe('Work1', () => { }); it('should not be able to submit work approval/disapproval before work evidence', async () => { - const { - dao, work1, account1, account2, - } = await loadFixture(deploy); - await dao.stakeAvailability(work1.target, 50, STAKE_DURATION, { from: account1 }); await work1.connect(account2).requestWork({ value: WORK1_PRICE }); await expect(work1.submitWorkApproval(0, true)).to.be.revertedWith('Status must be EvidenceSubmitted'); });