Skip to content

Commit

Permalink
added echidna fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cetceeve committed Dec 17, 2023
1 parent 96b6a63 commit c03bf20
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Create a digital passport for your physical items.

![100 Percent Coverage](./images/100coverage.png)

## Static Analysis!

[Slither Report](./contract/Slither-Report.md)

## Fuzzing!

![Echidna Fuzzing Results](./images/echidna.png)

## Description

A dApp that allows users to create a digital passport for physical items and make the information associated with these items easily accessible.
Expand Down
1 change: 1 addition & 0 deletions contract/crytic-export/combined_solc.json

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions contract/echidna/PropertyTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import "../src/ItemBlocks.sol";

/**
* @title
* @author
* @notice
*
* @dev There are some specific addresses in Echidna:
0x30000 calls the constructor.
0x10000, 0x20000, and 0x30000 randomly call other functions.
*/
contract ItemBlocksPropertyTest is ItemBlocks {
uint256 testTokenId = 0;

constructor() ItemBlocks(address(0x30000)) {
testTokenId = createPassport(7, "TestItemName", "TestItemDesc", "TestItemFamily", "TestItemUrl","TestItemImg");
}

// owner should never be zero address
function echidna_owner_not_zero() public view returns (bool) {
return ownerOf(testTokenId) != address(0);
}

// item creator should always be the first entry in allItem Owners
function echidna_set_creator() public view returns (bool){
return allItemOwners[7][0] == address(0x30000);
}

// it should be possible to create more items
function echidna_create_more() public view returns (bool) {
return createdItems[address(0x30000)].length >= 1;
}

// if there is a owner in the allItemsOwners array there should be a passport too
function echidna_need_to_create_history_and_passport() public view returns (bool) {
if (allItemOwners[7].length > 0) {
return bytes(itemPassports[7].name).length > 0;
} else {
return true;
}
}

// current owner should be the last entry in allItemOwners
function echidna_owner_is_last_entry_allItemOwners() public view returns (bool) {
if (allItemOwners[1].length > 0) {
address[] memory test = allItemOwners[1];
return test[test.length - 1] == ownerOf(1);
} else {
return true;
}
}

}
4 changes: 2 additions & 2 deletions contract/src/ItemBlocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ contract ItemBlocks is ERC721, Ownable {
_safeMint(to, tokenId);
}

function createPassport(uint tokenId, string calldata name, string calldata desc, string calldata family, string calldata url, string calldata img) public returns(uint256) {
function createPassport(uint tokenId, string memory name, string memory desc, string memory family, string memory url, string memory img) public returns(uint256) {
_safeMint(msg.sender, tokenId);
setCreator(msg.sender, tokenId);
return updatePassport(tokenId, name, desc, family, url, img);
}

function updatePassport(uint tokenId, string calldata name, string calldata desc, string calldata family, string calldata url, string calldata img) public returns(uint256) {
function updatePassport(uint tokenId, string memory name, string memory desc, string memory family, string memory url, string memory img) public returns(uint256) {
require( isEligible(tokenId, msg.sender), "Must be the owner of the item or the creator of it" );

itemPassports[tokenId] = Passport ({
Expand Down
Binary file added images/echidna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c03bf20

Please sign in to comment.