@onflow/flow-js-testing
Version:
This package will expose a set of utility methods, to allow Cadence code testing with libraries like Jest
46 lines (35 loc) • 1.21 kB
JavaScript
/** pragma type script **/
import {
getEnvironment,
replaceImportAddresses,
reportMissingImports,
reportMissing,
} from '@onflow/flow-cadut'
import { executeScript } from '../../interaction'
export const CODE = `
import FlowManager from 0x01
access(all) fun main(){
// the body can be empty, cause script will throw error if FlowManager is not
// added to service address
}
`;
/**
* Method to generate cadence code for checkManager script
* @param {Object.<string, string>} addressMap - contract name as a key and address where it's deployed as value
*/
export const checkManagerTemplate = async (addressMap = {}) => {
const envMap = await getEnvironment();
const fullMap = {
...envMap,
...addressMap,
};
// If there are any missing imports in fullMap it will be reported via console
reportMissingImports(CODE, fullMap, `checkManager =>`)
return replaceImportAddresses(CODE, fullMap);
};
export const checkManager = async (props = {}) => {
const { addressMap = {}, args = [] } = props
const code = await checkManagerTemplate(addressMap);
reportMissing("arguments", args.length, 0, `checkManager =>`);
return executeScript({code, processed: true, ...props})
}