From 60a1b4cf087d92e7d3ffae842a35c720e5f4b558 Mon Sep 17 00:00:00 2001 From: lbqds Date: Tue, 11 Jun 2024 08:58:12 +0800 Subject: [PATCH] Check if the contract method indices are the same --- packages/cli/src/project.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/cli/src/project.ts b/packages/cli/src/project.ts index 7d0c9a049..0507215d4 100644 --- a/packages/cli/src/project.ts +++ b/packages/cli/src/project.ts @@ -436,6 +436,22 @@ export class Project { return forceRecompile || changedSources.includes(name) } + private async checkMethodIndex(newArtifact: Compiled) { + const artifactPath = newArtifact.sourceInfo.getArtifactPath(this.artifactsRootDir) + let oldArtifact: Contract + try { + oldArtifact = await Contract.fromArtifactFile(artifactPath, '', '') + } catch (error) { + throw new Error(`Failed to load contract artifact, error: ${error}, contract: ${newArtifact.sourceInfo.name}`) + } + newArtifact.artifact.functions.forEach((newFuncSig, index) => { + const oldFuncSig = oldArtifact.functions[`${index}`] + if (oldFuncSig.name !== newFuncSig.name) { + throw new Error(`Function ${newFuncSig.name} has invalid index ${index}`) + } + }) + } + private async saveArtifactsToFile( projectRootDir: string, forceRecompile: boolean, @@ -453,6 +469,8 @@ export class Project { for (const [_, contract] of this.contracts) { if (Project.needToUpdate(forceRecompile, changedSources, contract.sourceInfo.name)) { await saveToFile(contract) + } else { + await this.checkMethodIndex(contract) } } for (const [_, script] of this.scripts) {