-
-
Save covelitein/613b69aad4a16dedaec600d0cd445884 to your computer and use it in GitHub Desktop.
dappworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { equal } = require('assert') | |
const { expect } = require('chai') | |
const toWei = (num) => ethers.utils.parseEther(num.toString()) | |
describe('Contracts', () => { | |
let contract, result | |
let id = 1 | |
let jobTitle = 'Content creator', | |
description = 'I need someone with a good professional writing skill, who understands writing dynamics', | |
tags = 'Professional, writer, Time management, Dynamics', | |
price = 0.3 | |
let Newtags = "Professional, writer, Time management, Resilience" | |
beforeEach(async () => { | |
const Contract = await ethers.getContractFactory('DappWorks') | |
;[deployer, client1, client2, freelancer1, freelancer2] = await ethers.getSigners() | |
contract = await Contract.deploy(); | |
await contract.deployed() | |
}) | |
beforeEach(async ()=> { | |
await contract.connect(client1).addJobListing(jobTitle, description, tags, { | |
value: toWei(price), | |
}); | |
}) | |
describe('Job Creation', ()=> { | |
it('should confirm fetching job listings', async ()=> { | |
result = await contract.getJobs() | |
expect(result).to.have.lengthOf(1) | |
}) | |
it('should confirm fetching a single job listing', async ()=> { | |
result = await contract.getJob(id); | |
expect(result.id).to.be.equal(1); | |
}) | |
it('should confirm updating of job', async ()=> { | |
result = await contract.getJob(1) | |
expect(result.tags).to.be.equal(tags) | |
await contract.updateJob(id, jobTitle, description, Newtags) | |
result = await contract.getJob(1); | |
expect(result.tags).to.be.equal(Newtags); | |
}) | |
it('should confirm job deletion', async ()=> { | |
result = await contract.getJobs(); | |
expect(result).to.be.have.lengthOf(1); | |
await contract.deleteJob(id) | |
result = await contract.getJobs(); | |
expect(result).to.be.have.lengthOf(0); | |
}) | |
it('should confirm bidding for job', async ()=> { | |
await contract.connect(freelancer1).bidForJob(id); | |
result = await contract.getBidders(id) | |
expect(result).to.have.lengthOf(1) | |
}) | |
it('should confirm accepting job bid', async ()=> { | |
await contract.connect(freelancer1).bidForJob(id); | |
result = await contract.connect(freelancer1).getAssignedJobs() | |
expect(result).to.have.lengthOf(0) | |
await contract.connect(client1).acceptBid(0, id, freelancer1.address) | |
result = await contract.connect(freelancer1).getAssignedJobs() | |
expect(result).to.have.lengthOf(1) | |
result = await contract.connect(client1).getFreelancers(id); | |
expect(result).to.have.lengthOf(1) | |
}) | |
it("should confirm payout of a job", async () => { | |
await contract.connect(freelancer1).bidForJob(id); | |
await contract.connect(client1).acceptBid(0, id, freelancer1.address); | |
await contract.connect(client1).payout(id); | |
result = await contract.getJob(id); | |
expect(result.paidOut).to.be.true; | |
}); | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment