This Solidity project implements a decentralized Student Grading System where:
- The Principal (Owner) deploys the contract and assigns Teachers.
- Teachers (Admins) are allowed to add students’ scores and associate them with subjects.
- Students can view their individual scores and grade remarks by subject.
- Teachers and Principal can view all the student records across subjects.
✅ This contract does not use OpenZeppelin libraries — all access control is handled with custom logic and modifiers.
-
👑 Principal Role:
- Deploys the contract.
- Assigns teacher addresses.
-
👨🏫 Teacher/Admin Role:
- Adds student grades per subject.
- Can view all students’ records.
-
👩🎓 Student Role:
- Views their subject-specific score, grade, and remark.
-
🧾 Grading Logic:
-
Automatically assigns:
- A: 70–100 ✅
- B: 60–69 ✅
- C: 50–59 ✅
- D: 40–49 ✅
- F: below 40 ❌
-
-
Structs:
Student: contains name, subjects, scores, and grades.Score: encapsulates subject, marks, grade.
-
Mappings:
students: maps student addresses to their record.teachers: maps teacher addresses to boolean.
-
Modifiers:
onlyPrincipal: restricts actions to the contract owner.onlyTeacher: restricts score input to verified teachers.onlyStudent: for student-specific views.onlyAdmin: for teachers or the principal.
-
Principal assigns one or more
teacheraddresses. -
Teachers add student scores using:
addStudentScore(studentAddress, studentName, subject, score) -
Students view their result by calling:
viewMyGradeBySubject("Mathematics")
-
Admin can retrieve all student results via:
getStudentRecords(studentAddress)
This project includes comprehensive tests written in Foundry to ensure:
- Role-based restrictions are enforced.
- Score grading is accurate.
- Students can only access their records.
- Admins can view all records.
Run test with:
forge test├── src/
│ └── StudentGradingSystem.sol
├── test/
│ └── StudentGradingSystemTest.t.sol
├── foundry.toml
└── README.md
MIT License
This contract was written and tested as part of a blockchain education cohort focused on building real-world decentralized applications using Solidity and Foundry.