npm install
npm test
. ├── contracts # sCrypt contract files │ ├── ackermann.scrypt # Ackermann function │ ├── advancedCounter.scrypt # Use external UTXOs to pay counter contract tx fees using sighash ANYONECANPAY │ ├── advancedTokenSale.scrypt # Sambe as above, but for token sale contract │ ├── counter.scrypt # Count the number of times a function has been called to showcase stateful contract │ ├── demo.scrypt # "hello world" contract │ ├── hashpuzzlep2pkh.scrypt # combining hash puzzle and p2pkh contracts │ ├── nonFungibleToken.scrypt # non-fungible token │ ├── p2pkh.scrypt # p2pkh contract written in sCrypt │ ├── rabin.scrypt # Rabin signature to import off-chain data into a contract via oracle │ ├── token.scrypt # Layer-1 tokens by storing token map as contract state in a single UTXO │ ├── tokenSale.scrypt # Selling tokens for bitcoins using atomic swap │ ├── tokenUtxo.scrypt # fungible token │ └── util.scrypt # utility functions and constants └── tests # contract test files ├── js # Javascript unit tests ├── testnet # e2e tests to deploy contract and call its function on testnet └── ts # Typescript unit tests
The major steps to write a sCrypt test are exemplified by tests/demo.scrypttest.js
.
- import / require
scrypttest
libary.
import { buildContractClass } from 'scrypttest';
- Use the imported function
buildContractClass
to get a reflected contract, which has same properties and methods as defined in the specified sCrypt contract.
const Demo = buildContractClass(path.join(__dirname, '../contracts/demo.scrypt'));
- Initialize the contract.
demo = new Demo(4, 7);
- Write tests for the instantiated contract as you would do in Javascript.
expect(demo.unlock(4 + 7)).to.equal(true);
Run unit tests file within the editor/explorer context menu.
Note: The test files must be suffixed by .scrypttest.js
or .scrypttest.ts
, otherwise the "Run sCrypt Test" option would not appear in the menu.
Tests could also be run from the console by executing npm test
, just like regular Javascript/TypeScript tests.
When your tests succeed locally, you can run them on testnet.
- Provide a private key with funds in
tests/runontestnet.js
const key = ''
npm run testnet
> scrypt_boilerplate@0.1.0 testnet ~/scrypt_boilerplate
> node tests/runontestnet.js
locking txid: 8d58ff9067f5fa893b5c695179559e108ebf850d0ce4fd1e42bc872417ffd424
unlocking txid: c60b57e93551a6c52282801130649c6a97edcca5d2b28b8b4ae2afe0ee59bf79
Succeeded on testnet