diff --git a/contracts/002_Mapping.sol b/contracts/002_Mapping.sol index f63aa9c..fe63f7a 100644 --- a/contracts/002_Mapping.sol +++ b/contracts/002_Mapping.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.17; // Declare the contract -contract Mappings{ +contract Mapping{ // Declare a mapping that associates uint keys with string values. mapping(uint => string) students; diff --git a/test/Mapping.js b/test/Mapping.js new file mode 100644 index 0000000..0d59d54 --- /dev/null +++ b/test/Mapping.js @@ -0,0 +1,36 @@ +const { expect } = require("chai"); +const { ethers } = require("hardhat"); + +describe("Mapping Test suite", function () { + let mapping; + beforeEach(async () => { + const Mapping = await ethers.getContractFactory("Mapping"); + mapping = await Mapping.deploy(); + await mapping.deployed(); + }); + + it("Should add and retrieve a student", async function () { + const id = 1; + const name = "Isaac"; + await mapping.addStudent(id, name); + const studentName = await mapping.viewStudent(id); + expect(studentName).to.equal(name); + }); + + it("Should add multiple students and retrieve them", async function () { + const students = [ + { id: 1, name: "Isaac" }, + { id: 2, name: "Pelz" }, + { id: 3, name: "Esther-ego" }, + ]; + + for (const student of students) { + await mapping.addStudent(student.id, student.name); + } + + for (const student of students) { + const studentName = await mapping.viewStudent(student.id); + expect(studentName).to.equal(student.name); + } + }); +}); \ No newline at end of file