Template Code
The Flow JS Testing Framework is essentially a set of helper methods. They can be used in an opinionated way, envisioned by Flow Team. Or they can work as building blocks, allowing developers to build their own testing solution as they see fit. Following methods used inside other framework methods, but we feel encouraged to list them here as well.
getTemplate(file, addressMap, byAddress)
​
Returns Cadence template as string with addresses replaced using addressMap
Name | Type | Optional | Description |
---|---|---|---|
file | string | relative (to the place from where the script was called) or absolute path to the file containing the code | |
addressMap | AddressMap | ✅ | object to use for address mapping of existing deployed contracts. Default: {} |
byAddress | boolean | ✅ | whether addressMap is {name:address} or {address:address} type. Default: false |
Returns​
Type | Description |
---|---|
string | content of a specified file |
Usage​
getContractCode(name, addressMap)
​
Returns Cadence template from file with name
in _basepath_/contracts
folder
Arguments​
Name | Type | Optional | Description |
---|---|---|---|
name | string | name of the contract template | |
addressMap | AddressMap | ✅ | object to use for address mapping of existing deployed contracts |
Returns​
Type | Description |
---|---|
string | Cadence template code for specified contract |
Usage​
getTransactionCode(name, addressMap)
​
Returns Cadence template from file with name
in _basepath_/transactions
folder
Arguments​
Name | Type | Optional | Description |
---|---|---|---|
name | string | name of the transaction template | |
addressMap | AddressMap | ✅ | object to use for address mapping of existing deployed contracts |
Returns​
Type | Description |
---|---|
string | Cadence template code for specified transaction |
Usage​
getScriptCode(name, addressMap)
​
Returns Cadence template from file with name
in _basepath_/scripts
folder
Arguments​
Name | Type | Optional | Description |
---|---|---|---|
name | string | name of the script template | |
addressMap | AddressMap | ✅ | object to use for address mapping of existing deployed contracts |
Returns​
Type | Description |
---|---|
string | Cadence template code for specified script |
Usage​
Examples​
If you don't have any contract dependencies, you can use those methods without specifying address map as second parameter.