Created
February 13, 2024 15:44
-
-
Save Zeegaths/ad0053ea3ef28b67ad95d9432a46b514 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { | |
time, | |
loadFixture, | |
} from "@nomicfoundation/hardhat-toolbox/network-helpers"; | |
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs"; | |
import { expect } from "chai"; | |
import { ethers } from "hardhat"; | |
describe("Todo List", function () { | |
async function deployTodoList() { | |
const TodoList = await ethers.getContractFactory("TodoList"); | |
const todolist= await TodoList.deploy(); | |
return { todolist }; | |
} | |
describe("create Todo List", function () { | |
it("Should set and get todo lists", async function () { | |
const { todolist } = await loadFixture(deployTodoList); | |
const tx = await todolist.createTodos("clean", "clothes"); | |
const todos = await todolist.getTodos(); | |
expect(todos).with.lengthOf(1); | |
expect(todos[0]).eq("clean"); | |
expect(todos[1]).eq("clothes"); | |
}); | |
}); | |
}); |
This file contains hidden or 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
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
contract TodoList { | |
//struct with the todo list | |
struct Todo { | |
string Title; | |
string description; | |
bool completed; | |
} | |
//array of structs | |
Todo[] todos; | |
//add items to the array | |
function createTodos(string memory _title, string memory _description) public { | |
Todo memory todo; | |
todo.Title = _title; | |
todo.description = _description; | |
todos.push(todo); | |
} | |
//returns the array of structs | |
function getTodos() public view returns(Todo[] memory) { | |
return todos; | |
} | |
//false to true | |
function toggleTodos(uint _index) external { | |
todos[_index].completed = !todos[_index].completed; | |
} | |
//updates the structs | |
function updateTodos(uint _index, string memory _title, string memory _description) external { | |
todos[_index].Title = _title; | |
todos[_index].description = _description; | |
} | |
//deletes a struct from the array | |
function deleteTodos(uint _index) external { | |
delete todos[_index]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment