(template: WalletTemplate, artifacts: Artifact[])
| 34 | |
| 35 | // debugs the template, optionally logging the execution data |
| 36 | export const debugTemplate = (template: WalletTemplate, artifacts: Artifact[]): DebugResults => { |
| 37 | // If a contract has the same name, but a different bytecode, then it is considered a name collision |
| 38 | const hasArtifactNameCollision = artifacts.some( |
| 39 | (artifact) => ( |
| 40 | artifacts.some((other) => other.contractName === artifact.contractName && other.bytecode !== artifact.bytecode) |
| 41 | ), |
| 42 | ); |
| 43 | |
| 44 | if (hasArtifactNameCollision) { |
| 45 | throw new Error('There are multiple artifacts with the same contractName. Please make sure that all artifacts have unique names.'); |
| 46 | } |
| 47 | |
| 48 | const results: DebugResults = {}; |
| 49 | const unlockingScriptIds = Object.keys(template.scripts).filter((key) => 'unlocks' in template.scripts[key]); |
| 50 | |
| 51 | for (const unlockingScriptId of unlockingScriptIds) { |
| 52 | const scenarioIds = (template.scripts[unlockingScriptId] as WalletTemplateScriptUnlocking).passes ?? []; |
| 53 | |
| 54 | const matchingArtifact = artifacts.find((artifact) => unlockingScriptId.startsWith(artifact.contractName)); |
| 55 | |
| 56 | for (const scenarioId of scenarioIds) { |
| 57 | results[`${unlockingScriptId}.${scenarioId}`] = debugSingleScenario(template, matchingArtifact, unlockingScriptId, scenarioId); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | verifyFullTransaction(template); |
| 62 | |
| 63 | return results; |
| 64 | }; |
| 65 | |
| 66 | const debugSingleScenario = ( |
| 67 | template: WalletTemplate, artifact: Artifact | undefined, unlockingScriptId: string, scenarioId: string, |
no test coverage detected