Skip to content

Commit

Permalink
Made the report look for many artifacts folders, test will still fail…
Browse files Browse the repository at this point in the history
… (bc they were not updated)
  • Loading branch information
martinvol committed Jul 24, 2023
1 parent c4d28fe commit 6de5d05
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 40 deletions.
4 changes: 4 additions & 0 deletions packages/protocol/lib/bytecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const CONTRACT_METADATA_REGEXPS = [
'a165627a7a72305820.{64}0029',
// 0.5.13
'a265627a7a72315820.{64}64736f6c6343.{6}0032',

'a264697066735822.{64}64736f6c6343.{6}0033',

'a264697066735822.{68}64736f6c6343.{6}0033'
]

const GENERAL_METADATA_REGEXP = new RegExp(
Expand Down
23 changes: 15 additions & 8 deletions packages/protocol/lib/compatibility/ast-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,19 @@ function generateASTCompatibilityReport(oldContract: ZContract, oldArtifacts: Bu
*/
export function reportASTIncompatibilities(
oldArtifacts: BuildArtifacts,
newArtifacts: BuildArtifacts): ASTCodeCompatibilityReport {
const reports = newArtifacts.listArtifacts()
.map((newArtifact) => {
const oldArtifact = oldArtifacts.getArtifactByName(newArtifact.contractName)
const oldZContract = oldArtifact ? makeZContract(oldArtifact) : null
return generateASTCompatibilityReport(oldZContract, oldArtifacts, makeZContract(newArtifact), newArtifacts)
})
return mergeReports(reports)
newArtifactsSets: BuildArtifacts[]): ASTCodeCompatibilityReport {

let out:ASTCodeCompatibilityReport[] = []
for (const newArtifacts of newArtifactsSets){
const reports = newArtifacts.listArtifacts()
.map((newArtifact) => {
const oldArtifact = oldArtifacts.getArtifactByName(newArtifact.contractName)
const oldZContract = oldArtifact ? makeZContract(oldArtifact) : null
return generateASTCompatibilityReport(oldZContract, oldArtifacts, makeZContract(newArtifact), newArtifacts)
})
out = [...out, ...reports]

}

return mergeReports(out)
}
43 changes: 25 additions & 18 deletions packages/protocol/lib/compatibility/ast-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Contract as Web3Contract } from '@celo/connect';
import { Artifact, TypeInfo } from '@celo/protocol/lib/compatibility/internal';
import {
BuildArtifacts,
compareStorageLayouts,
Contract as ZContract,
getStorageLayout,
Operation,
StorageLayoutInfo
StorageLayoutInfo,
Contract as ZContract,
compareStorageLayouts,
getStorageLayout
} from '@openzeppelin/upgrades';
const Web3 = require('web3')

Expand Down Expand Up @@ -198,6 +198,7 @@ export const generateCompatibilityReport = (oldArtifact: Artifact, oldArtifacts
const newLayout = getLayout(newArtifact, newArtifacts)
const layoutReport = generateLayoutCompatibilityReport(oldLayout, newLayout)
const structsReport = generateStructsCompatibilityReport(oldLayout, newLayout)

return {
contract: newArtifact.contractName,
compatible: layoutReport.compatible && structsReport.compatible,
Expand All @@ -206,19 +207,25 @@ export const generateCompatibilityReport = (oldArtifact: Artifact, oldArtifacts
}
}

export const reportLayoutIncompatibilities = (oldArtifacts: BuildArtifacts, newArtifacts: BuildArtifacts): ASTStorageCompatibilityReport[] => {
return newArtifacts.listArtifacts().map((newArtifact) => {
const oldArtifact = oldArtifacts.getArtifactByName(newArtifact.contractName)
if (oldArtifact !== undefined) {
return generateCompatibilityReport(oldArtifact, oldArtifacts, newArtifact, newArtifacts)
} else {
// Generate an empty report for new contracts, which are, by definition, backwards
// compatible.
return {
contract: newArtifact.contractName,
compatible: true,
errors: []
export const reportLayoutIncompatibilities = (oldArtifacts: BuildArtifacts, newArtifactsSets: BuildArtifacts[]): ASTStorageCompatibilityReport[] => {
let out: ASTStorageCompatibilityReport[] = []
for (const newArtifacts of newArtifactsSets){
const reports = newArtifacts.listArtifacts().map((newArtifact) => {
const oldArtifact = oldArtifacts.getArtifactByName(newArtifact.contractName)
if (oldArtifact !== undefined) {
return generateCompatibilityReport(oldArtifact, oldArtifacts, newArtifact, newArtifacts)
} else {
// Generate an empty report for new contracts, which are, by definition, backwards
// compatible.
return {
contract: newArtifact.contractName,
compatible: true,
errors: []
}
}
}
})
})

out = [...out, ...reports]
}
return out
}
18 changes: 11 additions & 7 deletions packages/protocol/lib/compatibility/ast-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const abi = require('ethereumjs-abi')
* A mapping {contract name => {@link ContractVersion}}.
*/
export class ASTContractVersions {
static fromArtifacts = async (artifacts: BuildArtifacts): Promise<ASTContractVersions>=> {
static fromArtifacts = async (artifactsSet: BuildArtifacts[]): Promise<ASTContractVersions>=> {
const contracts = {}

await Promise.all(artifacts.listArtifacts().filter(c => !isLibrary(c.contractName, artifacts)).map(async (artifact) => {
contracts[artifact.contractName] = await getContractVersion(artifact)
}))
for (const artifacts of artifactsSet){
await Promise.all(artifacts.listArtifacts().filter(c => !isLibrary(c.contractName, [artifacts])).map(async (artifact) => {
contracts[artifact.contractName] = await getContractVersion(artifact)
}))
}

return new ASTContractVersions(contracts)
}

Expand Down Expand Up @@ -54,9 +57,9 @@ export async function getContractVersion(artifact: Artifact): Promise<ContractVe
}

export class ASTContractVersionsChecker {
static create = async (oldArtifacts: BuildArtifacts, newArtifacts: BuildArtifacts, expectedVersionDeltas: ContractVersionDeltaIndex): Promise<ASTContractVersionsChecker> => {
const oldVersions = await ASTContractVersions.fromArtifacts(oldArtifacts)
const newVersions = await ASTContractVersions.fromArtifacts(newArtifacts)
static create = async (oldArtifacts: BuildArtifacts, newArtifactsSet: BuildArtifacts[], expectedVersionDeltas: ContractVersionDeltaIndex): Promise<ASTContractVersionsChecker> => {
const oldVersions = await ASTContractVersions.fromArtifacts([oldArtifacts])
const newVersions = await ASTContractVersions.fromArtifacts(newArtifactsSet)
const contracts = {}
Object.keys(newVersions.contracts).map((contract:string) => {
const versionDelta = expectedVersionDeltas[contract] === undefined ? ContractVersionDelta.fromChanges(false, false, false, false) : expectedVersionDeltas[contract]
Expand All @@ -65,6 +68,7 @@ export class ASTContractVersionsChecker {
})
return new ASTContractVersionsChecker(contracts)
}

constructor(public readonly contracts: ContractVersionCheckerIndex) {}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/protocol/lib/compatibility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class ASTBackwardReport {

static create = (
oldArtifactsFolder: string,
newArtifactsFolder: string,
newArtifactsFolders: string[],
oldArtifacts: BuildArtifacts,
newArtifacts: BuildArtifacts,
newArtifacts: BuildArtifacts[],
exclude: RegExp,
categorizer: Categorizer,
logFunction: (msg: string) => void): ASTBackwardReport => {
Expand All @@ -45,14 +45,14 @@ export class ASTBackwardReport {

return new ASTBackwardReport(
oldArtifactsFolder,
newArtifactsFolder,
newArtifactsFolders,
exclude.toString(),
versionedReport)
}

constructor(
public readonly oldArtifactsFolder: string,
public readonly newArtifactsFolder: string,
public readonly newArtifactsFolder: string[],
public readonly exclude: string,
public readonly report: ASTDetailedVersionedReport
) {}
Expand Down
10 changes: 7 additions & 3 deletions packages/protocol/scripts/check-backward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const argv = yargs

const oldArtifactsFolder = path.relative(process.cwd(), argv.old_contracts)
const newArtifactsFolder = path.relative(process.cwd(), argv.new_contracts)
const newArtifactsFolder08 = path.relative(process.cwd(), argv.new_contracts + '-0.8')
const newArtifactsFolders = [newArtifactsFolder, newArtifactsFolder08]

const out = (msg: string, force?: boolean): void => {
if (force || !argv.quiet) {
Expand All @@ -62,13 +64,15 @@ const outFile = argv.output_file ? argv.output_file : tmp.tmpNameSync({})
const exclude: RegExp = argv.exclude ? new RegExp(argv.exclude) : null
const oldArtifacts = instantiateArtifacts(oldArtifactsFolder)
const newArtifacts = instantiateArtifacts(newArtifactsFolder)
// console.log(newArtifactsFolder)
const newArtifacts08 = instantiateArtifacts(newArtifactsFolder08)

try {
const backward = ASTBackwardReport.create(
oldArtifactsFolder,
newArtifactsFolder,
newArtifactsFolders,
oldArtifacts,
newArtifacts,
[newArtifacts, newArtifacts08],
exclude,
new DefaultCategorizer(),
out
Expand All @@ -84,7 +88,7 @@ try {
const doVersionCheck = async () => {
const versionChecker = await ASTContractVersionsChecker.create(
oldArtifacts,
newArtifacts,
[newArtifacts, newArtifacts08],
backward.report.versionDeltas()
)
const mismatches = versionChecker.excluding(exclude).mismatches()
Expand Down

0 comments on commit 6de5d05

Please sign in to comment.