@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
@@ -0,0 +1,43 @@
1
+ import test from 'ava';
2
+ import { EthereumProvider, getTransactionReceipt } from './provider';
3
+
4
+ const hash = '0x1234';
5
+
6
+ function makeProviderReturning(result: unknown): EthereumProvider {
7
+ return { send: (_method: string, _params: unknown[]) => Promise.resolve(result) } as EthereumProvider;
8
+ }
9
+
10
+ test('getTransactionReceipt returns null', async t => {
11
+ const provider = makeProviderReturning(null);
12
+ t.is(await getTransactionReceipt(provider, hash), null);
13
+ });
14
+
15
+ test('getTransactionReceipt status returns 0x0', async t => {
16
+ const provider = makeProviderReturning({ status: '0x0' });
17
+ const receipt = await getTransactionReceipt(provider, hash);
18
+ t.is(receipt?.status, '0x0');
19
+ });
20
+
21
+ test('getTransactionReceipt status returns 0x1', async t => {
22
+ const provider = makeProviderReturning({ status: '0x1' });
23
+ const receipt = await getTransactionReceipt(provider, hash);
24
+ t.is(receipt?.status, '0x1');
25
+ });
26
+
27
+ test('getTransactionReceipt status normalizes to 0x0', async t => {
28
+ const provider = makeProviderReturning({ status: '0x000000000000000000000000' });
29
+ const receipt = await getTransactionReceipt(provider, hash);
30
+ t.is(receipt?.status, '0x0');
31
+ });
32
+
33
+ test('getTransactionReceipt status normalizes to 0x1', async t => {
34
+ const provider = makeProviderReturning({ status: '0x000000000000000000000001' });
35
+ const receipt = await getTransactionReceipt(provider, hash);
36
+ t.is(receipt?.status, '0x1');
37
+ });
38
+
39
+ test('getTransactionReceipt status returns empty hex', async t => {
40
+ const provider = makeProviderReturning({ status: '0x' });
41
+ const receipt = await getTransactionReceipt(provider, hash);
42
+ t.is(receipt?.status, '0x');
43
+ });
@@ -0,0 +1,103 @@
1
+ import BN from 'bn.js';
2
+
3
+ export interface EthereumProvider {
4
+ send(method: 'web3_clientVersion', params: []): Promise<string>;
5
+ send(method: 'net_version', params: []): Promise<string>;
6
+ send(method: 'eth_chainId', params: []): Promise<string>;
7
+ send(method: 'eth_getCode', params: [string, string]): Promise<string>;
8
+ send(method: 'eth_getStorageAt', params: [string, string, string]): Promise<string>;
9
+ send(method: 'eth_getTransactionByHash', params: [string]): Promise<null | EthereumTransaction>;
10
+ send(method: 'eth_getTransactionReceipt', params: [string]): Promise<null | EthereumTransactionReceipt>;
11
+ send(method: string, params: unknown[]): Promise<unknown>;
12
+ }
13
+
14
+ interface EthereumTransaction {
15
+ blockHash: string | null;
16
+ }
17
+
18
+ interface EthereumTransactionReceipt {
19
+ status: string;
20
+ to: string | null;
21
+ from: string;
22
+ blockHash: string;
23
+ blockNumber: string;
24
+ transactionHash: string;
25
+ transactionIndex: string;
26
+ }
27
+
28
+ export async function getNetworkId(provider: EthereumProvider): Promise<string> {
29
+ return provider.send('net_version', []);
30
+ }
31
+
32
+ export async function getChainId(provider: EthereumProvider): Promise<number> {
33
+ const id = await provider.send('eth_chainId', []);
34
+ return new BN(id.replace(/^0x/, ''), 'hex').toNumber();
35
+ }
36
+
37
+ export async function getClientVersion(provider: EthereumProvider): Promise<string> {
38
+ return provider.send('web3_clientVersion', []);
39
+ }
40
+
41
+ export async function getStorageAt(
42
+ provider: EthereumProvider,
43
+ address: string,
44
+ position: string,
45
+ block = 'latest',
46
+ ): Promise<string> {
47
+ const storage = await provider.send('eth_getStorageAt', [address, position, block]);
48
+ const padded = storage.replace(/^0x/, '').padStart(64, '0');
49
+ return '0x' + padded;
50
+ }
51
+
52
+ export async function getCode(provider: EthereumProvider, address: string, block = 'latest'): Promise<string> {
53
+ return provider.send('eth_getCode', [address, block]);
54
+ }
55
+
56
+ export async function hasCode(provider: EthereumProvider, address: string, block?: string): Promise<boolean> {
57
+ const code = await getCode(provider, address, block);
58
+ return code !== '0x';
59
+ }
60
+
61
+ export async function getTransactionByHash(
62
+ provider: EthereumProvider,
63
+ txHash: string,
64
+ ): Promise<EthereumTransaction | null> {
65
+ return provider.send('eth_getTransactionByHash', [txHash]);
66
+ }
67
+
68
+ export async function getTransactionReceipt(
69
+ provider: EthereumProvider,
70
+ txHash: string,
71
+ ): Promise<EthereumTransactionReceipt | null> {
72
+ const receipt = await provider.send('eth_getTransactionReceipt', [txHash]);
73
+ if (receipt?.status) {
74
+ receipt.status = receipt.status.match(/^0x0+$/) ? '0x0' : receipt.status.replace(/^0x0+/, '0x');
75
+ }
76
+ return receipt;
77
+ }
78
+
79
+ export const networkNames: { [chainId in number]?: string } = Object.freeze({
80
+ 1: 'mainnet',
81
+ 2: 'morden',
82
+ 3: 'ropsten',
83
+ 4: 'rinkeby',
84
+ 5: 'goerli',
85
+ 42: 'kovan',
86
+ });
87
+
88
+ export async function isDevelopmentNetwork(provider: EthereumProvider): Promise<boolean> {
89
+ const chainId = await getChainId(provider);
90
+ // 1337 => ganache and geth --dev
91
+ // 31337 => hardhat network
92
+ if (chainId === 1337 || chainId === 31337) {
93
+ return true;
94
+ } else {
95
+ const clientVersion = await getClientVersion(provider);
96
+ const [name] = clientVersion.split('/', 1);
97
+ return name === 'HardhatNetwork' || name === 'EthereumJS TestRPC';
98
+ }
99
+ }
100
+
101
+ export function isReceiptSuccessful(receipt: Pick<EthereumTransactionReceipt, 'status'>): boolean {
102
+ return receipt.status === '0x1';
103
+ }
@@ -0,0 +1,175 @@
1
+ {
2
+ "contracts": {
3
+ "Box": {
4
+ "address": "0xb682dEEf4f8e298d86bFc3e21f50c675151FB974",
5
+ "constructorCode": "608060405234801561001057600080fd5b506101a3806100206000396000f3fe",
6
+ "bodyBytecodeHash": "0e331fb885de0fa7c715c4819b6ded2449542cb3cce682718791be28ae0789e8",
7
+ "localBytecodeHash": "08100f44a71d905a66088b4c5d72f12417a580d454357e06dcc5ad12b3fa2cbc",
8
+ "deployedBytecodeHash": "08100f44a71d905a66088b4c5d72f12417a580d454357e06dcc5ad12b3fa2cbc",
9
+ "types": {
10
+ "t_uint256": {
11
+ "id": "t_uint256",
12
+ "kind": "elementary",
13
+ "label": "uint256"
14
+ },
15
+ "t_bool": {
16
+ "id": "t_bool",
17
+ "kind": "elementary",
18
+ "label": "bool"
19
+ },
20
+ "t_mapping<t_bool>": {
21
+ "id": "t_mapping<t_bool>",
22
+ "valueType": "t_bool",
23
+ "label": "mapping(key => bool)",
24
+ "kind": "mapping"
25
+ },
26
+ "t_struct<Box.MyStruct>": {
27
+ "id": "t_struct<Box.MyStruct>",
28
+ "kind": "struct",
29
+ "label": "Box.MyStruct",
30
+ "members": [
31
+ {
32
+ "label": "x",
33
+ "astId": 3,
34
+ "type": "t_bool",
35
+ "src": "124:6:0"
36
+ }
37
+ ]
38
+ },
39
+ "t_enum<Box.MyEnum>": {
40
+ "id": "t_enum<Box.MyEnum>",
41
+ "kind": "enum",
42
+ "label": "Box.MyEnum",
43
+ "members": [
44
+ "UP",
45
+ "DOWN"
46
+ ]
47
+ },
48
+ "t_array:dyn<t_uint256>": {
49
+ "id": "t_array:dyn<t_uint256>",
50
+ "valueType": "t_uint256",
51
+ "length": "dyn",
52
+ "kind": "array",
53
+ "label": "uint256[]"
54
+ },
55
+ "t_array:10<t_uint256>": {
56
+ "id": "t_array:10<t_uint256>",
57
+ "valueType": "t_uint256",
58
+ "length": "10",
59
+ "kind": "array",
60
+ "label": "uint256[10]"
61
+ },
62
+ "t_array:dyn<t_enum<Box.MyEnum>>": {
63
+ "id": "t_array:dyn<t_enum<Box.MyEnum>>",
64
+ "valueType": "t_enum<Box.MyEnum>",
65
+ "length": "dyn",
66
+ "kind": "array",
67
+ "label": "Box.MyEnum[]"
68
+ },
69
+ "t_bytes8": {
70
+ "id": "t_bytes8",
71
+ "kind": "elementary",
72
+ "label": "bytes8"
73
+ }
74
+ },
75
+ "storage": [
76
+ {
77
+ "contract": "Box",
78
+ "path": "contracts/Box.sol",
79
+ "label": "value",
80
+ "astId": 9,
81
+ "type": "t_uint256",
82
+ "src": "173:21:0"
83
+ },
84
+ {
85
+ "contract": "Box",
86
+ "path": "contracts/Box.sol",
87
+ "label": "flag",
88
+ "astId": 11,
89
+ "type": "t_bool",
90
+ "src": "200:17:0"
91
+ },
92
+ {
93
+ "contract": "Box",
94
+ "path": "contracts/Box.sol",
95
+ "label": "map",
96
+ "astId": 15,
97
+ "type": "t_mapping<t_bool>",
98
+ "src": "223:26:0"
99
+ },
100
+ {
101
+ "contract": "Box",
102
+ "path": "contracts/Box.sol",
103
+ "label": "foo",
104
+ "astId": 17,
105
+ "type": "t_struct<Box.MyStruct>",
106
+ "src": "255:20:0"
107
+ },
108
+ {
109
+ "contract": "Box",
110
+ "path": "contracts/Box.sol",
111
+ "label": "myEnum",
112
+ "astId": 19,
113
+ "type": "t_enum<Box.MyEnum>",
114
+ "src": "281:21:0"
115
+ },
116
+ {
117
+ "contract": "Box",
118
+ "path": "contracts/Box.sol",
119
+ "label": "dynArray",
120
+ "astId": 22,
121
+ "type": "t_array:dyn<t_uint256>",
122
+ "src": "308:23:0"
123
+ },
124
+ {
125
+ "contract": "Box",
126
+ "path": "contracts/Box.sol",
127
+ "label": "staticArray",
128
+ "astId": 26,
129
+ "type": "t_array:10<t_uint256>",
130
+ "src": "337:20:0"
131
+ },
132
+ {
133
+ "contract": "Box",
134
+ "path": "contracts/Box.sol",
135
+ "label": "enumArray",
136
+ "astId": 29,
137
+ "type": "t_array:dyn<t_enum<Box.MyEnum>>",
138
+ "src": "363:26:0"
139
+ },
140
+ {
141
+ "contract": "Box",
142
+ "path": "contracts/Box.sol",
143
+ "label": "byteArray",
144
+ "astId": 31,
145
+ "type": "t_bytes8",
146
+ "src": "395:16:0"
147
+ }
148
+ ],
149
+ "warnings": {
150
+ "hasConstructor": false,
151
+ "hasSelfDestruct": false,
152
+ "hasDelegateCall": false,
153
+ "hasInitialValuesInDeclarations": false,
154
+ "uninitializedBaseContracts": []
155
+ }
156
+ }
157
+ },
158
+ "solidityLibs": {},
159
+ "proxies": {
160
+ "my-project/Box": [
161
+ {
162
+ "address": "0xE4C10Db67595aF2Cb4166c8C274e0140f7E43059",
163
+ "version": "1.0.0",
164
+ "implementation": "0xb682dEEf4f8e298d86bFc3e21f50c675151FB974",
165
+ "admin": "0x1750499D05Ed1674d822430FB960d5F6731fDf64",
166
+ "kind": "Upgradeable"
167
+ }
168
+ ]
169
+ },
170
+ "manifestVersion": "2.2",
171
+ "version": "1.0.0",
172
+ "proxyAdmin": {
173
+ "address": "0x1750499D05Ed1674d822430FB960d5F6731fDf64"
174
+ }
175
+ }
@@ -0,0 +1,70 @@
1
+ import os from 'os';
2
+ import test from 'ava';
3
+ import path from 'path';
4
+ import util from 'util';
5
+ import rimrafAsync from 'rimraf';
6
+ import { promises as fs } from 'fs';
7
+ import { compare as compareVersions } from 'compare-versions';
8
+ import {
9
+ migrateManifestsData,
10
+ NetworkFileData,
11
+ ProjectFileData,
12
+ MigrationOutput,
13
+ migrateLegacyProject,
14
+ } from './migrate-oz-cli-project';
15
+
16
+ const rimraf = util.promisify(rimrafAsync);
17
+ const BASE_PATH = 'src/scripts';
18
+ const OPENZEPPELIN_FOLDER = '.openzeppelin';
19
+ const PROJECT_FILE = path.join(OPENZEPPELIN_FOLDER, 'project.json');
20
+ const EXPORT_FILE = 'openzeppelin-cli-export.json';
21
+ const NETWORK_FILE = path.join(OPENZEPPELIN_FOLDER, 'rinkeby.json');
22
+
23
+ let migratableData: NetworkFileData;
24
+ let migrationOutput: MigrationOutput;
25
+ let projectData: ProjectFileData;
26
+
27
+ test.before(async () => {
28
+ migratableData = JSON.parse(await fs.readFile(path.join(BASE_PATH, 'migratable-manifest.test.json'), 'utf8'));
29
+ projectData = JSON.parse(await fs.readFile(path.join(BASE_PATH, 'project-file.test.json'), 'utf8'));
30
+ migrationOutput = migrateManifestsData({ rinkeby: migratableData });
31
+
32
+ process.chdir(await fs.mkdtemp(path.join(os.tmpdir(), 'migration-test-')));
33
+ await fs.mkdir(OPENZEPPELIN_FOLDER);
34
+ await fs.writeFile(PROJECT_FILE, JSON.stringify(projectData, null, 2));
35
+ await fs.writeFile(NETWORK_FILE, JSON.stringify(migratableData, null, 2));
36
+ await migrateLegacyProject();
37
+ });
38
+
39
+ test.after(async () => {
40
+ await rimraf(process.cwd());
41
+ });
42
+
43
+ test('transforms manifest data', async t => {
44
+ t.snapshot(migrationOutput.newManifestsData);
45
+ });
46
+
47
+ test('produces network export data', async t => {
48
+ t.snapshot(migrationOutput.networksExportData);
49
+ });
50
+
51
+ test('deletes project file', async t => {
52
+ const error = await t.throwsAsync(() => fs.access(PROJECT_FILE));
53
+ t.is(error.message, `ENOENT: no such file or directory, access '${PROJECT_FILE}'`);
54
+ });
55
+
56
+ test('export file contains networks and compiler data', async t => {
57
+ const actual = JSON.parse(await fs.readFile(EXPORT_FILE, 'utf8'));
58
+ const expected = {
59
+ networks: migrationOutput.networksExportData,
60
+ compiler: projectData.compiler,
61
+ };
62
+ t.deepEqual(actual, expected);
63
+ });
64
+
65
+ test('zosversion', t => {
66
+ const migratableDataZosVersion = { zosversion: '2.2', ...migratableData };
67
+ delete migratableDataZosVersion.manifestVersion;
68
+ const output = migrateManifestsData({ rinkeby: migratableDataZosVersion });
69
+ t.true(compareVersions(output.newManifestsData.rinkeby.manifestVersion, '3.0', '>='));
70
+ });
@@ -0,0 +1,146 @@
1
+ # Snapshot report for `src/scripts/migrate-oz-cli-project.test.ts`
2
+
3
+ The actual snapshot is saved in `migrate-oz-cli-project.test.ts.snap`.
4
+
5
+ Generated by [AVA](https://avajs.dev).
6
+
7
+ ## transforms manifest data
8
+
9
+ > Snapshot 1
10
+
11
+ {
12
+ rinkeby: {
13
+ admin: {
14
+ address: '0x1750499D05Ed1674d822430FB960d5F6731fDf64',
15
+ },
16
+ impls: {
17
+ '08100f44a71d905a66088b4c5d72f12417a580d454357e06dcc5ad12b3fa2cbc': {
18
+ address: '0xb682dEEf4f8e298d86bFc3e21f50c675151FB974',
19
+ layout: {
20
+ storage: [
21
+ {
22
+ contract: 'Box',
23
+ label: 'value',
24
+ src: 'contracts/Box.sol',
25
+ type: 't_uint256',
26
+ },
27
+ {
28
+ contract: 'Box',
29
+ label: 'flag',
30
+ src: 'contracts/Box.sol',
31
+ type: 't_bool',
32
+ },
33
+ {
34
+ contract: 'Box',
35
+ label: 'map',
36
+ src: 'contracts/Box.sol',
37
+ type: 't_mapping(unknown,t_bool)',
38
+ },
39
+ {
40
+ contract: 'Box',
41
+ label: 'foo',
42
+ src: 'contracts/Box.sol',
43
+ type: 't_struct(MyStruct)3_storage',
44
+ },
45
+ {
46
+ contract: 'Box',
47
+ label: 'myEnum',
48
+ src: 'contracts/Box.sol',
49
+ type: 't_enum(MyEnum)4',
50
+ },
51
+ {
52
+ contract: 'Box',
53
+ label: 'dynArray',
54
+ src: 'contracts/Box.sol',
55
+ type: 't_array(t_uint256)dyn_storage',
56
+ },
57
+ {
58
+ contract: 'Box',
59
+ label: 'staticArray',
60
+ src: 'contracts/Box.sol',
61
+ type: 't_array(t_uint256)10_storage',
62
+ },
63
+ {
64
+ contract: 'Box',
65
+ label: 'enumArray',
66
+ src: 'contracts/Box.sol',
67
+ type: 't_array(t_enum(MyEnum)4)dyn_storage',
68
+ },
69
+ {
70
+ contract: 'Box',
71
+ label: 'byteArray',
72
+ src: 'contracts/Box.sol',
73
+ type: 't_bytes8',
74
+ },
75
+ ],
76
+ types: {
77
+ 't_array(t_enum(MyEnum)4)dyn_storage': {
78
+ label: 'MyEnum[]',
79
+ },
80
+ 't_array(t_uint256)10_storage': {
81
+ label: 'uint256[10]',
82
+ },
83
+ 't_array(t_uint256)dyn_storage': {
84
+ label: 'uint256[]',
85
+ },
86
+ t_bool: {
87
+ label: 'bool',
88
+ },
89
+ t_bytes8: {
90
+ label: 'bytes8',
91
+ },
92
+ 't_enum(MyEnum)4': {
93
+ label: 'MyEnum',
94
+ members: [
95
+ 'UP',
96
+ 'DOWN',
97
+ ],
98
+ },
99
+ 't_mapping(unknown,t_bool)': {
100
+ label: 'mapping(key => bool)',
101
+ },
102
+ 't_struct(MyStruct)3_storage': {
103
+ label: 'MyStruct',
104
+ members: [
105
+ {
106
+ label: 'x',
107
+ type: 't_bool',
108
+ },
109
+ ],
110
+ },
111
+ t_uint256: {
112
+ label: 'uint256',
113
+ },
114
+ },
115
+ },
116
+ },
117
+ },
118
+ manifestVersion: '3.2',
119
+ proxies: [
120
+ {
121
+ address: '0xE4C10Db67595aF2Cb4166c8C274e0140f7E43059',
122
+ kind: 'transparent',
123
+ },
124
+ ],
125
+ },
126
+ }
127
+
128
+ ## produces network export data
129
+
130
+ > Snapshot 1
131
+
132
+ {
133
+ rinkeby: {
134
+ proxies: {
135
+ 'my-project/Box': [
136
+ {
137
+ address: '0xE4C10Db67595aF2Cb4166c8C274e0140f7E43059',
138
+ admin: '0x1750499D05Ed1674d822430FB960d5F6731fDf64',
139
+ implementation: '0xb682dEEf4f8e298d86bFc3e21f50c675151FB974',
140
+ kind: 'Upgradeable',
141
+ version: '1.0.0',
142
+ },
143
+ ],
144
+ },
145
+ },
146
+ }