-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix backwards compatibility of upgrades-core (#221)
- Loading branch information
Showing
4 changed files
with
39 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# copies proxy artifacts to the location they were until 1.3.0 for backwards compatibility with truffle plugin | ||
|
||
cp artifacts/contracts/proxy/{AdminUpgradeabilityProxy.sol/AdminUpgradeabilityProxy.json,ProxyAdmin.sol/ProxyAdmin.json} artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,14 @@ import { isNullish } from './utils/is-nullish'; | |
export type ValidationLog = RunValidation[]; | ||
export type RunValidation = Record<string, ContractValidation>; | ||
|
||
// [email protected] introduced ValidationLog but for compatibility with ^1.0.0 | ||
// the functions exported by this module also accept a single RunValidation | ||
type Validations = ValidationLog | RunValidation; | ||
|
||
// aliases for backwards compatibility with ^1.0.0 | ||
export type Validation = RunValidation; | ||
export type ValidationResult = ContractValidation; | ||
|
||
export interface ContractValidation { | ||
version?: Version; | ||
inherit: string[]; | ||
|
@@ -121,19 +129,21 @@ export function validate(solcOutput: SolcOutput, decodeSrc: SrcDecoder): RunVali | |
return validation; | ||
} | ||
|
||
export function getContractVersion(validations: ValidationLog, contractName: string, compilationRun: number): Version { | ||
const { version } = validations[compilationRun][contractName]; | ||
export function getContractVersion(validation: RunValidation, contractName: string): Version { | ||
const { version } = validation[contractName]; | ||
if (version === undefined) { | ||
throw new Error(`Contract ${contractName} is abstract`); | ||
} | ||
return version; | ||
} | ||
|
||
export function getContractNameAndRunValidation(validations: ValidationLog, version: Version): [string, RunValidation] { | ||
export function getContractNameAndRunValidation(validations: Validations, version: Version): [string, RunValidation] { | ||
const validationLog = Array.isArray(validations) ? validations : [validations]; | ||
|
||
let runValidation; | ||
let contractName; | ||
|
||
for (const validation of validations) { | ||
for (const validation of validationLog) { | ||
contractName = Object.keys(validation).find( | ||
name => validation[name].version?.withMetadata === version.withMetadata, | ||
); | ||
|
@@ -150,7 +160,7 @@ export function getContractNameAndRunValidation(validations: ValidationLog, vers | |
return [contractName, runValidation]; | ||
} | ||
|
||
export function getStorageLayout(validations: ValidationLog, version: Version): StorageLayout { | ||
export function getStorageLayout(validations: Validations, version: Version): StorageLayout { | ||
const [contractName, runValidation] = getContractNameAndRunValidation(validations, version); | ||
const c = runValidation[contractName]; | ||
const layout: StorageLayout = { storage: [], types: {} }; | ||
|
@@ -161,8 +171,10 @@ export function getStorageLayout(validations: ValidationLog, version: Version): | |
return layout; | ||
} | ||
|
||
export function getUnlinkedBytecode(validations: ValidationLog, bytecode: string): string { | ||
for (const validation of validations) { | ||
export function getUnlinkedBytecode(validations: Validations, bytecode: string): string { | ||
const validationLog = Array.isArray(validations) ? validations : [validations]; | ||
|
||
for (const validation of validationLog) { | ||
const linkableContracts = Object.keys(validation).filter(name => validation[name].linkReferences.length > 0); | ||
|
||
for (const name of linkableContracts) { | ||
|
@@ -179,7 +191,7 @@ export function getUnlinkedBytecode(validations: ValidationLog, bytecode: string | |
return bytecode; | ||
} | ||
|
||
export function assertUpgradeSafe(validations: ValidationLog, version: Version, opts: ValidationOptions): void { | ||
export function assertUpgradeSafe(validations: Validations, version: Version, opts: ValidationOptions): void { | ||
const [contractName] = getContractNameAndRunValidation(validations, version); | ||
|
||
let errors = getErrors(validations, version); | ||
|
@@ -314,15 +326,15 @@ function describeError(e: ValidationError): string { | |
return log.join('\n '); | ||
} | ||
|
||
export function getErrors(validations: ValidationLog, version: Version): ValidationError[] { | ||
export function getErrors(validations: Validations, version: Version): ValidationError[] { | ||
const [contractName, runValidation] = getContractNameAndRunValidation(validations, version); | ||
const c = runValidation[contractName]; | ||
return c.errors | ||
.concat(...c.inherit.map(name => runValidation[name].errors)) | ||
.concat(...c.libraries.map(name => runValidation[name].errors)); | ||
} | ||
|
||
export function isUpgradeSafe(validations: ValidationLog, version: Version): boolean { | ||
export function isUpgradeSafe(validations: Validations, version: Version): boolean { | ||
return getErrors(validations, version).length == 0; | ||
} | ||
|
||
|