2024-01-22 21:48:51 +00:00
|
|
|
// SPDX-License-Identifier: UNLICENSED
|
|
|
|
pragma solidity ^0.8.23;
|
|
|
|
|
|
|
|
import { Test, console2 } from "forge-std/Test.sol";
|
|
|
|
import { DappIndexer } from "src/DappIndexer.sol";
|
2024-05-09 01:18:09 +00:00
|
|
|
import { CIDStorage } from "src/CIDStorage.sol";
|
2024-01-22 21:48:51 +00:00
|
|
|
|
|
|
|
contract DappIndexerTest is Test {
|
|
|
|
DappIndexer public dappIdxr;
|
|
|
|
string[] public dappsURI;
|
2024-05-09 01:18:09 +00:00
|
|
|
address public owner;
|
2024-01-22 21:48:51 +00:00
|
|
|
|
|
|
|
function setUp() public {
|
|
|
|
dappIdxr = new DappIndexer(address(this), address(this));
|
|
|
|
dappsURI = vm.envString("dapps", ' ');
|
2024-05-09 01:18:09 +00:00
|
|
|
owner = vm.envAddress("ACC0");
|
2024-01-22 21:48:51 +00:00
|
|
|
}
|
|
|
|
|
2024-05-09 01:18:09 +00:00
|
|
|
// Test adding a dapp that doesn't exist
|
2024-01-22 21:48:51 +00:00
|
|
|
function testAddDapp() public {
|
2024-05-09 01:18:09 +00:00
|
|
|
bytes32 dapp_name = bytes32("Dapp01");
|
2024-01-22 21:48:51 +00:00
|
|
|
bytes32 CID1;
|
|
|
|
bytes32 CID2;
|
|
|
|
|
2024-05-09 01:18:09 +00:00
|
|
|
(CID1, CID2) = CIDStorage.stringToBytes32Pair(dappsURI[0]);
|
2024-01-22 21:48:51 +00:00
|
|
|
|
|
|
|
// Add Dapp
|
2024-02-24 20:49:07 +00:00
|
|
|
console2.log("Dapp Name is:");
|
2024-05-09 01:18:09 +00:00
|
|
|
console2.logBytes32(dapp_name);
|
2024-01-22 21:48:51 +00:00
|
|
|
console2.log("Bytes32 first:");
|
|
|
|
console2.logBytes32(CID1);
|
|
|
|
console2.log("Bytes32 second:");
|
|
|
|
console2.logBytes32(CID2);
|
2024-05-09 01:18:09 +00:00
|
|
|
console2.log(CIDStorage.bytes32PairToString(CID1, CID2));
|
|
|
|
dappIdxr.addDapp(dapp_name, DappIndexer.PackedCID(CID1, CID2));
|
|
|
|
|
2024-01-22 21:48:51 +00:00
|
|
|
// retrive Dapp
|
2024-05-09 01:18:09 +00:00
|
|
|
DappIndexer.PackedCID memory dapp1 = dappIdxr.getDapp(dapp_name);
|
2024-01-22 21:48:51 +00:00
|
|
|
assertEq(CID1, dapp1.CID1);
|
|
|
|
assertEq(CID2, dapp1.CID2);
|
2024-05-09 01:18:09 +00:00
|
|
|
|
|
|
|
// reconstruct the CID and verify
|
|
|
|
string memory retrivedDappURI = CIDStorage.bytes32PairToString(dapp1.CID1, dapp1.CID2);
|
2024-01-22 23:28:25 +00:00
|
|
|
assertEq(dappsURI[0], retrivedDappURI);
|
|
|
|
}
|
|
|
|
|
2024-05-09 01:18:09 +00:00
|
|
|
//## ToDo ISSUE #2
|
|
|
|
//
|
|
|
|
//### Features testing
|
|
|
|
//
|
|
|
|
//- [x] test adding a dapp and retrive it. (addDapp, getDapp)
|
|
|
|
//
|
|
|
|
//- [ ] test removing a dapp that exists (verify dapps and dapp_names)
|
|
|
|
//- [ ] test dappExists (lower, upper, fuzz)
|
|
|
|
//- [ ] test removing a dapp that doesn't exist
|
|
|
|
//- [ ] test getting that names (listDappNames)
|
|
|
|
//- [ ] test getDappIndex (lower, upper, fuzz)
|
|
|
|
//- [ ] check if dapp name exists
|
|
|
|
//
|
|
|
|
//### Library testing
|
|
|
|
//
|
|
|
|
//- [ ] test adding longer CID
|
|
|
|
//- [ ] test adding shorter CID
|
|
|
|
//- [ ] test fuzz
|
|
|
|
//
|
|
|
|
//### Testing Roles Open Zeppelin Module
|
|
|
|
//
|
|
|
|
//- [ ] test roles for educational purposes.
|
|
|
|
//
|
2024-01-22 21:48:51 +00:00
|
|
|
|
|
|
|
}
|