{"id":26582987,"url":"https://github.com/digixglobal/contest","last_synced_at":"2025-03-23T08:19:32.475Z","repository":{"id":57108415,"uuid":"71422751","full_name":"DigixGlobal/contest","owner":"DigixGlobal","description":"[deprecated]  Delightful testing and scripting for Web3 contracts","archived":false,"fork":false,"pushed_at":"2017-06-14T08:47:11.000Z","size":82,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-14T02:42:37.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DigixGlobal.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":"2016-10-20T03:40:42.000Z","updated_at":"2024-03-08T20:02:30.000Z","dependencies_parsed_at":"2022-08-21T04:30:33.036Z","dependency_job_id":null,"html_url":"https://github.com/DigixGlobal/contest","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/DigixGlobal%2Fcontest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigixGlobal%2Fcontest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigixGlobal%2Fcontest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DigixGlobal%2Fcontest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DigixGlobal","download_url":"https://codeload.github.com/DigixGlobal/contest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245073130,"owners_count":20556490,"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":"2025-03-23T08:19:31.818Z","updated_at":"2025-03-23T08:19:32.456Z","avatar_url":"https://github.com/DigixGlobal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contest\n\n☠️ Contest is now deprecated. We recommend using node 7.10 + and the `async` pattern.\n\n### Web3 contract scripting and assertions\n\nSimplified API for testing contracts; generates mocha tests.\n\n## Features\n\n* Minimalist syntax for contract testing\n* Handle thrown calls\n* Assert transaction success/failure\n* Easily assert events data\n\n## Installation\n\nYou should be using truffle.\n\n```\nnpm install --save-dev @digix/contest\n```\n\n```javascript\nimport Contest from '@digix/contest';\nconst contest = new Contest({ debug: true, timeout: 2000 }); // `debug` defaults to false\n```\n\n## Usage\n\nContest wires up a series of promises for you with a convenient chaining syntax.\n\nEach chain should end in `done` - see the example below for usage.\n\nBefore calling methods, you must have a contract deployed:\n\n* Contract\n  * `.artifact(truffleArtifact)` for contracts deployed with truffle v3\n  * `.deploy(contract, [ params ])` deploys a new instance of contract with given params\n  * `.use(contractInstance)` use an existing instance of a an already-deployed contract\n\nOnce you have set a contract you can begin scripting against it:\n\n* Methods\n  * `.call(method, statement, samples)` call method with a series of statements\n  * `.tx(method, statement, samples, transformers)` same as above, initiate transaction\n  * If the first word in `statement` is `throw`, contest will expect the call/tx to throw.\n  * `samples` in the format `[ sample, sample, sample ]`, or pass a single `sample` for a single test\n  * `sample` for non-assertions (call/throw), use format `[input1, input2]`, for assertions, use `[[input1, input2], [output1, output2]]`\n  * `output` expected output to match; if output is a function, it will consume the method's output and resolve true/false\n  * `transformers` an array of functions that transform the outputs before asserting; e.g. `[v =\u003e v.toNumber(),v =\u003e '0x' +v]`\n* Events\n  * `.watch(method, statement, samples)` the next block must be a `tx`, it will match each sample in samples\n  * `sample` for `watch` is in the format `{ _param1: output1, _param2: output2 }`\n* Misc\n  `.wait(blocks, seconds)` alias for [tempo's waitForBlocks](https://github.com/DigixGlobal/tempo)\n* Test\n  * `.describe(description)` new describe block; for organixation only\n  * `.then(promise)` return a promise or execute arbitrary code\n  * `done()` end each chain with `done` to execute chain\n\n\n## Helpers\n\nContest also includes some common test helpers related to Ethereum. See `./src/helpers.js` for details.\n\n* `BIG_INT` BigNumber string representing maximum (256 integer)\n* `BIG_INT_MINUS_TWO`\n* `ONE_DAY_IN_SECONDS`\n* `asyncIterator(iterator, fn, callback)`\n* `randomInt(min, max)`\n* `randomHex(length, prefix)` - (`prefix` bool adds `0x`)\n* `randomAddress(prefix)`\n\nImport them as such: `import { BIG_INT, randomHex } from '@digix/contest/src/helpers';`\n\n## Example\n\n```javascript\nconst MetaCoin = artifacts.require('./MetaCoin.sol');\n\nnew Contest()\n.artifact(MetaCoin)\n// create a describe block to oragnise tests\n.describe('Account Balances')\n// pass an object to assert key/value paris for a method\n.call('getBalance', 'initializes with correct balances', {\n  [accounts[0]]: balance, // ES6 =\u003e { '0x123': 100, '0x456': 0 }\n  [accounts[1]]: 0, // will envoke and compare result of getBalance('0x456')\n})\n// notice that we're passing an array here instead of an object, use multi-input-output syntax\n.call('getBalance', 'some other statement', [\n  [[accounts[0]], [bal =\u003e bal \u003e 2]], // pass a function to resolve to `true` rather than equality assertion\n  [[accounts[1]], [0],\n])\n.describe('Library Import')\n// call a different method\n.call('getBalanceInEth', 'returns correct value from inherited method', {\n  [accounts[0]]: balance,\n  [accounts[1]]: 0,\n})\n// use `tx` to create a transaction. multiple transactions are executed in series\n.tx('sendCoin', 'transfer succeeds', [\n  [accounts[1], 10, { from: accounts[0] }],\n  [accounts[0], 10, { from: accounts[1] }],\n})\n.describe('Transfer balances')\n// listen for events with `watch`. it will match the outputs series with the next `tx` block\n.watch('Transfer', 'fires the events correctly', [\n  { _from: accounts[0], _to: accounts[1], _value: 10 },\n  { _from: accounts[1], _to: accounts[0], _value: 10 },\n  { _from: accounts[0], _to: accounts[1], _value: 10 },\n])\n.tx('sendCoin', 'transfer succeeds', [\n  [accounts[1], 10, { from: accounts[0] }],\n  [accounts[0], 10, { from: accounts[1] }],\n  [accounts[1], 10, { from: accounts[0] }],\n])\n// if you don't pass a 2nd statement param, it will not create a test, but will executed before the next block with a statements\n// the next block will do a series back and forth transactions without asserting\n.tx('sendCoin', [\n  [accounts[1], 10, { from: accounts[0] }],\n  [accounts[0], 10, { from: accounts[1] }],\n  [accounts[1], 10, { from: accounts[0] }],\n  [accounts[0], 10, { from: accounts[1] }],\n])\n// the keyword `throws` will cause the test pass only if the method throws\n.tx('sendCoin', 'throws when using bad numbers' [\n  [accounts[1], -22, { from: accounts[0] }],\n})\n.call('getBalance', 'balances after transaction are correct', {\n  [accounts[0]]: balance - transfer,\n  [accounts[1]]: transfer,\n})\n.done();\n```\n\n## Roadmap\n\n* Global config for re-runs (e.g. try different gas amounts on every test\n* Generate tests from Cucumber? Imagine a future where contracts are verified against english as such:\n\n```cucumber\nScenario: Interacting with ResolverClient\n\n  Scenario: Non admin fails to gain access\n    Given I am Jeff\n    And I use the contract ResolverClient\n    Then I cannot register contract\n\n  Scenario: Non admin fails to gain access\n    Given I am Ace\n    And I use the contract ResolverClient\n    And I register contract 'a:gold' as '0x123...def'\n    Then get contract 'a:gold' is '0x123...def'\n```\n\n## Tests\n\n* Mocked contract: `npm run test`\n* Truffle environment: `cd ./test/truffle; testrpc \u0026 truffle test`\n\n## License\n\nBSD-3-Clause, 2016\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigixglobal%2Fcontest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigixglobal%2Fcontest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigixglobal%2Fcontest/lists"}