@openzeppelin/upgrades-core 1.26.2 → 1.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/LICENSE +22 -0
  2. package/dist/cli/cli.d.ts +3 -0
  3. package/dist/cli/cli.d.ts.map +1 -0
  4. package/dist/cli/cli.js +9 -0
  5. package/dist/cli/cli.js.map +1 -0
  6. package/dist/cli/cli.test.d.ts +2 -0
  7. package/dist/cli/cli.test.d.ts.map +1 -0
  8. package/dist/cli/cli.test.js +52 -0
  9. package/dist/cli/cli.test.js.map +1 -0
  10. package/dist/cli/index.d.ts +4 -0
  11. package/dist/cli/index.d.ts.map +1 -0
  12. package/dist/cli/index.js +10 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/cli/validate/build-info-file.d.ts +22 -0
  15. package/dist/cli/validate/build-info-file.d.ts.map +1 -0
  16. package/dist/cli/validate/build-info-file.js +116 -0
  17. package/dist/cli/validate/build-info-file.js.map +1 -0
  18. package/dist/cli/validate/build-info-file.test.d.ts +2 -0
  19. package/dist/cli/validate/build-info-file.test.d.ts.map +1 -0
  20. package/dist/cli/validate/build-info-file.test.js +175 -0
  21. package/dist/cli/validate/build-info-file.test.js.map +1 -0
  22. package/dist/cli/validate/contract-report.d.ts +31 -0
  23. package/dist/cli/validate/contract-report.d.ts.map +1 -0
  24. package/dist/cli/validate/contract-report.js +107 -0
  25. package/dist/cli/validate/contract-report.js.map +1 -0
  26. package/dist/cli/validate/error.d.ts +4 -0
  27. package/dist/cli/validate/error.d.ts.map +1 -0
  28. package/dist/cli/validate/error.js +8 -0
  29. package/dist/cli/validate/error.js.map +1 -0
  30. package/dist/cli/validate/project-report.d.ts +18 -0
  31. package/dist/cli/validate/project-report.d.ts.map +1 -0
  32. package/dist/cli/validate/project-report.js +42 -0
  33. package/dist/cli/validate/project-report.js.map +1 -0
  34. package/dist/cli/validate/project-report.test.d.ts +2 -0
  35. package/dist/cli/validate/project-report.test.d.ts.map +1 -0
  36. package/dist/cli/validate/project-report.test.js +90 -0
  37. package/dist/cli/validate/project-report.test.js.map +1 -0
  38. package/dist/cli/validate/upgradeability-assessment.d.ts +19 -0
  39. package/dist/cli/validate/upgradeability-assessment.d.ts.map +1 -0
  40. package/dist/cli/validate/upgradeability-assessment.js +103 -0
  41. package/dist/cli/validate/upgradeability-assessment.js.map +1 -0
  42. package/dist/cli/validate/validate-upgrade-safety.d.ts +16 -0
  43. package/dist/cli/validate/validate-upgrade-safety.d.ts.map +1 -0
  44. package/dist/cli/validate/validate-upgrade-safety.js +23 -0
  45. package/dist/cli/validate/validate-upgrade-safety.js.map +1 -0
  46. package/dist/cli/validate/validate-upgrade-safety.test.d.ts +2 -0
  47. package/dist/cli/validate/validate-upgrade-safety.test.d.ts.map +1 -0
  48. package/dist/cli/validate/validate-upgrade-safety.test.js +74 -0
  49. package/dist/cli/validate/validate-upgrade-safety.test.js.map +1 -0
  50. package/dist/cli/validate/validations.d.ts +11 -0
  51. package/dist/cli/validate/validations.d.ts.map +1 -0
  52. package/dist/cli/validate/validations.js +40 -0
  53. package/dist/cli/validate/validations.js.map +1 -0
  54. package/dist/cli/validate/validations.test.d.ts +2 -0
  55. package/dist/cli/validate/validations.test.d.ts.map +1 -0
  56. package/dist/cli/validate/validations.test.js +64 -0
  57. package/dist/cli/validate/validations.test.js.map +1 -0
  58. package/dist/cli/validate.d.ts +16 -0
  59. package/dist/cli/validate.d.ts.map +1 -0
  60. package/dist/cli/validate.js +119 -0
  61. package/dist/cli/validate.js.map +1 -0
  62. package/dist/cli/validate.test.d.ts +2 -0
  63. package/dist/cli/validate.test.d.ts.map +1 -0
  64. package/dist/cli/validate.test.js +108 -0
  65. package/dist/cli/validate.test.js.map +1 -0
  66. package/dist/index.d.ts +1 -0
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +5 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/manifest.test.js +2 -1
  71. package/dist/manifest.test.js.map +1 -1
  72. package/dist/utils/annotations.d.ts +16 -0
  73. package/dist/utils/annotations.d.ts.map +1 -0
  74. package/dist/utils/annotations.js +46 -0
  75. package/dist/utils/annotations.js.map +1 -0
  76. package/dist/utils/contract-name.d.ts +2 -0
  77. package/dist/utils/contract-name.d.ts.map +1 -0
  78. package/dist/utils/contract-name.js +8 -0
  79. package/dist/utils/contract-name.js.map +1 -0
  80. package/dist/validate/index.d.ts +1 -1
  81. package/dist/validate/index.d.ts.map +1 -1
  82. package/dist/validate/index.js +2 -1
  83. package/dist/validate/index.js.map +1 -1
  84. package/dist/validate/query.d.ts +8 -1
  85. package/dist/validate/query.d.ts.map +1 -1
  86. package/dist/validate/query.js +16 -3
  87. package/dist/validate/query.js.map +1 -1
  88. package/dist/validate/run.d.ts +1 -4
  89. package/dist/validate/run.d.ts.map +1 -1
  90. package/dist/validate/run.js +8 -38
  91. package/dist/validate/run.js.map +1 -1
  92. package/package.json +9 -3
  93. package/src/cli/cli.test.ts +57 -0
  94. package/src/cli/cli.test.ts.md +138 -0
  95. package/src/cli/cli.test.ts.snap +0 -0
  96. package/src/cli/cli.ts +9 -0
  97. package/src/cli/index.ts +3 -0
  98. package/src/cli/validate/build-info-file.test.ts +211 -0
  99. package/src/cli/validate/build-info-file.ts +150 -0
  100. package/src/cli/validate/contract-report.ts +130 -0
  101. package/src/cli/validate/error.ts +3 -0
  102. package/src/cli/validate/project-report.test.ts +124 -0
  103. package/src/cli/validate/project-report.test.ts.md +40 -0
  104. package/src/cli/validate/project-report.test.ts.snap +0 -0
  105. package/src/cli/validate/project-report.ts +44 -0
  106. package/src/cli/validate/upgradeability-assessment.ts +137 -0
  107. package/src/cli/validate/validate-upgrade-safety.test.ts +102 -0
  108. package/src/cli/validate/validate-upgrade-safety.test.ts.md +98 -0
  109. package/src/cli/validate/validate-upgrade-safety.test.ts.snap +0 -0
  110. package/src/cli/validate/validate-upgrade-safety.ts +29 -0
  111. package/src/cli/validate/validations.test.ts +72 -0
  112. package/src/cli/validate/validations.test.ts.md +87 -0
  113. package/src/cli/validate/validations.test.ts.snap +0 -0
  114. package/src/cli/validate/validations.ts +53 -0
  115. package/src/cli/validate.test.ts +112 -0
  116. package/src/cli/validate.ts +134 -0
  117. package/src/index.ts +2 -0
  118. package/src/manifest.test.ts +2 -1
  119. package/src/utils/annotations.ts +47 -0
  120. package/src/utils/contract-name.ts +3 -0
  121. package/src/validate/index.ts +1 -0
  122. package/src/validate/query.ts +16 -3
  123. package/src/validate/run.ts +5 -41
  124. package/CHANGELOG.md +0 -265
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 zOS Global Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const validate_1 = require("./validate");
5
+ const run = async () => {
6
+ await (0, validate_1.main)(process.argv.slice(2));
7
+ };
8
+ void run();
9
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":";;;AAEA,yCAAkC;AAElC,MAAM,GAAG,GAAG,KAAK,IAAI,EAAE;IACrB,MAAM,IAAA,eAAI,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,KAAK,GAAG,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.test.d.ts","sourceRoot":"","sources":["../../src/cli/cli.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ava_1 = __importDefault(require("ava"));
7
+ const util_1 = require("util");
8
+ const child_process_1 = require("child_process");
9
+ const fs_1 = require("fs");
10
+ const path_1 = __importDefault(require("path"));
11
+ const os_1 = __importDefault(require("os"));
12
+ const rimraf_1 = __importDefault(require("rimraf"));
13
+ const hardhat_1 = require("hardhat");
14
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
15
+ const rimraf = (0, util_1.promisify)(rimraf_1.default);
16
+ const CLI = 'node dist/cli/cli.js';
17
+ async function getTempDir(t) {
18
+ const temp = await fs_1.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'upgrades-core-test-'));
19
+ t.teardown(() => rimraf(temp));
20
+ return temp;
21
+ }
22
+ (0, ava_1.default)('help', async (t) => {
23
+ const output = (await execAsync(`${CLI} validate --help`)).stdout;
24
+ t.snapshot(output);
25
+ });
26
+ (0, ava_1.default)('no args', async (t) => {
27
+ const output = (await execAsync(CLI)).stdout;
28
+ t.snapshot(output);
29
+ });
30
+ (0, ava_1.default)('validate - errors', async (t) => {
31
+ const temp = await getTempDir(t);
32
+ const buildInfo = await hardhat_1.artifacts.getBuildInfo(`contracts/test/cli/Validate.sol:Safe`);
33
+ await fs_1.promises.writeFile(path_1.default.join(temp, 'validate.json'), JSON.stringify(buildInfo));
34
+ const error = await t.throwsAsync(execAsync(`${CLI} validate ${temp}`));
35
+ const expectation = [`Stdout: ${error.stdout}`, `Stderr: ${error.stderr}`];
36
+ t.snapshot(expectation.join('\n'));
37
+ });
38
+ (0, ava_1.default)('validate - no upgradeable', async (t) => {
39
+ const temp = await getTempDir(t);
40
+ const buildInfo = await hardhat_1.artifacts.getBuildInfo(`contracts/test/cli/Storage088.sol:Storage088`);
41
+ await fs_1.promises.writeFile(path_1.default.join(temp, 'validate.json'), JSON.stringify(buildInfo));
42
+ const output = (await execAsync(`${CLI} validate ${temp}`)).stdout;
43
+ t.snapshot(output);
44
+ });
45
+ (0, ava_1.default)('validate - ok', async (t) => {
46
+ const temp = await getTempDir(t);
47
+ const buildInfo = await hardhat_1.artifacts.getBuildInfo(`contracts/test/cli/Annotation.sol:Annotation`);
48
+ await fs_1.promises.writeFile(path_1.default.join(temp, 'validate.json'), JSON.stringify(buildInfo));
49
+ const output = (await execAsync(`${CLI} validate ${temp}`)).stdout;
50
+ t.snapshot(output);
51
+ });
52
+ //# sourceMappingURL=cli.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.test.js","sourceRoot":"","sources":["../../src/cli/cli.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAA6C;AAC7C,+BAAiC;AACjC,iDAAqC;AACrC,2BAAoC;AACpC,gDAAwB;AACxB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AAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhF,MAAM,MAAM,GAAG,CAAC,MAAM,SAAS,CAAC,GAAG,GAAG,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IACnE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { ValidateUpgradeSafetyOptions, validateUpgradeSafety } from './validate/validate-upgrade-safety';
2
+ export { ProjectReport } from './validate/project-report';
3
+ export { ReferenceContractNotFound } from './validate/upgradeability-assessment';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReferenceContractNotFound = exports.ProjectReport = exports.validateUpgradeSafety = void 0;
4
+ var validate_upgrade_safety_1 = require("./validate/validate-upgrade-safety");
5
+ Object.defineProperty(exports, "validateUpgradeSafety", { enumerable: true, get: function () { return validate_upgrade_safety_1.validateUpgradeSafety; } });
6
+ var project_report_1 = require("./validate/project-report");
7
+ Object.defineProperty(exports, "ProjectReport", { enumerable: true, get: function () { return project_report_1.ProjectReport; } });
8
+ var upgradeability_assessment_1 = require("./validate/upgradeability-assessment");
9
+ Object.defineProperty(exports, "ReferenceContractNotFound", { enumerable: true, get: function () { return upgradeability_assessment_1.ReferenceContractNotFound; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAAA,8EAAyG;AAAlE,gIAAA,qBAAqB,OAAA;AAC5D,4DAA0D;AAAjD,+GAAA,aAAa,OAAA;AACtB,kFAAiF;AAAxE,sIAAA,yBAAyB,OAAA"}
@@ -0,0 +1,22 @@
1
+ import { SolcOutput, SolcInput } from '../..';
2
+ /**
3
+ * A build info file containing Solidity compiler input and output JSON objects.
4
+ */
5
+ export interface BuildInfoFile {
6
+ /**
7
+ * The Solidity compiler input JSON object.
8
+ */
9
+ input: SolcInput;
10
+ /**
11
+ * The Solidity compiler output JSON object.
12
+ */
13
+ output: SolcOutput;
14
+ }
15
+ /**
16
+ * Gets the build info files from the build info directory.
17
+ *
18
+ * @param buildInfoDir Build info directory, or undefined to use the default Hardhat or Foundry build-info dir.
19
+ * @returns The build info files with Solidity compiler input and output.
20
+ */
21
+ export declare function getBuildInfoFiles(buildInfoDir?: string): Promise<BuildInfoFile[]>;
22
+ //# sourceMappingURL=build-info-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-info-file.d.ts","sourceRoot":"","sources":["../../../src/cli/validate/build-info-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AA6B9C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,4BAI5D"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBuildInfoFiles = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ const error_1 = require("./error");
10
+ const HARDHAT_COMPILE_COMMAND = 'npx hardhat clean && npx hardhat compile';
11
+ const FOUNDRY_COMPILE_COMMAND = 'forge clean && forge build';
12
+ const STORAGE_LAYOUT_HELP = `\
13
+ If using Hardhat, include the 'storageLayout' output selection in your Hardhat config:
14
+ module.exports = {
15
+ solidity: {
16
+ settings: {
17
+ outputSelection: {
18
+ '*': {
19
+ '*': ['storageLayout'],
20
+ },
21
+ },
22
+ },
23
+ },
24
+ };
25
+ Then recompile your contracts with '${HARDHAT_COMPILE_COMMAND}' and try again.
26
+
27
+ If using Foundry, include the "storageLayout" extra output in foundry.toml:
28
+ [profile.default]
29
+ build_info = true
30
+ extra_output = ["storageLayout"]
31
+ Then recompile your contracts with '${FOUNDRY_COMPILE_COMMAND}' and try again.`;
32
+ /**
33
+ * Gets the build info files from the build info directory.
34
+ *
35
+ * @param buildInfoDir Build info directory, or undefined to use the default Hardhat or Foundry build-info dir.
36
+ * @returns The build info files with Solidity compiler input and output.
37
+ */
38
+ async function getBuildInfoFiles(buildInfoDir) {
39
+ const dir = await findDir(buildInfoDir);
40
+ const jsonFiles = await getJsonFiles(dir);
41
+ return await readBuildInfo(jsonFiles);
42
+ }
43
+ exports.getBuildInfoFiles = getBuildInfoFiles;
44
+ async function findDir(buildInfoDir) {
45
+ if (buildInfoDir !== undefined && !(await hasJsonFiles(buildInfoDir))) {
46
+ throw new error_1.ValidateCommandError(`The directory '${buildInfoDir}' does not exist or does not contain any build info files.`, () => `\
47
+ If using Foundry, ensure your foundry.toml file has build_info = true.
48
+ Compile your contracts with '${HARDHAT_COMPILE_COMMAND}' or '${FOUNDRY_COMPILE_COMMAND}' and try again with the correct path to the build info directory.`);
49
+ }
50
+ const dir = buildInfoDir ?? (await findDefaultDir());
51
+ return dir;
52
+ }
53
+ async function findDefaultDir() {
54
+ const hardhatRelativeDir = path_1.default.join('artifacts', 'build-info');
55
+ const foundryRelativeDir = path_1.default.join('out', 'build-info');
56
+ const hardhatDir = path_1.default.join(process.cwd(), hardhatRelativeDir);
57
+ const foundryDir = path_1.default.join(process.cwd(), foundryRelativeDir);
58
+ const hasHardhatBuildInfo = await hasJsonFiles(hardhatDir);
59
+ const hasFoundryBuildInfo = await hasJsonFiles(foundryDir);
60
+ if (hasHardhatBuildInfo && hasFoundryBuildInfo) {
61
+ throw new error_1.ValidateCommandError(`Found both Hardhat and Foundry build info directories: '${hardhatRelativeDir}' and '${foundryRelativeDir}'.`, () => `Specify the build info directory that you want to validate.`);
62
+ }
63
+ else if (hasHardhatBuildInfo) {
64
+ return hardhatDir;
65
+ }
66
+ else if (hasFoundryBuildInfo) {
67
+ return foundryDir;
68
+ }
69
+ else {
70
+ throw new error_1.ValidateCommandError(`Could not find the default Hardhat or Foundry build info directory.`, () => `Compile your contracts with '${HARDHAT_COMPILE_COMMAND}' or '${FOUNDRY_COMPILE_COMMAND}', or specify the build info directory that you want to validate.`);
71
+ }
72
+ }
73
+ async function hasJsonFiles(dir) {
74
+ return (await exists(dir)) && (await getJsonFiles(dir)).length > 0;
75
+ }
76
+ async function exists(dir) {
77
+ try {
78
+ await fs_1.promises.access(dir);
79
+ return true;
80
+ }
81
+ catch (e) {
82
+ return false;
83
+ }
84
+ }
85
+ async function getJsonFiles(dir) {
86
+ const files = await fs_1.promises.readdir(dir);
87
+ const jsonFiles = files.filter(file => file.endsWith('.json'));
88
+ return jsonFiles.map(file => path_1.default.join(dir, file));
89
+ }
90
+ async function readBuildInfo(buildInfoFilePaths) {
91
+ const buildInfoFiles = [];
92
+ for (const buildInfoFilePath of buildInfoFilePaths) {
93
+ const buildInfoJson = await readJSON(buildInfoFilePath);
94
+ if (buildInfoJson.input === undefined || buildInfoJson.output === undefined) {
95
+ throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} must contain Solidity compiler input and output.`);
96
+ }
97
+ else {
98
+ if (!hasStorageLayoutSetting(buildInfoJson)) {
99
+ throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} does not contain storage layout.`, () => STORAGE_LAYOUT_HELP);
100
+ }
101
+ buildInfoFiles.push({
102
+ input: buildInfoJson.input,
103
+ output: buildInfoJson.output,
104
+ });
105
+ }
106
+ }
107
+ return buildInfoFiles;
108
+ }
109
+ function hasStorageLayoutSetting(buildInfoJson) {
110
+ const o = buildInfoJson.input.settings?.outputSelection;
111
+ return o?.['*']?.['*'] && (o['*']['*'].includes('storageLayout') || o['*']['*'].includes('*'));
112
+ }
113
+ async function readJSON(path) {
114
+ return JSON.parse(await fs_1.promises.readFile(path, 'utf8'));
115
+ }
116
+ //# sourceMappingURL=build-info-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-info-file.js","sourceRoot":"","sources":["../../../src/cli/validate/build-info-file.ts"],"names":[],"mappings":";;;;;;AAEA,2BAAoC;AACpC,gDAAwB;AACxB,mCAA+C;AAE/C,MAAM,uBAAuB,GAAG,0CAA0C,CAAC;AAC3E,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AAC7D,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;sCAaU,uBAAuB;;;;;;sCAMvB,uBAAuB,kBAAkB,CAAC;AAiBhF;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CAAC,YAAqB;IAC3D,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,MAAM,aAAa,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AAJD,8CAIC;AAED,KAAK,UAAU,OAAO,CAAC,YAAgC;IACrD,IAAI,YAAY,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,YAAY,CAAC,CAAC,EAAE;QACrE,MAAM,IAAI,4BAAoB,CAC5B,kBAAkB,YAAY,4DAA4D,EAC1F,GAAG,EAAE,CAAC;;+BAEmB,uBAAuB,SAAS,uBAAuB,oEAAoE,CACrJ,CAAC;KACH;IACD,MAAM,GAAG,GAAG,YAAY,IAAI,CAAC,M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AAG,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxD,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,IAAY;IAClC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,aAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=build-info-file.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-info-file.test.d.ts","sourceRoot":"","sources":["../../../src/cli/validate/build-info-file.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ava_1 = __importDefault(require("ava"));
7
+ const fs_1 = require("fs");
8
+ const rimraf_1 = __importDefault(require("rimraf"));
9
+ const util_1 = __importDefault(require("util"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const os_1 = __importDefault(require("os"));
12
+ const build_info_file_1 = require("./build-info-file");
13
+ const rimraf = util_1.default.promisify(rimraf_1.default);
14
+ ava_1.default.beforeEach(async (t) => {
15
+ process.chdir(await fs_1.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), `upgrades-core-test-${t.title.replace(/\s/g, '-')}-`)));
16
+ });
17
+ ava_1.default.afterEach(async () => {
18
+ await rimraf(process.cwd());
19
+ });
20
+ const BUILD_INFO = {
21
+ input: {
22
+ language: 'Solidity',
23
+ sources: {
24
+ 'mypath/MyContract.sol': {
25
+ content: 'contract MyContract {}',
26
+ },
27
+ },
28
+ settings: {
29
+ outputSelection: {
30
+ '*': {
31
+ '*': ['storageLayout'],
32
+ },
33
+ },
34
+ },
35
+ },
36
+ output: {
37
+ sources: {
38
+ 'mypath/MyContract.sol': {
39
+ ast: {},
40
+ id: 123,
41
+ },
42
+ },
43
+ },
44
+ };
45
+ const BUILD_INFO_2 = {
46
+ input: {
47
+ language: 'Solidity',
48
+ sources: {
49
+ 'mypath/MyContract.sol': {
50
+ content: 'contract MyContractModified {}',
51
+ },
52
+ },
53
+ settings: {
54
+ outputSelection: {
55
+ '*': {
56
+ '*': ['storageLayout'],
57
+ },
58
+ },
59
+ },
60
+ },
61
+ output: {
62
+ sources: {
63
+ 'mypath/MyContract.sol': {
64
+ ast: {},
65
+ id: 456,
66
+ },
67
+ },
68
+ },
69
+ };
70
+ const BUILD_INFO_NO_LAYOUT = {
71
+ input: {
72
+ language: 'Solidity',
73
+ sources: {
74
+ 'mypath/MyContract.sol': {
75
+ content: 'contract MyContract {}',
76
+ },
77
+ },
78
+ settings: {
79
+ outputSelection: {
80
+ '*': {
81
+ '*': ['abi'],
82
+ },
83
+ },
84
+ },
85
+ },
86
+ output: {
87
+ sources: {
88
+ 'mypath/MyContract.sol': {
89
+ ast: {},
90
+ id: 123,
91
+ },
92
+ },
93
+ },
94
+ };
95
+ ava_1.default.serial('get build info files - default hardhat', async (t) => {
96
+ await fs_1.promises.mkdir('artifacts/build-info', { recursive: true });
97
+ await fs_1.promises.mkdir('out/build-info', { recursive: true }); // should be ignored since it's empty
98
+ await fs_1.promises.writeFile('artifacts/build-info/build-info.json', JSON.stringify(BUILD_INFO));
99
+ await fs_1.promises.writeFile('artifacts/build-info/build-info-2.json', JSON.stringify(BUILD_INFO_2));
100
+ const buildInfoFiles = await (0, build_info_file_1.getBuildInfoFiles)();
101
+ assertBuildInfoFiles(t, buildInfoFiles);
102
+ });
103
+ ava_1.default.serial('get build info files - default foundry', async (t) => {
104
+ await fs_1.promises.mkdir('out/build-info', { recursive: true });
105
+ await fs_1.promises.mkdir('artifacts/build-info', { recursive: true }); // should be ignored since it's empty
106
+ await fs_1.promises.writeFile('out/build-info/build-info.json', JSON.stringify(BUILD_INFO));
107
+ await fs_1.promises.writeFile('out/build-info/build-info-2.json', JSON.stringify(BUILD_INFO_2));
108
+ const buildInfoFiles = await (0, build_info_file_1.getBuildInfoFiles)();
109
+ assertBuildInfoFiles(t, buildInfoFiles);
110
+ });
111
+ ava_1.default.serial('get build info files - both hardhat and foundry dirs exist', async (t) => {
112
+ await fs_1.promises.mkdir('artifacts/build-info', { recursive: true });
113
+ await fs_1.promises.writeFile('artifacts/build-info/build-info.json', JSON.stringify(BUILD_INFO));
114
+ await fs_1.promises.mkdir('out/build-info', { recursive: true });
115
+ await fs_1.promises.writeFile('out/build-info/build-info-2.json', JSON.stringify(BUILD_INFO_2));
116
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)());
117
+ t.true(error?.message.includes('Found both Hardhat and Foundry build info directories'));
118
+ });
119
+ ava_1.default.serial('get build info files - no default dirs exist', async (t) => {
120
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)());
121
+ t.true(error?.message.includes('Could not find the default Hardhat or Foundry build info directory'));
122
+ });
123
+ ava_1.default.serial('get build info files - override with custom relative path', async (t) => {
124
+ await fs_1.promises.mkdir('artifacts/build-info', { recursive: true });
125
+ await fs_1.promises.mkdir('out/build-info', { recursive: true });
126
+ await fs_1.promises.mkdir('custom/build-info', { recursive: true });
127
+ await fs_1.promises.writeFile('custom/build-info/build-info.json', JSON.stringify(BUILD_INFO));
128
+ await fs_1.promises.writeFile('custom/build-info/build-info-2.json', JSON.stringify(BUILD_INFO_2));
129
+ const buildInfoFiles = await (0, build_info_file_1.getBuildInfoFiles)('custom/build-info');
130
+ assertBuildInfoFiles(t, buildInfoFiles);
131
+ });
132
+ ava_1.default.serial('get build info files - override with custom absolute path', async (t) => {
133
+ await fs_1.promises.mkdir('artifacts/build-info', { recursive: true });
134
+ await fs_1.promises.mkdir('out/build-info', { recursive: true });
135
+ await fs_1.promises.mkdir('custom/build-info', { recursive: true });
136
+ await fs_1.promises.writeFile('custom/build-info/build-info.json', JSON.stringify(BUILD_INFO));
137
+ await fs_1.promises.writeFile('custom/build-info/build-info-2.json', JSON.stringify(BUILD_INFO_2));
138
+ const buildInfoFiles = await (0, build_info_file_1.getBuildInfoFiles)(path_1.default.join(process.cwd(), 'custom/build-info'));
139
+ assertBuildInfoFiles(t, buildInfoFiles);
140
+ });
141
+ ava_1.default.serial('invalid build info file', async (t) => {
142
+ await fs_1.promises.mkdir('invalid-build-info', { recursive: true });
143
+ await fs_1.promises.writeFile('invalid-build-info/invalid.json', JSON.stringify({ output: {} }));
144
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)('invalid-build-info'));
145
+ t.true(error?.message.includes('must contain Solidity compiler input and output'));
146
+ });
147
+ ava_1.default.serial('dir does not exist', async (t) => {
148
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)('invalid-dir'));
149
+ t.true(error?.message.includes('does not exist'));
150
+ });
151
+ ava_1.default.serial('no build info files', async (t) => {
152
+ await fs_1.promises.mkdir('empty-dir', { recursive: true });
153
+ await fs_1.promises.writeFile('empty-dir/notjson.txt', 'abc');
154
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)('empty-dir'));
155
+ t.true(error?.message.includes('does not contain any build info files'));
156
+ });
157
+ ava_1.default.serial('no storage layout', async (t) => {
158
+ await fs_1.promises.mkdir('no-storage-layout', { recursive: true });
159
+ await fs_1.promises.writeFile('no-storage-layout/build-info.json', JSON.stringify(BUILD_INFO_NO_LAYOUT));
160
+ const error = await t.throwsAsync((0, build_info_file_1.getBuildInfoFiles)('no-storage-layout'));
161
+ t.true(error?.message.includes('does not contain storage layout'));
162
+ });
163
+ function assertBuildInfoFiles(t, buildInfoFiles) {
164
+ t.is(buildInfoFiles.length, 2);
165
+ const buildInfoFile1 = buildInfoFiles.find(b => b.input.sources['mypath/MyContract.sol'].content === 'contract MyContract {}');
166
+ const buildInfoFile2 = buildInfoFiles.find(b => b.input.sources['mypath/MyContract.sol'].content === 'contract MyContractModified {}');
167
+ if (buildInfoFile1 === undefined || buildInfoFile2 === undefined) {
168
+ t.fail('build info files not found');
169
+ }
170
+ else {
171
+ t.is(buildInfoFile1.output.sources['mypath/MyContract.sol'].id, 123);
172
+ t.is(buildInfoFile2.output.sources['mypath/MyContract.sol'].id, 456);
173
+ }
174
+ }
175
+ //# sourceMappingURL=build-info-file.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-info-file.test.js","sourceRoot":"","sources":["../../../src/cli/validate/build-info-file.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAA6C;AAE7C,2BAAoC;AACpC,oDAAiC;AACjC,gDAAwB;AACxB,gDAAwB;AACxB,4CAAoB;AACpB,uDAAqE;AAErE,MAAM,MAAM,GAAG,cAAI,CAAC,SAAS,CAAC,gBAAW,CAAC,CAAC;AAE3C,aAAI,CAAC,UAAU,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACxB,OAAO,CAAC,KAAK,CAAC,MAAM,aAAE,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChH,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;IACxB,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG;IACjB,KAAK,EAAE;QACL,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE;YACP,uBAAuB,EAAE;gBACvB,OAAO,EA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AC,CAAC,CAAC;IAE9F,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,WAAW,CAAC,IAAA,mCAAiB,EAAC,mBAAmB,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,iCAAiC,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC,CAAC;AAEH,SAAS,oBAAoB,CAAC,CAAmB,EAAE,cAA+B;IAChF,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAE/B,MAAM,cAAc,GAAG,cAAc,CAAC,IAAI,CACxC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,OAAO,KAAK,wBAAwB,CACnF,CAAC;IACF,MAAM,cAAc,GAAG,cAAc,CAAC,IAAI,CACxC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,OAAO,KAAK,gCAAgC,CAC3F,CAAC;IAEF,IAAI,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,SAAS,EAAE;QAChE,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;KACtC;SAAM;QACL,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QACrE,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;KACtE;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { ValidateUpgradeSafetyOptions, UpgradeableContractErrorReport } from '../..';
2
+ import { Report } from '../../standalone';
3
+ import { SourceContract } from './validations';
4
+ import { LayoutCompatibilityReport } from '../../storage/report';
5
+ /**
6
+ * Report for an upgradeable contract.
7
+ * Contains the standalone report, and if there is a reference contract, the reference contract name and storage layout report.
8
+ */
9
+ export declare class UpgradeableContractReport implements Report {
10
+ readonly contract: string;
11
+ readonly reference: string | undefined;
12
+ readonly standaloneReport: UpgradeableContractErrorReport;
13
+ readonly storageLayoutReport: LayoutCompatibilityReport | undefined;
14
+ constructor(contract: string, reference: string | undefined, standaloneReport: UpgradeableContractErrorReport, storageLayoutReport: LayoutCompatibilityReport | undefined);
15
+ get ok(): boolean;
16
+ /**
17
+ * Explain any errors in the report.
18
+ */
19
+ explain(color?: boolean): string;
20
+ }
21
+ /**
22
+ * Gets upgradeble contract reports for the upgradeable contracts in the given set of source contracts.
23
+ * Only contracts that are detected as upgradeable will be included in the reports.
24
+ * Reports include upgradeable contracts regardless of whether they pass or fail upgrade safety checks.
25
+ *
26
+ * @param sourceContracts The source contracts to check, which must include all contracts that are referenced by the given contracts. Can also include non-upgradeable contracts, which will be ignored.
27
+ * @param opts The validation options.
28
+ * @returns The upgradeable contract reports.
29
+ */
30
+ export declare function getContractReports(sourceContracts: SourceContract[], opts: ValidateUpgradeSafetyOptions): UpgradeableContractReport[];
31
+ //# sourceMappingURL=contract-report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-report.d.ts","sourceRoot":"","sources":["../../../src/cli/validate/contract-report.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,4BAA4B,EAE5B,8BAA8B,EAE/B,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAGjE;;;GAGG;AACH,qBAAa,yBAA0B,YAAW,MAAM;IAEpD,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IACtC,QAAQ,CAAC,gBAAgB,EAAE,8BAA8B;IACzD,QAAQ,CAAC,mBAAmB,EAAE,yBAAyB,GAAG,SAAS;gBAH1D,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,gBAAgB,EAAE,8BAA8B,EAChD,mBAAmB,EAAE,yBAAyB,GAAG,SAAS;IAGrE,IAAI,EAAE,IAAI,OAAO,CAEhB;IAED;;OAEG;IACH,OAAO,CAAC,KAAK,UAAO,GAAG,MAAM;CAiB9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,4BAA4B,+BAgBvG"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getContractReports = exports.UpgradeableContractReport = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const debug_1 = __importDefault(require("../../utils/debug"));
9
+ const __1 = require("../..");
10
+ const upgradeability_assessment_1 = require("./upgradeability-assessment");
11
+ const indent_1 = require("../../utils/indent");
12
+ /**
13
+ * Report for an upgradeable contract.
14
+ * Contains the standalone report, and if there is a reference contract, the reference contract name and storage layout report.
15
+ */
16
+ class UpgradeableContractReport {
17
+ constructor(contract, reference, standaloneReport, storageLayoutReport) {
18
+ this.contract = contract;
19
+ this.reference = reference;
20
+ this.standaloneReport = standaloneReport;
21
+ this.storageLayoutReport = storageLayoutReport;
22
+ }
23
+ get ok() {
24
+ return this.standaloneReport.ok && (this.storageLayoutReport === undefined || this.storageLayoutReport.ok);
25
+ }
26
+ /**
27
+ * Explain any errors in the report.
28
+ */
29
+ explain(color = true) {
30
+ const result = [];
31
+ const chalk = new chalk_1.default.Instance({ level: color && chalk_1.default.supportsColor ? chalk_1.default.supportsColor.level : 0 });
32
+ const icon = this.ok ? chalk.green('✔') : chalk.red('✘');
33
+ if (this.reference === undefined) {
34
+ result.push(` ${icon} ${this.contract}`);
35
+ }
36
+ else {
37
+ result.push(` ${icon} ${this.contract} (upgrades from ${this.reference})`);
38
+ }
39
+ if (!this.standaloneReport.ok) {
40
+ result.push((0, indent_1.indent)(this.standaloneReport.explain(color), 6));
41
+ }
42
+ if (this.storageLayoutReport !== undefined && !this.storageLayoutReport.ok) {
43
+ result.push((0, indent_1.indent)(this.storageLayoutReport.explain(color), 6));
44
+ }
45
+ return result.join('\n\n');
46
+ }
47
+ }
48
+ exports.UpgradeableContractReport = UpgradeableContractReport;
49
+ /**
50
+ * Gets upgradeble contract reports for the upgradeable contracts in the given set of source contracts.
51
+ * Only contracts that are detected as upgradeable will be included in the reports.
52
+ * Reports include upgradeable contracts regardless of whether they pass or fail upgrade safety checks.
53
+ *
54
+ * @param sourceContracts The source contracts to check, which must include all contracts that are referenced by the given contracts. Can also include non-upgradeable contracts, which will be ignored.
55
+ * @param opts The validation options.
56
+ * @returns The upgradeable contract reports.
57
+ */
58
+ function getContractReports(sourceContracts, opts) {
59
+ const upgradeableContractReports = [];
60
+ for (const sourceContract of sourceContracts) {
61
+ const upgradeabilityAssessment = (0, upgradeability_assessment_1.getUpgradeabilityAssessment)(sourceContract, sourceContracts);
62
+ if (upgradeabilityAssessment.upgradeable) {
63
+ const reference = upgradeabilityAssessment.referenceContract;
64
+ const uups = upgradeabilityAssessment.uups;
65
+ const kind = uups ? 'uups' : 'transparent';
66
+ const report = getUpgradeableContractReport(sourceContract, reference, { ...opts, kind: kind });
67
+ if (report !== undefined) {
68
+ upgradeableContractReports.push(report);
69
+ }
70
+ }
71
+ }
72
+ return upgradeableContractReports;
73
+ }
74
+ exports.getContractReports = getContractReports;
75
+ function getUpgradeableContractReport(contract, referenceContract, opts) {
76
+ let version;
77
+ try {
78
+ version = (0, __1.getContractVersion)(contract.validationData, contract.name);
79
+ }
80
+ catch (e) {
81
+ if (e.message.endsWith('is abstract')) {
82
+ // Skip abstract upgradeable contracts - they will be validated as part of their caller contracts
83
+ // for the functions that are in use.
84
+ return undefined;
85
+ }
86
+ else {
87
+ throw e;
88
+ }
89
+ }
90
+ (0, debug_1.default)('Checking: ' + contract.fullyQualifiedName);
91
+ const standaloneReport = getStandaloneReport(contract.validationData, version, opts);
92
+ let reference;
93
+ let storageLayoutReport;
94
+ if (opts.unsafeSkipStorageCheck !== true && referenceContract !== undefined) {
95
+ const layout = (0, __1.getStorageLayout)(contract.validationData, version);
96
+ const referenceVersion = (0, __1.getContractVersion)(referenceContract.validationData, referenceContract.name);
97
+ const referenceLayout = (0, __1.getStorageLayout)(referenceContract.validationData, referenceVersion);
98
+ reference = referenceContract.fullyQualifiedName;
99
+ storageLayoutReport = (0, __1.getStorageUpgradeReport)(referenceLayout, layout, (0, __1.withValidationDefaults)(opts));
100
+ }
101
+ return new UpgradeableContractReport(contract.fullyQualifiedName, reference, standaloneReport, storageLayoutReport);
102
+ }
103
+ function getStandaloneReport(data, version, opts) {
104
+ const errors = (0, __1.getErrors)(data, version, (0, __1.withValidationDefaults)(opts));
105
+ return new __1.UpgradeableContractErrorReport(errors);
106
+ }
107
+ //# sourceMappingURL=contract-report.js.map