From a5d33becd14042b219dbef442b624d2a5595da76 Mon Sep 17 00:00:00 2001 From: Tal Kol Date: Sat, 30 Apr 2022 03:14:04 +0100 Subject: [PATCH] Added counter tests --- README.md | 4 + build/.gitignore | 3 +- build/build.ts | 67 ++++-- contracts/main.ts | 14 ++ package-lock.json | 495 +++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +- test/counter.spec.ts | 27 ++- test/deposit.spec.ts | 5 - test/utils.ts | 11 + 9 files changed, 611 insertions(+), 20 deletions(-) create mode 100644 contracts/main.ts delete mode 100644 test/deposit.spec.ts create mode 100644 test/utils.ts diff --git a/README.md b/README.md index bc648bd..c0d1b44 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ To setup your machine for development, please make sure you have the following: * The `func` CLI tool (FunC compiler) * Installation instructions can be found [here](https://github.com/ton-defi-org/ton-binaries) * Run in terminal `func -V` to verify your installation +* The `fift` CLI tool + * Installation instructions can be found [here](https://github.com/ton-defi-org/ton-binaries) + * Don't forget to set the `FIFTPATH` env variable as part of the installation above + * Run in terminal `fift -V` and `fift` to verify your installation * A decent IDE with FunC and TypeScript support * We recommend using [Visual Studio Code](https://code.visualstudio.com/) with the [FunC plugin](https://marketplace.visualstudio.com/items?itemName=tonwhales.func-vscode) installed diff --git a/build/.gitignore b/build/.gitignore index c9e8cd3..22e613e 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1,2 +1,3 @@ *.fif -*.fc \ No newline at end of file +*.fc +*.cell \ No newline at end of file diff --git a/build/build.ts b/build/build.ts index 954c4e1..e2150f3 100644 --- a/build/build.ts +++ b/build/build.ts @@ -4,10 +4,10 @@ // ./contracts/*.fc - root contracts that are deployed separately are here // ./contracts/imports/*.fc - utility code that should be imported as compilation dependency is here -import * as fs from "fs"; -import * as path from "path"; -import * as process from "process"; -import * as child_process from "child_process"; +import fs from "fs"; +import path from "path"; +import process from "process"; +import child_process from "child_process"; import fg from "fast-glob"; console.log(`=================================================================`); @@ -23,9 +23,19 @@ if (!funcVersion.includes(`Func build information`)) { process.exit(1); } +// make sure fift cli is available +let fiftVersion = ""; +try { + fiftVersion = child_process.execSync("fift -V").toString(); +} catch (e) {} +if (!fiftVersion.includes(`Fift build information`)) { + console.log(`\nFATAL ERROR: 'fift' executable is not found, is it installed and in path?`); + process.exit(1); +} + const rootContracts = fg.sync(["contracts/*.fc", "contracts/*.func"]); for (const rootContract of rootContracts) { - // compile a new file + // compile a new root contract console.log(`\n* Found root contract '${rootContract}' - let's compile it:`); const contractName = path.parse(rootContract).name; @@ -40,8 +50,18 @@ for (const rootContract of rootContracts) { console.log(` - Deleting old build artifact '${mergedFuncArtifact}'`); fs.unlinkSync(mergedFuncArtifact); } + const fiftCellArtifact = `build/${contractName}.cell.fif`; + if (fs.existsSync(fiftCellArtifact)) { + console.log(` - Deleting old build artifact '${fiftCellArtifact}'`); + fs.unlinkSync(fiftCellArtifact); + } + const cellArtifact = `build/${contractName}.cell`; + if (fs.existsSync(cellArtifact)) { + console.log(` - Deleting old build artifact '${cellArtifact}'`); + fs.unlinkSync(cellArtifact); + } - // create one string with all source code from all merged files + // create a merged fc file with source code from all dependencies let sourceToCompile = ""; const importFiles = fg.sync(["contracts/imports/**/*.fc", "contracts/imports/**/*.func"]); for (const importFile of importFiles) { @@ -53,9 +73,9 @@ for (const rootContract of rootContracts) { fs.writeFileSync(mergedFuncArtifact, sourceToCompile); console.log(` - Build artifact created '${mergedFuncArtifact}'`); - // run the compiler + // run the func compiler to create a fif file console.log(` - Trying to compile '${mergedFuncArtifact}' with 'func' compiler..`); - const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1`).toString(); + const buildErrors = child_process.execSync(`func -APS -o build/${contractName}.fif ${mergedFuncArtifact} 2>&1 >&-`).toString(); if (buildErrors.length > 0) { console.log(` - OH NO! Compilation Errors! The compiler output was:`); console.log(`\n${buildErrors}`); @@ -64,12 +84,35 @@ for (const rootContract of rootContracts) { console.log(` - Compilation successful!`); } - // make sure build artifact was created - if (!fs.existsSync(`build/${contractName}.fif`)) { - console.log(` - For some reason 'build/${contractName}.fif' was not created!`); + // make sure fif build artifact was created + if (!fs.existsSync(fiftArtifact)) { + console.log(` - For some reason '${fiftArtifact}' was not created!`); + process.exit(1); + } else { + console.log(` - Build artifact created '${fiftArtifact}'`); + } + + // create a temp cell.fif that will generate the cell + let fiftCellSource = `"Asm.fif" include\n`; + fiftCellSource += `${fs.readFileSync(fiftArtifact).toString()}\n`; + fiftCellSource += `boc>B "${cellArtifact}" B>file`; + fs.writeFileSync(fiftCellArtifact, fiftCellSource); + + // run fift cli to create the cell + try { + child_process.execSync(`fift ${fiftCellArtifact}`); + } catch (e) { + console.log(`FATAL ERROR: 'fift' executable failed, is FIFTPATH env variable defined?`); + process.exit(1); + } + + // make sure cell build artifact was created + if (!fs.existsSync(cellArtifact)) { + console.log(` - For some reason '${cellArtifact}' was not created!`); process.exit(1); } else { - console.log(` - Build artifact created 'build/${contractName}.fif'`); + console.log(` - Build artifact created '${cellArtifact}'`); + fs.unlinkSync(fiftCellArtifact); } } diff --git a/contracts/main.ts b/contracts/main.ts new file mode 100644 index 0000000..b4148d5 --- /dev/null +++ b/contracts/main.ts @@ -0,0 +1,14 @@ +// this file assists with instantiating the contract (code and data cells) + +import * as fs from "fs"; +import { Cell, beginCell, Address } from "ton"; + +// returns contract code cell by relying on the build output in the build directory +export function createCode() { + return Cell.fromBoc(fs.readFileSync(__dirname + "/../build/main.cell"))[0]; +} + +// returns contract storage cell according to save_data() contract method +export function createData(params: { ownerAddress: Address; counter: number }) { + return beginCell().storeAddress(params.ownerAddress).storeUint(params.counter, 64).endCell(); +} diff --git a/package-lock.json b/package-lock.json index 28d7eec..5d4c149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,10 @@ "chai": "^4.3.4", "fast-glob": "^3.2.11", "mocha": "^9.1.3", + "prando": "^6.0.1", "prettier": "^2.6.2", + "ton": "^9.6.3", + "ton-contract-executor": "^0.4.8", "ts-node": "^10.4.0", "typescript": "^4.5.4" } @@ -75,6 +78,13 @@ "node": ">= 8" } }, + "node_modules/@scarf/scarf": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.1.1.tgz", + "integrity": "sha512-VGbKDbk1RFIaSmdVb0cNjjWJoRWRI/Weo23AjRCC2nryO0iAS8pzsToJfPVPtVs74WHw4L1UTADNdIYRLkirZQ==", + "dev": true, + "hasInstallScript": true + }, "node_modules/@tsconfig/node10": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", @@ -212,6 +222,15 @@ "node": "*" } }, + "node_modules/axios": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.14.7" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -227,6 +246,12 @@ "node": ">=8" } }, + "node_modules/bn.js": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz", + "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw==", + "dev": true + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -390,6 +415,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/dataloader": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/dataloader/-/dataloader-2.1.0.tgz", + "integrity": "sha512-qTcEYLen3r7ojZNgVUaRggOI+KM7jrKxXeSHhogh/TWxYMeONEMqY+hmkobiYQozsGIyg9OYVzO4ZIfoB4I0pQ==", + "dev": true + }, "node_modules/debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", @@ -473,6 +504,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/ethjs-unit": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz", + "integrity": "sha1-xmWSHkduh7ziqdWIpv4EBbLEFpk=", + "dev": true, + "dependencies": { + "bn.js": "4.11.6", + "number-to-bn": "1.7.0" + }, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, + "node_modules/ethjs-unit/node_modules/bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true + }, "node_modules/fast-glob": { "version": "3.2.11", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", @@ -535,6 +586,32 @@ "flat": "cli.js" } }, + "node_modules/follow-redirects": { + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/fp-ts": { + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-2.12.1.tgz", + "integrity": "sha512-oxvgqUYR6O9VkKXrxkJ0NOyU0FrE705MeqgBUMEPWyTu6Pwn768cJbHChw2XOBlgFLKfIHxjr2OOBFpv2mUGZw==", + "dev": true + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -660,6 +737,28 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "node_modules/io-ts": { + "version": "2.2.16", + "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-2.2.16.tgz", + "integrity": "sha512-y5TTSa6VP6le0hhmIyN0dqEXkrZeJLeC5KApJq6VLci3UEKF80lZ+KuoUs02RhBxNWlrqSNxzfI7otLX1Euv8Q==", + "dev": true, + "peerDependencies": { + "fp-ts": "^2.5.0" + } + }, + "node_modules/io-ts-reporters": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/io-ts-reporters/-/io-ts-reporters-2.0.1.tgz", + "integrity": "sha512-RVpLstYBsmTGgCW9wJ5KVyN/eRnRUDp87Flt4D1O3aJ7oAnd8csq8aXuu7ZeNK8qEDKmjUl9oUuzfwikaNAMKQ==", + "dev": true, + "dependencies": { + "@scarf/scarf": "^1.1.1" + }, + "peerDependencies": { + "fp-ts": "^2.10.5", + "io-ts": "^2.2.16" + } + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -702,6 +801,16 @@ "node": ">=0.10.0" } }, + "node_modules/is-hex-prefixed": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", + "dev": true, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -750,6 +859,15 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jssha": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.2.0.tgz", + "integrity": "sha512-QuruyBENDWdN4tZwJbQq7/eAK85FqrI4oDbXjy5IBhYD+2pTJyBUWZe8ctWaCkrV0gy6AaelgOZZBMeswEa/6Q==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -900,6 +1018,26 @@ "node": ">=0.10.0" } }, + "node_modules/number-to-bn": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", + "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", + "dev": true, + "dependencies": { + "bn.js": "4.11.6", + "strip-hex-prefix": "1.0.0" + }, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, + "node_modules/number-to-bn/node_modules/bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -978,6 +1116,12 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/prando": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/prando/-/prando-6.0.1.tgz", + "integrity": "sha512-ghUWxQ1T9IJmPu6eshc3VU0OwveUtXQ33ZLXYUcz1Oc5ppKLDXKp0TBDj6b0epwhEctzcQSNGR2iHyvQSn4W5A==", + "dev": true + }, "node_modules/prettier": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz", @@ -1053,6 +1197,21 @@ "node": ">=0.10.0" } }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -1131,6 +1290,19 @@ "node": ">=8" } }, + "node_modules/strip-hex-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "dev": true, + "dependencies": { + "is-hex-prefixed": "1.0.0" + }, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -1158,6 +1330,30 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, + "node_modules/symbol.inspect": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/symbol.inspect/-/symbol.inspect-1.0.1.tgz", + "integrity": "sha512-YQSL4duoHmLhsTD1Pw8RW6TZ5MaTX5rXJnqacJottr2P2LZBF/Yvrc3ku4NUpMOm8aM0KOCqM+UAkMA5HWQCzQ==", + "dev": true + }, + "node_modules/teslabot": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/teslabot/-/teslabot-1.5.0.tgz", + "integrity": "sha512-e2MmELhCgrgZEGo7PQu/6bmYG36IDH+YrBI1iGm6jovXkeDIGa3pZ2WSqRjzkuw2vt1EqfkZoV5GpXgqL8QJVg==", + "dev": true + }, + "node_modules/tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "dependencies": { + "rimraf": "^3.0.0" + }, + "engines": { + "node": ">=8.17.0" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -1170,6 +1366,77 @@ "node": ">=8.0" } }, + "node_modules/ton": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/ton/-/ton-9.9.0.tgz", + "integrity": "sha512-6t+/5b/6DbQH58ywJoc96CN1txcxXjZfYXk/vDeJClqfFR5Z9QikfoPGjLPHTkpLo8jALGPrcKnZDYIwU6biew==", + "dev": true, + "dependencies": { + "axios": "^0.25.0", + "bn.js": "5.2.0", + "dataloader": "^2.0.0", + "ethjs-unit": "0.1.6", + "fp-ts": "^2.11.1", + "io-ts": "^2.2.16", + "io-ts-reporters": "^2.0.0", + "symbol.inspect": "1.0.1", + "teslabot": "^1.3.0", + "ton-crypto": "2.1.0", + "tweetnacl": "1.0.3" + } + }, + "node_modules/ton-compiler": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/ton-compiler/-/ton-compiler-0.9.0.tgz", + "integrity": "sha512-7ZyjmSSmI8s/hd+H3c8qCzvUxDWLml4T8Lhr3DNAucadWhAXiVniTgPHHQNt5nbfZMvHKGevGw18pRkf5cFBZA==", + "dev": true, + "dependencies": { + "arg": "^5.0.1", + "tmp": "^0.2.1" + }, + "bin": { + "fift": "bin/fift", + "func": "bin/func", + "ton-compiler": "bin/ton-compiler" + } + }, + "node_modules/ton-compiler/node_modules/arg": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.1.tgz", + "integrity": "sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==", + "dev": true + }, + "node_modules/ton-contract-executor": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/ton-contract-executor/-/ton-contract-executor-0.4.8.tgz", + "integrity": "sha512-5XTLQre1KP6doi0Qobj3xF3g9DF2nKy5Lv5T6n7THEPp6P/m4fvjkXdrYE9Wldezv454JZ2cpisSUjNeqo9oJg==", + "dev": true, + "dependencies": { + "bn.js": "^5.2.0", + "ton": "^9.6.3", + "ton-compiler": "^0.9.0" + } + }, + "node_modules/ton-crypto": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ton-crypto/-/ton-crypto-2.1.0.tgz", + "integrity": "sha512-PZnmCOShfgq9tCRM8E7hG8nCkpkOyZvDLPXmZN92ZEBrfTT0NKKf0imndkxG5DkgWMjc6IKfgpnEaJDH9qN6ZQ==", + "dev": true, + "dependencies": { + "jssha": "3.2.0", + "ton-crypto-primitives": "2.0.0", + "tweetnacl": "1.0.3" + } + }, + "node_modules/ton-crypto-primitives": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ton-crypto-primitives/-/ton-crypto-primitives-2.0.0.tgz", + "integrity": "sha512-K+qKjpS0h9sPW6oExcpxnzuQ7nEgHEiDKwIqE/jWD25o8iFGe3FWj1gKxFNbKE9wwYKc5IV8FwrU+raF0KO5nQ==", + "dev": true, + "dependencies": { + "jssha": "3.2.0" + } + }, "node_modules/ts-node": { "version": "10.7.0", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", @@ -1222,6 +1489,12 @@ "node": ">=0.3.1" } }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", @@ -1409,6 +1682,12 @@ "fastq": "^1.6.0" } }, + "@scarf/scarf": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.1.1.tgz", + "integrity": "sha512-VGbKDbk1RFIaSmdVb0cNjjWJoRWRI/Weo23AjRCC2nryO0iAS8pzsToJfPVPtVs74WHw4L1UTADNdIYRLkirZQ==", + "dev": true + }, "@tsconfig/node10": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", @@ -1519,6 +1798,15 @@ "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true }, + "axios": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz", + "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", + "dev": true, + "requires": { + "follow-redirects": "^1.14.7" + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1531,6 +1819,12 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, + "bn.js": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz", + "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw==", + "dev": true + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1658,6 +1952,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "dataloader": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/dataloader/-/dataloader-2.1.0.tgz", + "integrity": "sha512-qTcEYLen3r7ojZNgVUaRggOI+KM7jrKxXeSHhogh/TWxYMeONEMqY+hmkobiYQozsGIyg9OYVzO4ZIfoB4I0pQ==", + "dev": true + }, "debug": { "version": "4.3.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", @@ -1714,6 +2014,24 @@ "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true }, + "ethjs-unit": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz", + "integrity": "sha1-xmWSHkduh7ziqdWIpv4EBbLEFpk=", + "dev": true, + "requires": { + "bn.js": "4.11.6", + "number-to-bn": "1.7.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true + } + } + }, "fast-glob": { "version": "3.2.11", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", @@ -1761,6 +2079,18 @@ "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true }, + "follow-redirects": { + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "dev": true + }, + "fp-ts": { + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-2.12.1.tgz", + "integrity": "sha512-oxvgqUYR6O9VkKXrxkJ0NOyU0FrE705MeqgBUMEPWyTu6Pwn768cJbHChw2XOBlgFLKfIHxjr2OOBFpv2mUGZw==", + "dev": true + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1854,6 +2184,22 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "io-ts": { + "version": "2.2.16", + "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-2.2.16.tgz", + "integrity": "sha512-y5TTSa6VP6le0hhmIyN0dqEXkrZeJLeC5KApJq6VLci3UEKF80lZ+KuoUs02RhBxNWlrqSNxzfI7otLX1Euv8Q==", + "dev": true, + "requires": {} + }, + "io-ts-reporters": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/io-ts-reporters/-/io-ts-reporters-2.0.1.tgz", + "integrity": "sha512-RVpLstYBsmTGgCW9wJ5KVyN/eRnRUDp87Flt4D1O3aJ7oAnd8csq8aXuu7ZeNK8qEDKmjUl9oUuzfwikaNAMKQ==", + "dev": true, + "requires": { + "@scarf/scarf": "^1.1.1" + } + }, "is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -1884,6 +2230,12 @@ "is-extglob": "^2.1.1" } }, + "is-hex-prefixed": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", + "dev": true + }, "is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -1917,6 +2269,12 @@ "argparse": "^2.0.1" } }, + "jssha": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jssha/-/jssha-3.2.0.tgz", + "integrity": "sha512-QuruyBENDWdN4tZwJbQq7/eAK85FqrI4oDbXjy5IBhYD+2pTJyBUWZe8ctWaCkrV0gy6AaelgOZZBMeswEa/6Q==", + "dev": true + }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -2026,6 +2384,24 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, + "number-to-bn": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/number-to-bn/-/number-to-bn-1.7.0.tgz", + "integrity": "sha1-uzYjWS9+X54AMLGXe9QaDFP+HqA=", + "dev": true, + "requires": { + "bn.js": "4.11.6", + "strip-hex-prefix": "1.0.0" + }, + "dependencies": { + "bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true + } + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -2077,6 +2453,12 @@ "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true }, + "prando": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/prando/-/prando-6.0.1.tgz", + "integrity": "sha512-ghUWxQ1T9IJmPu6eshc3VU0OwveUtXQ33ZLXYUcz1Oc5ppKLDXKp0TBDj6b0epwhEctzcQSNGR2iHyvQSn4W5A==", + "dev": true + }, "prettier": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.6.2.tgz", @@ -2119,6 +2501,15 @@ "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", "dev": true }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -2163,6 +2554,15 @@ "ansi-regex": "^5.0.1" } }, + "strip-hex-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "dev": true, + "requires": { + "is-hex-prefixed": "1.0.0" + } + }, "strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -2178,6 +2578,27 @@ "has-flag": "^4.0.0" } }, + "symbol.inspect": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/symbol.inspect/-/symbol.inspect-1.0.1.tgz", + "integrity": "sha512-YQSL4duoHmLhsTD1Pw8RW6TZ5MaTX5rXJnqacJottr2P2LZBF/Yvrc3ku4NUpMOm8aM0KOCqM+UAkMA5HWQCzQ==", + "dev": true + }, + "teslabot": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/teslabot/-/teslabot-1.5.0.tgz", + "integrity": "sha512-e2MmELhCgrgZEGo7PQu/6bmYG36IDH+YrBI1iGm6jovXkeDIGa3pZ2WSqRjzkuw2vt1EqfkZoV5GpXgqL8QJVg==", + "dev": true + }, + "tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "requires": { + "rimraf": "^3.0.0" + } + }, "to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -2187,6 +2608,74 @@ "is-number": "^7.0.0" } }, + "ton": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/ton/-/ton-9.9.0.tgz", + "integrity": "sha512-6t+/5b/6DbQH58ywJoc96CN1txcxXjZfYXk/vDeJClqfFR5Z9QikfoPGjLPHTkpLo8jALGPrcKnZDYIwU6biew==", + "dev": true, + "requires": { + "axios": "^0.25.0", + "bn.js": "5.2.0", + "dataloader": "^2.0.0", + "ethjs-unit": "0.1.6", + "fp-ts": "^2.11.1", + "io-ts": "^2.2.16", + "io-ts-reporters": "^2.0.0", + "symbol.inspect": "1.0.1", + "teslabot": "^1.3.0", + "ton-crypto": "2.1.0", + "tweetnacl": "1.0.3" + } + }, + "ton-compiler": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/ton-compiler/-/ton-compiler-0.9.0.tgz", + "integrity": "sha512-7ZyjmSSmI8s/hd+H3c8qCzvUxDWLml4T8Lhr3DNAucadWhAXiVniTgPHHQNt5nbfZMvHKGevGw18pRkf5cFBZA==", + "dev": true, + "requires": { + "arg": "^5.0.1", + "tmp": "^0.2.1" + }, + "dependencies": { + "arg": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.1.tgz", + "integrity": "sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==", + "dev": true + } + } + }, + "ton-contract-executor": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/ton-contract-executor/-/ton-contract-executor-0.4.8.tgz", + "integrity": "sha512-5XTLQre1KP6doi0Qobj3xF3g9DF2nKy5Lv5T6n7THEPp6P/m4fvjkXdrYE9Wldezv454JZ2cpisSUjNeqo9oJg==", + "dev": true, + "requires": { + "bn.js": "^5.2.0", + "ton": "^9.6.3", + "ton-compiler": "^0.9.0" + } + }, + "ton-crypto": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ton-crypto/-/ton-crypto-2.1.0.tgz", + "integrity": "sha512-PZnmCOShfgq9tCRM8E7hG8nCkpkOyZvDLPXmZN92ZEBrfTT0NKKf0imndkxG5DkgWMjc6IKfgpnEaJDH9qN6ZQ==", + "dev": true, + "requires": { + "jssha": "3.2.0", + "ton-crypto-primitives": "2.0.0", + "tweetnacl": "1.0.3" + } + }, + "ton-crypto-primitives": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ton-crypto-primitives/-/ton-crypto-primitives-2.0.0.tgz", + "integrity": "sha512-K+qKjpS0h9sPW6oExcpxnzuQ7nEgHEiDKwIqE/jWD25o8iFGe3FWj1gKxFNbKE9wwYKc5IV8FwrU+raF0KO5nQ==", + "dev": true, + "requires": { + "jssha": "3.2.0" + } + }, "ts-node": { "version": "10.7.0", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.7.0.tgz", @@ -2216,6 +2705,12 @@ } } }, + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", + "dev": true + }, "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", diff --git a/package.json b/package.json index 26a4127..fbe2623 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "prettier": "npx prettier --write '{test,contracts,build}/**/*.{ts,js,json}'", "build": "ts-node ./build/build.ts", - "test": "mocha test/**/*.spec.ts" + "test": "mocha --exit test/**/*.spec.ts" }, "devDependencies": { "@types/chai": "^4.3.0", @@ -15,7 +15,10 @@ "chai": "^4.3.4", "fast-glob": "^3.2.11", "mocha": "^9.1.3", + "prando": "^6.0.1", "prettier": "^2.6.2", + "ton": "^9.6.3", + "ton-contract-executor": "^0.4.8", "ts-node": "^10.4.0", "typescript": "^4.5.4" }, diff --git a/test/counter.spec.ts b/test/counter.spec.ts index da6e2d9..4ea177c 100644 --- a/test/counter.spec.ts +++ b/test/counter.spec.ts @@ -1,5 +1,30 @@ import { expect } from "chai"; +import { SmartContract } from "ton-contract-executor"; +import { createCode, createData } from "../contracts/main"; +import { randomAddress } from "./utils"; describe("Counter tests", () => { - + it("should run getter counter() and get counter value", async () => { + const contract = await SmartContract.fromCell( + createCode(), + createData({ + ownerAddress: randomAddress(0, "seed1"), + counter: 17, + }) + ); + const call = await contract.invokeGetMethod("counter", []); + expect(call.result[0].toNumber()).to.equal(17); + }); + + it("should run getter meaning_of_life()", async () => { + const contract = await SmartContract.fromCell( + createCode(), + createData({ + ownerAddress: randomAddress(0, "seed1"), + counter: 17, + }) + ); + const call = await contract.invokeGetMethod("meaning_of_life", []); + expect(call.result[0].toNumber()).to.equal(42); + }); }); diff --git a/test/deposit.spec.ts b/test/deposit.spec.ts deleted file mode 100644 index a2754b4..0000000 --- a/test/deposit.spec.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expect } from "chai"; - -describe("Deposit and withdraw tests", () => { - -}); diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 0000000..239bf29 --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,11 @@ +import { Address } from "ton"; +import Prando from "prando"; + +export function randomAddress(workchain: number, seed: string) { + const random = new Prando(seed); + const hash = Buffer.alloc(32); + for (let i = 0; i < hash.length; i++) { + hash[i] = random.nextInt(0, 255); + } + return new Address(workchain, hash); +}