{"id":19070837,"url":"https://github.com/ohager/signum-smartc-testbed","last_synced_at":"2025-04-28T14:47:59.176Z","repository":{"id":197470815,"uuid":"698642220","full_name":"ohager/signum-smartc-testbed","owner":"ohager","description":"A Test Environment for automated testing of Signum SmartC - Smart Contract Compiler","archived":false,"fork":false,"pushed_at":"2024-08-04T15:29:45.000Z","size":902,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T14:50:31.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ohager.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-09-30T14:24:56.000Z","updated_at":"2024-08-04T15:29:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4632374-d7b0-43ff-b959-91073bbc075a","html_url":"https://github.com/ohager/signum-smartc-testbed","commit_stats":null,"previous_names":["ohager/signum-smartc-testbed"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohager%2Fsignum-smartc-testbed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohager%2Fsignum-smartc-testbed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohager%2Fsignum-smartc-testbed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohager%2Fsignum-smartc-testbed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohager","download_url":"https://codeload.github.com/ohager/signum-smartc-testbed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251333834,"owners_count":21572901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-09T01:20:51.920Z","updated_at":"2025-04-28T14:47:59.131Z","avatar_url":"https://github.com/ohager.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# signum-smartc-testbed\n\nA Test Environment for automated testing of Signum SmartC - Smart Contract Compiler\n\nDevelop and your SmartC Contracts faster and more secure using a full TDD approach!\n\n![image](https://github.com/ohager/signum-smartc-testbed/assets/3920663/9a3ba02c-5bb3-420e-885c-e805b0ce10ca)\n\n## Motivation\n\nThe [SmartC Simulator](https://deleterium.info/sc-simulator) is an awesome environment to develop Smart Contracts for [Signum Blockchain](https://signum.network).\nIt gives you a lot of power to develop and debug your Smart Contracts. But it turns out to be a bit time-consuming. This project's\ngoal is to speed up development by applying pure TDD and give you automation on tests. This way the developer can focus more on the code\nand develop faster more complex scenarios without being victim of testing fatigue. In the end, it makes the contracts even more secure.\n\n---\n\n##🧪 This is still experimental\n\n**☢️ Use at your own risk ☢️**\n\n## Quick Start\n\nUse the [Public Project Template](https://github.com/ohager/signum-smartc-testbed-starter) or create your local starter project(*):\n\n1. `npx tiged git@github.com:ohager/signum-smartc-testbed-starter.git \u003cyour-project-folder\u003e`\n2. `npm install`\n3. `npm test`\n\nIf no error occurs you can start developing your own contract!\n\n\u003e (*) requires NodeJS18+ installed\n\n## How to use?\n\nUse the testbed as a programmable testing environment. Use it together with test runner like [Jest](https://jestjs.io/) or [Vitest](https://vitest.dev/) (recommended)\n\nInstall it using your favorite package manager\n\n`npm i signum-smartc-testbed --dev` or `yarn add signum-smartc-testbed -D` (or similar)\n\nFollow instructions how to set up the Testrunner, i.e. Jest or Vitest (recommended).\n\nA recommended project structure is like this:\n\n```\n.\n├── contract\n│   ├── context.ts \u003c\u003c constants like Account Ids, Map Keys, Token Ids etc\n│   ├── method-1\n│   │   ├── method-1.scenarios.ts \u003c\u003c Transaction Set for method-1\n│   │   └── method-1.test.ts \u003c\u003c The unit tests\n│   ├── method-2\n│   │   ├── method-2.scenarios.ts\n│   │   └── method-12.test.ts\n│   └── contract.smart.c \u003c\u003c The contract itself\n├── package.json\n├── README.md\n├── tsconfig.json\n├── vitest.config.ts\n└── yarn.lock\n```\n\nWithin the unit tests it's recommended to reset the testbed on each test to avoid having previous states. As a consequence\nthe test runner must not run the tests in parallel, but in-line.\n\nA typical test suite may look like this (taken from a real application)\n\n```ts\ndescribe(\"Stock Contract - Change Usage Fee\", () =\u003e {\n  test(\"should change fee and take effect\", () =\u003e {\n    const testbed =\n      SimulatorTestbed.loadContract(ContractPath).runScenario(ChangeUsageFee);\n\n    const bc = testbed.blockchain;\n    expect(testbed.getContractMemoryValue(\"usageFee\")).toEqual(2_5000_0000n);\n    expect(testbed.getContractMemoryValue(\"stats_stockQuantity\")).toEqual(400n);\n    expect(bc.transactions).toHaveLength(7);\n    const feepayment = bc.transactions[5];\n    expect(feepayment.amount).toEqual(2_5000_0000n);\n    expect(feepayment.recipient).toEqual(Context.VeridiBlocAccount);\n    const veridiBloc = bc.accounts.find(\n      (a) =\u003e a.id === Context.VeridiBlocAccount,\n    );\n    expect(veridiBloc?.balance).toEqual(7_0000_0000n); // 5 + 2,5 - 0,5\n  });\n  test(\"try to change fee when not creator\", () =\u003e {\n    const testbed = SimulatorTestbed.loadContract(ContractPath).runScenario(\n      ChangeUsageFeeNotAllowed,\n    );\n    const bc = testbed.blockchain;\n    expect(testbed.getContractMemoryValue(\"usageFee\")).toEqual(5_0000_0000n);\n    const errors = bc\n      .getMapsPerSlot()\n      .filter(\n        (x) =\u003e\n          x.k1 === Context.Maps.KeyError \u0026\u0026\n          x.value === Context.ErrorCodes.NoPermission,\n      );\n    expect(errors).toHaveLength(2);\n  });\n});\n```\n\nLook at [API Documentation](https://ohager.github.io/signum-smartc-testbed/index.html) for details.\n\n\n\n## ROADMAP\n\n- [x] Github Starter Template\n- [x] Unit Tests\n- [x] Externalize Utility Functions, e.g. method args conversion\n- [x] Stable MultiSlot Support\n- [ ] Adding Testbed for real Blockchain Node\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohager%2Fsignum-smartc-testbed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohager%2Fsignum-smartc-testbed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohager%2Fsignum-smartc-testbed/lists"}