{"id":18757713,"url":"https://github.com/libotony/sharp","last_synced_at":"2025-07-18T14:42:51.988Z","repository":{"id":35109718,"uuid":"193661180","full_name":"libotony/sharp","owner":"libotony","description":"Write contract tests in Connex #causeican","archived":false,"fork":false,"pushed_at":"2022-02-11T00:58:02.000Z","size":38,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T08:08:37.047Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libotony.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}},"created_at":"2019-06-25T07:53:10.000Z","updated_at":"2019-10-20T08:48:14.000Z","dependencies_parsed_at":"2022-08-08T05:01:24.127Z","dependency_job_id":null,"html_url":"https://github.com/libotony/sharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libotony%2Fsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libotony%2Fsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libotony%2Fsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libotony%2Fsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libotony","download_url":"https://codeload.github.com/libotony/sharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239647204,"owners_count":19674115,"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-07T17:44:25.237Z","updated_at":"2025-02-19T11:27:22.863Z","avatar_url":"https://github.com/libotony.png","language":"TypeScript","readme":"# Sharp\n\nExperimental contract test utility package - just as `elegant` as [Connex](https://connex.vecha.in/#/).\n\n\u003e With VeChain-Enhanced VMOutput, you will be able to inspect more elements of a contract call than before\n\n## Features\n\n+ ContractMeta - manages contract bytecode and ABI\n+ Awaiter - wait tx to be packed\n+ Assertion - assert as much as you can image(event log, transfer log, method output)\n\n## Get Started\n\n[Sharp Example Project](https://github.com/libotony/sharp-example-vip180#sharp-example-project), a project shows a step by step guide of using sharp.\n\n## API\n\n```\nimport { ContractMeta, Awaiter, Assertion } from 'sharp'\n```\n\n### Contract Meta\n\n``` javascript\nconst bytecode = '0x.....'\nconst abiJSON = [...]\n\nconst contract = new ContractMeta(abiJSON, bytecode)\n\n//Get the bytecode\nconsole.log(contract.Code)\n\n//Search the abi definition\nconst abi = contract.ABI('balanceOf', 'function')\nconst transferEvent = contract.ABI('Transfer', 'event')\n\n//Build the deploy clause\nconst clause = contract\n    .deploy()\n    .value(100)             //100wei as endowment for contract creation\n    .asClause(arg0, arg1)   //args for constructor\n\n//Work with connex\nconst method = connex.thor.account(address).method(contract.ABI('balanceOf'))\nconst output = await method.call(accountA) //query the balance of the account\n\nconsole.log(output)\n```\n\n### Awaiter\n\n``` javascript\n//Wait until transaction was packed to the chain\nconst receipt = await Awaiter.receipt(thor.transaction(txid), thor.ticker())\n```\n\n### Assertion\n\n``` javascript\nconst accountA = '0x...'\nconst accountB = '0x...'\nconst amount = new BigNumber('1000000').times(1e18)\n\n//Ensure transfer VET emits an transfer log\nconst receipt: Connex.Thor.Receipt = await connex.thor.transaction(txid).getReceipt()\n\nAssertion\n    .transfer()\n    .logs(accountA, accountB, amount.toString())\n    .equal(receipt.outputs[0].transfers[0])\n\n//Ensure transfer energy emits an transfer event log\nconst method = connex.thor.account(address).method(contract.ABI('transfer'))\nconst output: Connex.Thor.VMOutput = method\n    .caller(accountA)\n    .call(accountB, amount.toString())\n\nAssertion\n    .event(contract.ABI('Transfer', 'event'))\n    .by(address)\n    .logs(accountA, accountB, amount.toString())\n    .equal(ret.outputs[0].events[0])\n\n//Ensure balanceOf method outputs the token balance\nconst method = connex.thor.account(address).method(contract.ABI('balanceOf'))\nconst output: Connex.Thor.VMOutput = method.call(accountB)\n\nAssertion\n    .method(contract.ABI('balanceOf'))\n    .outputs(amount.toString())\n    .equal(ret)\n\n//Ensure contract reverted with message\nconst output: Connex.Thor.VMOutput = method.call()\n\nAssertion\n    .revert()\n    .with('Must have set allowance for this contract')\n    .equal(output)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibotony%2Fsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibotony%2Fsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibotony%2Fsharp/lists"}