Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: implement test for JustCounter contract #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 76 additions & 4 deletions test/JustCounter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Import necessary modules and libraries
const { loadFixture } = require("@nomicfoundation/hardhat-network-helpers");
const { expect } = require("chai");

// Test suite for the JustCounter contract
describe("JustCounter Test Suite", function () {
// define loadFixture
// fixtures can return anything you consider useful for your tests
Expand All @@ -10,21 +12,27 @@ describe("JustCounter Test Suite", function () {
return { JustCounter, owner, addr1, addr2 };
}

describe("Post Deployment State Variables", async () => {
// Test for pre-deployment
describe("Pre-Deployment State Variables", async () => {
it("Should return state variables", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);
expect(await JustCounter.count()).to.equal(0);
expect(await JustCounter.underCount()).to.equal(0);
})
})

// test for post deployment state variables
describe.only("State Variables Changes", async () => {

let amount = 5
let count1 = 0

it("Should store number", async () => {
let amount = 5
// let amount = 5
// get loadFixture variables
const { JustCounter } = await loadFixture(deployTokenFixture);
// get current state variable count
let count1 = await JustCounter.count()
count1 = await JustCounter.count()
console.log("count before state change___", count1)
// write assertion statement for count1
expect(count1).to.equal(0);
Expand All @@ -35,8 +43,72 @@ describe("JustCounter Test Suite", function () {
// write assertion statement for count after store txn
expect(count2).to.equal(amount);
})
})

// Test for retrieve number from state
it ("Should retrieve number", async () => {

const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.store(amount)
let count2 = await JustCounter.retrieve()
expect(count2).to.equal(amount);
})

// Test for increament of count by one
it ("Should increase count by one", async () => {

const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.store(amount)
await JustCounter.increaseCount()
let count3 = await JustCounter.retrieve()
expect(count3).to.equal(amount + 1);
})

// Test for decreament by one
it ("Should decrease count by one", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.store(amount)
await JustCounter.decreaseCount()
let counts = await JustCounter.retrieve()
expect(counts).to.equal(amount - 1);
})

// Test for even number checker
it ("Checks if number is even", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.store(amount)
let counts = await JustCounter.isCountEven()
expect(counts).to.equal(false);
})

// Test to get current value of undercount
it ("Gets the current value of undercount variable", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);

let count = await JustCounter.getUnderCount();
expect(count).to.equal(0)
})

// Test to increase undercount variable by one
it ("Increases Undercount variable by one", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.increaseUnderCount();
let counts = await JustCounter.getUnderCount();
expect(counts).to.equal(1);
})

// Test to decrease undercount by one
it ("Decrease Undercount variable by one", async () => {
const { JustCounter } = await loadFixture(deployTokenFixture);

await JustCounter.decreaseUnderCount();
let counts = await JustCounter.getUnderCount();
expect(counts).to.equal(-1);
})

})
});