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

Assignment 2 #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion contracts/002_Mapping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 36 additions & 0 deletions test/Mapping.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});