{"id":22072531,"url":"https://github.com/broxus/ton-testing-suite","last_synced_at":"2025-07-24T11:30:38.929Z","repository":{"id":53473768,"uuid":"327344224","full_name":"broxus/ton-testing-suite","owner":"broxus","description":"Node JS framework for testing FreeTON (TON) smart contracts.","archived":false,"fork":false,"pushed_at":"2021-12-08T17:16:26.000Z","size":113,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-28T19:44:57.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/broxus.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":"2021-01-06T14:57:27.000Z","updated_at":"2021-12-08T17:16:30.000Z","dependencies_parsed_at":"2022-09-06T11:41:49.578Z","dependency_job_id":null,"html_url":"https://github.com/broxus/ton-testing-suite","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/broxus%2Fton-testing-suite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broxus%2Fton-testing-suite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broxus%2Fton-testing-suite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/broxus%2Fton-testing-suite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/broxus","download_url":"https://codeload.github.com/broxus/ton-testing-suite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227432007,"owners_count":17775893,"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-30T21:13:33.833Z","updated_at":"2024-11-30T21:13:34.471Z","avatar_url":"https://github.com/broxus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TON testing suite\n\n⚡ This package has been deprecated in favor of [locklift](https://github.com/broxus/ton-locklift) package.\nUse it at your own risk! ⚡\n\nSet of tools for making testing smart contracts on TON easier.\n\n## Installation\n\n```\nnpm install --save ton-testing-suite\n```\n\n## Project structure\n\nWe recommend to use the following structure in root of your project.\n\n```\nmigration/\ntest/\ncontracts/\nbuild/\n```\n\n### Compiling contracts\n\nThe testing suite is searching the ABI and base64 TVC in the build folder. You can compile it yourself of use the [compile.js](./compile.js) script. It requires\n\n- `tvm_linker` available binary ([source](https://github.com/tonlabs/TVM-linker))\n- `solc-ton` available binary ([source](https://github.com/tonlabs/TON-Solidity-Compiler/))\n- `build` folder is available\n\nTo compile the contracts, run the `node compile.js`.\n\n## Configuring TON\n\nTo start working with testing suite, you should specify seed for keys derivation and network.\n\n```javascript\nconst freeton = require('ton-testing-suite');\n\nconst tonWrapper = new freeton.TonWrapper({\n  network: 'https://net.ton.dev',\n  seed: 'regret neutral ... sand',\n});\n\n(async() =\u003e {\n  await tonWrapper.setup();\n})();\n```\n\n### Giver configuration\n\nThe process of deploying contracts in TON differs from the Ethereum's.\nSince there's no EOA accounts, someone should pay for deployment. For this reason, giver contract is used.\nGiver contract should implement the `sendGrams(address dest, uint64 amount) public pure` method.\nTesting suite will call it each time the `deploy` is used.\nThe example is bellow:\n\n```solidity\npragma solidity \u003e= 0.6.0;\npragma AbiHeader expire;\n\ncontract Giver {\n    constructor() public {\n        tvm.accept();\n    }\n\n    function sendGrams(address dest, uint64 amount) public pure {\n        tvm.accept();\n        require(address(this).balance \u003e amount, 60);\n        dest.transfer(amount, false, 1);\n    }\n}\n```\n\nAfter the Giver contract is deployed and have TON on it - pass it's address and ABI to the `TonWrapper` configuration.\nExample bellow is given for a [local TON node](https://hub.docker.com/r/tonlabs/local-node) - it has a pre-deployed Giver.\n\n```javascript\nconst freeton = require('ton-testing-suite');\n\nconst giverConfig = {\n  address: '0:841288ed3b55d9cdafa806807f02a0ae0c169aa5edfe88a789a6482429756a94',\n  abi: { \"ABI version\": 1, \"functions\": [ { \"name\": \"constructor\", \"inputs\": [], \"outputs\": [] }, { \"name\": \"sendGrams\", \"inputs\": [ {\"name\":\"dest\",\"type\":\"address\"}, {\"name\":\"amount\",\"type\":\"uint64\"} ], \"outputs\": [] } ], \"events\": [], \"data\": [] },\n};\n\nconst tonWrapper = new freeton.TonWrapper({\n  network: 'http://localhost',\n  seed: 'regret neutral ... sand',\n  giverConfig\n});\n\n(async() =\u003e {\n  await tonWrapper.setup();\n})();\n```\n\n## Running migrations\n\nMigration is the process of deploying contracts to the network and performing initial setup before tests.\nHere's an example of deploying single contract with constructor and init params.\n\n```javascript\n(async () =\u003e {\n  await tonWrapper.setup();\n  \n  tonWrapper.keys.map((key, i) =\u003e console.log(`Key #${i} - ${JSON.stringify(key)}`));\n\n  const migration = new freeton.Migration(tonWrapper);\n  \n  // Contract named 'Example.sol' in the 'contracts' folder\n  const Example = await freeton\n    .requireContract(tonWrapper, 'Example');\n  \n  // - Deploy Bridge\n  await migration.deploy({\n    contract: Example,\n    constructorParams: {\n      firstParam: 123,\n      secondParams: true,\n    },\n    initParams: {\n      thirdParam: 123123,\n    },\n    initialBalance: utils.convertCrystal('10', 'nano'),\n    _randomNonce: true,\n  }).catch(e =\u003e console.log(e));\n\n  migration.logHistory();\n  \n  process.exit(0);\n})();\n```\n\n### Using `_randomNonce`\n\nIn TON, contract address is derived from the contract code, `initParams` and signer key.\nAs you see there's no nonce as in Ethereum. It means, that deploying the same contract with the same params\nwill result in an error, because of already used address. To bypass this, add special initial param to your contract:\n\n```solidity\ncontract Example {\n    uint static _randomNonce;\n}\n```\n\nAnd specify `_randomNonce: true`, so testing suit will automatically pass the random number to it.\n\nMigration details will be saved in the `migration-log.json`.\n\n## Running tests\n\nWe recommend to use mocha for your tests. Save your tests in the `test` folder. Here's a test example:\n\n```javascript\nconst { expect } = require('chai');\nconst freeton = require('ton-testing-suite');\n\nlet Example;\n\nconst tonWrapper = new freeton.TonWrapper({\n  network: 'http://localhost',\n  seed: '....',\n});\n\n\ndescribe('Test event configurations', function() {\n  this.timeout(12000000);\n\n  before(async function() {\n    await tonWrapper.setup();\n\n    Example = await freeton\n      .requireContract(tonWrapper, 'Example');\n    await Example.loadMigration();\n  \n    console.log(`Example address: ${Example.address}`);\n  });\n\n    it('Check initial state', async function() {\n      await Bridge.run('updateStatus', {\n        status: true,\n      });\n\n      const {\n        status,\n      } = await Bridge.runLocal('getStatus', {});\n    \n      expect(status).to.equal(false, 'Wrong status');\n    });\n});\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroxus%2Fton-testing-suite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbroxus%2Fton-testing-suite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbroxus%2Fton-testing-suite/lists"}