The smart contract can be tested using Remix IDE. After compiling & deploying, an example interaction with the deployed contract looks like this:
- Make sure account is the deployer's account
- addBook(1, 3, "KingRat") adds 3 copies of a Book to the libraryBooks mapping with id = 3 and title = "KingRat"
- addBook(1, 1, "KingRat") adds 1 more copy of the same book
- addBook(2, 1, "The Bitcoin Standard") adds a new book with id=2 and title "The Bitcoin Standard"
- libraryBooks(1) and libraryBooks(2) to see their count and title
- since the mapping is public, everyone can easy see which books are available
- Try switching to other account and see that only owner is allowed to add new books
- BorrowBook(1) borrows the book with id=1, check libraryBooks(1) to see that count of "KingRat" is decreased by 1
- BorrowBook(2) borrows book with id=2, -/-
Now, to see who borrowed which books:
- borrowedBooks(0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c, 1) pass an address (this one is an example, you can copy a real one directly in Remix) and array index as argument and the mapping returns the book id that is borrowed
- Since the mapping is public anyone can easily see it
- returnBook(1) returns the book with id=1, see libraryBook(1)'s count is increased by 1
- returnBook(2) -/-
- returnBook(1) should revert now because the user has already returned it
- BorrowBook(3) should revert because book with id=3 doesn't exist