Skip to content

Commit

Permalink
Check if the contract method indices are the same
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbqds committed Jun 11, 2024
1 parent c067b42 commit 60a1b4c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/cli/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@ export class Project {
return forceRecompile || changedSources.includes(name)
}

private async checkMethodIndex(newArtifact: Compiled<Contract>) {
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,
Expand All @@ -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) {
Expand Down

0 comments on commit 60a1b4c

Please sign in to comment.