{"id":35253329,"url":"https://github.com/0x76agabond/diamond-testing-framework","last_synced_at":"2026-04-10T10:02:55.816Z","repository":{"id":318046162,"uuid":"1069815847","full_name":"0x76agabond/diamond-testing-framework","owner":"0x76agabond","description":"A structured, OOP-style framework for testing Diamond (EIP-2535) contracts. Designed for modularity, clarity, full test coverage across facets.","archived":false,"fork":false,"pushed_at":"2025-10-25T08:59:24.000Z","size":66,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-02T14:17:30.814Z","etag":null,"topics":["diamond-standard","eip-2535","oop","solidity","testing"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0x76agabond.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-04T17:16:22.000Z","updated_at":"2025-10-25T11:15:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"1b1305ba-ca4a-4b8a-9020-4aa12f6eb1a2","html_url":"https://github.com/0x76agabond/diamond-testing-framework","commit_stats":null,"previous_names":["0x76agabond/diamond-testing-framework"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/0x76agabond/diamond-testing-framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x76agabond%2Fdiamond-testing-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x76agabond%2Fdiamond-testing-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x76agabond%2Fdiamond-testing-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x76agabond%2Fdiamond-testing-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0x76agabond","download_url":"https://codeload.github.com/0x76agabond/diamond-testing-framework/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0x76agabond%2Fdiamond-testing-framework/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31637748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T07:40:12.752Z","status":"ssl_error","status_checked_at":"2026-04-10T07:40:11.664Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diamond-standard","eip-2535","oop","solidity","testing"],"created_at":"2025-12-30T07:15:17.243Z","updated_at":"2026-04-10T10:02:55.808Z","avatar_url":"https://github.com/0x76agabond.png","language":"Solidity","readme":"# Diamond Testing via OOP (DTO)\n\nA structured, **OOP-style framework** for testing **Diamond (EIP-2535)** contracts.  \nDesigned for modularity, clarity, full **test** coverage across facets.\n\n---\n\n## Abstract\n\n**DTO** is a small framework/pattern for testing Diamond contracts.  \nIt uses isolated runners for complex integration logic by combining:\n- Scoped `{}` blocks to keep each run separate  \n- `try/catch` to trap expected failures  \n- `tPrototype` / `tFacet` contracts as modular test units  \n\nThe goal is to provide an elegant way to run large, cross-module test logic inside a single test case — without crashing the whole suite.\n\n## Motivation\n\nWhen I first researched **EIP-2535 (Diamond Standard)**, the most frustrating thing was how people (and even AI tools like GPT or Gemini) kept calling it *too complicated*.  \nOpenZeppelin openly refuses to support it. The meme is always the same: *“just use another proxy.”*\n\nBut I see Diamond as a **game-changer for blockchain** — essentially a **microservice system on-chain**.  \nNaturally, a complex system needs **integration tests across multiple modules**, which normal frameworks don’t handle gracefully.\n\nWith current methods, there’s no clean way to run *massive, cross-facet integration tests*.  \nThis project shows how an OOP-style test harness can make Diamond testing simpler and more modular.\n\n---\n\n## Note on Gas\n\nYes, this pattern adds some gas overhead because each `{}` block and `try/catch` introduces extra execution cost.  \nBut since this is **test logic only**, not production flow, the gas cost doesn’t matter.  \n👉 The focus here is **clarity and isolation**, not efficiency.\n\n---\n\n## Facet → Interface → tFacet\n\nA Diamond is infinitely modular — each Facet lives as its own isolated logic block.  \nSo a monolithic test style (like Foundry’s default `Test.sol` approach) doesn’t scale well here.\n\nThe idea is simple:  \n👉 **if the system is modular, the test should mirror that modularity.**\n\n- Each **Facet** defines a specific behavior in the Diamond.  \n- Each **Interface** describes that behavior’s surface.  \n- Each **tFacet** sets up selectors and builds the cut based on its Interface.  \n- **tPrototype** represents many **tFacet** just like the **Diamond** represents many **Facets** \n\n![tPrototype → tFacet → Diamond diagram](https://drive.usercontent.google.com/download?id=1vTxBjWOo6NQLSyZW7zl2RnZf8-fC68q-\u0026export=view\u0026authuser=0)\n\n---\n\n## Pattern\n\n### 1. `tPrototype`\n- Abstract base contract for test units.  \n- Holds `selectors[]` and defines `setUp()`, `buildCut()`, `baseCut()`.  \n\n### 2. `tFacet`\n- Inherits from `tPrototype`.  \n- Declares the real Facet, builds selectors, and implements setup logic.  \n- Gets cut into the Diamond, then disposed to free stack space.\n\n### 3. Scoped `{}` Blocks\n- Each `{}` represents an isolated sub-test.  \n- Keeps state and revert scope clean.  \n\n### 4. `try/catch` Isolation\n- Prevents one failed sub-test from stopping the entire run.  \n- Each scenario can run independently and log its own results.\n\n---\n\n## Hack\n\n- All `tFacet` contracts were generated from Interfaces using Gemini-CLI.\n\n---\n\n## Note\n- **/test/TestAddFacet.t** is a simple unit test for diamond\n- **/test/TestMassiveIntegration.t.sol** shows how to use scoped `{}` blocks and `try/catch` to handle large initialization and test flows.  \n- **/test/TestSetupDiamond.t.sol** adds an abstraction layer for modular DiamondCuts using the `tPrototype` / `tFacet` pattern.\n- Since this is a `test framework`, you should check `test` directory for example\n---\n\n## Requirements\n- Foundry \n- Solidity \n- foundry.toml with `rpc_endpoints`\n\n## Getting Started\n1. Clone repo  \n2. Run `forge install` (if needed)  \n3. Add `rpc_endpoints`\n4. forge build \n5. forge test TestSetupDiamond.t -vvv\n---\n\n\n## Example\n\n### tPrototype\n\n```solidity\nabstract contract tPrototype is Test {\n    bytes4[] public selectors;\n\n    // @notice Build facet cut struct based on selectors\n    // @param facet The facet contract address\n    // @return cut as An array containing one FacetCut with all selectors\n    function setUp() public virtual;\n    function buildCut() external view virtual returns (IDiamondCut.FacetCut[] memory);\n\n    // basically same in all sub contract\n    function baseCut(address facet) internal view returns (IDiamondCut.FacetCut[] memory)\n    {        \n        IDiamondCut.FacetCut[] memory cut = new IDiamondCut.FacetCut[](1);\n        cut[0] = IDiamondCut.FacetCut({\n            facetAddress: facet,\n            action: IDiamondCut.FacetCutAction.Add,\n            functionSelectors: selectors\n        });\n\n        return cut;\n    }\n}\n\n\n```\n### tFacet\n```solidity\ncontract tAdd1Facet is tPrototype {\n    // for main call\n    Add1Facet public facet;\n\n    // set up here\n    function setUp() public override {\n        // Generate based on Facet\n        facet = new Add1Facet();\n\n        // Generate based on Interface\n        selectors = new bytes4[](3);\n        selectors[0] = IAdd1Facet.whoami1.selector;\n        selectors[1] = IAdd1Facet.add1.selector;\n        selectors[2] = IAdd1Facet.add1error.selector;\n    }\n\n    // basically same in all sub contract\n    function buildCut() external override view returns (IDiamondCut.FacetCut[] memory) {\n        return baseCut(address(facet));\n    }\n}\n```\n### Test Setup\n\n```solidity\n// Because all tFacet (tAdd1Facet, tAdd2Facet...) inherit tPrototype we can setup it like this\nfunction cutHelper(tPrototype temp, bytes memory data) internal \n{\n    IDiamondCut.FacetCut[] memory cut; \n    temp.setUp();\n    cut= temp.buildCut();\n    IDiamondCut(address(diamond)).diamondCut(cut, address(diamond), data);\n}\n\nfunction setupDiamond() internal\n{\n    vm.startPrank(vm.addr(key_owner));\n\n    // Deploy DiamondCutFacet and the main Diamond contract\n    {\n        DiamondCutFacet cutFacet = new DiamondCutFacet();  \n        diamond = new Diamond(address(vm.addr(key_owner)), address(cutFacet));\n    }\n                \n    // start setup here\n    {\n        // Base utility facets\n        cutHelper(new tDiamondLoupe(), \"\");  \n\n        // Functional modules              \n        cutHelper(new tAdd1Facet(), \"\");   \n           \n        // Initialization facet (with parameters)\n        cutHelper(new tAddFacet(), abi.encodeWithSelector(IAddFacet.init.selector, 500));   \n    }\n\n    vm.stopPrank();\n}\n\n```\n### Test Runner\n\n```solidity\n\n// test_massive_integration \n// use scope {} and try/catch pattern\n\n{\n    try IAdd17Facet(address(diamond)).add17(summer) returns (uint256 newSummer) {\n        summer = newSummer;\n        console.log(summer);\n    } catch {\n        console.log(\"Error calling add17\");\n    }\n}\n\n// handle Failpath\nconsole.log(\" use Try / Catch pattern - Failpath \");\nconsole.log(\" ================================== \");\n{\n    try IAdd1Facet(address(diamond)).add1error() {\n        console.log(\"add1error did not revert\");\n    } catch {\n        console.log(\"add1error reverted as expected\");\n    }\n}\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x76agabond%2Fdiamond-testing-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0x76agabond%2Fdiamond-testing-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0x76agabond%2Fdiamond-testing-framework/lists"}