-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
blockchain_development_integration/pi_network/tests/Insurance.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { expect } = require("chai"); | ||
const { ethers } = require("hardhat"); | ||
|
||
describe("Insurance Contract", function () { | ||
let Insurance, insurance, policyHolder; | ||
|
||
beforeEach(async function () { | ||
[policyHolder] = await ethers.getSigners(); | ||
Insurance = await ethers.getContractFactory("Insurance"); | ||
insurance = await Insurance.deploy(); | ||
await insurance.deployed(); | ||
}); | ||
|
||
it("should allow a user to purchase a policy", async function () { | ||
await insurance.connect(policyHolder).purchasePolicy(ethers.utils.parseEther("1"), ethers.utils.parseEther("5"), { value: ethers.utils.parseEther("1") }); | ||
const policy = await insurance.policies(1); | ||
expect(policy.policyHolder).to.equal(policyHolder.address); | ||
expect(policy.coverageAmount).to.equal(ethers.utils.parseEther("5")); | ||
expect(policy.isActive).to.be.true; | ||
}); | ||
|
||
it("should allow a policy holder to claim a policy", async function () { | ||
await insurance.connect(policyHolder).purchasePolicy(ethers.utils.parseEther("1"), ethers.utils.parseEther("5"), { value: ethers.utils.parseEther("1") }); | ||
await insurance.connect(policyHolder).claimPolicy(1); | ||
const policy = await insurance.policies(1); | ||
expect(policy.isActive).to.be.false; | ||
}); | ||
}); |