@openzeppelin/upgrades-core 1.9.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 (336) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.dbg.json +4 -0
  3. package/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +80 -0
  4. package/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +160 -0
  5. package/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +155 -0
  6. package/artifacts/AdminUpgradeabilityProxy.json +155 -0
  7. package/artifacts/ProxyAdmin.json +160 -0
  8. package/artifacts/contracts/proxy/AdminUpgradeabilityProxy.sol/AdminUpgradeabilityProxy.json +155 -0
  9. package/artifacts/contracts/proxy/ProxyAdmin.sol/ProxyAdmin.json +160 -0
  10. package/contracts/Initializable.sol +64 -0
  11. package/dist/ast-dereferencer.d.ts +8 -0
  12. package/dist/ast-dereferencer.d.ts.map +1 -0
  13. package/dist/ast-dereferencer.js +29 -0
  14. package/dist/ast-dereferencer.js.map +1 -0
  15. package/dist/deployment.d.ts +18 -0
  16. package/dist/deployment.d.ts.map +1 -0
  17. package/dist/deployment.js +110 -0
  18. package/dist/deployment.js.map +1 -0
  19. package/dist/deployment.test.d.ts +2 -0
  20. package/dist/deployment.test.d.ts.map +1 -0
  21. package/dist/deployment.test.js +92 -0
  22. package/dist/deployment.test.js.map +1 -0
  23. package/dist/eip-1967.d.ts +7 -0
  24. package/dist/eip-1967.d.ts.map +1 -0
  25. package/dist/eip-1967.js +63 -0
  26. package/dist/eip-1967.js.map +1 -0
  27. package/dist/error.d.ts +21 -0
  28. package/dist/error.d.ts.map +1 -0
  29. package/dist/error.js +21 -0
  30. package/dist/error.js.map +1 -0
  31. package/dist/impl-store.d.ts +7 -0
  32. package/dist/impl-store.d.ts.map +1 -0
  33. package/dist/impl-store.js +94 -0
  34. package/dist/impl-store.js.map +1 -0
  35. package/dist/impl-store.test.d.ts +2 -0
  36. package/dist/impl-store.test.d.ts.map +1 -0
  37. package/dist/impl-store.test.js +55 -0
  38. package/dist/impl-store.test.js.map +1 -0
  39. package/dist/index.d.ts +16 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +32 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/levenshtein.d.ts +12 -0
  44. package/dist/levenshtein.d.ts.map +1 -0
  45. package/dist/levenshtein.js +89 -0
  46. package/dist/levenshtein.js.map +1 -0
  47. package/dist/levenshtein.test.d.ts +2 -0
  48. package/dist/levenshtein.test.d.ts.map +1 -0
  49. package/dist/levenshtein.test.js +88 -0
  50. package/dist/levenshtein.test.js.map +1 -0
  51. package/dist/link-refs.d.ts +11 -0
  52. package/dist/link-refs.d.ts.map +1 -0
  53. package/dist/link-refs.js +36 -0
  54. package/dist/link-refs.js.map +1 -0
  55. package/dist/link-refs.test.d.ts +2 -0
  56. package/dist/link-refs.test.d.ts.map +1 -0
  57. package/dist/link-refs.test.js +76 -0
  58. package/dist/link-refs.test.js.map +1 -0
  59. package/dist/manifest-storage-layout.d.ts +6 -0
  60. package/dist/manifest-storage-layout.d.ts.map +1 -0
  61. package/dist/manifest-storage-layout.js +95 -0
  62. package/dist/manifest-storage-layout.js.map +1 -0
  63. package/dist/manifest-storage-layout.test.d.ts +2 -0
  64. package/dist/manifest-storage-layout.test.d.ts.map +1 -0
  65. package/dist/manifest-storage-layout.test.js +105 -0
  66. package/dist/manifest-storage-layout.test.js.map +1 -0
  67. package/dist/manifest.d.ts +36 -0
  68. package/dist/manifest.d.ts.map +1 -0
  69. package/dist/manifest.js +154 -0
  70. package/dist/manifest.js.map +1 -0
  71. package/dist/manifest.test.d.ts +2 -0
  72. package/dist/manifest.test.d.ts.map +1 -0
  73. package/dist/manifest.test.js +17 -0
  74. package/dist/manifest.test.js.map +1 -0
  75. package/dist/provider.d.ts +37 -0
  76. package/dist/provider.d.ts.map +1 -0
  77. package/dist/provider.js +74 -0
  78. package/dist/provider.js.map +1 -0
  79. package/dist/provider.test.d.ts +2 -0
  80. package/dist/provider.test.d.ts.map +1 -0
  81. package/dist/provider.test.js +41 -0
  82. package/dist/provider.test.js.map +1 -0
  83. package/dist/scripts/migrate-oz-cli-project.d.ts +108 -0
  84. package/dist/scripts/migrate-oz-cli-project.d.ts.map +1 -0
  85. package/dist/scripts/migrate-oz-cli-project.js +321 -0
  86. package/dist/scripts/migrate-oz-cli-project.js.map +1 -0
  87. package/dist/scripts/migrate-oz-cli-project.test.d.ts +2 -0
  88. package/dist/scripts/migrate-oz-cli-project.test.d.ts.map +1 -0
  89. package/dist/scripts/migrate-oz-cli-project.test.js +60 -0
  90. package/dist/scripts/migrate-oz-cli-project.test.js.map +1 -0
  91. package/dist/set-proxy-kind.d.ts +5 -0
  92. package/dist/set-proxy-kind.d.ts.map +1 -0
  93. package/dist/set-proxy-kind.js +25 -0
  94. package/dist/set-proxy-kind.js.map +1 -0
  95. package/dist/solc-api.d.ts +39 -0
  96. package/dist/solc-api.d.ts.map +1 -0
  97. package/dist/solc-api.js +3 -0
  98. package/dist/solc-api.js.map +1 -0
  99. package/dist/src-decoder.d.ts +6 -0
  100. package/dist/src-decoder.d.ts.map +1 -0
  101. package/dist/src-decoder.js +36 -0
  102. package/dist/src-decoder.js.map +1 -0
  103. package/dist/src-decoder.test.d.ts +2 -0
  104. package/dist/src-decoder.test.d.ts.map +1 -0
  105. package/dist/src-decoder.test.js +29 -0
  106. package/dist/src-decoder.test.js.map +1 -0
  107. package/dist/storage/compare.d.ts +55 -0
  108. package/dist/storage/compare.d.ts.map +1 -0
  109. package/dist/storage/compare.js +181 -0
  110. package/dist/storage/compare.js.map +1 -0
  111. package/dist/storage/compat.d.ts +4 -0
  112. package/dist/storage/compat.d.ts.map +1 -0
  113. package/dist/storage/compat.js +9 -0
  114. package/dist/storage/compat.js.map +1 -0
  115. package/dist/storage/extract.d.ts +7 -0
  116. package/dist/storage/extract.d.ts.map +1 -0
  117. package/dist/storage/extract.js +86 -0
  118. package/dist/storage/extract.js.map +1 -0
  119. package/dist/storage/index.d.ts +8 -0
  120. package/dist/storage/index.d.ts.map +1 -0
  121. package/dist/storage/index.js +65 -0
  122. package/dist/storage/index.js.map +1 -0
  123. package/dist/storage/layout.d.ts +31 -0
  124. package/dist/storage/layout.d.ts.map +1 -0
  125. package/dist/storage/layout.js +46 -0
  126. package/dist/storage/layout.js.map +1 -0
  127. package/dist/storage/report.d.ts +8 -0
  128. package/dist/storage/report.d.ts.map +1 -0
  129. package/dist/storage/report.js +175 -0
  130. package/dist/storage/report.js.map +1 -0
  131. package/dist/storage/report.test.d.ts +2 -0
  132. package/dist/storage/report.test.d.ts.map +1 -0
  133. package/dist/storage/report.test.js +82 -0
  134. package/dist/storage/report.test.js.map +1 -0
  135. package/dist/storage.test.d.ts +2 -0
  136. package/dist/storage.test.d.ts.map +1 -0
  137. package/dist/storage.test.js +436 -0
  138. package/dist/storage.test.js.map +1 -0
  139. package/dist/stub-provider.d.ts +14 -0
  140. package/dist/stub-provider.d.ts.map +1 -0
  141. package/dist/stub-provider.js +128 -0
  142. package/dist/stub-provider.js.map +1 -0
  143. package/dist/utils/assert.d.ts +3 -0
  144. package/dist/utils/assert.d.ts.map +1 -0
  145. package/dist/utils/assert.js +14 -0
  146. package/dist/utils/assert.js.map +1 -0
  147. package/dist/utils/curry.d.ts +6 -0
  148. package/dist/utils/curry.d.ts.map +1 -0
  149. package/dist/utils/curry.js +16 -0
  150. package/dist/utils/curry.js.map +1 -0
  151. package/dist/utils/debug.d.ts +4 -0
  152. package/dist/utils/debug.d.ts.map +1 -0
  153. package/dist/utils/debug.js +8 -0
  154. package/dist/utils/debug.js.map +1 -0
  155. package/dist/utils/deep-array.d.ts +3 -0
  156. package/dist/utils/deep-array.d.ts.map +1 -0
  157. package/dist/utils/deep-array.js +13 -0
  158. package/dist/utils/deep-array.js.map +1 -0
  159. package/dist/utils/deep-array.test.d.ts +2 -0
  160. package/dist/utils/deep-array.test.d.ts.map +1 -0
  161. package/dist/utils/deep-array.test.js +23 -0
  162. package/dist/utils/deep-array.test.js.map +1 -0
  163. package/dist/utils/function.d.ts +4 -0
  164. package/dist/utils/function.d.ts.map +1 -0
  165. package/dist/utils/function.js +43 -0
  166. package/dist/utils/function.js.map +1 -0
  167. package/dist/utils/function.test.d.ts +2 -0
  168. package/dist/utils/function.test.d.ts.map +1 -0
  169. package/dist/utils/function.test.js +34 -0
  170. package/dist/utils/function.test.js.map +1 -0
  171. package/dist/utils/indent.d.ts +2 -0
  172. package/dist/utils/indent.d.ts.map +1 -0
  173. package/dist/utils/indent.js +8 -0
  174. package/dist/utils/indent.js.map +1 -0
  175. package/dist/utils/is-nullish.d.ts +2 -0
  176. package/dist/utils/is-nullish.d.ts.map +1 -0
  177. package/dist/utils/is-nullish.js +8 -0
  178. package/dist/utils/is-nullish.js.map +1 -0
  179. package/dist/utils/is-nullish.test.d.ts +2 -0
  180. package/dist/utils/is-nullish.test.d.ts.map +1 -0
  181. package/dist/utils/is-nullish.test.js +17 -0
  182. package/dist/utils/is-nullish.test.js.map +1 -0
  183. package/dist/utils/is-value-type.d.ts +3 -0
  184. package/dist/utils/is-value-type.d.ts.map +1 -0
  185. package/dist/utils/is-value-type.js +8 -0
  186. package/dist/utils/is-value-type.js.map +1 -0
  187. package/dist/utils/itemize.d.ts +3 -0
  188. package/dist/utils/itemize.d.ts.map +1 -0
  189. package/dist/utils/itemize.js +18 -0
  190. package/dist/utils/itemize.js.map +1 -0
  191. package/dist/utils/log.d.ts +4 -0
  192. package/dist/utils/log.d.ts.map +1 -0
  193. package/dist/utils/log.js +35 -0
  194. package/dist/utils/log.js.map +1 -0
  195. package/dist/utils/make-non-enumerable.d.ts +2 -0
  196. package/dist/utils/make-non-enumerable.d.ts.map +1 -0
  197. package/dist/utils/make-non-enumerable.js +9 -0
  198. package/dist/utils/make-non-enumerable.js.map +1 -0
  199. package/dist/utils/map-values.d.ts +2 -0
  200. package/dist/utils/map-values.d.ts.map +1 -0
  201. package/dist/utils/map-values.js +12 -0
  202. package/dist/utils/map-values.js.map +1 -0
  203. package/dist/utils/parse-type-id.d.ts +9 -0
  204. package/dist/utils/parse-type-id.d.ts.map +1 -0
  205. package/dist/utils/parse-type-id.js +92 -0
  206. package/dist/utils/parse-type-id.js.map +1 -0
  207. package/dist/utils/parse-type-id.test.d.ts +2 -0
  208. package/dist/utils/parse-type-id.test.d.ts.map +1 -0
  209. package/dist/utils/parse-type-id.test.js +25 -0
  210. package/dist/utils/parse-type-id.test.js.map +1 -0
  211. package/dist/utils/pick.d.ts +2 -0
  212. package/dist/utils/pick.d.ts.map +1 -0
  213. package/dist/utils/pick.js +12 -0
  214. package/dist/utils/pick.js.map +1 -0
  215. package/dist/utils/type-id.d.ts +4 -0
  216. package/dist/utils/type-id.d.ts.map +1 -0
  217. package/dist/utils/type-id.js +65 -0
  218. package/dist/utils/type-id.js.map +1 -0
  219. package/dist/validate/compat.d.ts +6 -0
  220. package/dist/validate/compat.d.ts.map +1 -0
  221. package/dist/validate/compat.js +4 -0
  222. package/dist/validate/compat.js.map +1 -0
  223. package/dist/validate/data.d.ts +14 -0
  224. package/dist/validate/data.d.ts.map +1 -0
  225. package/dist/validate/data.js +50 -0
  226. package/dist/validate/data.js.map +1 -0
  227. package/dist/validate/error.d.ts +7 -0
  228. package/dist/validate/error.d.ts.map +1 -0
  229. package/dist/validate/error.js +78 -0
  230. package/dist/validate/error.js.map +1 -0
  231. package/dist/validate/index.d.ts +8 -0
  232. package/dist/validate/index.d.ts.map +1 -0
  233. package/dist/validate/index.js +24 -0
  234. package/dist/validate/index.js.map +1 -0
  235. package/dist/validate/overrides.d.ts +14 -0
  236. package/dist/validate/overrides.d.ts.map +1 -0
  237. package/dist/validate/overrides.js +72 -0
  238. package/dist/validate/overrides.js.map +1 -0
  239. package/dist/validate/query.d.ts +15 -0
  240. package/dist/validate/query.d.ts.map +1 -0
  241. package/dist/validate/query.js +111 -0
  242. package/dist/validate/query.js.map +1 -0
  243. package/dist/validate/query.test.d.ts +2 -0
  244. package/dist/validate/query.test.d.ts.map +1 -0
  245. package/dist/validate/query.test.js +48 -0
  246. package/dist/validate/query.test.js.map +1 -0
  247. package/dist/validate/run.d.ts +39 -0
  248. package/dist/validate/run.d.ts.map +1 -0
  249. package/dist/validate/run.js +199 -0
  250. package/dist/validate/run.js.map +1 -0
  251. package/dist/validate.test.d.ts +2 -0
  252. package/dist/validate.test.d.ts.map +1 -0
  253. package/dist/validate.test.js +116 -0
  254. package/dist/validate.test.js.map +1 -0
  255. package/dist/version.d.ts +9 -0
  256. package/dist/version.d.ts.map +1 -0
  257. package/dist/version.js +66 -0
  258. package/dist/version.js.map +1 -0
  259. package/dist/version.test.d.ts +2 -0
  260. package/dist/version.test.d.ts.map +1 -0
  261. package/dist/version.test.js +53 -0
  262. package/dist/version.test.js.map +1 -0
  263. package/package.json +58 -0
  264. package/src/ast-dereferencer.ts +42 -0
  265. package/src/deployment.test.ts +98 -0
  266. package/src/deployment.ts +122 -0
  267. package/src/eip-1967.ts +77 -0
  268. package/src/error.ts +26 -0
  269. package/src/impl-store.test.ts +59 -0
  270. package/src/impl-store.ts +124 -0
  271. package/src/index.ts +18 -0
  272. package/src/levenshtein.test.ts +91 -0
  273. package/src/levenshtein.ts +116 -0
  274. package/src/link-refs.test.ts +77 -0
  275. package/src/link-refs.ts +41 -0
  276. package/src/manifest-storage-layout.test.ts +118 -0
  277. package/src/manifest-storage-layout.ts +107 -0
  278. package/src/manifest.test.ts +13 -0
  279. package/src/manifest.ts +178 -0
  280. package/src/provider.test.ts +43 -0
  281. package/src/provider.ts +103 -0
  282. package/src/scripts/migratable-manifest.test.json +175 -0
  283. package/src/scripts/migrate-oz-cli-project.test.ts +70 -0
  284. package/src/scripts/migrate-oz-cli-project.test.ts.md +146 -0
  285. package/src/scripts/migrate-oz-cli-project.test.ts.snap +0 -0
  286. package/src/scripts/migrate-oz-cli-project.ts +484 -0
  287. package/src/scripts/project-file.test.json +25 -0
  288. package/src/set-proxy-kind.ts +27 -0
  289. package/src/solc-api.ts +42 -0
  290. package/src/src-decoder.test.ts +30 -0
  291. package/src/src-decoder.ts +37 -0
  292. package/src/storage/compare.ts +249 -0
  293. package/src/storage/compat.ts +3 -0
  294. package/src/storage/extract.ts +110 -0
  295. package/src/storage/index.ts +73 -0
  296. package/src/storage/layout.ts +88 -0
  297. package/src/storage/report.test.ts +95 -0
  298. package/src/storage/report.test.ts.md +154 -0
  299. package/src/storage/report.test.ts.snap +0 -0
  300. package/src/storage/report.ts +215 -0
  301. package/src/storage.test.ts +479 -0
  302. package/src/storage.test.ts.md +643 -0
  303. package/src/storage.test.ts.snap +0 -0
  304. package/src/stub-provider.ts +120 -0
  305. package/src/utils/assert.ts +9 -0
  306. package/src/utils/curry.ts +17 -0
  307. package/src/utils/debug.ts +3 -0
  308. package/src/utils/deep-array.test.ts +21 -0
  309. package/src/utils/deep-array.ts +9 -0
  310. package/src/utils/function.test.ts +37 -0
  311. package/src/utils/function.ts +53 -0
  312. package/src/utils/indent.ts +3 -0
  313. package/src/utils/is-nullish.test.ts +15 -0
  314. package/src/utils/is-nullish.ts +3 -0
  315. package/src/utils/is-value-type.ts +5 -0
  316. package/src/utils/itemize.ts +16 -0
  317. package/src/utils/log.ts +34 -0
  318. package/src/utils/make-non-enumerable.ts +4 -0
  319. package/src/utils/map-values.ts +7 -0
  320. package/src/utils/parse-type-id.test.ts +22 -0
  321. package/src/utils/parse-type-id.test.ts.md +264 -0
  322. package/src/utils/parse-type-id.test.ts.snap +0 -0
  323. package/src/utils/parse-type-id.ts +104 -0
  324. package/src/utils/pick.ts +7 -0
  325. package/src/utils/type-id.ts +57 -0
  326. package/src/validate/compat.ts +9 -0
  327. package/src/validate/data.ts +55 -0
  328. package/src/validate/error.ts +75 -0
  329. package/src/validate/index.ts +17 -0
  330. package/src/validate/overrides.ts +93 -0
  331. package/src/validate/query.test.ts +48 -0
  332. package/src/validate/query.ts +127 -0
  333. package/src/validate/run.ts +278 -0
  334. package/src/validate.test.ts +133 -0
  335. package/src/version.test.ts +59 -0
  336. package/src/version.ts +71 -0
Binary file
@@ -0,0 +1,120 @@
1
+ import crypto from 'crypto';
2
+
3
+ import { ImplDeployment } from './manifest';
4
+
5
+ const defaultClientVersion = 'unknown';
6
+
7
+ function genChainId(): number {
8
+ return 100 + crypto.randomBytes(2).readUInt16BE(0);
9
+ }
10
+
11
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
12
+ export function stubProvider(chainId = genChainId(), clientVersion = defaultClientVersion) {
13
+ const contracts = new Set<string>();
14
+ const pendingTxs = new Set<string>();
15
+ const failedTxs = new Set<string>();
16
+ const blocks = new Map<string, string[]>();
17
+ const txBlock = new Map<string, string>();
18
+ const methodCounters = new Map<string, number>();
19
+
20
+ function mine() {
21
+ const blockHash = '0x' + crypto.randomBytes(32).toString('hex');
22
+ blocks.set(blockHash, [...pendingTxs]);
23
+ for (const tx of pendingTxs) {
24
+ txBlock.set(tx, blockHash);
25
+ }
26
+ pendingTxs.clear();
27
+ }
28
+
29
+ async function deploy(immediate = true): Promise<ImplDeployment> {
30
+ const address = '0x' + crypto.randomBytes(20).toString('hex');
31
+ const txHash = '0x' + crypto.randomBytes(32).toString('hex');
32
+ contracts.add(address);
33
+ pendingTxs.add(txHash);
34
+ if (immediate) {
35
+ mine();
36
+ }
37
+ return {
38
+ address,
39
+ txHash,
40
+ layout: {
41
+ storage: [],
42
+ types: {},
43
+ },
44
+ };
45
+ }
46
+
47
+ const deployPending = () => deploy(false);
48
+
49
+ return {
50
+ mine,
51
+ deploy,
52
+ deployPending,
53
+ get deployCount() {
54
+ return contracts.size;
55
+ },
56
+ isContract(address: string) {
57
+ return contracts.has(address);
58
+ },
59
+ removeContract(address: string) {
60
+ return contracts.delete(address);
61
+ },
62
+ addContract(address: string) {
63
+ return contracts.add(address);
64
+ },
65
+ getMethodCount(method: string) {
66
+ return methodCounters.get(method) ?? 0;
67
+ },
68
+ failTx(txHash: string) {
69
+ return failedTxs.add(txHash);
70
+ },
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ async send(method: string, params?: unknown[]): Promise<any> {
73
+ methodCounters.set(method, 1 + (methodCounters.get(method) ?? 0));
74
+
75
+ if (method === 'eth_chainId') {
76
+ return '0x' + chainId.toString(16);
77
+ } else if (method === 'eth_getCode') {
78
+ const param = params?.[0];
79
+ if (typeof param !== 'string') {
80
+ throw new Error('Param must be string');
81
+ }
82
+ if (contracts.has(param)) {
83
+ return '0x1234';
84
+ } else {
85
+ return '0x';
86
+ }
87
+ } else if (method === 'eth_getTransactionByHash') {
88
+ const param = params?.[0];
89
+ if (typeof param !== 'string') {
90
+ throw new Error('Param must be string');
91
+ }
92
+ if (txBlock.has(param) || pendingTxs.has(param)) {
93
+ return {
94
+ blockHash: txBlock.get(param) || null,
95
+ };
96
+ } else {
97
+ return null;
98
+ }
99
+ } else if (method === 'web3_clientVersion') {
100
+ return clientVersion;
101
+ } else if (method === 'eth_getTransactionReceipt') {
102
+ const param = params?.[0];
103
+ if (typeof param !== 'string') {
104
+ throw new Error('Param must be string');
105
+ }
106
+ if (txBlock.has(param)) {
107
+ return {
108
+ transactionHash: param,
109
+ blockHash: txBlock.get(param),
110
+ status: failedTxs.has(param) ? '0x0' : '0x1',
111
+ };
112
+ } else {
113
+ return null;
114
+ }
115
+ } else {
116
+ throw new Error(`Method ${method} not stubbed`);
117
+ }
118
+ },
119
+ };
120
+ }
@@ -0,0 +1,9 @@
1
+ export function assertUnreachable(_: never): never {
2
+ assert(false);
3
+ }
4
+
5
+ export function assert(p: unknown): asserts p {
6
+ if (!p) {
7
+ throw new Error('An unexpected condition occurred. Please report this at https://zpl.in/upgrades/report');
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ export interface Curried<A, B, T> {
2
+ (a: A): (b: B) => T;
3
+ (a: A, b: B): T;
4
+ }
5
+
6
+ export function curry2<A, B, T>(fn: (a: A, b: B) => T): Curried<A, B, T> {
7
+ function curried(a: A): (b: B) => T;
8
+ function curried(a: A, b: B): T;
9
+ function curried(a: A, ...b: [] | [B]): T | ((b: B) => T) {
10
+ if (b.length === 0) {
11
+ return b => fn(a, b);
12
+ } else {
13
+ return fn(a, ...b);
14
+ }
15
+ }
16
+ return curried;
17
+ }
@@ -0,0 +1,3 @@
1
+ import debug from 'debug';
2
+
3
+ export default debug('@openzeppelin:upgrades:core');
@@ -0,0 +1,21 @@
1
+ import test from 'ava';
2
+
3
+ import { deepEqual } from './deep-array';
4
+
5
+ test('depth 0', t => {
6
+ t.true(deepEqual('a', 'a'));
7
+ t.false(deepEqual('a', 'b'));
8
+ t.false(deepEqual('a', ['a']));
9
+ t.false(deepEqual(['a'], 'a'));
10
+ });
11
+
12
+ test('depth 1', t => {
13
+ t.true(deepEqual(['a', 'b'], ['a', 'b']));
14
+ t.false(deepEqual(['a'], ['a', 'b']));
15
+ t.false(deepEqual(['a', 'b'], ['a', 'c']));
16
+ });
17
+
18
+ test('depth 2', t => {
19
+ t.true(deepEqual([['a'], ['b']], [['a'], ['b']]));
20
+ t.false(deepEqual([['a'], ['b']], [['a'], ['c']]));
21
+ });
@@ -0,0 +1,9 @@
1
+ export type DeepArray<T> = T | DeepArray<T>[];
2
+
3
+ export function deepEqual<T>(a: DeepArray<T>, b: DeepArray<T>): boolean {
4
+ if (Array.isArray(a) && Array.isArray(b)) {
5
+ return a.length === b.length && a.every((v, i) => deepEqual(v, b[i]));
6
+ } else {
7
+ return a === b;
8
+ }
9
+ }
@@ -0,0 +1,37 @@
1
+ import test from 'ava';
2
+ import { artifacts } from 'hardhat';
3
+ import { FunctionDefinition } from 'solidity-ast';
4
+ import { findAll } from 'solidity-ast/utils';
5
+
6
+ import { getFunctionSignature } from './function';
7
+ import { SolcOutput } from '../solc-api';
8
+ import { astDereferencer } from '../ast-dereferencer';
9
+
10
+ testContract('ContractFunctionSignatures');
11
+ testContract('LibraryFunctionSignatures');
12
+
13
+ function testContract(contractName: string) {
14
+ test(contractName, async t => {
15
+ const fileName = 'contracts/test/FunctionSignatures.sol';
16
+ const buildInfo = await artifacts.getBuildInfo(`${fileName}:${contractName}`);
17
+ if (buildInfo === undefined) {
18
+ throw new Error('Build info not found');
19
+ }
20
+
21
+ const solcOutput: SolcOutput = buildInfo.output;
22
+
23
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
+ const signatures = Object.keys(solcOutput.contracts[fileName][contractName].evm.methodIdentifiers!);
25
+
26
+ const functions: Record<string, FunctionDefinition> = {};
27
+ for (const def of findAll('FunctionDefinition', solcOutput.sources[fileName].ast)) {
28
+ functions[def.name] = def;
29
+ }
30
+ const deref = astDereferencer(solcOutput);
31
+
32
+ for (const signature of signatures) {
33
+ const name = signature.replace(/\(.*/, '');
34
+ t.is(getFunctionSignature(functions[name], deref), signature);
35
+ }
36
+ });
37
+ }
@@ -0,0 +1,53 @@
1
+ import type { FunctionDefinition, VariableDeclaration } from 'solidity-ast';
2
+ import { ASTDereferencer } from '../ast-dereferencer';
3
+ import { assert, assertUnreachable } from './assert';
4
+
5
+ function serializeTypeName(parameter: VariableDeclaration, deref: ASTDereferencer): string {
6
+ const { typeName, storageLocation } = parameter;
7
+ assert(!!typeName);
8
+
9
+ if (storageLocation === 'storage') {
10
+ assert(typeof typeName.typeDescriptions.typeString === 'string');
11
+ return typeName.typeDescriptions.typeString.replace(/^struct /, '') + ' storage';
12
+ }
13
+
14
+ switch (typeName.nodeType) {
15
+ case 'ArrayTypeName':
16
+ case 'ElementaryTypeName': {
17
+ assert(typeof typeName.typeDescriptions.typeString === 'string');
18
+ return typeName.typeDescriptions.typeString;
19
+ }
20
+
21
+ case 'UserDefinedTypeName': {
22
+ const userDefinedType = deref(
23
+ ['StructDefinition', 'EnumDefinition', 'ContractDefinition'],
24
+ typeName.referencedDeclaration,
25
+ );
26
+ switch (userDefinedType.nodeType) {
27
+ case 'StructDefinition':
28
+ return '(' + userDefinedType.members.map(member => serializeTypeName(member, deref)) + ')';
29
+
30
+ case 'EnumDefinition':
31
+ assert(userDefinedType.members.length < 256);
32
+ return 'uint8';
33
+
34
+ case 'ContractDefinition':
35
+ return 'address';
36
+
37
+ default:
38
+ return assertUnreachable(userDefinedType);
39
+ }
40
+ }
41
+
42
+ case 'FunctionTypeName': {
43
+ return `function`;
44
+ }
45
+
46
+ default:
47
+ throw new Error(`Unsuported TypeName node type: ${typeName.nodeType}`);
48
+ }
49
+ }
50
+
51
+ export function getFunctionSignature(fnDef: FunctionDefinition, deref: ASTDereferencer): string {
52
+ return `${fnDef.name}(${fnDef.parameters.parameters.map(parameter => serializeTypeName(parameter, deref)).join()})`;
53
+ }
@@ -0,0 +1,3 @@
1
+ export function indent(text: string, amount: number, amount0 = amount): string {
2
+ return text.replace(/^/gm, (_, i) => ' '.repeat(i === 0 ? amount0 : amount));
3
+ }
@@ -0,0 +1,15 @@
1
+ import test from 'ava';
2
+
3
+ import { isNullish } from './is-nullish';
4
+
5
+ test('null', t => {
6
+ t.true(isNullish(null));
7
+ });
8
+
9
+ test('undefined', t => {
10
+ t.true(isNullish(undefined));
11
+ });
12
+
13
+ test('number 5', t => {
14
+ t.false(isNullish(5));
15
+ });
@@ -0,0 +1,3 @@
1
+ export function isNullish(value: unknown): value is null | undefined {
2
+ return value === null || value === undefined;
3
+ }
@@ -0,0 +1,5 @@
1
+ import { ParsedTypeDetailed } from '../storage/layout';
2
+
3
+ export function isValueType(type: ParsedTypeDetailed): boolean {
4
+ return type.args === undefined || ['t_contract', 't_enum'].includes(type.head);
5
+ }
@@ -0,0 +1,16 @@
1
+ // itemize returns a markdown-like list of the items
2
+
3
+ // itemize['a\nb', 'c'] =
4
+ // - a
5
+ // b
6
+ // - c
7
+
8
+ import { indent } from './indent';
9
+
10
+ export function itemize(...items: string[]): string {
11
+ return itemizeWith('-', ...items);
12
+ }
13
+
14
+ export function itemizeWith(bullet: string, ...items: string[]): string {
15
+ return items.map(item => bullet + indent(item, 2, 1)).join('\n');
16
+ }
@@ -0,0 +1,34 @@
1
+ import chalk from 'chalk';
2
+
3
+ import { indent } from './indent';
4
+
5
+ let silenced = false;
6
+
7
+ function log(prefix: string, title: string, lines: string[]): void {
8
+ if (silenced) {
9
+ return;
10
+ }
11
+
12
+ const parts = [chalk.yellow.bold(prefix + ':') + ' ' + title + '\n'];
13
+
14
+ if (lines.length > 0) {
15
+ parts.push(lines.map(l => indent(l, 4) + '\n').join(''));
16
+ }
17
+
18
+ console.error(parts.join('\n'));
19
+ }
20
+
21
+ export function logNote(title: string, lines: string[] = []): void {
22
+ log('Note', title, lines);
23
+ }
24
+
25
+ export function logWarning(title: string, lines: string[] = []): void {
26
+ log('Warning', title, lines);
27
+ }
28
+
29
+ export function silenceWarnings(): void {
30
+ logWarning(`All subsequent Upgrades warnings will be silenced.`, [
31
+ `Make sure you have manually checked all uses of unsafe flags.`,
32
+ ]);
33
+ silenced = true;
34
+ }
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export function makeNonEnumerable<O extends any>(obj: O, key: keyof O): void {
3
+ Object.defineProperty(obj, key, { enumerable: false });
4
+ }
@@ -0,0 +1,7 @@
1
+ export function mapValues<V, W>(obj: Record<string, V>, fn: (value: V) => W): Record<string, W> {
2
+ const res: Partial<Record<string, W>> = {};
3
+ for (const k in obj) {
4
+ res[k] = fn(obj[k]);
5
+ }
6
+ return res as Record<string, W>;
7
+ }
@@ -0,0 +1,22 @@
1
+ import test from 'ava';
2
+
3
+ import { parseTypeId } from './parse-type-id';
4
+
5
+ const fixtures = [
6
+ 't_uint256',
7
+ 't_enum(MyEnum)',
8
+ 't_struct(MyComplexStruct)storage',
9
+ 't_array(t_uint256)3_storage',
10
+ 't_mapping(t_uint256,t_uint256)',
11
+ 't_mapping(unknown,t_uint256)',
12
+ 't_mapping(t_uint256,t_array(t_bool)dyn_storage)',
13
+ 't_mapping(t_uint256,t_mapping(t_string_memory_ptr,t_address))',
14
+ 't_function_internal_nonpayable(t_uint256)returns()',
15
+ 't_array(t_function_internal_nonpayable(t_uint256)returns(t_address))10_storage',
16
+ ];
17
+
18
+ for (const f of fixtures) {
19
+ test(f, t => {
20
+ t.snapshot(parseTypeId(f));
21
+ });
22
+ }
@@ -0,0 +1,264 @@
1
+ # Snapshot report for `src/utils/parse-type-id.test.ts`
2
+
3
+ The actual snapshot is saved in `parse-type-id.test.ts.snap`.
4
+
5
+ Generated by [AVA](https://avajs.dev).
6
+
7
+ ## t_array(t_function_internal_nonpayable(t_uint256)returns(t_address))10_storage
8
+
9
+ > Snapshot 1
10
+
11
+ {
12
+ args: [
13
+ {
14
+ args: [
15
+ {
16
+ args: undefined,
17
+ head: 't_uint256',
18
+ id: 't_uint256',
19
+ rets: undefined,
20
+ tail: undefined,
21
+ },
22
+ ],
23
+ head: 't_function_internal_nonpayable',
24
+ id: 't_function_internal_nonpayable(t_uint256)returns(t_address)',
25
+ rets: [
26
+ {
27
+ args: undefined,
28
+ head: 't_address',
29
+ id: 't_address',
30
+ rets: undefined,
31
+ tail: undefined,
32
+ },
33
+ ],
34
+ tail: undefined,
35
+ },
36
+ ],
37
+ head: 't_array',
38
+ id: 't_array(t_function_internal_nonpayable(t_uint256)returns(t_address))10_storage',
39
+ rets: undefined,
40
+ tail: '10_storage',
41
+ }
42
+
43
+ ## t_array(t_uint256)3_storage
44
+
45
+ > Snapshot 1
46
+
47
+ {
48
+ args: [
49
+ {
50
+ args: undefined,
51
+ head: 't_uint256',
52
+ id: 't_uint256',
53
+ rets: undefined,
54
+ tail: undefined,
55
+ },
56
+ ],
57
+ head: 't_array',
58
+ id: 't_array(t_uint256)3_storage',
59
+ rets: undefined,
60
+ tail: '3_storage',
61
+ }
62
+
63
+ ## t_function_internal_nonpayable(t_uint256)returns()
64
+
65
+ > Snapshot 1
66
+
67
+ {
68
+ args: [
69
+ {
70
+ args: undefined,
71
+ head: 't_uint256',
72
+ id: 't_uint256',
73
+ rets: undefined,
74
+ tail: undefined,
75
+ },
76
+ ],
77
+ head: 't_function_internal_nonpayable',
78
+ id: 't_function_internal_nonpayable(t_uint256)returns()',
79
+ rets: [],
80
+ tail: undefined,
81
+ }
82
+
83
+ ## t_mapping(t_uint256,t_array(t_bool)dyn_storage)
84
+
85
+ > Snapshot 1
86
+
87
+ {
88
+ args: [
89
+ {
90
+ args: undefined,
91
+ head: 't_uint256',
92
+ id: 't_uint256',
93
+ rets: undefined,
94
+ tail: undefined,
95
+ },
96
+ {
97
+ args: [
98
+ {
99
+ args: undefined,
100
+ head: 't_bool',
101
+ id: 't_bool',
102
+ rets: undefined,
103
+ tail: undefined,
104
+ },
105
+ ],
106
+ head: 't_array',
107
+ id: 't_array(t_bool)dyn_storage',
108
+ rets: undefined,
109
+ tail: 'dyn_storage',
110
+ },
111
+ ],
112
+ head: 't_mapping',
113
+ id: 't_mapping(t_uint256,t_array(t_bool)dyn_storage)',
114
+ rets: undefined,
115
+ tail: undefined,
116
+ }
117
+
118
+ ## t_mapping(t_uint256,t_mapping(t_string_memory_ptr,t_address))
119
+
120
+ > Snapshot 1
121
+
122
+ {
123
+ args: [
124
+ {
125
+ args: undefined,
126
+ head: 't_uint256',
127
+ id: 't_uint256',
128
+ rets: undefined,
129
+ tail: undefined,
130
+ },
131
+ {
132
+ args: [
133
+ {
134
+ args: undefined,
135
+ head: 't_string_memory_ptr',
136
+ id: 't_string_memory_ptr',
137
+ rets: undefined,
138
+ tail: undefined,
139
+ },
140
+ {
141
+ args: undefined,
142
+ head: 't_address',
143
+ id: 't_address',
144
+ rets: undefined,
145
+ tail: undefined,
146
+ },
147
+ ],
148
+ head: 't_mapping',
149
+ id: 't_mapping(t_string_memory_ptr,t_address)',
150
+ rets: undefined,
151
+ tail: undefined,
152
+ },
153
+ ],
154
+ head: 't_mapping',
155
+ id: 't_mapping(t_uint256,t_mapping(t_string_memory_ptr,t_address))',
156
+ rets: undefined,
157
+ tail: undefined,
158
+ }
159
+
160
+ ## t_mapping(t_uint256,t_uint256)
161
+
162
+ > Snapshot 1
163
+
164
+ {
165
+ args: [
166
+ {
167
+ args: undefined,
168
+ head: 't_uint256',
169
+ id: 't_uint256',
170
+ rets: undefined,
171
+ tail: undefined,
172
+ },
173
+ {
174
+ args: undefined,
175
+ head: 't_uint256',
176
+ id: 't_uint256',
177
+ rets: undefined,
178
+ tail: undefined,
179
+ },
180
+ ],
181
+ head: 't_mapping',
182
+ id: 't_mapping(t_uint256,t_uint256)',
183
+ rets: undefined,
184
+ tail: undefined,
185
+ }
186
+
187
+ ## t_uint256
188
+
189
+ > Snapshot 1
190
+
191
+ {
192
+ args: undefined,
193
+ head: 't_uint256',
194
+ id: 't_uint256',
195
+ rets: undefined,
196
+ tail: undefined,
197
+ }
198
+
199
+ ## t_mapping(unknown,t_uint256)
200
+
201
+ > Snapshot 1
202
+
203
+ {
204
+ args: [
205
+ {
206
+ args: undefined,
207
+ head: 'unknown',
208
+ id: 'unknown',
209
+ rets: undefined,
210
+ tail: undefined,
211
+ },
212
+ {
213
+ args: undefined,
214
+ head: 't_uint256',
215
+ id: 't_uint256',
216
+ rets: undefined,
217
+ tail: undefined,
218
+ },
219
+ ],
220
+ head: 't_mapping',
221
+ id: 't_mapping(unknown,t_uint256)',
222
+ rets: undefined,
223
+ tail: undefined,
224
+ }
225
+
226
+ ## t_enum(MyEnum)
227
+
228
+ > Snapshot 1
229
+
230
+ {
231
+ args: [
232
+ {
233
+ args: undefined,
234
+ head: 'MyEnum',
235
+ id: 'MyEnum',
236
+ rets: undefined,
237
+ tail: undefined,
238
+ },
239
+ ],
240
+ head: 't_enum',
241
+ id: 't_enum(MyEnum)',
242
+ rets: undefined,
243
+ tail: undefined,
244
+ }
245
+
246
+ ## t_struct(MyComplexStruct)storage
247
+
248
+ > Snapshot 1
249
+
250
+ {
251
+ args: [
252
+ {
253
+ args: undefined,
254
+ head: 'MyComplexStruct',
255
+ id: 'MyComplexStruct',
256
+ rets: undefined,
257
+ tail: undefined,
258
+ },
259
+ ],
260
+ head: 't_struct',
261
+ id: 't_struct(MyComplexStruct)storage',
262
+ rets: undefined,
263
+ tail: 'storage',
264
+ }