├── .circleci └── config.yml ├── .eslintrc.base.js ├── .gitattributes ├── .github └── ISSUE_TEMPLATE │ ├── blank.md │ └── config.yml ├── .gitignore ├── .mergify.yml ├── .prettierrc.base.js ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bootstrap ├── package.json └── yarn.lock ├── examples ├── cli-create2 │ ├── .gitignore │ ├── .openzeppelin │ │ ├── .gitkeep │ │ └── project.json │ ├── README.md │ ├── contracts │ │ └── Sample.sol │ ├── index.js │ ├── migrations │ │ └── .gitkeep │ ├── package.json │ ├── scripts │ │ └── test.sh │ └── truffle.js ├── first-project │ ├── .gitignore │ ├── .openzeppelin │ │ └── project.json │ ├── README.md │ ├── contracts │ │ ├── Counter.sol │ │ └── __upgradeable__ │ │ │ └── CounterUpgradeable.sol │ ├── networks.js │ ├── package.json │ ├── scripts │ │ └── test-ci.sh │ └── src │ │ └── index.js ├── linking-contracts │ ├── .gitignore │ ├── .openzeppelin │ │ └── project.json │ ├── README.md │ ├── contracts │ │ └── TokenExchange.sol │ ├── networks.js │ └── package.json ├── truffle-migrate │ ├── .gitignore │ ├── .openzeppelin │ │ ├── .session │ │ ├── dev-1563225115456.json │ │ └── project.json │ ├── README.md │ ├── contracts │ │ ├── Migrations.sol │ │ ├── MyContract_v0.sol │ │ └── MyContract_v1.sol │ ├── index.js │ ├── migrations │ │ ├── 1_initial_migration.js │ │ ├── 2_deploy_v0.js │ │ └── 3_deploy_v1.js │ ├── package.json │ └── truffle-config.js └── upgrades-library │ ├── .gitignore │ ├── README.md │ ├── contracts │ ├── MyContractV0.sol │ └── MyContractV1.sol │ ├── index.js │ ├── package.json │ └── test │ └── main.test.js ├── legacy ├── README.md ├── zos-lib │ └── package.json └── zos │ └── package.json ├── lerna.json ├── netlify.toml ├── package.json ├── packages ├── .github │ └── README.md ├── cli │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .gitignore │ ├── .prettierrc.js │ ├── AUTHORS │ ├── LICENSE │ ├── README.md │ ├── changelog.md │ ├── contracts │ │ └── mocks │ │ │ ├── Boolean.sol │ │ │ ├── ERC20Fake.sol │ │ │ ├── Impl.sol │ │ │ ├── ImplV1.sol │ │ │ ├── ImplV1b.sol │ │ │ ├── ImplV2.sol │ │ │ ├── Imports.sol │ │ │ ├── Libraries.sol │ │ │ ├── SimpleNonUpgradeable.sol │ │ │ ├── WithConstructorNonUpgradeable.sol │ │ │ └── WithLibraryNonUpgradeable.sol │ ├── docs │ │ ├── antora.yml │ │ └── modules │ │ │ └── ROOT │ │ │ ├── assets │ │ │ └── images │ │ │ │ └── architecture.png │ │ │ ├── nav.adoc │ │ │ └── pages │ │ │ ├── .gitignore │ │ │ ├── compiling.adoc │ │ │ ├── configuration.adoc │ │ │ ├── contracts-architecture.adoc │ │ │ ├── dependencies.adoc │ │ │ ├── deploying-with-create2.adoc │ │ │ ├── faq.adoc │ │ │ ├── getting-started.adoc │ │ │ ├── index.adoc │ │ │ ├── migrate-cli-versions.adoc │ │ │ ├── publishing-ethereum-package.adoc │ │ │ └── truffle.adoc │ ├── mocks │ │ ├── config-files │ │ │ ├── networks.js │ │ │ └── truffle.js │ │ ├── mock-dependency-to-compile │ │ │ ├── .openzeppelin │ │ │ │ └── project.json │ │ │ ├── README.md │ │ │ ├── contracts │ │ │ │ └── subfolder │ │ │ │ │ ├── Dependency.sol │ │ │ │ │ └── DependencyLib.sol │ │ │ ├── networks.js │ │ │ └── package.json │ │ ├── mock-project-to-compile │ │ │ ├── .openzeppelin │ │ │ │ └── project.json │ │ │ ├── README.md │ │ │ ├── contracts │ │ │ │ └── subfolder │ │ │ │ │ ├── Greeter.sol │ │ │ │ │ ├── GreeterLib.sol │ │ │ │ │ └── GreeterLib2.sol │ │ │ ├── networks.js │ │ │ ├── node_modules │ │ │ │ └── mock-dependency-to-compile │ │ │ └── package.json │ │ ├── mock-project-with-repeated-names │ │ │ ├── .openzeppelin │ │ │ │ └── project.json │ │ │ ├── README.md │ │ │ ├── contracts │ │ │ │ └── subfolder │ │ │ │ │ ├── Greeter.sol │ │ │ │ │ └── Greeter2.sol │ │ │ ├── networks.js │ │ │ └── package.json │ │ ├── mock-stdlib with spaces │ │ │ ├── contracts │ │ │ │ ├── GreeterImpl.sol │ │ │ │ └── GreeterLib.sol │ │ │ └── package.json │ │ ├── mock-stdlib-2 │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ └── GreeterImpl.json │ │ │ ├── contracts │ │ │ │ └── GreeterImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── mock-stdlib-empty │ │ │ ├── contracts │ │ │ │ └── .gitkeep │ │ │ └── package.json │ │ ├── mock-stdlib-invalid │ │ │ ├── package.json │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── mock-stdlib-libdeps │ │ │ ├── contracts │ │ │ │ ├── GreeterLibLib.sol │ │ │ │ ├── GreeterLibWithLib.sol │ │ │ │ └── GreeterLibWithLibImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── mock-stdlib-undeployed-2 │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ └── GreeterImpl.json │ │ │ ├── contracts │ │ │ │ └── GreeterImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ └── zos.json │ │ ├── mock-stdlib-undeployed │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ ├── GreeterBase.json │ │ │ │ │ └── GreeterImpl.json │ │ │ ├── contracts │ │ │ │ ├── GreeterBase.sol │ │ │ │ └── GreeterImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ └── zos.json │ │ ├── mock-stdlib-unpublished │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ ├── GreeterBase.json │ │ │ │ │ └── GreeterImpl.json │ │ │ ├── contracts │ │ │ │ ├── GreeterBase.sol │ │ │ │ └── GreeterImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── mock-stdlib-unsupported │ │ │ ├── contracts │ │ │ │ └── GreeterImpl.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── mock-stdlib │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ ├── GreeterImpl.json │ │ │ │ │ └── GreeterLib.json │ │ │ ├── contracts │ │ │ │ ├── GreeterImpl.sol │ │ │ │ └── GreeterLib.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ ├── zos.json │ │ │ └── zos.test.json │ │ ├── networks │ │ │ ├── network-app-with-contract.zos.test.json │ │ │ ├── network-deprecated-manifest-version.zos.test.json │ │ │ ├── network-missing-manifest-version.zos.test.json │ │ │ ├── network-unsupported-manifest-version.zos.test.json │ │ │ ├── network-with-older-stdlibs.zos.test.json │ │ │ └── network-with-stdlibs.zos.test.json │ │ └── packages │ │ │ ├── package-deprecated-manifest-version.zos.json │ │ │ ├── package-empty-lite.zos.json │ │ │ ├── package-empty.zos.json │ │ │ ├── package-missing-manifest-version.zos.json │ │ │ ├── package-unsupported-manifest-version.zos.json │ │ │ ├── package-with-contracts-and-multiple-stdlibs.zos.json │ │ │ ├── package-with-contracts-and-stdlib-v2.zos.json │ │ │ ├── package-with-contracts-and-stdlib.zos.json │ │ │ ├── package-with-contracts-v2.zos.json │ │ │ ├── package-with-contracts.zos.json │ │ │ ├── package-with-invalid-contracts.zos.json │ │ │ ├── package-with-invalid-stdlib.zos.json │ │ │ ├── package-with-manifest-version-2.zos.json │ │ │ ├── package-with-multiple-stdlibs.zos.json │ │ │ ├── package-with-stdlib-range.zos.json │ │ │ ├── package-with-stdlib.zos.json │ │ │ ├── package-with-undeployed-stdlib.zos.json │ │ │ └── package-with-unpublished-stdlib.zos.json │ ├── package.json │ ├── scripts │ │ ├── copy-files.sh │ │ ├── prepare-docs.js │ │ └── ts_prepare.sh │ ├── solc │ │ ├── list.json │ │ ├── solc │ │ ├── soljson-v0.4.24+commit.e67f0147.js │ │ ├── soljson-v0.5.0+commit.1d4f565a.js │ │ ├── soljson-v0.5.10-nightly.2019.5.28+commit.ff8898b8.js │ │ └── soljson-v0.5.9+commit.e560f70d.js │ ├── src │ │ ├── @types │ │ │ └── solc-wrapper.d.ts │ │ ├── bin │ │ │ ├── errors.ts │ │ │ ├── helpers.ts │ │ │ ├── options.ts │ │ │ ├── oz-cli.ts │ │ │ └── program.ts │ │ ├── commands │ │ │ ├── accounts.ts │ │ │ ├── add.ts │ │ │ ├── balance.ts │ │ │ ├── bump.ts │ │ │ ├── call.ts │ │ │ ├── check.ts │ │ │ ├── compile.ts │ │ │ ├── create.ts │ │ │ ├── create2.ts │ │ │ ├── deploy │ │ │ │ ├── action.ts │ │ │ │ ├── index.ts │ │ │ │ └── spec.ts │ │ │ ├── freeze.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── interfaces.ts │ │ │ ├── link.ts │ │ │ ├── publish.ts │ │ │ ├── push.ts │ │ │ ├── remove.ts │ │ │ ├── send-tx.ts │ │ │ ├── session.ts │ │ │ ├── set-admin.ts │ │ │ ├── status.ts │ │ │ ├── transfer.ts │ │ │ ├── unlink.ts │ │ │ ├── unpack.ts │ │ │ ├── update.ts │ │ │ ├── utils.ts │ │ │ └── verify │ │ │ │ ├── action.ts │ │ │ │ ├── index.ts │ │ │ │ └── spec.ts │ │ ├── index.ts │ │ ├── interface │ │ │ └── ValidationLogger.ts │ │ ├── models │ │ │ ├── TestHelper.ts │ │ │ ├── Verifier.ts │ │ │ ├── compiler │ │ │ │ ├── Compiler.ts │ │ │ │ ├── ProjectCompilerOptions.ts │ │ │ │ ├── Typechain.ts │ │ │ │ └── solidity │ │ │ │ │ ├── CompilerProvider.ts │ │ │ │ │ ├── SolidityContractsCompiler.ts │ │ │ │ │ ├── SolidityProjectCompiler.ts │ │ │ │ │ └── SourcesGatherer.ts │ │ │ ├── config │ │ │ │ ├── ConfigManager.ts │ │ │ │ ├── NetworkConfig.ts │ │ │ │ ├── TruffleConfig.ts │ │ │ │ └── blueprint.networks.js │ │ │ ├── dependency │ │ │ │ └── Dependency.ts │ │ │ ├── files │ │ │ │ ├── KitFile.ts │ │ │ │ ├── ManifestVersion.ts │ │ │ │ ├── NetworkFile.ts │ │ │ │ ├── ProjectFile.ts │ │ │ │ ├── constants.ts │ │ │ │ ├── index.ts │ │ │ │ └── kit-config.schema.json │ │ │ ├── local │ │ │ │ ├── ContractManager.ts │ │ │ │ ├── KitController.ts │ │ │ │ ├── LocalController.ts │ │ │ │ └── index.ts │ │ │ └── network │ │ │ │ ├── NetworkController.ts │ │ │ │ ├── ProjectDeployer.ts │ │ │ │ ├── Session.ts │ │ │ │ ├── TransactionController.ts │ │ │ │ ├── defaults.ts │ │ │ │ └── index.ts │ │ ├── prompts │ │ │ ├── choices.ts │ │ │ ├── method-params.ts │ │ │ ├── migrations.ts │ │ │ ├── prompt.ts │ │ │ ├── typechain.ts │ │ │ └── validators.ts │ │ ├── register-command.ts │ │ ├── scripts │ │ │ ├── accounts.ts │ │ │ ├── add-all.ts │ │ │ ├── add.ts │ │ │ ├── balance.ts │ │ │ ├── bump.ts │ │ │ ├── call.ts │ │ │ ├── check.ts │ │ │ ├── create.ts │ │ │ ├── freeze.ts │ │ │ ├── index.ts │ │ │ ├── init.ts │ │ │ ├── interfaces.ts │ │ │ ├── link.ts │ │ │ ├── publish.ts │ │ │ ├── push.ts │ │ │ ├── query-deployment.ts │ │ │ ├── query-signed-deployment.ts │ │ │ ├── remove.ts │ │ │ ├── send-tx.ts │ │ │ ├── session.ts │ │ │ ├── set-admin.ts │ │ │ ├── transfer.ts │ │ │ ├── unlink.ts │ │ │ ├── unpack.ts │ │ │ └── update.ts │ │ ├── telemetry │ │ │ ├── index.ts │ │ │ └── send-to-firebase.ts │ │ ├── test │ │ │ ├── bin │ │ │ │ └── helpers.test.js │ │ │ ├── commands │ │ │ │ ├── accounts.test.js │ │ │ │ ├── add.test.js │ │ │ │ ├── balance.test.js │ │ │ │ ├── bump.test.js │ │ │ │ ├── call.test.js │ │ │ │ ├── check.test.js │ │ │ │ ├── compile.test.js │ │ │ │ ├── create.test.js │ │ │ │ ├── create2.test.js │ │ │ │ ├── deploy.test.ts │ │ │ │ ├── freeze.test.js │ │ │ │ ├── init.test.js │ │ │ │ ├── link.test.js │ │ │ │ ├── publish.test.js │ │ │ │ ├── push.test.js │ │ │ │ ├── remove.test.js │ │ │ │ ├── send-tx.test.js │ │ │ │ ├── session.test.js │ │ │ │ ├── setAdmin.test.js │ │ │ │ ├── share.js │ │ │ │ ├── transfer.test.js │ │ │ │ ├── unlink.test.js │ │ │ │ ├── unpack.test.js │ │ │ │ └── update.test.js │ │ │ ├── config │ │ │ │ ├── ConfigManager.test.js │ │ │ │ ├── NetworkConfig.test.js │ │ │ │ └── TruffleConfig.test.js │ │ │ ├── helpers │ │ │ │ ├── captureLogs.js │ │ │ │ └── cleanup.js │ │ │ ├── interface │ │ │ │ └── ValidationLogger.test.js │ │ │ ├── models │ │ │ │ ├── ContractManager.test.js │ │ │ │ ├── Dependency.test.js │ │ │ │ ├── ManifestVersion.test.js │ │ │ │ ├── NetworkFile.test.js │ │ │ │ ├── ProjectFile.test.js │ │ │ │ ├── TestHelper.test.js │ │ │ │ ├── compiler │ │ │ │ │ ├── Compiler.test.js │ │ │ │ │ └── solidity │ │ │ │ │ │ ├── SolidityContractsCompiler.test.js │ │ │ │ │ │ └── SolidityProjectCompiler.test.js │ │ │ │ └── network │ │ │ │ │ └── NetworkController.test.js │ │ │ ├── prompts │ │ │ │ └── prompt.test.js │ │ │ ├── scripts │ │ │ │ ├── accounts.test.js │ │ │ │ ├── add.test.js │ │ │ │ ├── balance.test.js │ │ │ │ ├── bump.test.js │ │ │ │ ├── call.test.js │ │ │ │ ├── check.test.js │ │ │ │ ├── create.test.js │ │ │ │ ├── freeze.test.js │ │ │ │ ├── init.test.js │ │ │ │ ├── link.test.js │ │ │ │ ├── migrate.test.js │ │ │ │ ├── publish.test.js │ │ │ │ ├── push.test.js │ │ │ │ ├── query-deployment.test.js │ │ │ │ ├── query-signed-deployment.test.js │ │ │ │ ├── remove.test.js │ │ │ │ ├── send-tx.test.js │ │ │ │ ├── session.test.js │ │ │ │ ├── set-admin.test.js │ │ │ │ ├── transfer.test.js │ │ │ │ ├── unlink.test.js │ │ │ │ ├── unpack.test.js │ │ │ │ ├── update.test.js │ │ │ │ └── verify.test.js │ │ │ ├── setup.js │ │ │ ├── telemetry.test.js │ │ │ └── utils │ │ │ │ ├── async.test.js │ │ │ │ ├── events.test.js │ │ │ │ ├── input.test.js │ │ │ │ ├── naming.test.js │ │ │ │ ├── solidity.test.js │ │ │ │ └── units.test.js │ │ ├── transpiler.ts │ │ └── utils │ │ │ ├── async.ts │ │ │ ├── child.ts │ │ │ ├── constants.ts │ │ │ ├── contract.ts │ │ │ ├── events.ts │ │ │ ├── input.ts │ │ │ ├── naming.ts │ │ │ ├── patch.ts │ │ │ ├── solidity.ts │ │ │ ├── stdout.ts │ │ │ ├── try.ts │ │ │ └── units.ts │ ├── truffle.js │ ├── tsconfig.docs.json │ ├── tsconfig.json │ └── tsconfig.test.json ├── lib │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .gitignore │ ├── .jshintrc │ ├── .prettierrc.js │ ├── AUTHORS │ ├── LICENSE │ ├── README.md │ ├── changelog.md │ ├── contracts │ │ ├── .npmignore │ │ ├── Initializable.sol │ │ ├── README.adoc │ │ ├── application │ │ │ ├── App.sol │ │ │ ├── ImplementationDirectory.sol │ │ │ ├── ImplementationProvider.sol │ │ │ └── Package.sol │ │ ├── cryptography │ │ │ └── ECDSA.sol │ │ ├── mocks │ │ │ ├── ClashingImplementation.sol │ │ │ ├── DeprecatedAdminUpgradeabilityProxy.sol │ │ │ ├── DeprecatedApp.sol │ │ │ ├── DummyImplementation.sol │ │ │ ├── GetFunctionMocks.sol │ │ │ ├── InitializableMock.sol │ │ │ ├── Invalid.sol │ │ │ ├── MockStandaloneERC721.sol │ │ │ ├── MultipleInheritanceInitializableMocks.sol │ │ │ ├── ProxyCreator.sol │ │ │ ├── RegressionImplementation.sol │ │ │ ├── SingleInheritanceInitializableMocks.sol │ │ │ ├── StorageMocks.sol │ │ │ ├── StorageMocks2.sol │ │ │ ├── StorageMocks3.sol │ │ │ ├── StorageMocksForComparison.sol │ │ │ ├── WithConstructorImplementation.sol │ │ │ ├── WithInitialValues.sol │ │ │ ├── WithInitialize.sol │ │ │ ├── WithLibrary.sol │ │ │ ├── WithStructInConstructor.sol │ │ │ └── zos │ │ │ │ ├── ZosAdminUpgradeabilityProxy.sol │ │ │ │ ├── ZosBaseAdminUpgradeabilityProxy.sol │ │ │ │ ├── ZosBaseUpgradeabilityProxy.sol │ │ │ │ ├── ZosInitializableAdminUpgradeabilityProxy.sol │ │ │ │ ├── ZosInitializableUpgradeabilityProxy.sol │ │ │ │ └── ZosUpgradeabilityProxy.sol │ │ ├── ownership │ │ │ └── Ownable.sol │ │ ├── upgradeability │ │ │ ├── AdminUpgradeabilityProxy.sol │ │ │ ├── BaseAdminUpgradeabilityProxy.sol │ │ │ ├── BaseUpgradeabilityProxy.sol │ │ │ ├── InitializableAdminUpgradeabilityProxy.sol │ │ │ ├── InitializableUpgradeabilityProxy.sol │ │ │ ├── Proxy.sol │ │ │ ├── ProxyAdmin.sol │ │ │ ├── ProxyFactory.sol │ │ │ └── UpgradeabilityProxy.sol │ │ └── utils │ │ │ └── Address.sol │ ├── docs │ │ ├── antora.yml │ │ ├── modules │ │ │ ├── .gitignore │ │ │ └── ROOT │ │ │ │ ├── nav.adoc │ │ │ │ └── pages │ │ │ │ ├── creating-upgradeable-from-solidity.adoc │ │ │ │ ├── index.adoc │ │ │ │ ├── proxies.adoc │ │ │ │ └── writing-upgradeable.adoc │ │ └── templates │ │ │ └── contract.hbs │ ├── package.json │ ├── scripts │ │ ├── prepare-docs.sh │ │ └── ts_prepare.sh │ ├── src │ │ ├── application │ │ │ ├── App.ts │ │ │ ├── ImplementationDirectory.ts │ │ │ └── Package.ts │ │ ├── artifacts │ │ │ ├── BuildArtifacts.ts │ │ │ ├── Contract.ts │ │ │ ├── Contracts.ts │ │ │ └── ZWeb3.ts │ │ ├── errors.ts │ │ ├── helpers │ │ │ ├── advanceBlock.ts │ │ │ ├── encodeCall.ts │ │ │ └── sleep.ts │ │ ├── index.ts │ │ ├── project │ │ │ ├── AppProject.ts │ │ │ ├── BasePackageProject.ts │ │ │ ├── BaseSimpleProject.ts │ │ │ ├── PackageProject.ts │ │ │ ├── ProxyAdminProject.ts │ │ │ ├── SimpleProject.ts │ │ │ └── mixin │ │ │ │ └── ProxyAdminProjectMixin.ts │ │ ├── proxy │ │ │ ├── MinimalProxy.ts │ │ │ ├── Proxy.ts │ │ │ ├── ProxyAdmin.ts │ │ │ └── ProxyFactory.ts │ │ ├── test │ │ │ ├── behaviors │ │ │ │ └── Ownable.ts │ │ │ ├── helpers │ │ │ │ ├── assertEvent.ts │ │ │ │ ├── assertRevert.ts │ │ │ │ ├── assertions.ts │ │ │ │ └── signing.ts │ │ │ └── index.ts │ │ ├── utils │ │ │ ├── ABIs.ts │ │ │ ├── Addresses.ts │ │ │ ├── Bytecode.ts │ │ │ ├── Constants.ts │ │ │ ├── ContractAST.ts │ │ │ ├── Logger.ts │ │ │ ├── Migrator.ts │ │ │ ├── Mixin.ts │ │ │ ├── Semver.ts │ │ │ ├── Solidity.ts │ │ │ ├── Transactions.ts │ │ │ └── errors │ │ │ │ └── DeployError.ts │ │ └── validations │ │ │ ├── Constructors.ts │ │ │ ├── InitialValues.ts │ │ │ ├── Instructions.ts │ │ │ ├── Layout.ts │ │ │ ├── Storage.ts │ │ │ ├── VanillaContracts.ts │ │ │ └── index.ts │ ├── test-environment.config.js │ ├── test │ │ ├── contracts │ │ │ ├── Initializable.test.js │ │ │ ├── ProxyAdmin.test.js │ │ │ ├── application │ │ │ │ ├── App.test.js │ │ │ │ ├── ImplementationDirectory.test.js │ │ │ │ ├── ManagePackages.behavior.js │ │ │ │ ├── ManageProxies.behavior.js │ │ │ │ └── Package.test.js │ │ │ └── upgradeability │ │ │ │ ├── AdminUpgradeabilityProxy.behaviour.js │ │ │ │ ├── AdminUpgradeabilityProxy.test.js │ │ │ │ ├── InitializableAdminUpgradeabilityProxy.test.js │ │ │ │ ├── UpgradeabilityProxy.behaviour.js │ │ │ │ ├── UpgradeabilityProxy.test.js │ │ │ │ └── storageSlot.test.js │ │ ├── setup.js │ │ └── src │ │ │ ├── ProxyAdmin.test.js │ │ │ ├── ProxyFactory.test.js │ │ │ ├── application │ │ │ ├── App.test.js │ │ │ ├── ImplementationDirectory.test.js │ │ │ └── Package.test.js │ │ │ ├── artifacts │ │ │ ├── Contract.test.js │ │ │ ├── Contracts.test.js │ │ │ └── ZWeb3.test.js │ │ │ ├── helpers │ │ │ └── encodeCall.test.js │ │ │ ├── project │ │ │ ├── AdminProxy.behaviour.js │ │ │ ├── AppProject.test.js │ │ │ ├── DependenciesProject.behaviour.js │ │ │ ├── Implementations.behaviour.js │ │ │ ├── PackageProject.behavior.js │ │ │ ├── PackageProject.test.js │ │ │ ├── ProxyAdminProject.test.js │ │ │ ├── ProxyProject.behaviour.js │ │ │ └── SimpleProject.test.js │ │ │ ├── utils │ │ │ ├── ABIs.test.js │ │ │ ├── Bytecode.test.js │ │ │ ├── Logger.test.js │ │ │ ├── Migrator.test.js │ │ │ └── Transactions.test.js │ │ │ └── validations │ │ │ ├── Layout.test.js │ │ │ ├── Storage.test.js │ │ │ └── Validations.test.js │ ├── tsconfig.json │ └── tsconfig.test.json └── transpiler │ ├── .eslintignore │ ├── .eslintrc.js │ ├── .gitignore │ ├── .prettierrc.js │ ├── LICENSE │ ├── package.json │ ├── src │ ├── index.ts │ ├── solc │ │ ├── artifact.ts │ │ ├── ast-node.ts │ │ ├── ast-utils.ts │ │ ├── get-inheritance-chain.ts │ │ └── schemas │ │ │ └── ast.ts │ ├── transformation.ts │ ├── transformations │ │ ├── append-directive.ts │ │ ├── build-super-calls-for-chain.ts │ │ ├── fix-import-directives.ts │ │ ├── get-var-inits.ts │ │ ├── index.ts │ │ ├── prepend-base-class.ts │ │ ├── purge-contracts.ts │ │ ├── purge-var-inits.ts │ │ ├── transform-constructor.ts │ │ ├── transform-contract-name.ts │ │ └── transform-parents.ts │ └── transpiler.ts │ ├── test │ └── solc-0.5 │ │ ├── .openzeppelin │ │ └── project.json │ │ ├── contracts │ │ ├── ClassInheritance.sol │ │ ├── ComplexConstructor.sol │ │ ├── DiamondInheritance.sol │ │ ├── ElementaryTypes.sol │ │ ├── ElementaryTypesWithConstructor.sol │ │ ├── GLDToken.sol │ │ ├── Imports.sol │ │ ├── SimpleInheritance.sol │ │ ├── StringConstructor.sol │ │ └── one │ │ │ └── two │ │ │ └── three │ │ │ └── Deep.sol │ │ ├── jest.config.js │ │ ├── networks.js │ │ ├── package.json │ │ ├── test │ │ ├── ClassInheritance.test.ts │ │ ├── DiamondInheritance.test.ts │ │ ├── ElementaryTypes.test.ts │ │ ├── ElementaryTypesWithConstructor.test.ts │ │ ├── GLDToken.test.ts │ │ ├── Imports.ts │ │ ├── LocalContract.behaviour.ts │ │ ├── SimpleInheritance.test.ts │ │ ├── StringConstructor.test.ts │ │ ├── __snapshots__ │ │ │ ├── ClassInheritance.test.ts.snap │ │ │ ├── DiamondInheritance.test.ts.snap │ │ │ ├── ElementaryTypes.test.ts.snap │ │ │ ├── ElementaryTypesWithConstructor.test.ts.snap │ │ │ ├── GLDToken.test.ts.snap │ │ │ ├── SimpleInheritance.test.ts.snap │ │ │ └── StringConstructor.test.ts.snap │ │ ├── compile.test.ts │ │ └── setup.ts │ │ ├── tsconfig.json │ │ └── yarn.lock │ └── tsconfig.json ├── scripts └── check-yarn-lockfile.sh ├── tests ├── cli │ ├── .gitignore │ ├── dependencies │ │ ├── mock-stdlib-1.1.0 │ │ │ ├── build │ │ │ │ └── contracts │ │ │ │ │ ├── Greeter.json │ │ │ │ │ ├── Numbers.json │ │ │ │ │ ├── Parent.json │ │ │ │ │ └── SharedNumbers.json │ │ │ ├── contracts │ │ │ │ ├── Greeter.sol │ │ │ │ ├── InternalLibrary.sol │ │ │ │ ├── Parent.sol │ │ │ │ └── SharedLibrary.sol │ │ │ ├── migrations │ │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ └── zos.json │ │ └── mock-stdlib-1.2.0 │ │ │ ├── build │ │ │ └── contracts │ │ │ │ ├── Greeter.json │ │ │ │ ├── Numbers.json │ │ │ │ ├── Parent.json │ │ │ │ └── SharedNumbers.json │ │ │ ├── contracts │ │ │ ├── Greeter.sol │ │ │ ├── InternalLibrary.sol │ │ │ ├── Parent.sol │ │ │ └── SharedLibrary.sol │ │ │ ├── migrations │ │ │ └── .gitkeep │ │ │ ├── package.json │ │ │ ├── truffle.js │ │ │ └── zos.json │ ├── test │ │ ├── README.md │ │ ├── files │ │ │ ├── GreeterWrapper.sol │ │ │ ├── GreeterWrapperV2.sol │ │ │ ├── Samples.sol │ │ │ └── SamplesV2.sol │ │ ├── package.json │ │ ├── scripts │ │ │ └── test.sh │ │ ├── src │ │ │ ├── integration.test.js │ │ │ └── project.js │ │ └── truffle.js │ └── workdir │ │ ├── .gitignore │ │ ├── .gitkeep │ │ ├── contracts │ │ └── .gitkeep │ │ ├── migrations │ │ └── .gitkeep │ │ ├── package.json │ │ ├── scripts │ │ ├── getaccounts.js │ │ ├── run.js │ │ └── shared.js │ │ └── truffle.js ├── deploy │ ├── .gitignore │ ├── .openzeppelin │ │ └── project.json │ ├── contracts │ │ ├── Answer.sol │ │ └── ValueWithConstructor.sol │ ├── networks.js │ ├── package.json │ └── test.js ├── kits │ ├── .gitignore │ ├── test │ │ ├── .eslintrc.js │ │ ├── .prettierrc.js │ │ ├── README.md │ │ ├── counter.patch │ │ ├── gsn.patch │ │ ├── package.json │ │ ├── scripts │ │ │ └── test.sh │ │ └── src │ │ │ └── integration.test.js │ └── workdir │ │ └── .gitkeep ├── mocks │ ├── mock-dependency │ │ ├── .gitignore │ │ ├── build │ │ │ └── contracts │ │ │ │ └── Greeter.json │ │ ├── contracts │ │ │ ├── DependencyInvalid.sol │ │ │ ├── DependencyStorageMock.sol │ │ │ └── Greeter.sol │ │ ├── migrations │ │ │ └── .gitkeep │ │ ├── package-lock.json │ │ ├── package.json │ │ └── truffle.js │ └── mock-solc-0.6 │ │ ├── .gitignore │ │ ├── .openzeppelin │ │ └── project.json │ │ ├── build │ │ └── contracts │ │ │ ├── Base.json │ │ │ ├── Initializable.json │ │ │ ├── InitializableMock.json │ │ │ ├── Sample.json │ │ │ ├── SampleChild.json │ │ │ ├── SampleFather.json │ │ │ ├── SampleGramps.json │ │ │ ├── SampleHuman.json │ │ │ └── SampleMother.json │ │ ├── contracts │ │ ├── .gitkeep │ │ ├── Sample.sol │ │ └── initializable │ │ │ ├── Initializable.sol │ │ │ ├── InitializableMock.sol │ │ │ └── MultipleInheritanceInitializableMocks.sol │ │ ├── networks.js │ │ └── package.json └── util │ ├── fund.js │ ├── share.js │ └── test.sh ├── tsconfig.json └── yarn.lock /.eslintrc.base.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', // Specifies the ESLint parser 3 | extends: [ 4 | 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin 5 | 'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier 6 | 'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. 7 | ], 8 | parserOptions: { 9 | ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features 10 | sourceType: 'module', // Allows for the use of imports 11 | }, 12 | rules: { 13 | '@typescript-eslint/no-use-before-define': 0, 14 | '@typescript-eslint/no-empty-interface': 0, 15 | } 16 | }; -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/blank.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report or Feature request 3 | about: Open a new issue 4 | --- 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Support request 3 | url: https://forum.openzeppelin.com/c/support/sdk/19 4 | about: Ask the community in the Community Forum 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lerna-debug.log 2 | .vscode 3 | node_modules 4 | build 5 | *.tsbuildinfo 6 | -------------------------------------------------------------------------------- /.mergify.yml: -------------------------------------------------------------------------------- 1 | pull_request_rules: 2 | - name: merge 3 | actions: 4 | merge: 5 | method: squash 6 | rebase_fallback: merge 7 | conditions: 8 | - base=master 9 | - label=status:ready-to-merge 10 | - label!=no-mergify 11 | - '#approved-reviews-by>=1' 12 | - '#changes-requested-reviews-by=0' 13 | - 'status-success="ci/circleci: test-cli"' 14 | - 'status-success="ci/circleci: test-lib"' 15 | - 'status-success="ci/circleci: example-create-instances-from-solidity"' 16 | - 'status-success="ci/circleci: example-upgrades-library"' 17 | - 'status-success="ci/circleci: example-cli-create2"' 18 | - 'status-success="ci/circleci: example-first-project"' 19 | - 'status-success="ci/circleci: integration-cli-geth"' 20 | - 'status-success="ci/circleci: integration-cli-hdwallet"' 21 | - 'status-success="ci/circleci: integration-cli-kits"' 22 | - name: delete head branch after merge 23 | conditions: 24 | - merged 25 | - head~=^(fix|feature|docs|design|refactor|test|rename|dx)/ 26 | actions: 27 | delete_head_branch: {} 28 | -------------------------------------------------------------------------------- /.prettierrc.base.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | semi: true, 3 | trailingComma: 'all', 4 | singleQuote: true, 5 | printWidth: 120, 6 | tabWidth: 2, 7 | }; -------------------------------------------------------------------------------- /bootstrap/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@openzeppelin/bootstrap", 3 | "version": "2.6.0", 4 | "license": "MIT", 5 | "private": true, 6 | "dependencies": { 7 | "@openzeppelin/cli": "2.5.3" 8 | }, 9 | "resolutions": { 10 | "@openzeppelin/cli/@openzeppelin/upgrades": "2.5.3" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/cli-create2/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | node_modules 3 | zos.dev-*.json 4 | .openzeppelin/* 5 | -------------------------------------------------------------------------------- /examples/cli-create2/.openzeppelin/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/examples/cli-create2/.openzeppelin/.gitkeep -------------------------------------------------------------------------------- /examples/cli-create2/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "name": "example-cli-create2", 4 | "version": "1.0.0", 5 | "contracts": ["Sample"], 6 | "dependencies": {} 7 | } 8 | -------------------------------------------------------------------------------- /examples/cli-create2/contracts/Sample.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Sample { 4 | uint256 public value; 5 | 6 | constructor(uint256 _value) public { 7 | value = _value; 8 | } 9 | } -------------------------------------------------------------------------------- /examples/cli-create2/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/examples/cli-create2/migrations/.gitkeep -------------------------------------------------------------------------------- /examples/cli-create2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-cli-create2", 3 | "version": "2.8.0-rc.0", 4 | "private": true, 5 | "description": "Example project for using create2", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "scripts/test.sh" 9 | }, 10 | "author": "santiago@openzeppelin.com", 11 | "license": "MIT", 12 | "dependencies": { 13 | "@openzeppelin/cli": "2.8.0-rc.0", 14 | "@openzeppelin/upgrades": "2.8.0-rc.0", 15 | "web3": "1.2.2" 16 | }, 17 | "devDependencies": { 18 | "chai": "^4.2.0", 19 | "ganache-cli": "^6.4.2", 20 | "truffle": "^5.0.5" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/cli-create2/scripts/test.sh: -------------------------------------------------------------------------------- 1 | # Exit script as soon as a command fails. 2 | set -o errexit 3 | 4 | # Executes cleanup function at script exit. 5 | trap cleanup EXIT 6 | 7 | ganache_port=9545 8 | 9 | cleanup() { 10 | # Kill the ganache instance that we started (if we started one and if it's still running). 11 | if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then 12 | kill -9 $ganache_pid 13 | fi 14 | } 15 | 16 | ganache_running() { 17 | nc -z localhost "$ganache_port" 18 | } 19 | 20 | start_ganache() { 21 | node_modules/.bin/ganache-cli --networkId 4447 -p $ganache_port > /dev/null & 22 | ganache_pid=$! 23 | } 24 | 25 | # Run ganache 26 | if ganache_running; then 27 | echo "Using existing ganache instance" 28 | else 29 | echo "Starting our own ganache instance" 30 | start_ganache 31 | fi 32 | 33 | if [ "$CI" = true ]; then 34 | node_modules/.bin/truffle version 35 | node_modules/.bin/truffle compile 36 | fi 37 | 38 | node_modules/.bin/truffle exec index.js --network local 39 | -------------------------------------------------------------------------------- /examples/cli-create2/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | local: { 4 | host: 'localhost', 5 | port: 9545, 6 | gas: 5000000, 7 | gasPrice: 5e9, 8 | network_id: '*', 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/first-project/.gitignore: -------------------------------------------------------------------------------- 1 | /build/* 2 | /zos.dev* 3 | .zos* 4 | .zos.session 5 | .openzeppelin/* 6 | -------------------------------------------------------------------------------- /examples/first-project/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": [ 4 | "Counter" 5 | ], 6 | "dependencies": {}, 7 | "name": "example-first-project", 8 | "version": "1.0.0", 9 | "compiler": { 10 | "manager": "openzeppelin", 11 | "solcVersion": "0.5.9", 12 | "compilerSettings": { 13 | "optimizer": { 14 | "enabled": false, 15 | "runs": "200" 16 | } 17 | }, 18 | "artifactsDir": "build/contracts", 19 | "contractsDir": "contracts" 20 | }, 21 | "telemetryOptIn": false 22 | } 23 | -------------------------------------------------------------------------------- /examples/first-project/README.md: -------------------------------------------------------------------------------- 1 | # OpenZeppelin SDK example: your first project 2 | 3 | This is a sample project with a single contract for getting started with the OpenZeppelin SDK. Head over to our [documentation](https://docs.openzeppelin.com) to see the guide for this project. 4 | 5 | To run it on your machine: 6 | - Install dependencies with `npm install` 7 | - Start a ganache instance with `npx ganache-cli -p 8545 -d` 8 | - Create a new `Counter` contract instance with `npx openzeppelin deploy Counter --network development` 9 | - Run the main script with `node src/index.js` 10 | -------------------------------------------------------------------------------- /examples/first-project/contracts/Counter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Counter { 4 | uint256 public value; 5 | 6 | function increase(uint256 amount) public { 7 | value += amount; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/first-project/contracts/__upgradeable__/CounterUpgradeable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 3 | 4 | contract CounterUpgradeable is Initializable { 5 | function initialize() external initializer { 6 | __init(true); 7 | } 8 | 9 | function __init(bool callChain) internal { 10 | 11 | 12 | 13 | } 14 | 15 | uint256 public value; 16 | 17 | function increase(uint256 amount) public { 18 | value += amount; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/first-project/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | test: { 12 | protocol: 'http', 13 | host: 'localhost', 14 | port: 9555, 15 | gas: 5000000, 16 | gasPrice: 5e9, 17 | networkId: '4447', 18 | }, 19 | }, 20 | }; 21 | -------------------------------------------------------------------------------- /examples/first-project/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-first-project", 3 | "version": "2.8.0-rc.0", 4 | "description": "", 5 | "private": true, 6 | "main": "index.js", 7 | "author": "santiago@openzeppelin.com", 8 | "license": "MIT", 9 | "scripts": { 10 | "test": "scripts/test-ci.sh" 11 | }, 12 | "dependencies": { 13 | "@openzeppelin/contract-loader": "0.6.0", 14 | "web3": "1.2.2" 15 | }, 16 | "devDependencies": { 17 | "@openzeppelin/cli": "2.8.0-rc.0", 18 | "@openzeppelin/upgrades": "2.8.0-rc.0", 19 | "ganache-cli": "^6.4.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/first-project/scripts/test-ci.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | set -o xtrace 5 | trap cleanup EXIT 6 | 7 | ganache_port=9555 8 | 9 | oz="node_modules/.bin/oz" 10 | 11 | cleanup() { 12 | if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then 13 | kill -9 $ganache_pid 14 | fi 15 | } 16 | 17 | start_ganache() { 18 | node_modules/.bin/ganache-cli --version 19 | node_modules/.bin/ganache-cli -d -i 4447 -p $ganache_port > /dev/null & 20 | ganache_pid=$! 21 | } 22 | 23 | 24 | rm -f .openzeppelin/dev-4447.json 25 | start_ganache 26 | sleep 2 27 | 28 | $oz --version 29 | 30 | $oz deploy Counter --kind upgradeable --network test 31 | 32 | RESULT=$(PROVIDER_URL="http://localhost:${ganache_port}" node src/index.js) 33 | if [ "$RESULT" != "20" ]; then 34 | echo "Invalid result. Expected 20, got $RESULT." 35 | exit 1 36 | fi 37 | 38 | echo $RESULT 39 | -------------------------------------------------------------------------------- /examples/first-project/src/index.js: -------------------------------------------------------------------------------- 1 | const Web3 = require('web3'); 2 | const { setupLoader } = require('@openzeppelin/contract-loader'); 3 | 4 | async function main() { 5 | const web3 = new Web3(process.env.PROVIDER_URL || 'http://localhost:8545'); 6 | const loader = setupLoader({ provider: web3 }).web3; 7 | 8 | // Create web3 contract instance 9 | const address = '0xCfEB869F69431e42cdB54A4F4f105C19C080A601'; 10 | const counter = loader.fromArtifact('Counter', address); 11 | 12 | // Retrieve accounts from the local node, we will use the first one to send the transaction 13 | const accounts = await web3.eth.getAccounts(); 14 | 15 | // Send a transaction to increase() the Counter contract 16 | await counter.methods.increase(20) 17 | .send({ from: accounts[0], gas: 50000, gasPrice: 1e6 }); 18 | 19 | // Call the value() function of the deployed Counter contract 20 | const value = await counter.methods.value().call(); 21 | console.log(value); 22 | } 23 | 24 | if (require.main === module) { 25 | main(); 26 | } 27 | -------------------------------------------------------------------------------- /examples/linking-contracts/.gitignore: -------------------------------------------------------------------------------- 1 | /build/* 2 | /.zos.session 3 | /zos.dev-* 4 | .zos* 5 | -------------------------------------------------------------------------------- /examples/linking-contracts/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": ["TokenExchange"], 4 | "name": "example-linking-contracts", 5 | "version": "1.0.0", 6 | "dependencies": { 7 | "openzeppelin-eth": "2.2.0" 8 | }, 9 | "compiler": { 10 | "manager": "zos", 11 | "compilerSettings": { 12 | "optimizer": {} 13 | }, 14 | "solcVersion": "0.5.9" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/linking-contracts/README.md: -------------------------------------------------------------------------------- 1 | # OpenZeppelin SDK example: linking Ethereum Packages 2 | 3 | This project demos how to link an Ethereum Package into your project. It uses `@openzeppelin/contracts-ethereum-package` to easily deploy an upgradeable ERC20. Head over to [our documentation](https://docs.zeppelinos.org/docs/linking.html) for a walkthrough on how this project was set up. -------------------------------------------------------------------------------- /examples/linking-contracts/contracts/TokenExchange.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | 5 | // TODO: Update these import paths to @openzeppelin/contracts-ethereum-package once it is released 6 | import "openzeppelin-eth/contracts/token/ERC20/IERC20.sol"; 7 | import "openzeppelin-eth/contracts/math/SafeMath.sol"; 8 | 9 | contract TokenExchange is Initializable { 10 | using SafeMath for uint256; 11 | 12 | uint256 public rate; 13 | IERC20 public token; 14 | 15 | function initialize(uint256 _rate, IERC20 _token) public initializer { 16 | rate = _rate; 17 | token = _token; 18 | } 19 | 20 | function() external payable { 21 | uint256 tokens = msg.value.mul(rate); 22 | token.transfer(msg.sender, tokens); 23 | } 24 | 25 | // Added on subsequent version! 26 | address public owner; 27 | 28 | function withdraw() public { 29 | require(msg.sender == owner); 30 | msg.sender.transfer(address(this).balance); 31 | } 32 | 33 | function setOwner(address _owner) public { 34 | require(owner == address(0)); 35 | owner = _owner; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /examples/linking-contracts/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /examples/linking-contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-linking-contracts", 3 | "version": "2.8.0-rc.0", 4 | "private": true, 5 | "description": "", 6 | "main": "index.js", 7 | "keywords": [], 8 | "author": "Santiago Palladino ", 9 | "license": "MIT", 10 | "dependencies": { 11 | "@openzeppelin/upgrades": "2.8.0-rc.0", 12 | "openzeppelin-eth": "^2.2.0" 13 | }, 14 | "devDependencies": { 15 | "@openzeppelin/cli": "2.8.0-rc.0", 16 | "ganache-cli": "^6.4.3" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/truffle-migrate/.gitignore: -------------------------------------------------------------------------------- 1 | zos.dev-*.json 2 | build/ 3 | -------------------------------------------------------------------------------- /examples/truffle-migrate/.openzeppelin/.session: -------------------------------------------------------------------------------- 1 | { 2 | "network": "local", 3 | "expires": "2019-07-15T21:26:29.500Z" 4 | } -------------------------------------------------------------------------------- /examples/truffle-migrate/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "name": "example-truffle-migrate", 4 | "version": "0.1.0", 5 | "contracts": ["MyContract_v1"], 6 | "dependencies": {} 7 | } 8 | -------------------------------------------------------------------------------- /examples/truffle-migrate/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.4.22 <0.6.0; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint256 public last_completed_migration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) _; 9 | } 10 | 11 | constructor() public { 12 | owner = msg.sender; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } -------------------------------------------------------------------------------- /examples/truffle-migrate/contracts/MyContract_v0.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | 5 | contract MyContract_v0 is Initializable { 6 | uint256 public value; 7 | 8 | function initialize(uint256 _value) initializer public { 9 | value = _value; 10 | } 11 | 12 | function version() public pure returns (string memory) { 13 | return "v0"; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/truffle-migrate/contracts/MyContract_v1.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | 5 | contract MyContract_v1 is Initializable { 6 | uint256 public value; 7 | 8 | function initialize(uint256 _value) initializer public { 9 | value = _value; 10 | } 11 | 12 | function version() public pure returns (string memory) { 13 | return "v1"; 14 | } 15 | 16 | function add(uint256 _value) public { 17 | value = value + _value; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /examples/truffle-migrate/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const MyContract = artifacts.require('MyContract_v0'); 4 | 5 | async function main() { 6 | // We can use the `deployed()` truffle helper to retrieve the upgradeable instance 7 | const deployed = await MyContract.deployed(); 8 | const value = await deployed.value(); 9 | const version = await deployed.version(); 10 | console.log(`Value of MyContract (${version}) deployed instance: ${value.toString()}`); 11 | if (value.toString() !== "52") { 12 | throw Error("Returned value is incorrect"); 13 | } 14 | } 15 | 16 | // Handle truffle exec 17 | module.exports = function(callback) { 18 | main().then(() => callback()).catch(err => callback(err)) 19 | }; 20 | -------------------------------------------------------------------------------- /examples/truffle-migrate/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require("./Migrations.sol"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /examples/truffle-migrate/migrations/2_deploy_v0.js: -------------------------------------------------------------------------------- 1 | // Load zos scripts and truffle wrapper function 2 | const { scripts, ConfigManager } = require('@openzeppelin/cli'); 3 | const { add, push, create } = scripts; 4 | 5 | async function deploy(options) { 6 | // Register v0 of MyContract in the zos project 7 | add({ contractsData: [{ name: 'MyContract_v0', alias: 'MyContract' }] }); 8 | 9 | // Push implementation contracts to the network 10 | await push(options); 11 | 12 | // Create an instance of MyContract, setting initial value to 42 13 | await create(Object.assign({ contractAlias: 'MyContract', methodName: 'initialize', methodArgs: [42] }, options)); 14 | } 15 | 16 | module.exports = function(deployer, networkName, accounts) { 17 | deployer.then(async () => { 18 | const { network, txParams } = await ConfigManager.initNetworkConfiguration({ network: networkName, from: accounts[1] }) 19 | await deploy({ network, txParams }) 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /examples/truffle-migrate/migrations/3_deploy_v1.js: -------------------------------------------------------------------------------- 1 | // Load zos scripts and truffle wrapper function 2 | const { ConfigManager, scripts } = require('@openzeppelin/cli'); 3 | const { add, push, update } = scripts; 4 | 5 | async function deploy(options) { 6 | // Register v1 of MyContract in the zos project as MyContract 7 | add({ contractsData: [{ name: 'MyContract_v1', alias: 'MyContract' }] }); 8 | 9 | // Push implementation contracts to the network 10 | await push(options); 11 | 12 | // Update instance, adding +10 to value as part of the migration 13 | await update(Object.assign({ contractAlias: 'MyContract', methodName: 'add', methodArgs: [10] }, options)); 14 | } 15 | 16 | module.exports = function(deployer, networkName, accounts) { 17 | deployer.then(async () => { 18 | const { network, txParams } = await ConfigManager.initNetworkConfiguration({ network: networkName, from: accounts[1] }) 19 | await deploy({ network, txParams }) 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /examples/truffle-migrate/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-truffle-migrate", 3 | "version": "2.8.0-rc.0", 4 | "description": "OpenZeppelin SDK example: using truffle migrations", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "check": "truffle exec index.js --network local", 9 | "test": "truffle test" 10 | }, 11 | "author": "santiago@openzeppelin.com", 12 | "license": "MIT", 13 | "dependencies": { 14 | "@openzeppelin/upgrades": "2.8.0-rc.0" 15 | }, 16 | "devDependencies": { 17 | "@openzeppelin/cli": "2.8.0-rc.0", 18 | "truffle": "^5.0.5" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/truffle-migrate/truffle-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | local: { 4 | host: 'localhost', 5 | port: 9545, 6 | network_id: '*', 7 | gasPrice: 10e9 8 | } 9 | }, 10 | compilers: { 11 | solc: { 12 | version: '0.5.4', 13 | settings: { 14 | optimizer: { 15 | enabled: true, 16 | runs: 200 17 | } 18 | } 19 | } 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /examples/upgrades-library/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | build/* 3 | -------------------------------------------------------------------------------- /examples/upgrades-library/contracts/MyContractV0.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | 5 | contract MyContractV0 is Initializable { 6 | uint256 public value; 7 | 8 | function initialize(uint256 _value) initializer public { 9 | value = _value; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /examples/upgrades-library/contracts/MyContractV1.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./MyContractV0.sol"; 4 | 5 | contract MyContractV1 is MyContractV0 { 6 | function add(uint256 _value) public { 7 | value = value + _value; 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /examples/upgrades-library/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-openzeppelin-upgrades-simple", 3 | "version": "2.8.0-rc.0", 4 | "private": true, 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "test": "oz compile && NODE_ENV=test mocha" 9 | }, 10 | "license": "ISC", 11 | "dependencies": { 12 | "@openzeppelin/upgrades": "2.8.0-rc.0" 13 | }, 14 | "devDependencies": { 15 | "@openzeppelin/cli": "2.8.0-rc.0", 16 | "@openzeppelin/test-environment": "^0.1.3", 17 | "chai": "^4.1.2", 18 | "mocha": "^6.2.2" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/upgrades-library/test/main.test.js: -------------------------------------------------------------------------------- 1 | const Web3 = require('web3'); 2 | 3 | const { provider } = require('@openzeppelin/test-environment'); 4 | const main = require('../index.js').main; 5 | const assert = require('chai').assert; 6 | 7 | describe('main', function() { 8 | it('upgrades the contract successfully', async function () { 9 | const web3 = new Web3(provider); 10 | const instance = await main(web3); 11 | assert.isString(instance.address); 12 | const value = await instance.methods.value().call(); 13 | assert.equal(value, 52); 14 | }) 15 | }); 16 | -------------------------------------------------------------------------------- /legacy/README.md: -------------------------------------------------------------------------------- 1 | # Legacy package definitions 2 | 3 | This folder contains legacy `package.json` files with old namings, to trick Github into tracking dependents for them as well in the Insights section of the repository. 4 | 5 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "npmClient": "yarn", 3 | "useWorkspaces": true, 4 | "version": "2.8.0-rc.0", 5 | "command": { 6 | "publish": { 7 | "ignoreChanges": [ 8 | "examples/**" 9 | ] 10 | }, 11 | "version": { 12 | "exact": true, 13 | "force-publish": true 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run docs" 3 | publish = "build/site" 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "engines": { 5 | "yarn": "^1.9.0" 6 | }, 7 | "workspaces": [ 8 | "examples/*", 9 | "packages/*", 10 | "tests/cli/test", 11 | "tests/cli/workdir", 12 | "tests/kits/test", 13 | "tests/kits/workdir", 14 | "tests/mocks/*", 15 | "tests/deploy" 16 | ], 17 | "nohoist": [ 18 | "**/mock-stdlib" 19 | ], 20 | "scripts": { 21 | "docs": "oz-docs -c packages/cli/docs -c packages/lib/docs", 22 | "docs:watch": "npm run docs watch packages/lib/contracts packages/cli/src/{commands,bin}", 23 | "lint:check": "lerna run lint:check", 24 | "prepare": "yarn --cwd bootstrap && lerna run prepare" 25 | }, 26 | "devDependencies": { 27 | "lerna": "^3.13.4", 28 | "mock-stdlib-root": "file:./packages/cli/mocks/mock-stdlib", 29 | "@openzeppelin/docs-utils": "^0.1.0", 30 | "yarn": "^1.17.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/.github/README.md: -------------------------------------------------------------------------------- 1 | ../../README.md -------------------------------------------------------------------------------- /packages/cli/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | /solc -------------------------------------------------------------------------------- /packages/cli/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['../../.eslintrc.base.js'], 3 | rules: { 4 | '@typescript-eslint/explicit-function-return-type': 'off', 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /packages/cli/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .zos.session 3 | zos.* 4 | build 5 | /test-build 6 | /lib 7 | .node-xmlhttprequest-sync-* 8 | 9 | .openzeppelin/.session 10 | -------------------------------------------------------------------------------- /packages/cli/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require("../../.prettierrc.base.js"), 3 | }; 4 | -------------------------------------------------------------------------------- /packages/cli/AUTHORS: -------------------------------------------------------------------------------- 1 | ajsantander 2 | elopio 3 | facuspagnuolo 4 | fiiiu 5 | frangio 6 | maraoz 7 | martriay 8 | nventuro 9 | spalladino 10 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/Boolean.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Boolean { 4 | bool public value; 5 | 6 | function initialize(bool _value) public { 7 | value = _value; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/ERC20Fake.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract ERC20Fake { 4 | mapping (address => uint256) private _balances; 5 | 6 | function giveAway(address account, uint256 amount) public { 7 | _balances[account] = amount; 8 | } 9 | 10 | function balanceOf(address owner) public view returns (uint256) { 11 | return _balances[owner]; 12 | } 13 | } 14 | 15 | contract ERC20FakeDetailed is ERC20Fake { 16 | string private _name; 17 | string private _symbol; 18 | uint8 private _decimals; 19 | 20 | constructor (string memory name, string memory symbol, uint8 decimals) public { 21 | _name = name; 22 | _symbol = symbol; 23 | _decimals = decimals; 24 | } 25 | 26 | function name() public view returns (string memory) { 27 | return _name; 28 | } 29 | 30 | function symbol() public view returns (string memory) { 31 | return _symbol; 32 | } 33 | 34 | function decimals() public view returns (uint8) { 35 | return _decimals; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/Impl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Impl { 4 | function say() public pure returns (string memory); 5 | } 6 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/ImplV1b.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "mock-stdlib-libdeps/contracts/GreeterLibWithLibImpl.sol"; 4 | 5 | contract ImplV1b is GreeterLibWithLibImpl { 6 | function say() public view returns(uint256) { 7 | return state.getNumber(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/Imports.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/upgrades/contracts/mocks/StorageMocksForComparison.sol"; 4 | import "@openzeppelin/upgrades/contracts/mocks/Invalid.sol"; 5 | import "@openzeppelin/upgrades/contracts/mocks/WithInitialize.sol"; 6 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/Libraries.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library UintLib { 4 | function double(uint256 self) public pure returns (uint256) { 5 | return self * 2; 6 | } 7 | } 8 | 9 | library Uint32Lib { 10 | function triple(uint32 self) public pure returns (uint32) { 11 | return self * 3; 12 | } 13 | } 14 | 15 | library NumberLib { 16 | struct Number { 17 | uint256 x; 18 | } 19 | 20 | function double(Number storage self) public { 21 | self.x = self.x * 2; 22 | } 23 | } -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/SimpleNonUpgradeable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract SimpleNonUpgradeable { 4 | uint public answer = 42; 5 | } 6 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/WithConstructorNonUpgradeable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract WithConstructorNonUpgradeable { 4 | uint public answer; 5 | 6 | constructor(uint x, string memory y, uint[] memory zs) public { 7 | answer = x + bytes(y).length + zs[1]; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/contracts/mocks/WithLibraryNonUpgradeable.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import './Libraries.sol'; 4 | 5 | contract WithLibraryNonUpgradeable { 6 | uint public answer = UintLib.double(21); 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: cli 2 | title: CLI 3 | version: '2.8' 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | -------------------------------------------------------------------------------- /packages/cli/docs/modules/ROOT/assets/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/docs/modules/ROOT/assets/images/architecture.png -------------------------------------------------------------------------------- /packages/cli/docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[Overview] 2 | * xref:getting-started.adoc[Getting Started] 3 | * xref:dependencies.adoc[Using Dependencies] 4 | * xref:compiling.adoc[Compiling] 5 | * xref:deploying-with-create2.adoc[Deploying With `CREATE2`] 6 | * xref:truffle.adoc[Using With Truffle] 7 | * xref:migrate-cli-versions.adoc[Migrating CLI version] 8 | * xref:faq.adoc[Frequently Asked Questions] 9 | * xref:upgrades::index.adoc[Upgrades Library] 10 | 11 | .API Reference 12 | * xref:commands.adoc[Commands] 13 | * xref:configuration.adoc[Configuration Files] 14 | * xref:contracts-architecture.adoc[Contracts Architecture] 15 | -------------------------------------------------------------------------------- /packages/cli/docs/modules/ROOT/pages/.gitignore: -------------------------------------------------------------------------------- 1 | commands.adoc 2 | -------------------------------------------------------------------------------- /packages/cli/mocks/config-files/networks.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | require('ts-node/register'); 3 | 4 | module.exports = { 5 | networks: { 6 | local: { 7 | host: 'localhost', 8 | port: 8545, 9 | network_id: '*', 10 | gas: 5000000, 11 | }, 12 | testing: { 13 | host: 'localhost', 14 | network_id: '4447', 15 | port: 9555, 16 | }, 17 | invalid: { 18 | host: 'localhost', 19 | network_id: '-39', 20 | port: 9555, 21 | }, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/cli/mocks/config-files/truffle.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/camelcase */ 2 | require('ts-node/register'); 3 | 4 | module.exports = { 5 | networks: { 6 | local: { 7 | host: 'localhost', 8 | port: 8545, 9 | network_id: '*', 10 | gas: 5000000, 11 | }, 12 | testing: { 13 | host: 'localhost', 14 | network_id: '4447', 15 | port: 9555, 16 | }, 17 | }, 18 | compilers: { 19 | solc: { 20 | version: '0.5.3', 21 | evmVersion: 'constantinople', 22 | }, 23 | }, 24 | mocha: { 25 | forbidOnly: !!process.env.CI, 26 | }, 27 | }; 28 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": ["GreeterImpl"], 4 | "dependencies": {}, 5 | "name": "mock-project-with-root-imports", 6 | "version": "1.0.0", 7 | "compiler": { 8 | "compilerSettings": { 9 | "optimizer": { 10 | "enabled": false, 11 | "runs": "200" 12 | } 13 | }, 14 | "typechain": { 15 | "enabled": false 16 | }, 17 | "manager": "openzeppelin", 18 | "solcVersion": "0.5.16", 19 | "artifactsDir": "build/contracts", 20 | "contractsDir": "contracts" 21 | }, 22 | "telemetryOptIn": false 23 | } 24 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/README.md: -------------------------------------------------------------------------------- 1 | # mock-dependency-to-compile 2 | 3 | This project is used to test that the following import styles are supported by the compiler **on a dependency**: 4 | 5 | ```solidity 6 | // contracts/subfolder/GreeterImpl.sol 7 | import "contracts/subfolder/GreeterLib.sol"; 8 | import "./GreeterLib2.sol"; 9 | ``` 10 | 11 | This project is here and not in `test/mocks` because otherwise truffle tried to compile it and failed, as it assumed that `import "contracts/subfolder/GreeterLib.sol"` was relative to the main project root, and not to the `mock-project-with-root-imports`. -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/contracts/subfolder/Dependency.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Test import with path relative to current file 4 | import "./DependencyLib.sol"; 5 | 6 | contract Dependency { 7 | using DependencyLib for string; 8 | 9 | event Greeting(string greeting); 10 | 11 | function greet(string memory who) public { 12 | emit Greeting(who.wrap()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/contracts/subfolder/DependencyLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library DependencyLib { 4 | function wrap(string memory self) public pure returns (string memory) { 5 | return self; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-dependency-to-compile/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-dependency-to-compile", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC" 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": ["GreeterImpl"], 4 | "dependencies": {}, 5 | "name": "mock-project-with-root-imports", 6 | "version": "1.0.0", 7 | "compiler": { 8 | "compilerSettings": { 9 | "optimizer": { 10 | "enabled": false, 11 | "runs": "200" 12 | } 13 | }, 14 | "typechain": { 15 | "enabled": false 16 | }, 17 | "manager": "openzeppelin", 18 | "solcVersion": "0.5.16", 19 | "artifactsDir": "build/contracts", 20 | "contractsDir": "contracts" 21 | }, 22 | "telemetryOptIn": false 23 | } 24 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/README.md: -------------------------------------------------------------------------------- 1 | # mock-project-to-compile 2 | 3 | This project is used to test that the following import styles are supported by the compiler: 4 | 5 | ```solidity 6 | // contracts/subfolder/GreeterImpl.sol 7 | import "contracts/subfolder/GreeterLib.sol"; 8 | import "./GreeterLib2.sol"; 9 | ``` 10 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/contracts/subfolder/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | // Test import with path relative to project root 4 | import "contracts/subfolder/GreeterLib.sol"; 5 | 6 | // Test import with path relative to current file 7 | import "./GreeterLib2.sol"; 8 | 9 | // Test import from a dependency 10 | import "mock-dependency-to-compile/contracts/subfolder/Dependency.sol"; 11 | 12 | contract Greeter { 13 | using GreeterLib for string; 14 | using GreeterLib2 for string; 15 | 16 | event Greeting(string greeting); 17 | 18 | function greet(string memory who) public { 19 | emit Greeting(who.wrap()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/contracts/subfolder/GreeterLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library GreeterLib { 4 | function wrap(string memory self) public pure returns (string memory) { 5 | return self; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/contracts/subfolder/GreeterLib2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library GreeterLib2 { 4 | function wrap2(string memory self) public pure returns (string memory) { 5 | return self; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/node_modules/mock-dependency-to-compile: -------------------------------------------------------------------------------- 1 | ../../mock-dependency-to-compile -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-to-compile/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-project-to-compile", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mock-dependency-to-compile": "../mock-dependency-to-compile/" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": ["GreeterImpl"], 4 | "dependencies": {}, 5 | "name": "mock-project-with-root-imports", 6 | "version": "1.0.0", 7 | "compiler": { 8 | "compilerSettings": { 9 | "optimizer": { 10 | "enabled": false, 11 | "runs": "200" 12 | } 13 | }, 14 | "typechain": { 15 | "enabled": false 16 | }, 17 | "manager": "openzeppelin", 18 | "solcVersion": "0.5.16", 19 | "artifactsDir": "build/contracts", 20 | "contractsDir": "contracts" 21 | }, 22 | "telemetryOptIn": false 23 | } 24 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/README.md: -------------------------------------------------------------------------------- 1 | # mock-project-with-repeated-names 2 | 3 | This project is used to test a project with more than one contract with the same name. -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/contracts/subfolder/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | contract Greeter { } 3 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/contracts/subfolder/Greeter2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | contract Greeter { } 3 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-project-with-repeated-names/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-project-with-repeated-names", 3 | "version": "1.0.0", 4 | "description": "", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1" 7 | }, 8 | "keywords": [], 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mock-dependency-to-compile": "../mock-dependency-to-compile/" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib with spaces/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./GreeterLib.sol"; 4 | 5 | contract GreeterImpl { 6 | using GreeterLib for string; 7 | event Greeting(string greeting); 8 | 9 | function greet(string memory who) public { 10 | emit Greeting(greeting(who)); 11 | } 12 | 13 | function greeting(string memory who) public pure returns (string memory) { 14 | return who.wrap(); 15 | } 16 | 17 | function version() public pure returns (string memory) { 18 | return "1.1.0"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib with spaces/contracts/GreeterLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library GreeterLib { 4 | function wrap(string memory self) public pure returns (string memory) { 5 | return self; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib with spaces/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-with-spaces", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GreeterImpl { 4 | event Greeting(string greeting); 5 | 6 | function greet(string memory who) public { 7 | emit Greeting(greeting(who)); 8 | } 9 | 10 | function greeting(string memory who) public pure returns (string memory) { 11 | return who; 12 | } 13 | 14 | function version() public pure returns (string memory) { 15 | return "1.2.0"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-2/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-2", 3 | "version": "1.2.0", 4 | "description": "Mock stdlib 2 for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-2", 3 | "manifestVersion": "2.2", 4 | "version": "1.2.0", 5 | "contracts": ["GreeterImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-2/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.2.0", 3 | "manifestVersion": "2.2", 4 | "provider": { 5 | "address": "0x0000000000000000000000000000000000000210" 6 | }, 7 | "package": { 8 | "address": "0x0000000000000000000000000000000000000280" 9 | }, 10 | "contracts": { 11 | "Greeter": { 12 | "address": "0x102030", 13 | "bytecodeHash": "0x0002" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-empty/contracts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-empty/contracts/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-empty/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-empty", 3 | "version": "1.1.0", 4 | "description": "Mock empty stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "author": "santiago@zeppelin.solutions", 8 | "license": "MIT" 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-invalid/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-invalid", 3 | "version": "1.1.0", 4 | "description": "Invalid mock stdlib for tests in zos-cli", 5 | "private": true, 6 | "author": "facundo@zeppelin.solutions", 7 | "license": "MIT" 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-invalid/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-invalid", 3 | "version": "2.0.0", 4 | "manifestVersion": "2.2", 5 | "contracts": [] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-invalid/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "3.0.0", 3 | "manifestVersion": "2.2", 4 | "provider": {}, 5 | "contracts": {} 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/contracts/GreeterLibLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library GreeterLibLib { 4 | struct StateState { 5 | uint256 aNumber; 6 | } 7 | 8 | function getANumber(StateState storage self) public view returns (uint256) { 9 | return self.aNumber; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/contracts/GreeterLibWithLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./GreeterLibLib.sol"; 4 | 5 | library GreeterLibWithLib { 6 | using GreeterLibLib for GreeterLibLib.StateState; 7 | 8 | struct State { 9 | GreeterLibLib.StateState state; 10 | } 11 | 12 | function getNumber(State storage self) public view returns (uint256) { 13 | return self.state.getANumber(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/contracts/GreeterLibWithLibImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./GreeterLibWithLib.sol"; 4 | 5 | contract GreeterLibWithLibImpl { 6 | using GreeterLibWithLib for GreeterLibWithLib.State; 7 | 8 | GreeterLibWithLib.State state; 9 | 10 | function greeting() public view returns (uint256) { 11 | return state.getNumber(); 12 | } 13 | 14 | function version() public pure returns (string memory) { 15 | return "1.1.0"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-libdeps/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-libdeps", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-libdeps", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": ["GreeterLibWithLibImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-libdeps/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "provider": { 5 | "address": "0x0000000000000000000000000000000000000010" 6 | }, 7 | "package": { 8 | "address": "0x0000000000000000000000000000000000000080" 9 | }, 10 | "contracts": { 11 | "GreeterLibWithLibImpl": { 12 | "address": "0x1020", 13 | "bytecodeHash": "0x0001" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed-2/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GreeterImpl { 4 | event Greeting(string greeting); 5 | 6 | function greet(string memory who) public { 7 | emit Greeting(greeting(who)); 8 | } 9 | 10 | function greeting(string memory who) public pure returns (string memory) { 11 | return who; 12 | } 13 | 14 | function version() public pure returns (string memory) { 15 | return "1.2.0"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed-2/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-undeployed-2/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed-2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-undeployed-2", 3 | "version": "1.2.0", 4 | "description": "Mock stdlib for tests in zos-cli that is not deployed to any network", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed-2/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed-2/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-undeployed-2", 3 | "manifestVersion": "2.2", 4 | "version": "1.2.0", 5 | "contracts": ["GreeterImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/contracts/GreeterBase.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GreeterBase { 4 | event Greeting(string greeting); 5 | 6 | uint256 public value; 7 | 8 | function initialize(uint256 _value) public { 9 | value = _value; 10 | } 11 | 12 | function clashingInitialize(uint256 _value) public { 13 | value = _value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./GreeterBase.sol"; 4 | 5 | // This contract and its parent are used in CLI scripts/create.test.js to check initialization 6 | // of a contract loaded from a dependency. Do not import this file or its parent from any mock 7 | // contract in CLI, since one of the goals of the test is to check processing a contract that 8 | // has not been locally compiled. Also, make sure to change the absolute path in the build artifacts 9 | // so they point to a path that does not exist in your machine, since that's the typical scenario 10 | // for contracts loaded from libs. 11 | 12 | contract GreeterImpl is GreeterBase { 13 | function clashingInitialize(string memory _value) public { 14 | value = bytes(_value).length; 15 | } 16 | 17 | function greet(string memory who) public { 18 | emit Greeting(greeting(who)); 19 | } 20 | 21 | function greeting(string memory who) public pure returns (string memory) { 22 | return who; 23 | } 24 | 25 | function version() public pure returns (string memory) { 26 | return "1.1.0"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-undeployed/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-undeployed", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli that is not deployed to any network", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-undeployed/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-undeployed", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": ["GreeterImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/contracts/GreeterBase.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GreeterBase { 4 | event Greeting(string greeting); 5 | 6 | uint256 public value; 7 | 8 | function initialize(uint256 _value) public { 9 | value = _value; 10 | } 11 | 12 | function clashingInitialize(uint256 _value) public { 13 | value = _value; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-unpublished/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-unpublished", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli that is not published to any network", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-unpublished", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": ["GreeterImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unpublished/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "contracts": { 5 | "Greeter": { 6 | "address": "0x1020", 7 | "bytecodeHash": "0x0001" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GreeterImpl { 4 | event Greeting(string greeting); 5 | 6 | function greet(string memory who) public { 7 | emit Greeting(greeting(who)); 8 | } 9 | 10 | function greeting(string memory who) public pure returns (string memory) { 11 | return who; 12 | } 13 | 14 | function version() public pure returns (string memory) { 15 | return "1.1.0"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib-unsupported/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-unsupported", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib-unsupported", 3 | "version": "1.1.0", 4 | "contracts": ["GreeterImpl"] 5 | } 6 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib-unsupported/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "provider": { 4 | "address": "0x0000000000000000000000000000000000000010" 5 | }, 6 | "package": { 7 | "address": "0x0000000000000000000000000000000000000080" 8 | }, 9 | "contracts": { 10 | "Greeter": { 11 | "address": "0x1020", 12 | "bytecodeHash": "0x0001" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/contracts/GreeterImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./GreeterLib.sol"; 4 | 5 | contract GreeterImpl { 6 | using GreeterLib for string; 7 | 8 | mapping(uint256 => string) public greetings; 9 | event Greeting(string greeting); 10 | 11 | function greet(string memory who) public { 12 | emit Greeting(greeting(who)); 13 | } 14 | 15 | function greeting(string memory who) public pure returns (string memory) { 16 | return who.wrap(); 17 | } 18 | 19 | function version() public pure returns (string memory) { 20 | return "1.1.0"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/contracts/GreeterLib.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library GreeterLib { 4 | function wrap(string memory self) public pure returns (string memory) { 5 | return self; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/cli/mocks/mock-stdlib/migrations/.gitkeep -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": ["GreeterImpl"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/mock-stdlib/zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "provider": { 5 | "address": "0x0000000000000000000000000000000000000010" 6 | }, 7 | "package": { 8 | "address": "0x0000000000000000000000000000000000000080" 9 | }, 10 | "contracts": { 11 | "GreeterImpl": { 12 | "address": "0x1020", 13 | "bytecodeHash": "0x0001" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-app-with-contract.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "provider": { 5 | "address": "0x0000000000000000000000000000000000000010" 6 | }, 7 | "package": { 8 | "address": "0x0000000000000000000000000000000000000080" 9 | }, 10 | "contracts": { 11 | "Greeter": { 12 | "address": "0x1020", 13 | "bytecodeHash": "0x0001" 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-deprecated-manifest-version.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "zosversion": "2.2" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-missing-manifest-version.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0" 3 | } 4 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-unsupported-manifest-version.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "3" 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-with-older-stdlibs.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "contracts": [], 5 | "dependencies": { 6 | "mock-stdlib": { 7 | "version": "^1.1.0", 8 | "package": "0x0000000000000000000000000000000000000210" 9 | }, 10 | "mock-stdlib-2": { 11 | "version": "^1.0.0", 12 | "package": "0x0000000000000000000000000000000000000210" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/networks/network-with-stdlibs.zos.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.0", 3 | "manifestVersion": "2.2", 4 | "contracts": [], 5 | "dependencies": { 6 | "mock-stdlib": { 7 | "version": "^1.1.0", 8 | "package": "0x0000000000000000000000000000000000000210" 9 | }, 10 | "mock-stdlib-2": { 11 | "version": "^1.2.0", 12 | "package": "0x0000000000000000000000000000000000000210" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-deprecated-manifest-version.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "version": "1.1.0", 4 | "contracts": [], 5 | "zosversion": "2.2", 6 | "publish": true 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-empty-lite.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "version": "1.1.0", 4 | "manifestVersion": "2.2", 5 | "contracts": [] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-empty.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": [], 6 | "publish": true 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-missing-manifest-version.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "version": "1.1.0", 4 | "contracts": [] 5 | } 6 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-unsupported-manifest-version.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "version": "1.1.0", 4 | "contracts": [], 5 | "manifestVersion": "3", 6 | "publish": true 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-contracts-and-multiple-stdlibs.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "contracts": ["ImplV1"], 7 | "dependencies": { 8 | "mock-stdlib-undeployed": "1.1.0", 9 | "mock-stdlib-undeployed-2": "1.2.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-contracts-and-stdlib-v2.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.0", 6 | "contracts": ["ImplV1"], 7 | "dependencies": { 8 | "mock-stdlib-2": "1.2.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-contracts-and-stdlib.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "version": "1.1.0", 5 | "contracts": ["ImplV1"], 6 | "dependencies": { 7 | "mock-stdlib-undeployed": "1.1.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-contracts-v2.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.2.0", 6 | "contracts": ["ImplV1", "WithLibraryImplV1"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-contracts.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "solidityLibs": {}, 7 | "contracts": ["ImplV1", "WithLibraryImplV1"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-invalid-contracts.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "contracts": [ 7 | "ImplV1", 8 | "WithFailingConstructor", 9 | "WithSelfDestruct", 10 | "WithParentWithSelfDestruct", 11 | "WithDelegateCall", 12 | "WithParentWithDelegateCall" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-invalid-stdlib.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "dependencies": { 7 | "mock-stdlib-invalid": "1.0.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-manifest-version-2.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2", 4 | "version": "1.1.0", 5 | "contracts": ["ImplV1", "ImplV2"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-multiple-stdlibs.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "contracts": [], 7 | "dependencies": { 8 | "mock-stdlib": "1.1.0", 9 | "mock-stdlib-2": "1.2.0", 10 | "mock-stdlib-undeployed": "1.1.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-stdlib-range.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "contracts": [], 7 | "dependencies": { 8 | "mock-stdlib": "^1.0.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-stdlib.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "contracts": [], 7 | "dependencies": { 8 | "mock-stdlib": "1.1.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-undeployed-stdlib.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "dependencies": { 7 | "mock-stdlib-undeployed": "1.1.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/mocks/packages/package-with-unpublished-stdlib.zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Herbs", 3 | "manifestVersion": "2.2", 4 | "publish": true, 5 | "version": "1.1.0", 6 | "dependencies": { 7 | "mock-stdlib-unpublished": "1.1.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/scripts/copy-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # blueprint.networks.js 4 | cp src/models/config/blueprint.networks.js lib/models/config/blueprint.networks.js 5 | -------------------------------------------------------------------------------- /packages/cli/src/bin/errors.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | import { Loggy } from '@openzeppelin/upgrades'; 3 | 4 | const GENERIC_ERROR_MESSAGE = 5 | 'There was an undefined error. Please execute the same command again in verbose mode if necessary.'; 6 | 7 | function handle(error: Error, verbose = false): void { 8 | if (!verbose) { 9 | Loggy.stopAll(); 10 | const errorMessage = error.message || GENERIC_ERROR_MESSAGE; 11 | Loggy.noSpin.error(__filename, 'call', 'error-message', errorMessage); 12 | } else { 13 | Loggy.noSpin.error(__filename, 'call', 'error-message', error.stack); 14 | } 15 | 16 | process.exit(1); 17 | } 18 | 19 | export default function registerErrorHandler(program: Command): void { 20 | const handler = (error: Error) => handle(error, program.verbose); 21 | 22 | process.on('unhandledRejection', handler); 23 | process.on('uncaughtException', handler); 24 | 25 | program.on('command:*', function(): void { 26 | console.error(`Invalid command: ${program.args.join(' ')}\nSee --help for a list of available commands.`); 27 | process.exit(1); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /packages/cli/src/bin/helpers.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import findUp from 'find-up'; 3 | 4 | import { OPEN_ZEPPELIN_FOLDER } from '../models/files/constants'; 5 | 6 | export default function findRootDirectory(cwd: string): string | null { 7 | const filePath = findUp.sync(['package.json', OPEN_ZEPPELIN_FOLDER], { cwd }); 8 | if (!filePath) return null; 9 | return path.dirname(filePath); 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/src/commands/bump.ts: -------------------------------------------------------------------------------- 1 | import push from './push'; 2 | import bump from '../scripts/bump'; 3 | import Telemetry from '../telemetry'; 4 | import ProjectFile from '../models/files/ProjectFile'; 5 | 6 | const name = 'bump'; 7 | const signature = `${name} `; 8 | const description = 'bump your project to a new '; 9 | 10 | const register: (program: any) => any = program => 11 | program 12 | .command(signature, undefined, { noHelp: true }) 13 | .usage(' [options]') 14 | .description(description) 15 | .withPushOptions() 16 | .action(action); 17 | 18 | async function action(version: string, options: any): Promise { 19 | await Telemetry.report('bump', { version }, options.interactive); 20 | await bump({ version }); 21 | await push.runActionIfRequested({ ...options }); 22 | } 23 | 24 | export default { name, signature, description, register, action }; 25 | -------------------------------------------------------------------------------- /packages/cli/src/commands/check.ts: -------------------------------------------------------------------------------- 1 | import check from '../scripts/check'; 2 | import { compile } from '../models/compiler/Compiler'; 3 | import ConfigManager from '../models/config/ConfigManager'; 4 | import Telemetry from '../telemetry'; 5 | 6 | const name = 'check'; 7 | const signature = `${name} [contract]`; 8 | const description = 'checks your contracts for potential issues'; 9 | 10 | const register: (program: any) => any = program => 11 | program 12 | .command(signature, undefined, { noHelp: true }) 13 | .usage('[contract] [options]') 14 | .description(description) 15 | .option('--skip-compile', 'skips contract compilation') 16 | .action(action); 17 | 18 | async function action(contractName: string, options: any): Promise { 19 | ConfigManager.initStaticConfiguration(); 20 | if (!options.skipCompile) await compile(); 21 | await Telemetry.report('check', { contractName }, options.interactive); 22 | check({ contractName }); 23 | } 24 | 25 | export default { name, signature, description, register, action }; 26 | -------------------------------------------------------------------------------- /packages/cli/src/commands/deploy/index.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | 3 | import { generateSignature, register as _register } from '../../register-command'; 4 | 5 | import * as spec from './spec'; 6 | 7 | export { name, description } from './spec'; 8 | 9 | export const signature = generateSignature(spec.name, spec.args); 10 | 11 | export function register(program: Command) { 12 | _register(program, spec, () => import('./action')); 13 | } 14 | -------------------------------------------------------------------------------- /packages/cli/src/commands/freeze.ts: -------------------------------------------------------------------------------- 1 | import freeze from '../scripts/freeze'; 2 | import ConfigManager from '../models/config/ConfigManager'; 3 | import Telemetry from '../telemetry'; 4 | 5 | const name = 'freeze'; 6 | const signature: string = name; 7 | const description = 'freeze current release version of your published project'; 8 | 9 | const register: (program: any) => any = program => 10 | program 11 | .command(signature, undefined, { noHelp: true }) 12 | .usage('--network [options]') 13 | .description(description) 14 | .withNetworkOptions() 15 | .action(action); 16 | 17 | async function action(options: any): Promise { 18 | const { network, txParams } = await ConfigManager.initNetworkConfiguration(options); 19 | await Telemetry.report('freeze', { network, txParams }, options.interactive); 20 | await freeze({ network, txParams }); 21 | if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0); 22 | } 23 | 24 | export default { name, signature, description, register, action }; 25 | -------------------------------------------------------------------------------- /packages/cli/src/commands/status.ts: -------------------------------------------------------------------------------- 1 | const name = 'status'; 2 | const signature: string = name; 3 | const description = 'print information about the local status of your app in a specific network'; 4 | 5 | const register: (program: any) => any = program => 6 | program 7 | .command(signature, undefined, { noHelp: true }) 8 | .description(description) 9 | .usage('--network ') 10 | .option('--fetch', 'retrieve app information directly from the network instead of from the local network file') 11 | .option('--fix', 'update local network file with information retrieved from the network') 12 | .withNetworkOptions() 13 | .action(action); 14 | 15 | async function action(options: any): Promise { 16 | throw Error('Status command has been removed.'); 17 | if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0); 18 | } 19 | 20 | export default { name, signature, description, register, action }; 21 | -------------------------------------------------------------------------------- /packages/cli/src/commands/unpack.ts: -------------------------------------------------------------------------------- 1 | import unpack from '../scripts/unpack'; 2 | import Telemetry from '../telemetry'; 3 | 4 | const name = 'unpack'; 5 | const signature = `${name} [kit]`; 6 | const description = `download and install an OpenZeppelin Starter Kit to the current directory`; 7 | 8 | const register: (program: any) => any = program => 9 | program 10 | .command(signature, undefined, { noHelp: true }) 11 | .usage('[kit]') 12 | .description(description) 13 | .withNonInteractiveOption() 14 | .action(action); 15 | 16 | async function action(kit: string, options: any): Promise { 17 | await Telemetry.report('unpack', { repoOrName: kit }, options.interactive); 18 | await unpack({ repoOrName: kit }); 19 | } 20 | 21 | export default { name, signature, description, register, action }; 22 | -------------------------------------------------------------------------------- /packages/cli/src/commands/utils.ts: -------------------------------------------------------------------------------- 1 | import { Option } from '../register-command'; 2 | 3 | interface Options { 4 | [key: string]: Option; 5 | } 6 | 7 | export const commonOptions: Options = { 8 | noInteractive: { 9 | format: '--no-interactive', 10 | description: 'disable interactive prompts', 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/cli/src/commands/verify/action.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../../models/network/NetworkController'; 2 | import { Options, Args } from './spec'; 3 | 4 | export async function action(params: Options & Args & { dontExitProcess: boolean }): Promise { 5 | const controller = new NetworkController(params.network, params.txParams, params.networkFile); 6 | 7 | try { 8 | controller.logErrorIfContractDeploymentIsInvalid(params.contract, true); 9 | } catch (e) { 10 | if (!e.message.includes('has changed locally')) { 11 | e.message += '\n\nVerification of regular instances is not yet supported.'; 12 | } 13 | throw e; 14 | } 15 | 16 | await controller.verifyAndPublishContract( 17 | params.contract, 18 | params.optimizer, 19 | (params as any).optimizerRuns ?? 200, 20 | params.remote, 21 | (params as any).apiKey ?? '', 22 | ); 23 | 24 | if (!params.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0); 25 | } 26 | -------------------------------------------------------------------------------- /packages/cli/src/commands/verify/index.ts: -------------------------------------------------------------------------------- 1 | import { Command } from 'commander'; 2 | 3 | import { generateSignature, register as _register } from '../../register-command'; 4 | 5 | import * as spec from './spec'; 6 | 7 | export { name, description } from './spec'; 8 | 9 | export const signature = generateSignature(spec.name, spec.args); 10 | 11 | export function register(program: Command) { 12 | _register(program, spec, () => import('./action')); 13 | } 14 | -------------------------------------------------------------------------------- /packages/cli/src/index.ts: -------------------------------------------------------------------------------- 1 | // module information 2 | const version = 'v' + require('../package.json').version; 3 | 4 | // commands 5 | import commands from './commands'; 6 | import scripts from './scripts'; 7 | 8 | // model objects 9 | import files from './models/files'; 10 | import local from './models/local'; 11 | import network from './models/network'; 12 | import TestHelper from './models/TestHelper'; 13 | import ConfigManager from './models/config/ConfigManager'; 14 | 15 | // utils 16 | import * as naming from './utils/naming'; 17 | import log, { silent } from './utils/stdout'; 18 | const stdout = { log, silent }; 19 | 20 | export { version, files, local, network, commands, scripts, naming, stdout, ConfigManager, TestHelper }; 21 | -------------------------------------------------------------------------------- /packages/cli/src/models/TestHelper.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../models/network/NetworkController'; 2 | import NetworkFile from '../models/files/NetworkFile'; 3 | import { ProxyAdminProject, AppProject, TxParams } from '@openzeppelin/upgrades'; 4 | 5 | /** 6 | * Initializes a zOS application testing and deploying it to the test network, 7 | * along with dependencies (if specified) 8 | * @param txParams optional txParams (from, gas, gasPrice) to use on every transaction 9 | * @param networkFile optional `NetworkFile` object to use, instead of zos.test.json 10 | */ 11 | export default async function( 12 | txParams: TxParams = {}, 13 | networkFile?: NetworkFile, 14 | ): Promise { 15 | const controller = new NetworkController('test', txParams, networkFile); 16 | await controller.deployDependencies(); 17 | await controller.push(networkFile.projectFile.contracts, { reupload: false, force: true }); 18 | 19 | return controller.project; 20 | } 21 | -------------------------------------------------------------------------------- /packages/cli/src/models/compiler/ProjectCompilerOptions.ts: -------------------------------------------------------------------------------- 1 | import { CompilerOptions } from './solidity/SolidityContractsCompiler'; 2 | 3 | export interface TypechainOptions { 4 | enabled: boolean; 5 | outDir?: string; 6 | target?: string; 7 | } 8 | 9 | export interface ProjectCompilerOptions extends CompilerOptions { 10 | /** Either truffle or openzeppelin */ 11 | manager?: string; 12 | /** Folder from which root contracts will be loaded */ 13 | inputDir?: string; 14 | /** Output dir for compilation json artifacts */ 15 | outputDir?: string; 16 | /** Imports like 'contracts/foo/bar.sol' will be relative to this path */ 17 | workingDir?: string; 18 | /** Compile even if there were no changes to the sources */ 19 | force?: boolean; 20 | /** Options for generating typechain wrappers for contracts */ 21 | typechain?: TypechainOptions; 22 | } 23 | -------------------------------------------------------------------------------- /packages/cli/src/models/compiler/Typechain.ts: -------------------------------------------------------------------------------- 1 | import { mkdirpSync } from 'fs-extra'; 2 | import path from 'path'; 3 | import { tsGenerator } from 'ts-generator'; 4 | import { TypeChain as typeChain } from 'typechain/dist/TypeChain'; 5 | 6 | export default async function typechain(files: string, outDir: string, target: string): Promise { 7 | const cwd = process.cwd(); 8 | mkdirpSync(outDir); 9 | 10 | return tsGenerator( 11 | { cwd }, 12 | new typeChain({ 13 | cwd, 14 | rawConfig: { 15 | files, 16 | outDir, 17 | target, 18 | }, 19 | }), 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /packages/cli/src/models/config/blueprint.networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/cli/src/models/files/KitFile.ts: -------------------------------------------------------------------------------- 1 | export const MANIFEST_VERSION = '0.1.0'; 2 | 3 | export default interface KitFile { 4 | manifestVersion: string; 5 | message: string; 6 | files: string[]; 7 | hooks: object; 8 | } 9 | -------------------------------------------------------------------------------- /packages/cli/src/models/files/constants.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | 3 | export const OPEN_ZEPPELIN_FOLDER = '.openzeppelin'; 4 | export const LOCK_FILE = '.lock'; 5 | export const LOCK_FILE_PATH = path.join(OPEN_ZEPPELIN_FOLDER, LOCK_FILE); 6 | -------------------------------------------------------------------------------- /packages/cli/src/models/files/index.ts: -------------------------------------------------------------------------------- 1 | import { MANIFEST_VERSION, checkVersion } from './ManifestVersion'; 2 | import NetworkFile from './NetworkFile'; 3 | import ProjectFile from './ProjectFile'; 4 | 5 | export default { 6 | checkVersion, 7 | NetworkFile, 8 | ProjectFile, 9 | MANIFEST_VERSION, 10 | }; 11 | -------------------------------------------------------------------------------- /packages/cli/src/models/files/kit-config.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "object", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "properties": { 5 | "manifestVersion": { "type": "string" }, 6 | "message": { "type": "string" }, 7 | "files": { "type": "array" }, 8 | "hooks": { "type": "object" } 9 | }, 10 | "additionalProperties": false, 11 | "required": ["manifestVersion", "message", "files", "hooks"] 12 | } -------------------------------------------------------------------------------- /packages/cli/src/models/local/index.ts: -------------------------------------------------------------------------------- 1 | import LocalController from './LocalController'; 2 | 3 | export default { 4 | LocalController, 5 | }; 6 | -------------------------------------------------------------------------------- /packages/cli/src/models/network/defaults.ts: -------------------------------------------------------------------------------- 1 | export const DEFAULT_TX_TIMEOUT = 750; // same as web3 2 | export const DEFAULT_TX_BLOCK_TIMEOUT = 50; // same as web3 3 | export const DEFAULT_EXPIRATION_TIMEOUT = 15 * 60; // 15 minutes 4 | -------------------------------------------------------------------------------- /packages/cli/src/models/network/index.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from './NetworkController'; 2 | 3 | export default { 4 | NetworkController, 5 | }; 6 | -------------------------------------------------------------------------------- /packages/cli/src/prompts/validators.ts: -------------------------------------------------------------------------------- 1 | export function notEmpty(input) { 2 | if (input && input.length > 0) return true; 3 | return 'Please enter a non-empty value'; 4 | } 5 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/accounts.ts: -------------------------------------------------------------------------------- 1 | import { ZWeb3, Loggy } from '@openzeppelin/upgrades'; 2 | 3 | export default async function accounts({ network }: { network: string }): Promise { 4 | const defaultAccount = await ZWeb3.defaultAccount(); 5 | const accounts = await ZWeb3.eth.getAccounts(); 6 | 7 | if (accounts && accounts.length !== 0) { 8 | Loggy.noSpin(__filename, `accounts`, `network-name`, `Accounts for ${network}:`); 9 | Loggy.noSpin(__filename, `accounts`, `default-account`, `Default: ${defaultAccount}`); 10 | Loggy.noSpin( 11 | __filename, 12 | `accounts`, 13 | `all-accounts`, 14 | `All:\n${accounts.map((account, index) => `- ${index}: ${account}`).join('\n')}`, 15 | ); 16 | } else { 17 | Loggy.noSpin(__filename, `accounts`, `accounts-msg`, `There are no accounts for ${network}`); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/add-all.ts: -------------------------------------------------------------------------------- 1 | import { Loggy } from '@openzeppelin/upgrades'; 2 | import LocalController from '../models/local/LocalController'; 3 | import ProjectFile from '../models/files/ProjectFile'; 4 | 5 | export default function addAll({ projectFile }: { projectFile?: ProjectFile }): void { 6 | const controller = new LocalController(projectFile); 7 | controller.addAll(); 8 | Loggy.noSpin(__filename, 'add', 'add-contracts', 'All local contracts have been added to the project.'); 9 | controller.writePackage(); 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/add.ts: -------------------------------------------------------------------------------- 1 | import { Loggy } from '@openzeppelin/upgrades'; 2 | 3 | import LocalController from '../models/local/LocalController'; 4 | import { AddParams } from './interfaces'; 5 | 6 | export default function add({ contracts, projectFile }: AddParams): void | never { 7 | if (contracts.length === 0) throw new Error('At least one contract name must be provided to add.'); 8 | 9 | const controller = new LocalController(projectFile); 10 | contracts.forEach(name => { 11 | controller.checkCanAdd(name); 12 | controller.add(name); 13 | }); 14 | 15 | if (contracts.length > 1) { 16 | Loggy.noSpin(__filename, 'add', 'add-contracts', 'All the selected contracts have been added to the project'); 17 | } 18 | controller.writePackage(); 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/balance.ts: -------------------------------------------------------------------------------- 1 | import stdout from '../utils/stdout'; 2 | import TransactionController from '../models/network/TransactionController'; 3 | import { BalanceParams } from './interfaces'; 4 | 5 | export default async function balance({ accountAddress, contractAddress }: BalanceParams): Promise { 6 | if (!accountAddress) throw Error('An account address must be specified.'); 7 | const controller = new TransactionController(); 8 | const balance = await controller.getBalanceOf(accountAddress, contractAddress); 9 | if (balance) stdout(balance); 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/bump.ts: -------------------------------------------------------------------------------- 1 | import LocalController from '../models/local/LocalController'; 2 | import { BumpParams } from './interfaces'; 3 | 4 | export default async function bumpVersion({ version, projectFile }: BumpParams): Promise { 5 | if (!version) throw Error('A version name must be provided to initialize a new version.'); 6 | const controller = new LocalController(projectFile); 7 | controller.bumpVersion(version); 8 | controller.writePackage(); 9 | } 10 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/call.ts: -------------------------------------------------------------------------------- 1 | import TransactionController from '../models/network/TransactionController'; 2 | import { CallParams } from './interfaces'; 3 | import stdout from '../utils/stdout'; 4 | 5 | export default async function call({ 6 | proxyAddress, 7 | methodName, 8 | methodArgs, 9 | network, 10 | txParams, 11 | networkFile, 12 | }: Partial): Promise { 13 | if (!proxyAddress) throw Error('A contract address must be specified.'); 14 | if (!methodName) throw Error('A method name must be specified.'); 15 | 16 | const controller = new TransactionController(txParams, network, networkFile); 17 | const returnedValue = await controller.callContractMethod(proxyAddress, methodName, methodArgs); 18 | if (returnedValue !== undefined) stdout(returnedValue); 19 | } 20 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/check.ts: -------------------------------------------------------------------------------- 1 | import { Loggy } from '@openzeppelin/upgrades'; 2 | 3 | import LocalController from '../models/local/LocalController'; 4 | import { CheckParams } from './interfaces'; 5 | 6 | export default function check({ contractName, projectFile }: CheckParams): void { 7 | const controller = new LocalController(projectFile); 8 | const success = contractName ? controller.validate(contractName) : controller.validateAll(); 9 | if (success) { 10 | Loggy.noSpin(__filename, 'check', 'check-script', 'No issues were found'); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/freeze.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../models/network/NetworkController'; 2 | import { FreezeParams } from './interfaces'; 3 | 4 | export default async function freeze({ network, txParams = {}, networkFile }: FreezeParams): Promise { 5 | const controller = new NetworkController(network, txParams, networkFile); 6 | try { 7 | await controller.freeze(); 8 | } finally { 9 | controller.writeNetworkPackageIfNeeded(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/index.ts: -------------------------------------------------------------------------------- 1 | import add from './add'; 2 | import addAll from './add-all'; 3 | import bump from './bump'; 4 | import create from './create'; 5 | import freeze from './freeze'; 6 | import init from './init'; 7 | import link from './link'; 8 | import publish from './publish'; 9 | import push from './push'; 10 | import queryDeployment from './query-deployment'; 11 | import querySignedDeployment from './query-signed-deployment'; 12 | import remove from './remove'; 13 | import session from './session'; 14 | import setAdmin from './set-admin'; 15 | import unlink from './unlink'; 16 | import update from './update'; 17 | import transfer from './transfer'; 18 | import balance from './balance'; 19 | import accounts from './accounts'; 20 | 21 | export default { 22 | add, 23 | addAll, 24 | bump, 25 | create, 26 | freeze, 27 | init, 28 | link, 29 | publish, 30 | push, 31 | queryDeployment, 32 | querySignedDeployment, 33 | remove, 34 | session, 35 | setAdmin, 36 | unlink, 37 | update, 38 | transfer, 39 | balance, 40 | accounts, 41 | }; 42 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/init.ts: -------------------------------------------------------------------------------- 1 | import LocalController from '../models/local/LocalController'; 2 | import ProjectFile from '../models/files/ProjectFile'; 3 | import { InitParams } from './interfaces'; 4 | 5 | export default async function init({ 6 | name, 7 | version, 8 | publish = false, 9 | dependencies = [], 10 | installDependencies = false, 11 | force = false, 12 | projectFile = new ProjectFile(), 13 | typechainEnabled = false, 14 | typechainOutdir = null, 15 | typechainTarget = null, 16 | }: InitParams): Promise { 17 | const controller = new LocalController(projectFile, true); 18 | controller.init(name, version, force, publish); 19 | 20 | const typechain = { enabled: typechainEnabled }; 21 | if (typechainEnabled) Object.assign(typechain, { outDir: typechainOutdir, target: typechainTarget }); 22 | controller.projectFile.setCompilerOptions({ typechain }); 23 | 24 | if (dependencies.length !== 0) await controller.linkDependencies(dependencies, installDependencies); 25 | controller.writePackage(); 26 | } 27 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/link.ts: -------------------------------------------------------------------------------- 1 | import stdout from '../utils/stdout'; 2 | import LocalController from '../models/local/LocalController'; 3 | import { LinkParams } from './interfaces'; 4 | 5 | export default async function link({ dependencies = [], installDependencies = false, projectFile }: LinkParams) { 6 | if (!dependencies.length) throw Error('At least one dependency name and version to be linked must be provided.'); 7 | const controller = new LocalController(projectFile); 8 | 9 | await controller.linkDependencies(dependencies, installDependencies); 10 | controller.writePackage(); 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/publish.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../models/network/NetworkController'; 2 | import { PublishParams } from './interfaces'; 3 | 4 | export default async function publish({ network, txParams = {}, networkFile }: PublishParams): Promise { 5 | const controller = new NetworkController(network, txParams, networkFile); 6 | 7 | try { 8 | await controller.publish(); 9 | } finally { 10 | controller.writeNetworkPackageIfNeeded(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/query-deployment.ts: -------------------------------------------------------------------------------- 1 | import stdout from '../utils/stdout'; 2 | import NetworkController from '../models/network/NetworkController'; 3 | import { QueryDeploymentParams } from './interfaces'; 4 | import { Loggy } from '@openzeppelin/upgrades'; 5 | import { validateSalt } from '../utils/input'; 6 | 7 | export default async function queryDeployment({ 8 | salt, 9 | sender, 10 | network, 11 | txParams = {}, 12 | networkFile, 13 | }: QueryDeploymentParams): Promise { 14 | validateSalt(salt, true); 15 | const controller = new NetworkController(network, txParams, networkFile); 16 | 17 | try { 18 | const address = await controller.getProxyDeploymentAddress(salt, sender); 19 | const senderLog = sender ? ` from ${sender} ` : ' '; 20 | Loggy.noSpin( 21 | __filename, 22 | 'queryDeployment', 23 | 'query-deployment', 24 | `Any contract created with salt ${salt}${senderLog}will be deployed to the following address`, 25 | ); 26 | stdout(address); 27 | 28 | return address; 29 | } finally { 30 | controller.writeNetworkPackageIfNeeded(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/remove.ts: -------------------------------------------------------------------------------- 1 | import { Loggy } from '@openzeppelin/upgrades'; 2 | 3 | import LocalController from '../models/local/LocalController'; 4 | import { RemoveParams } from './interfaces'; 5 | 6 | export default function remove({ contracts, projectFile }: RemoveParams): void | never { 7 | if (contracts.length === 0) throw new Error('At least one contract name must be provided to remove.'); 8 | 9 | const controller = new LocalController(projectFile); 10 | contracts.forEach(contractName => controller.remove(contractName)); 11 | Loggy.noSpin( 12 | __filename, 13 | 'remove', 14 | 'remove-contracts', 15 | `All specified contracts have been removed from the project. To add them again, run 'openzeppelin add'.`, 16 | ); 17 | controller.writePackage(); 18 | } 19 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/send-tx.ts: -------------------------------------------------------------------------------- 1 | import TransactionController from '../models/network/TransactionController'; 2 | import { SendTxParams } from './interfaces'; 3 | 4 | export default async function sendTx({ 5 | proxyAddress, 6 | methodName, 7 | methodArgs, 8 | value, 9 | gas, 10 | network, 11 | txParams, 12 | networkFile, 13 | }: Partial): Promise { 14 | if (!proxyAddress) throw Error('A contract address must be specified.'); 15 | if (!methodName) throw Error('A method name must be specified.'); 16 | if (value) txParams = { value, ...txParams }; 17 | if (gas) txParams = { gas, ...txParams }; 18 | 19 | const controller = new TransactionController(txParams, network, networkFile); 20 | await controller.sendTransaction(proxyAddress, methodName, methodArgs); 21 | } 22 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/session.ts: -------------------------------------------------------------------------------- 1 | import Session from '../models/network/Session'; 2 | import { SessionParams } from './interfaces'; 3 | 4 | export default function session({ 5 | network, 6 | from, 7 | timeout, 8 | blockTimeout, 9 | close = false, 10 | expires, 11 | }: SessionParams): void | never { 12 | const anyNetworkOption = network || from || timeout || blockTimeout; 13 | if (!!anyNetworkOption === !!close) { 14 | throw Error('Please provide either a network option (--network, --timeout, --blockTimeout, --from) or --close.'); 15 | } 16 | close ? Session.close() : Session.open({ network, from, timeout, blockTimeout }, expires); 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/set-admin.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../models/network/NetworkController'; 2 | import { SetAdminParams } from './interfaces'; 3 | 4 | export default async function setAdmin({ 5 | newAdmin, 6 | packageName, 7 | contractName, 8 | proxyAddress, 9 | network, 10 | txParams = {}, 11 | networkFile, 12 | }: SetAdminParams): Promise { 13 | if (!contractName && !proxyAddress && packageName) { 14 | throw Error('The address or name of the contract to transfer upgradeability admin rights must be provided.'); 15 | } 16 | 17 | if (!newAdmin) { 18 | throw Error('The address of the new admin must be provided.'); 19 | } 20 | 21 | const controller = new NetworkController(network, txParams, networkFile); 22 | 23 | try { 24 | if (contractName || proxyAddress) { 25 | const proxies = await controller.setProxiesAdmin(packageName, contractName, proxyAddress, newAdmin); 26 | } else { 27 | await controller.setProxyAdminOwner(newAdmin); 28 | } 29 | } finally { 30 | controller.writeNetworkPackageIfNeeded(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/transfer.ts: -------------------------------------------------------------------------------- 1 | import TransactionController from '../models/network/TransactionController'; 2 | import { TransferParams } from './interfaces'; 3 | 4 | export default async function transfer({ 5 | to, 6 | value, 7 | unit = 'ether', 8 | from, 9 | txParams = {}, 10 | }: TransferParams): Promise { 11 | if (!to) throw Error('A recipient address must be specified'); 12 | if (!value) throw Error('An amount to be transferred must be specified'); 13 | 14 | if (from) txParams = { ...txParams, from }; 15 | const controller = new TransactionController(txParams); 16 | await controller.transfer(to, value, unit); 17 | } 18 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/unlink.ts: -------------------------------------------------------------------------------- 1 | import LocalController from '../models/local/LocalController'; 2 | import { UnlinkParams } from './interfaces'; 3 | 4 | export default async function unlink({ dependencies = [], projectFile }: UnlinkParams): Promise { 5 | if (!dependencies.length) throw Error('At least one dependency name must be provided.'); 6 | const controller = new LocalController(projectFile); 7 | 8 | controller.unlinkDependencies(dependencies); 9 | controller.writePackage(); 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/src/scripts/update.ts: -------------------------------------------------------------------------------- 1 | import NetworkController from '../models/network/NetworkController'; 2 | import { UpdateParams } from './interfaces'; 3 | 4 | export default async function update({ 5 | packageName, 6 | contractName, 7 | proxyAddress, 8 | methodName, 9 | methodArgs, 10 | all, 11 | network, 12 | force = false, 13 | txParams = {}, 14 | networkFile, 15 | }: Partial) { 16 | if (!packageName && !contractName && !proxyAddress && !all) { 17 | throw Error( 18 | 'The package name, contract name, or address to upgrade must be provided, or set the `all` flag to upgrade all contracts in the application.', 19 | ); 20 | } 21 | 22 | const controller = new NetworkController(network, txParams, networkFile); 23 | 24 | try { 25 | await controller.logErrorIfProjectDeploymentIsInvalid(!force); 26 | const proxies = await controller.upgradeProxies(packageName, contractName, proxyAddress, methodName, methodArgs); 27 | } finally { 28 | controller.writeNetworkPackageIfNeeded(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/cli/src/test/bin/helpers.test.js: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import findRootDirectory from '../../bin/helpers'; 3 | 4 | describe('bin helpers', function() { 5 | describe('findRootDirectory', function() { 6 | context('when no package.json file and zos file found', function() { 7 | it('returns the original path', function() { 8 | const rootDirectory = findRootDirectory('/unexistent-directory'); 9 | expect(rootDirectory).to.be.null; 10 | }); 11 | }); 12 | 13 | context('when package.json or zos.json found', function() { 14 | it('returns the correct directory', function() { 15 | const path = 'mocks/mock-stdlib-2/build/contracts'; 16 | findRootDirectory(path).should.match(/\/mocks\/mock-stdlib-2/g); 17 | }); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/accounts.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('accounts command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse('should call accounts script', 'accounts', 'zos accounts --network local', function(accounts) { 10 | accounts.should.have.been.calledWithExactly({ network: 'local' }); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/balance.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('balance command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse( 10 | 'should call balance script with account address', 11 | 'balance', 12 | 'zos balance 0x42 --network test', 13 | function(transfer) { 14 | transfer.should.have.been.calledWithExactly({ 15 | accountAddress: '0x42', 16 | contractAddress: undefined, 17 | }); 18 | }, 19 | ); 20 | 21 | itShouldParse( 22 | 'should call balance script with account and contract address', 23 | 'balance', 24 | 'zos balance 0x42 --erc20 0x10 --network test', 25 | function(transfer) { 26 | transfer.should.have.been.calledWithExactly({ 27 | accountAddress: '0x42', 28 | contractAddress: '0x10', 29 | }); 30 | }, 31 | ); 32 | }); 33 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/call.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('call command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse( 10 | 'should call call script with mandatory options', 11 | 'call', 12 | 'zos call --to 0x42 --network test --method someMethod --args 42 --from 0x40', 13 | function(call) { 14 | call.should.have.been.calledWithExactly({ 15 | proxyAddress: '0x42', 16 | methodName: 'someMethod', 17 | methodArgs: ['42'], 18 | network: 'test', 19 | txParams: { from: '0x40' }, 20 | }); 21 | }, 22 | ); 23 | }); 24 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/check.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('check command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse('should call check script with an contract name', 'check', 'oz check Impl --skip-compile', function( 10 | check, 11 | ) { 12 | check.should.have.been.calledWithExactly({ contractName: 'Impl' }); 13 | }); 14 | 15 | itShouldParse('should call check script for all contracts', 'check', 'oz check --skip-compile', function(check) { 16 | check.should.have.been.calledWithExactly({ contractName: undefined }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/freeze.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('freeze command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse('should call freeze script with network option', 'freeze', 'zos freeze --network test', function( 10 | freeze, 11 | ) { 12 | freeze.should.have.been.calledWithExactly({ 13 | network: 'test', 14 | txParams: {}, 15 | }); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/publish.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('publish command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse('should call publish script with network', 'publish', 'zos publish --network test', function(publish) { 10 | publish.should.have.been.calledWithExactly({ 11 | network: 'test', 12 | txParams: {}, 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/session.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('session command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse( 10 | 'should call session script with --expires option', 11 | 'session', 12 | 'zos session --network test --expires 3600', 13 | function(session) { 14 | session.should.have.been.calledWithExactly({ 15 | close: undefined, 16 | expires: '3600', 17 | from: undefined, 18 | network: 'test', 19 | timeout: undefined, 20 | blockTimeout: undefined, 21 | }); 22 | }, 23 | ); 24 | 25 | itShouldParse( 26 | 'should call session script with --close option', 27 | 'session', 28 | 'zos session --network test --close', 29 | function(session) { 30 | session.should.have.been.calledWithExactly({ close: true }); 31 | }, 32 | ); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/transfer.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('transfer command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse( 10 | 'should call transfer script with options', 11 | 'transfer', 12 | 'zos transfer --network test --unit gwei --to 0x42 --from 0x40 --value 10', 13 | function(transfer) { 14 | transfer.should.have.been.calledWithExactly({ 15 | from: '0x40', 16 | to: '0x42', 17 | value: '10', 18 | unit: 'gwei', 19 | txParams: { from: '0x40' }, 20 | }); 21 | }, 22 | ); 23 | }); 24 | -------------------------------------------------------------------------------- /packages/cli/src/test/commands/unpack.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../setup'); 3 | 4 | import { stubCommands, itShouldParse } from './share'; 5 | 6 | describe('unpack command', function() { 7 | stubCommands(); 8 | 9 | itShouldParse('should call unpack script with a name', 'unpack', 'zos unpack starter', function(unpack) { 10 | unpack.should.have.been.calledWithExactly({ repoOrName: 'starter' }); 11 | }); 12 | 13 | itShouldParse('should call unpack script with a github repo', 'unpack', 'zos unpack openzeppelin/starter', function( 14 | unpack, 15 | ) { 16 | unpack.should.have.been.calledWithExactly({ 17 | repoOrName: 'openzeppelin/starter', 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/cli/src/test/helpers/cleanup.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra'; 2 | 3 | export function cleanup(path) { 4 | try { 5 | fs.removeSync(path); 6 | } catch (e) { 7 | /* swallow exception */ 8 | } 9 | } 10 | 11 | export function cleanupfn(path) { 12 | return function() { 13 | cleanup(path); 14 | }; 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/src/test/utils/solidity.test.js: -------------------------------------------------------------------------------- 1 | require('../setup'); 2 | 3 | import { getImports } from '../../utils/solidity'; 4 | 5 | describe('utils.solidity', function() { 6 | describe('getImports', function() { 7 | it('returns no imports from empty file', function() { 8 | getImports('').should.be.empty; 9 | }); 10 | 11 | it.skip('returns no imports from commented out file', function() { 12 | getImports(`// import "Foo.sol";`).should.be.empty; 13 | }); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /packages/cli/src/transpiler.ts: -------------------------------------------------------------------------------- 1 | import { transpileContracts } from '@openzeppelin/upgradeability-transpiler'; 2 | import { CompiledContract } from './models/compiler/solidity/SolidityContractsCompiler'; 3 | import { Contracts } from '@openzeppelin/upgrades'; 4 | import fs from 'fs-extra'; 5 | 6 | export async function transpileAndSave(contracts: string[]): Promise { 7 | const artifacts: CompiledContract[] = await Promise.all(Contracts.listBuildArtifacts().map(p => fs.readJson(p))); 8 | const output = transpileContracts(contracts, artifacts, Contracts.getLocalContractsDir()); 9 | 10 | for (const file of output) { 11 | await fs.outputFile(file.path, file.source); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/cli/src/utils/async.ts: -------------------------------------------------------------------------------- 1 | import { map, isEmpty } from 'lodash'; 2 | 3 | export async function allPromisesOrError( 4 | promisesWithObjects: any[], 5 | toErrorMessage?: (error: any, object: any) => string, 6 | ): Promise { 7 | const failures = []; 8 | const handlingFailure = async (item: any) => { 9 | let promise; 10 | let object = null; 11 | try { 12 | if (Array.isArray(item)) { 13 | [promise, object] = item; 14 | } else { 15 | promise = item; 16 | } 17 | return await promise; 18 | } catch (error) { 19 | failures.push({ error, object }); 20 | return null; 21 | } 22 | }; 23 | 24 | const results = await Promise.all(map(promisesWithObjects, handlingFailure)); 25 | 26 | if (!isEmpty(failures)) { 27 | if (failures.length === 1) throw failures[0].error; 28 | const message = failures 29 | .map(({ error, object }) => (toErrorMessage ? toErrorMessage(error, object) : error.message || error)) 30 | .join('\n'); 31 | throw Error(message); 32 | } 33 | 34 | return results; 35 | } 36 | -------------------------------------------------------------------------------- /packages/cli/src/utils/child.ts: -------------------------------------------------------------------------------- 1 | import util from 'util'; 2 | import child from 'child_process'; 3 | 4 | const exec = util.promisify(child.exec); 5 | 6 | export default { 7 | exec, 8 | execSync: child.execSync, 9 | }; 10 | -------------------------------------------------------------------------------- /packages/cli/src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | import { AbiItem } from 'web3-utils'; 2 | 3 | export const ERC20_PARTIAL_ABI: AbiItem[] = [ 4 | { 5 | constant: true, 6 | inputs: [ 7 | { 8 | name: '_owner', 9 | type: 'address', 10 | }, 11 | ], 12 | name: 'balanceOf', 13 | outputs: [ 14 | { 15 | name: 'balance', 16 | type: 'uint256', 17 | }, 18 | ], 19 | payable: false, 20 | stateMutability: 'view', 21 | type: 'function', 22 | }, 23 | { 24 | constant: true, 25 | inputs: [], 26 | name: 'symbol', 27 | outputs: [ 28 | { 29 | name: '', 30 | type: 'string', 31 | }, 32 | ], 33 | payable: false, 34 | stateMutability: 'view', 35 | type: 'function', 36 | }, 37 | { 38 | constant: true, 39 | inputs: [], 40 | name: 'decimals', 41 | outputs: [ 42 | { 43 | name: '', 44 | type: 'uint8', 45 | }, 46 | ], 47 | payable: false, 48 | stateMutability: 'view', 49 | type: 'function', 50 | }, 51 | ]; 52 | -------------------------------------------------------------------------------- /packages/cli/src/utils/contract.ts: -------------------------------------------------------------------------------- 1 | import { fromContractFullName } from './naming'; 2 | 3 | export interface ParsedContractReference { 4 | proxyAddress: string | undefined; 5 | contractName: string | undefined; 6 | packageName: string | undefined; 7 | } 8 | 9 | export function parseContractReference(contractReference: string): ParsedContractReference { 10 | let proxyAddress; 11 | let contractName; 12 | let packageName; 13 | 14 | if (contractReference && contractReference.startsWith('0x')) { 15 | proxyAddress = contractReference; 16 | } else if (contractReference) { 17 | ({ contractName, package: packageName } = fromContractFullName(contractReference)); 18 | } 19 | 20 | return { proxyAddress, contractName, packageName }; 21 | } 22 | -------------------------------------------------------------------------------- /packages/cli/src/utils/events.ts: -------------------------------------------------------------------------------- 1 | import { Loggy } from '@openzeppelin/upgrades'; 2 | 3 | export function describeEvents(events: any): void { 4 | let description = ''; 5 | Object.values(events) 6 | .filter(({ event }) => event) 7 | .forEach(({ event, returnValues }) => { 8 | const emitted = Object.keys(returnValues) 9 | .filter(key => !isNaN(Number(key))) 10 | .map(key => returnValues[key]); 11 | 12 | if (emitted.length !== 0) description = description.concat(`\n - ${event}(${emitted.join(', ')})`); 13 | }); 14 | 15 | if (description) { 16 | Loggy.noSpin(__filename, 'describe', 'describe-events', `Events emitted: ${description}`); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/cli/src/utils/naming.ts: -------------------------------------------------------------------------------- 1 | import { pickBy } from 'lodash'; 2 | 3 | export function toContractFullName(packageName: string, contractName: string): string { 4 | if (!packageName) return contractName; 5 | return [packageName, contractName].join('/'); 6 | } 7 | 8 | export function fromContractFullName(contractFullName: string): { contractName?: string; package?: string } { 9 | if (!contractFullName) return {}; 10 | const fragments = contractFullName.split('/'); 11 | const contractName = fragments.pop(); 12 | if (fragments.length === 0) return { contractName }; 13 | else return pickBy({ contractName, package: fragments.join('/') }); 14 | } 15 | -------------------------------------------------------------------------------- /packages/cli/src/utils/patch.ts: -------------------------------------------------------------------------------- 1 | // in order to properly stub and mock libs which export function by default 2 | // more https://github.com/sinonjs/sinon/issues/562 3 | 4 | export const cache: object = {}; 5 | 6 | export default function(lib: string): any { 7 | // eslint-disable-next-line @typescript-eslint/no-var-requires 8 | const module = require(lib); 9 | if (!cache.hasOwnProperty(lib)) cache[lib] = module; 10 | return (...args: any[]) => cache[lib].apply(this, args); 11 | } 12 | -------------------------------------------------------------------------------- /packages/cli/src/utils/stdout.ts: -------------------------------------------------------------------------------- 1 | const state: { silent: boolean } = { 2 | silent: false, 3 | }; 4 | 5 | export default function log(...args: any[]): void { 6 | if (!state.silent && process.env.NODE_ENV !== 'test') { 7 | console.log(...args); 8 | } 9 | } 10 | 11 | export function silent(value: boolean): void { 12 | state.silent = value; 13 | } 14 | -------------------------------------------------------------------------------- /packages/cli/src/utils/try.ts: -------------------------------------------------------------------------------- 1 | export function tryFunc(func: () => T, ifException: T = null): T { 2 | try { 3 | return func(); 4 | } catch (_) { 5 | return ifException; 6 | } 7 | } 8 | 9 | export async function tryAwait(func: () => Promise, ifException: T = null): Promise { 10 | try { 11 | return await func(); 12 | } catch (_) { 13 | return ifException; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/cli/src/utils/units.ts: -------------------------------------------------------------------------------- 1 | import BN from 'bignumber.js'; 2 | import web3Utils from 'web3-utils'; 3 | 4 | export function isValidUnit(unit: string): boolean { 5 | return Object.keys(web3Utils.unitMap).includes(unit.toLowerCase()); 6 | } 7 | 8 | export function prettifyTokenAmount(amount: string, decimals?: string, symbol?: string): string { 9 | const prettifiedAmount = decimals ? new BN(amount).shiftedBy(-decimals).toFormat() : amount; 10 | 11 | return symbol ? `${prettifiedAmount} ${symbol}` : prettifiedAmount; 12 | } 13 | 14 | export function toWei(value: string, unit: any): string { 15 | return web3Utils.toWei(value, unit); 16 | } 17 | 18 | export function fromWei(value: string, unit: any): string { 19 | return web3Utils.fromWei(value, unit); 20 | } 21 | -------------------------------------------------------------------------------- /packages/cli/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | local: { 4 | host: 'localhost', 5 | port: 8545, 6 | network_id: '*', 7 | gas: 5000000 8 | }, 9 | testing: { 10 | host: 'localhost', 11 | network_id: '4447', 12 | port: 9555 13 | }, 14 | }, 15 | compilers: { 16 | solc: { 17 | version: "0.5.3", 18 | evmVersion: "constantinople" 19 | } 20 | }, 21 | mocha: { 22 | forbidOnly: !!process.env.CI 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.docs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "defaultSeverity": "warning", 4 | "compilerOptions": { 5 | "allowJs": true, 6 | }, 7 | "include": [ 8 | "./src" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "./lib", 6 | "allowJs": false, 7 | "noEmitOnError": true, 8 | "declaration": true, 9 | "sourceMap": true 10 | }, 11 | "include": [ 12 | "./src" 13 | ], 14 | "exclude": [ 15 | "src/models/config/blueprint.networks.js", 16 | "src/test" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/cli/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "test-build", 5 | "allowJs": true, 6 | "noEmitOnError": false 7 | }, 8 | "include": [ 9 | "./src" 10 | ], 11 | "exclude": [] 12 | } 13 | -------------------------------------------------------------------------------- /packages/lib/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib -------------------------------------------------------------------------------- /packages/lib/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '../../.eslintrc.base.js', 4 | ], 5 | }; -------------------------------------------------------------------------------- /packages/lib/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | build/ 3 | lib/ 4 | coverage/ 5 | coverage.json 6 | .node-xmlhttprequest-sync-* 7 | -------------------------------------------------------------------------------- /packages/lib/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require("../../.prettierrc.base.js"), 3 | }; 4 | -------------------------------------------------------------------------------- /packages/lib/AUTHORS: -------------------------------------------------------------------------------- 1 | ajsantander 2 | elopio 3 | facuspagnuolo 4 | fiiiu 5 | frangio 6 | maraoz 7 | martriay 8 | spalladino 9 | -------------------------------------------------------------------------------- /packages/lib/contracts/.npmignore: -------------------------------------------------------------------------------- 1 | mocks 2 | -------------------------------------------------------------------------------- /packages/lib/contracts/README.adoc: -------------------------------------------------------------------------------- 1 | = API Reference 2 | 3 | == Proxies 4 | 5 | NOTE: Proxy contracts and their documentation have moved to xref:contracts:api:proxy.adoc[Contracts]. 6 | 7 | {{ProxyFactory}} 8 | 9 | == Application 10 | 11 | {{App}} 12 | 13 | {{ImplementationDirectory}} 14 | 15 | {{ImplementationProvider}} 16 | 17 | {{Package}} 18 | 19 | == Utility 20 | 21 | {{Initializable}} 22 | -------------------------------------------------------------------------------- /packages/lib/contracts/application/ImplementationProvider.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | /** 4 | * @title ImplementationProvider 5 | * @dev Abstract contract for providing implementation addresses for other contracts by name. 6 | */ 7 | contract ImplementationProvider { 8 | /** 9 | * @dev Abstract function to return the implementation address of a contract. 10 | * @param contractName Name of the contract. 11 | * @return Implementation address of the contract. 12 | */ 13 | function getImplementation(string memory contractName) public view returns (address); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/ClashingImplementation.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | 4 | /** 5 | * @dev Implementation contract with an admin() function made to clash with 6 | * @dev AdminUpgradeabilityProxy's to test correct functioning of the 7 | * @dev Transparent Proxy feature. 8 | */ 9 | contract ClashingImplementation { 10 | 11 | function admin() external pure returns (address) { 12 | return 0x0000000000000000000000000000000011111142; 13 | } 14 | 15 | function delegatedFunction() external pure returns (bool) { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/GetFunctionMocks.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract GetFunctionBase { 4 | uint256 x; 5 | 6 | function initialize(uint256 _x) public { 7 | x = _x; 8 | } 9 | 10 | function initialize(string memory _x) public { 11 | x = bytes(_x).length; 12 | } 13 | 14 | function initialize(uint256 _x, uint256 _y) public { 15 | x = _x + _y; 16 | } 17 | 18 | function another(uint256 _x) public { 19 | x = _x; 20 | } 21 | } 22 | 23 | contract GetFunctionChild is GetFunctionBase { 24 | function initialize(bytes memory _x) public { 25 | x = _x.length; 26 | } 27 | } 28 | 29 | contract GetFunctionOtherChild is GetFunctionBase { 30 | function initialize(bytes32 _x) public { 31 | x = uint256(_x); 32 | } 33 | } 34 | 35 | contract GetFunctionGrandchild is GetFunctionChild, GetFunctionOtherChild { } 36 | 37 | contract GetFunctionOtherGrandchild is GetFunctionOtherChild, GetFunctionChild { } -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/InitializableMock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "../Initializable.sol"; 4 | 5 | /** 6 | * @title InitializableMock 7 | * @dev This contract is a mock to test initializable functionality 8 | */ 9 | contract InitializableMock is Initializable { 10 | 11 | bool public initializerRan; 12 | uint256 public x; 13 | 14 | function initialize() public initializer { 15 | initializerRan = true; 16 | } 17 | 18 | function initializeNested() public initializer { 19 | initialize(); 20 | } 21 | 22 | function initializeWithX(uint256 _x) public payable initializer { 23 | x = _x; 24 | } 25 | 26 | function nonInitializable(uint256 _x) public payable { 27 | x = _x; 28 | } 29 | 30 | function fail() public pure { 31 | require(false, "InitializableMock forced failure"); 32 | } 33 | 34 | function secret() private pure returns (string memory) { 35 | return 'Im secret'; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/ProxyCreator.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "../application/App.sol"; 4 | import "../Initializable.sol"; 5 | 6 | contract ProxyCreator is Initializable { 7 | 8 | address public created; 9 | 10 | function initialize(App app, string memory packageName, string memory contractName, address admin, bytes memory data) public initializer { 11 | created = address(app.create(packageName, contractName, admin, data)); 12 | } 13 | 14 | function name() public pure returns (string memory) { 15 | return "ProxyCreator"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/StorageMocks3.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./StorageMocks2.sol"; 4 | 5 | contract StorageMockWithTransitiveReferences { 6 | StorageMockWithEnums.MyEnum internal my_enum; 7 | StorageMockWithStructs.MyStruct internal my_struct; 8 | SimpleStorageMock internal my_contract; 9 | } 10 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/WithConstructorImplementation.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract WithConstructorImplementation { 4 | uint256 public value; 5 | string public text; 6 | 7 | constructor(uint256 _value, string memory _text) public { 8 | require(_value > 0); 9 | value = _value; 10 | text = _text; 11 | } 12 | } -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/WithInitialValues.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract WithoutInitialValuesInFieldsDeclarations { 4 | uint constant myConst = 115994; 5 | 6 | function doSomething() public pure returns (string memory) { 7 | return 'do'; 8 | } 9 | } 10 | 11 | contract WithInitialValuesInFieldsDeclarations { 12 | string public allaps = 'allaps'; 13 | 14 | function doSomething() public pure returns (string memory) { 15 | return 'do'; 16 | } 17 | } 18 | 19 | contract WithParentWithInitialValuesInFieldsDeclarations is WithInitialValuesInFieldsDeclarations { 20 | string public myVar; 21 | 22 | function doSomething() public pure returns (string memory) { 23 | return 'do'; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/WithLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library MyLibrary { 4 | function answer() external pure returns(uint256) { 5 | return 42; 6 | } 7 | } 8 | 9 | contract WithLibraryMock { 10 | function reply() external pure returns(uint256) { 11 | return MyLibrary.answer(); 12 | } 13 | } -------------------------------------------------------------------------------- /packages/lib/contracts/mocks/WithStructInConstructor.sol: -------------------------------------------------------------------------------- 1 | pragma experimental ABIEncoderV2; 2 | 3 | contract WithStructInConstructor { 4 | 5 | struct Data { 6 | string foo; 7 | string bar; 8 | uint256 buz; 9 | } 10 | 11 | Data public localData; 12 | address public sender; 13 | 14 | constructor(Data memory _data) public { 15 | localData.foo = _data.foo; 16 | localData.bar = _data.bar; 17 | localData.buz = _data.buz; 18 | sender = msg.sender; 19 | } 20 | 21 | function foo() public view returns (string memory) { 22 | return localData.foo; 23 | } 24 | 25 | function bar() public view returns (string memory) { 26 | return localData.bar; 27 | } 28 | 29 | function buz() public view returns (uint256) { 30 | return localData.buz; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/lib/docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: upgrades 2 | title: Upgrades Library 3 | version: '2.8' 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | -------------------------------------------------------------------------------- /packages/lib/docs/modules/.gitignore: -------------------------------------------------------------------------------- 1 | /api 2 | /ROOT/pages/api.adoc 3 | -------------------------------------------------------------------------------- /packages/lib/docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[Overview] 2 | * xref:creating-upgradeable-from-solidity.adoc[Creating Upgradeable Contracts From Solidity] 3 | * xref:api.adoc[API Reference] 4 | -------------------------------------------------------------------------------- /packages/lib/docs/modules/ROOT/pages/proxies.adoc: -------------------------------------------------------------------------------- 1 | = Proxy Upgrade Pattern 2 | 3 | Moved to xref:upgrades-plugins::proxies.adoc[Upgrades Plugins]. 4 | -------------------------------------------------------------------------------- /packages/lib/docs/modules/ROOT/pages/writing-upgradeable.adoc: -------------------------------------------------------------------------------- 1 | = Writing Upgradeable Contracts 2 | 3 | Moved to xref:upgrades-plugins::writing-upgradeable.adoc[Upgrades Plugins]. 4 | -------------------------------------------------------------------------------- /packages/lib/scripts/prepare-docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | log() { 6 | echo "$*" >&2 7 | } 8 | 9 | if [ ! -d node_modules ]; then 10 | yarn --cwd ../.. 11 | fi 12 | 13 | log "Building API reference for Upgrades contracts..." 14 | solidity-docgen -i contracts/ -o docs/modules/ROOT/pages/api -e contracts/mocks -x adoc -t docs/templates 15 | mv docs/modules/ROOT/pages/api/index.adoc docs/modules/ROOT/pages/api.adoc 16 | log "Building API reference for Upgrades contracts... Done" 17 | -------------------------------------------------------------------------------- /packages/lib/src/errors.ts: -------------------------------------------------------------------------------- 1 | export class ContractNotFound extends Error { 2 | constructor(contractName: string, dependency?: string) { 3 | if (dependency === undefined) { 4 | super(`Contract ${contractName} not found`); 5 | } else { 6 | super(`Contract ${contractName} not found in ${dependency}`); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /packages/lib/src/helpers/advanceBlock.ts: -------------------------------------------------------------------------------- 1 | import ZWeb3 from '../artifacts/ZWeb3'; 2 | 3 | export default function advanceBlock(): Promise { 4 | return new Promise((resolve, reject) => { 5 | if (typeof ZWeb3.provider == 'string') { 6 | return reject('provider not set'); 7 | } 8 | 9 | ZWeb3.provider.send( 10 | { 11 | jsonrpc: '2.0', 12 | method: 'evm_mine', 13 | params: [], 14 | id: Date.now(), 15 | }, 16 | (err, res) => { 17 | return err ? reject(err) : resolve(res); 18 | }, 19 | ); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /packages/lib/src/helpers/encodeCall.ts: -------------------------------------------------------------------------------- 1 | // TODO: Once we migrate to Web3 1.x, we could replace these two dependencies with Web3, since it uses these two under the hood: https://github.com/ethereum/web3.js/blob/1.0/packages/web3-eth-abi/src/index.js 2 | import { defaultAbiCoder, ParamType } from 'ethers/utils/abi-coder'; 3 | import { sha3 } from 'web3-utils'; 4 | 5 | export function encodeParams(types: (string | ParamType)[] = [], rawValues: any[] = []): string { 6 | return defaultAbiCoder.encode(types, rawValues); 7 | } 8 | 9 | export default function encodeCall(name: string, types: (string | ParamType)[] = [], rawValues: any[] = []): string { 10 | const encodedParameters = encodeParams(types, rawValues).substring(2); 11 | const signatureHash = sha3(`${name}(${types.join(',')})`).substring(2, 10); 12 | return `0x${signatureHash}${encodedParameters}`; 13 | } 14 | 15 | export function decodeCall(types: (string | ParamType)[] = [], data: any[] = []): any[] { 16 | return defaultAbiCoder.decode(types, data); 17 | } 18 | -------------------------------------------------------------------------------- /packages/lib/src/helpers/sleep.ts: -------------------------------------------------------------------------------- 1 | export default function sleep(ms: number): Promise { 2 | return new Promise(resolve => setTimeout(resolve, ms)); 3 | } 4 | -------------------------------------------------------------------------------- /packages/lib/src/project/mixin/ProxyAdminProjectMixin.ts: -------------------------------------------------------------------------------- 1 | import Constructable, { AbstractType, GetMixinType } from '../../utils/Mixin'; 2 | import ProxyAdmin from '../../proxy/ProxyAdmin'; 3 | 4 | // A mixin that adds ProxyAdmin field and related ProxyAdminProject methods 5 | // Intented to as a building block for Project class 6 | // Can't extend contructor at that moment due to TypeScript limitations https://github.com/Microsoft/TypeScript/issues/14126 7 | function ProxyAdminProjectMixin(Base: T) { 8 | return class extends Base { 9 | public proxyAdmin: ProxyAdmin; 10 | 11 | public async transferAdminOwnership(newAdminOwner: string): Promise { 12 | await this.proxyAdmin.transferOwnership(newAdminOwner); 13 | } 14 | 15 | public async changeProxyAdmin(proxyAddress: string, newAdmin: string): Promise { 16 | return this.proxyAdmin.changeProxyAdmin(proxyAddress, newAdmin); 17 | } 18 | }; 19 | } 20 | 21 | export default ProxyAdminProjectMixin; 22 | -------------------------------------------------------------------------------- /packages/lib/src/proxy/MinimalProxy.ts: -------------------------------------------------------------------------------- 1 | import ZWeb3 from '../artifacts/ZWeb3'; 2 | import { toAddress } from '../utils/Addresses'; 3 | 4 | export default class MinimalProxy { 5 | public address: string; 6 | 7 | public static at(address: string): MinimalProxy { 8 | return new this(address); 9 | } 10 | 11 | public constructor(address: string) { 12 | this.address = toAddress(address); 13 | } 14 | 15 | public async implementation(): Promise { 16 | // Implementation address is in bytes 10-29 17 | // (see http://eips.ethereum.org/EIPS/eip-1167) 18 | // We are slicing on the hex representation, hence 2 chars per byte, 19 | // and have also to account for the initial 0x in the string 20 | const code = await ZWeb3.eth.getCode(this.address); 21 | return `0x${code.slice(22, 62)}`; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/lib/src/test/helpers/assertEvent.ts: -------------------------------------------------------------------------------- 1 | // TS-TODO: use typed web3 stuff here 2 | 3 | import assert from 'assert'; 4 | 5 | function inLogs(logs: any, eventName: string, eventArgs: any = {}): any { 6 | const event: any = logs.find( 7 | (e: any) => e.event === eventName && Object.entries(eventArgs).every(([k, v]) => e.args[k] === v), 8 | ); 9 | 10 | assert(!!event, `Expected to find ${eventName} with ${eventArgs} in ${logs}`); 11 | return event; 12 | } 13 | 14 | async function inTransaction(tx: any, eventName: string, eventArgs = {}): Promise { 15 | const { logs }: any = await tx; 16 | return inLogs(logs, eventName, eventArgs); 17 | } 18 | 19 | export default { 20 | inLogs, 21 | inTransaction, 22 | }; 23 | -------------------------------------------------------------------------------- /packages/lib/src/test/helpers/assertRevert.ts: -------------------------------------------------------------------------------- 1 | import assert from 'assert'; 2 | 3 | export default async function assertRevert(promise: Promise, invariants = (): void => undefined) { 4 | try { 5 | await promise; 6 | } catch (error) { 7 | const revertFound = error.toString().search('revert') >= 0; 8 | assert(revertFound, `Expected "revert", got ${error} instead`); 9 | invariants(); 10 | return; 11 | } 12 | 13 | assert.fail('Expected VM revert'); 14 | } 15 | -------------------------------------------------------------------------------- /packages/lib/src/test/helpers/signing.ts: -------------------------------------------------------------------------------- 1 | import Web3 from 'web3'; 2 | const web3 = new Web3(null); 3 | 4 | export const signer = '0x239938d1Bd73e99a5042d29DcFFf6991e0Fe5626'; 5 | export const signerPk = '0xbe7e12ce20410c5f0207bd6c7bcae39052679bfd401c62849657ebfe23e3711b'; 6 | 7 | export function signDeploy( 8 | factory: string, 9 | salt: string, 10 | logic: string, 11 | admin: string, 12 | initData = '', 13 | pk: string = signerPk, 14 | ): string { 15 | // Encodes and tightly packs the arguments and calculates keccak256 16 | const hash = web3.utils.soliditySha3( 17 | { type: 'uint256', value: salt }, 18 | { type: 'address', value: logic }, 19 | { type: 'address', value: admin }, 20 | { type: 'bytes', value: initData }, 21 | { type: 'address', value: factory }, 22 | ); 23 | // Prepends the Ethereum Signed Message string, hashes, and signs 24 | const signed = web3.eth.accounts.sign(hash, pk); 25 | return signed.signature; 26 | } 27 | -------------------------------------------------------------------------------- /packages/lib/src/test/index.ts: -------------------------------------------------------------------------------- 1 | import assertions from './helpers/assertions'; 2 | import assertEvent from './helpers/assertEvent'; 3 | import assertRevert from './helpers/assertRevert'; 4 | import { signDeploy, signer, signerPk } from './helpers/signing'; 5 | import shouldBehaveLikeOwnable from './behaviors/Ownable'; 6 | 7 | const helpers = { 8 | assertions, 9 | assertRevert, 10 | assertEvent, 11 | signDeploy, 12 | signer, 13 | signerPk, 14 | }; 15 | 16 | const behaviors = { 17 | shouldBehaveLikeOwnable, 18 | }; 19 | 20 | export { helpers, behaviors }; 21 | -------------------------------------------------------------------------------- /packages/lib/src/utils/Addresses.ts: -------------------------------------------------------------------------------- 1 | import { isEmpty, isString } from 'lodash'; 2 | import utils from 'web3-utils'; 3 | 4 | export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; 5 | 6 | // TS-TODO: Web3 typings? => contract. 7 | export function toAddress(contractOrAddress: string | any): string { 8 | if (isEmpty(contractOrAddress)) throw Error(`Contract or address expected`); 9 | else if (isString(contractOrAddress)) return utils.toChecksumAddress(contractOrAddress); 10 | else return utils.toChecksumAddress(contractOrAddress.address); 11 | } 12 | 13 | export function isZeroAddress(address: string): boolean { 14 | return !address || address === ZERO_ADDRESS; 15 | } 16 | 17 | // TS-TODO: if uint256 is a string, then why are we doing uint256.toString()? 18 | export function uint256ToAddress(uint256: string): string { 19 | const padded = utils.leftPad(uint256.toString(), 64); 20 | const address = padded.replace('0x000000000000000000000000', '0x'); 21 | return utils.toChecksumAddress(address); 22 | } 23 | -------------------------------------------------------------------------------- /packages/lib/src/utils/Constants.ts: -------------------------------------------------------------------------------- 1 | export const IMPLEMENTATION_LABEL = 'eip1967.proxy.implementation'; 2 | export const DEPRECATED_IMPLEMENTATION_LABEL = 'org.zeppelinos.proxy.implementation'; 3 | export const ADMIN_LABEL = 'eip1967.proxy.admin'; 4 | export const DEPRECATED_ADMIN_LABEL = 'org.zeppelinos.proxy.admin'; 5 | -------------------------------------------------------------------------------- /packages/lib/src/utils/Migrator.ts: -------------------------------------------------------------------------------- 1 | import Transactions from './Transactions'; 2 | import encodeCall from '../helpers/encodeCall'; 3 | import { Loggy } from '../utils/Logger'; 4 | import { TxParams } from '../artifacts/ZWeb3'; 5 | 6 | export default async function migrate( 7 | appAddress: string, 8 | proxyAddress: string, 9 | proxyAdminAddress: string, 10 | txParams: TxParams = {}, 11 | ): Promise { 12 | const data = encodeCall('changeProxyAdmin', ['address', 'address'], [proxyAddress, proxyAdminAddress]); 13 | Loggy.spin(__filename, 'migrate', 'migrate-version', `Proxy ${proxyAddress} admin changed to ${proxyAdminAddress}`); 14 | await Transactions.sendRawTransaction(appAddress, { data }, { ...txParams }); 15 | Loggy.succeed('migrate-version', `Proxy ${proxyAddress} admin changed to ${proxyAdminAddress}`); 16 | } 17 | -------------------------------------------------------------------------------- /packages/lib/src/utils/Mixin.ts: -------------------------------------------------------------------------------- 1 | type Constructable = new (...args: any[]) => T; 2 | export type Callable = (...args: any[]) => T; 3 | export type AbstractType = () => void & { prototype: T }; 4 | 5 | export type GetMixinType = InstanceType>; 6 | 7 | export default Constructable; 8 | -------------------------------------------------------------------------------- /packages/lib/src/utils/Solidity.ts: -------------------------------------------------------------------------------- 1 | export function flattenSourceCode(contractPaths: string[], root = process.cwd()): Promise { 2 | // eslint-disable-next-line @typescript-eslint/no-var-requires 3 | return require('truffle-flattener')(contractPaths, root); 4 | } 5 | -------------------------------------------------------------------------------- /packages/lib/src/utils/errors/DeployError.ts: -------------------------------------------------------------------------------- 1 | export class DeployError extends Error { 2 | public constructor(error: Error, props: any) { 3 | super(error.message); 4 | this.stack = error.stack; 5 | this.name = 'DeployError'; 6 | Object.keys(props).forEach((prop: string) => (this[prop] = props[prop])); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/lib/src/validations/Constructors.ts: -------------------------------------------------------------------------------- 1 | import Contract from '../artifacts/Contract'; 2 | import { BuildArtifacts } from '..'; 3 | import ContractAST, { FunctionDefinitionFilter } from '../utils/ContractAST'; 4 | 5 | export function hasConstructor(contract: Contract, buildArtifacts: BuildArtifacts): boolean { 6 | return ( 7 | new ContractAST(contract, buildArtifacts, FunctionDefinitionFilter) 8 | .getLinearizedBaseContracts() 9 | .filter(hasNonEmptyConstructorInAST).length > 0 10 | ); 11 | } 12 | 13 | function hasNonEmptyConstructorInAST(contractNode: any): boolean { 14 | return ( 15 | contractNode.nodes 16 | .filter((n: any) => n.nodeType === 'FunctionDefinition' && n.kind === 'constructor') 17 | .filter((n: any) => n.body.statements.length > 0 || n.modifiers.length > 0).length > 0 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /packages/lib/src/validations/VanillaContracts.ts: -------------------------------------------------------------------------------- 1 | import Contract from '../artifacts/Contract'; 2 | import ContractAST from '../utils/ContractAST'; 3 | 4 | let ETHEREUM_PACKAGE_CONTRACTS = '@openzeppelin/contracts-ethereum-package/'; 5 | 6 | export function importsEthereumPackageContracts(contract: Contract, buildArtifacts?: any): string[] | undefined { 7 | const ast = new ContractAST(contract, buildArtifacts, { nodesFilter: [] }); 8 | const illegalImports = [...ast.getImports()] 9 | .filter(i => i.startsWith(ETHEREUM_PACKAGE_CONTRACTS)) 10 | .map(i => i.slice(ETHEREUM_PACKAGE_CONTRACTS.length)) 11 | .map(i => i.replace(/^contracts\//, '')); 12 | 13 | return illegalImports.length > 0 ? illegalImports : undefined; 14 | } 15 | 16 | // Used for testing purposes; 17 | export function setEthereumPackageContractsPackageName(value: string): void { 18 | ETHEREUM_PACKAGE_CONTRACTS = value; 19 | } 20 | -------------------------------------------------------------------------------- /packages/lib/test-environment.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | accounts: { 3 | ether: 1e6, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /packages/lib/test/setup.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | process.env.NODE_ENV = 'test'; 3 | 4 | import { provider } from '@openzeppelin/test-environment'; 5 | 6 | import ZWeb3 from '../src/artifacts/ZWeb3'; 7 | import Contracts from '../src/artifacts/Contracts'; 8 | import { helpers } from '../src/test'; 9 | import { Loggy } from '../src/utils/Logger'; 10 | 11 | import chaiAsPromised from 'chai-as-promised'; 12 | import chaiString from 'chai-string'; 13 | import sinonChai from 'sinon-chai'; 14 | 15 | Loggy.silent(false); 16 | Loggy.testing(true); 17 | ZWeb3.initialize(provider); 18 | 19 | Contracts.setArtifactsDefaults({ gas: 6721975, gasPrice: 100000000000 }); 20 | 21 | require('chai') 22 | .use(chaiAsPromised) // TODO: Remove this dependency 23 | .use(chaiString) 24 | .use(helpers.assertions) 25 | .use(sinonChai) 26 | .should(); 27 | -------------------------------------------------------------------------------- /packages/lib/test/src/project/PackageProject.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | require('../../setup'); 3 | 4 | import { accounts } from '@openzeppelin/test-environment'; 5 | 6 | import PackageProject from '../../../src/project/PackageProject'; 7 | import shouldBehaveLikePackageProject from './PackageProject.behavior'; 8 | 9 | describe('PackageProject', function() { 10 | const [owner] = accounts; 11 | const version = '0.2.0'; 12 | 13 | beforeEach('deploying', async function() { 14 | this.project = await PackageProject.fetchOrDeploy(version, { from: owner }, {}); 15 | }); 16 | 17 | shouldBehaveLikePackageProject({ 18 | fetch: async function() { 19 | const thepackage = await this.project.getProjectPackage(); 20 | this.project = await PackageProject.fetchOrDeploy( 21 | version, 22 | { from: owner }, 23 | { packageAddress: thepackage.address }, 24 | ); 25 | }, 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/lib/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib", 5 | "allowJs": false, 6 | "noEmitOnError": true, 7 | "declaration": true, 8 | "sourceMap": true 9 | }, 10 | "include": [ 11 | "./src" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/lib/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true 5 | }, 6 | "include": [ 7 | "./src" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/transpiler/.eslintignore: -------------------------------------------------------------------------------- 1 | /lib 2 | node_modules -------------------------------------------------------------------------------- /packages/transpiler/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['../../.eslintrc.base.js'], 3 | rules: { 4 | '@typescript-eslint/explicit-function-return-type': [ 5 | 'error', 6 | { 7 | allowExpressions: true, 8 | }, 9 | ], 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/transpiler/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib/ 3 | coverage/ 4 | coverage.json 5 | .node-xmlhttprequest-sync-* 6 | .session 7 | __upgradable__ 8 | build -------------------------------------------------------------------------------- /packages/transpiler/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require("../../.prettierrc.base.js"), 3 | }; 4 | -------------------------------------------------------------------------------- /packages/transpiler/src/solc/artifact.ts: -------------------------------------------------------------------------------- 1 | import { SourceUnit } from './ast-node'; 2 | 3 | export interface Artifact { 4 | contractName: string; 5 | fileName: string; 6 | ast: SourceUnit; 7 | source: string; 8 | sourcePath: string; 9 | } 10 | -------------------------------------------------------------------------------- /packages/transpiler/src/solc/get-inheritance-chain.ts: -------------------------------------------------------------------------------- 1 | import { getContract } from './ast-utils'; 2 | import { Artifact } from './artifact'; 3 | 4 | export function getInheritanceChain(contract: string, contractsToArtifactsMap: Record): Artifact[] { 5 | const art = contractsToArtifactsMap[contract]; 6 | const contractNode = getContract(art); 7 | 8 | return contractNode.linearizedBaseContracts.map(base => contractsToArtifactsMap[base]); 9 | } 10 | -------------------------------------------------------------------------------- /packages/transpiler/src/solc/schemas/ast.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Schema of an Abstract Syntax Tree Node. 3 | * This schema only describes the properies that are mandatory across all nodes. 4 | * Additional attrs can exist depending on the entity the Node represents. 5 | */ 6 | 7 | // A fully qualified, minimal object for this Schema is: 8 | /* 9 | { 10 | "nodeType": "Literal", 11 | } 12 | */ 13 | 14 | const array = { type: 'array' }, 15 | number = { type: 'number' }, 16 | bool = { type: 'boolean' }, 17 | string = { type: 'string' }, 18 | object = { type: 'object' }, 19 | attrNull = { type: 'null' }; 20 | 21 | export default { 22 | type: 'object', 23 | 24 | properties: { 25 | nodeType: { type: 'string', minLength: 1 }, 26 | }, 27 | 28 | patternProperties: { 29 | '^.+$': { 30 | oneOf: [array, string, object, number, attrNull, bool], 31 | }, 32 | }, 33 | 34 | required: ['nodeType'], 35 | additionalProperties: false, 36 | }; 37 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformation.ts: -------------------------------------------------------------------------------- 1 | export interface Transformation { 2 | start: number; 3 | end: number; 4 | text: string; 5 | } 6 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/append-directive.ts: -------------------------------------------------------------------------------- 1 | import { getImportDirectives, getPragmaDirectives, getSourceIndices } from '../solc/ast-utils'; 2 | import { Node } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | 5 | export function appendDirective(fileNode: Node, directive: string): Transformation { 6 | const retVal = { 7 | start: 0, 8 | end: 0, 9 | text: directive, 10 | }; 11 | const importsAndPragmas = [...getPragmaDirectives(fileNode), ...getImportDirectives(fileNode)]; 12 | if (importsAndPragmas.length) { 13 | const [last] = importsAndPragmas.slice(-1); 14 | const [start, len] = getSourceIndices(last); 15 | retVal.start = start + len; 16 | retVal.end = start + len; 17 | } 18 | 19 | return retVal; 20 | } 21 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/get-var-inits.ts: -------------------------------------------------------------------------------- 1 | import { getVarDeclarations, getNodeSources } from '../solc/ast-utils'; 2 | import { ContractDefinition, VariableDeclaration } from '../solc/ast-node'; 3 | 4 | export function getVarInits( 5 | contractNode: ContractDefinition, 6 | source: string, 7 | ): [VariableDeclaration, number, RegExpExecArray][] { 8 | const varDeclarations = getVarDeclarations(contractNode); 9 | return varDeclarations 10 | .filter(vr => vr.value && !vr.constant) 11 | .map(vr => { 12 | const [start, , varSource] = getNodeSources(vr, source); 13 | const match = /(.*)(=.*)/.exec(varSource); 14 | if (!match) throw new Error(`Can't find = in ${varSource}`); 15 | return [vr, start, match]; 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/index.ts: -------------------------------------------------------------------------------- 1 | export { appendDirective } from './append-directive'; 2 | export { prependBaseClass } from './prepend-base-class'; 3 | export { transformParentsNames } from './transform-parents'; 4 | export { transformContractName } from './transform-contract-name'; 5 | export { purgeVarInits } from './purge-var-inits'; 6 | export { transformConstructor } from './transform-constructor'; 7 | export { purgeExceptContracts } from './purge-contracts'; 8 | export { fixImportDirectives } from './fix-import-directives'; 9 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/prepend-base-class.ts: -------------------------------------------------------------------------------- 1 | import { getNodeSources } from '../solc/ast-utils'; 2 | import { ContractDefinition } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | 5 | export function prependBaseClass(contractNode: ContractDefinition, source: string, cls: string): Transformation { 6 | const hasInheritance = contractNode.baseContracts.length; 7 | 8 | const [start, , nodeSource] = getNodeSources(contractNode, source); 9 | 10 | const regExp = RegExp(`\\bcontract\\s+${contractNode.name}(\\s+is)?`); 11 | 12 | const match = regExp.exec(nodeSource); 13 | if (!match) throw new Error(`Can't find ${contractNode.name} in ${nodeSource}`); 14 | 15 | return { 16 | start: start + match.index + match[0].length, 17 | end: start + match.index + match[0].length, 18 | text: hasInheritance ? ` ${cls},` : ` is ${cls}`, 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/purge-contracts.ts: -------------------------------------------------------------------------------- 1 | import { getSourceIndices, getContracts } from '../solc/ast-utils'; 2 | import { SourceUnit } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | import { Artifact } from '../solc/artifact'; 5 | 6 | export function purgeExceptContracts(astNode: SourceUnit, contracts: Artifact[]): Transformation[] { 7 | const toPurge = getContracts(astNode).filter(node => contracts.every(c => node.name !== c.contractName)); 8 | return toPurge.map(contractNode => { 9 | const [start, len] = getSourceIndices(contractNode); 10 | 11 | return { 12 | start, 13 | end: start + len, 14 | text: '', 15 | }; 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/purge-var-inits.ts: -------------------------------------------------------------------------------- 1 | import { getVarInits } from './get-var-inits'; 2 | import { ContractDefinition } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | 5 | export function purgeVarInits(contractNode: ContractDefinition, source: string): Transformation[] { 6 | return getVarInits(contractNode, source).map(([, start, match]) => ({ 7 | start: start + match[1].length, 8 | end: start + match[1].length + match[2].length, 9 | text: '', 10 | })); 11 | } 12 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/transform-contract-name.ts: -------------------------------------------------------------------------------- 1 | import { getNodeSources } from '../solc/ast-utils'; 2 | import { ContractDefinition } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | 5 | export function transformContractName( 6 | contractNode: ContractDefinition, 7 | source: string, 8 | newName: string, 9 | ): Transformation { 10 | const [start, , nodeSource] = getNodeSources(contractNode, source); 11 | 12 | const subStart = nodeSource.indexOf(contractNode.name); 13 | if (subStart === -1) throw new Error(`Can't find ${contractNode.name} in ${nodeSource}`); 14 | 15 | return { 16 | start: start + subStart, 17 | end: start + subStart + contractNode.name.length, 18 | text: newName, 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /packages/transpiler/src/transformations/transform-parents.ts: -------------------------------------------------------------------------------- 1 | import { getNodeSources } from '../solc/ast-utils'; 2 | import { ContractDefinition } from '../solc/ast-node'; 3 | import { Transformation } from '../transformation'; 4 | import { Artifact } from '../solc/artifact'; 5 | 6 | export function transformParentsNames( 7 | contractNode: ContractDefinition, 8 | source: string, 9 | contracts: Artifact[], 10 | ): Transformation[] { 11 | const hasInheritance = contractNode.baseContracts.length; 12 | 13 | if (hasInheritance) { 14 | return contractNode.baseContracts 15 | .filter(base => contracts.map(o => o.contractName).includes(base.baseName.name)) 16 | .map(base => { 17 | const [start] = getNodeSources(base.baseName, source); 18 | const [, len] = getNodeSources(base, source); 19 | 20 | return { 21 | start: start, 22 | end: start + len, 23 | text: `${base.baseName.name}Upgradeable`, 24 | }; 25 | }); 26 | } else return []; 27 | } 28 | -------------------------------------------------------------------------------- /packages/transpiler/src/transpiler.ts: -------------------------------------------------------------------------------- 1 | import { Transformation } from './transformation'; 2 | 3 | export function transpile(source: string, transformations: Transformation[]): string { 4 | let cursor = 0; 5 | 6 | const sorted = transformations.sort((a, b) => { 7 | return a.start - b.start; 8 | }); 9 | 10 | for (let i = 0; i < sorted.length - 1; i++) { 11 | if (sorted[i].end > sorted[i + 1].start) 12 | throw new Error( 13 | `Transformations ${sorted[i].start}:${sorted[i].end}:${sorted[i].text.slice(20)}... and ${ 14 | sorted[i + 1].start 15 | }:${sorted[i + 1].end}:${sorted[i + 1].text.slice(20)}... overlap over the source file`, 16 | ); 17 | } 18 | 19 | let transpiledCode = sorted.reduce((output, trans) => { 20 | const { start, end, text } = trans; 21 | output += source.slice(cursor, start); 22 | output += text; 23 | cursor = end; 24 | return output; 25 | }, ''); 26 | 27 | transpiledCode += source.slice(cursor); 28 | return transpiledCode; 29 | } 30 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": [], 4 | "dependencies": {}, 5 | "name": "transpiler-test", 6 | "version": "1.0.0", 7 | "telemetryOptIn": false, 8 | "compiler": { 9 | "manager": "openzeppelin", 10 | "solcVersion": "0.5.16", 11 | "compilerSettings": { 12 | "optimizer": { 13 | "enabled": false, 14 | "runs": "200" 15 | } 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/ClassInheritance.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract CIA { 4 | uint256 public foo; 5 | event log(string); 6 | constructor(uint bar) public { 7 | foo = bar; 8 | emit log("SIA"); 9 | } 10 | } 11 | 12 | contract CIB is CIA(324) { 13 | uint256 public val = 123; 14 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/ComplexConstructor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract CCA { 4 | constructor(uint x) public { } 5 | } 6 | contract CCB is CCA { 7 | constructor(uint y) public CCA(y+1) { } 8 | } 9 | contract CCC is CCB { 10 | constructor(uint z) public CCB(z+1) { } 11 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/DiamondInheritance.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract DA { 4 | event Log(string); 5 | uint256 public foo = 42; 6 | constructor() public { 7 | emit Log("DA"); 8 | } 9 | } 10 | 11 | contract DB1 is DA { 12 | string public hello = "hello"; 13 | constructor() public { 14 | emit Log("DB1"); 15 | } 16 | } 17 | 18 | contract DB2 is DA { 19 | bool public bar = true; 20 | constructor() public { 21 | emit Log("DB2"); 22 | } 23 | } 24 | 25 | contract DC is DB2, DB1 { 26 | address public owner = address(0x123); 27 | constructor() public { 28 | emit Log("DC"); 29 | } 30 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/ElementaryTypes.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract ElementaryTypes { 4 | address public owner = address(0x123); 5 | bool active = true; 6 | string hello = "hello"; 7 | int count = -123; 8 | uint ucount = 123; 9 | bytes32 samevar = "stringliteral"; 10 | } 11 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/ElementaryTypesWithConstructor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract ElementaryTypesWithConstructor { 4 | address public owner; 5 | bool active; 6 | string hello; 7 | int count; 8 | uint ucount; 9 | bytes32 samevar; 10 | 11 | constructor() public { 12 | owner = address(0x123); 13 | active = true; 14 | hello = "hello"; 15 | count = -123; 16 | ucount = 123; 17 | samevar = "stringliteral"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/GLDToken.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol"; 5 | 6 | contract GLDToken is ERC20, ERC20Detailed { 7 | constructor(uint256 initialSupply) public ERC20Detailed("Gold", "GLD", 18) { 8 | _mint(msg.sender, initialSupply); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/Imports.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import * as ERC20 from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | import {ERC20Detailed as Detailed} from "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol"; 5 | import "@openzeppelin/contracts/math/Math.sol" as math; 6 | import { DA, DB1, DB2, DC } from "./DiamondInheritance.sol"; 7 | import "@openzeppelin/contracts/math/SafeMath.sol"; 8 | import "./one/two/three/Deep.sol"; 9 | 10 | contract Imports is ERC20.ERC20, Detailed, DC { 11 | constructor(uint256 initialSupply) public Detailed("Gold", "GLD", 18) { 12 | uint finalSupply = math.Math.max(0, initialSupply); 13 | _mint(msg.sender, SafeMath.add(finalSupply, 10)); 14 | } 15 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/SimpleInheritance.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract SIA { 4 | uint256 public foo; 5 | event log(string); 6 | constructor() public { 7 | emit log("SIA"); 8 | } 9 | } 10 | 11 | contract SIB is SIA { 12 | uint256 public val = 123; 13 | } 14 | 15 | contract SIC is SIB { 16 | string public bar = "hello"; 17 | constructor() public { 18 | bar = "changed"; 19 | emit log("SIC"); 20 | } 21 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/StringConstructor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract StringConstructor { 4 | constructor(string memory message) public { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/contracts/one/two/three/Deep.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "../../../ElementaryTypes.sol"; 4 | 5 | contract Deep {} -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['/test'], 3 | transform: { 4 | '^.+\\.tsx?$': 'ts-jest', 5 | }, 6 | globals: { 7 | 'ts-jest': { 8 | diagnostics: true, 9 | }, 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transpiler-test", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": ".src/index.ts", 6 | "scripts": { 7 | "clean": "rm -rf build/contracts && rm -rf contracts/__upgradable__", 8 | "compile:contracts": "../../../../bootstrap/node_modules/.bin/oz compile", 9 | "test": "npm run clean && npm run compile:contracts && jest --verbose" 10 | }, 11 | "author": "Igor Yalovoy ", 12 | "license": "MIT", 13 | "dependencies": { 14 | "@openzeppelin/contracts": "^2.4.0" 15 | }, 16 | "devDependencies": { 17 | "@types/jest": "^24.0.25", 18 | "fs-extra": "^8.1.0", 19 | "jest": "^24.9.0", 20 | "ts-jest": "^24.3.0", 21 | "ts-node": "^8.5.4" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/ClassInheritance.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`ClassInheritance contract`, (): void => { 4 | shouldTranspileToValidContract('CIB', { 5 | CIB: { 6 | path: 'ClassInheritance', 7 | fileName: 'ClassInheritance', 8 | contracts: ['CIB', 'CIA'], 9 | }, 10 | CIA: { 11 | path: 'ClassInheritance', 12 | fileName: 'ClassInheritance', 13 | contracts: ['CIA'], 14 | }, 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/DiamondInheritance.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`Diamond contract`, (): void => { 4 | shouldTranspileToValidContract('DC', { 5 | DC: { 6 | path: 'DiamondInheritance', 7 | fileName: 'DiamondInheritance', 8 | contracts: ['DC', 'DB1', 'DB2', 'DA'], 9 | }, 10 | DB1: { 11 | path: 'DiamondInheritance', 12 | fileName: 'DiamondInheritance', 13 | contracts: ['DC', 'DB1', 'DB2', 'DA'], 14 | }, 15 | DB2: { 16 | path: 'DiamondInheritance', 17 | fileName: 'DiamondInheritance', 18 | contracts: ['DC', 'DB1', 'DB2', 'DA'], 19 | }, 20 | DA: { 21 | path: 'DiamondInheritance', 22 | fileName: 'DiamondInheritance', 23 | contracts: ['DC', 'DB1', 'DB2', 'DA'], 24 | }, 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/ElementaryTypes.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`ElementaryTypes contract`, (): void => { 4 | shouldTranspileToValidContract('ElementaryTypes', { 5 | ElementaryTypes: { 6 | path: 'ElementaryTypes', 7 | fileName: 'ElementaryTypes', 8 | contracts: ['ElementaryTypes'], 9 | }, 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/ElementaryTypesWithConstructor.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`ElementaryTypesWithConstructor contract`, (): void => { 4 | shouldTranspileToValidContract('ElementaryTypesWithConstructor', { 5 | ElementaryTypesWithConstructor: { 6 | path: 'ElementaryTypesWithConstructor', 7 | fileName: 'ElementaryTypesWithConstructor', 8 | contracts: ['ElementaryTypesWithConstructor'], 9 | }, 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/GLDToken.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`GLDToken contract`, (): void => { 4 | shouldTranspileToValidContract('GLDToken', { 5 | GLDToken: { 6 | path: 'GLDToken', 7 | fileName: 'GLDToken', 8 | contracts: ['GLDToken'], 9 | }, 10 | ERC20Detailed: { 11 | path: '@openzeppelin/contracts/token/ERC20/ERC20Detailed', 12 | fileName: 'ERC20Detailed', 13 | contracts: ['ERC20Detailed'], 14 | }, 15 | ERC20: { 16 | path: '@openzeppelin/contracts/token/ERC20/ERC20', 17 | fileName: 'ERC20', 18 | contracts: ['ERC20'], 19 | }, 20 | Context: { 21 | path: '@openzeppelin/contracts/GSN/Context', 22 | fileName: 'Context', 23 | contracts: ['Context'], 24 | }, 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/Imports.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | // todo: once all imports are supported enable this test 4 | describe(`Import contract`, (): void => { 5 | shouldTranspileToValidContract('Imports', { 6 | Imports: { 7 | path: 'Imports', 8 | fileName: 'Imports', 9 | contracts: ['Imports'], 10 | }, 11 | DC: { 12 | path: 'DiamondInheritance', 13 | fileName: 'DiamondInheritance', 14 | contracts: ['DC', 'DB1', 'DB2', 'DA'], 15 | }, 16 | ERC20Detailed: { 17 | path: '@openzeppelin/contracts/token/ERC20/ERC20Detailed', 18 | fileName: 'ERC20Detailed', 19 | contracts: ['ERC20Detailed'], 20 | }, 21 | ERC20: { 22 | path: '@openzeppelin/contracts/token/ERC20/ERC20', 23 | fileName: 'ERC20', 24 | contracts: ['ERC20'], 25 | }, 26 | Context: { 27 | path: '@openzeppelin/contracts/GSN/Context', 28 | fileName: 'Context', 29 | contracts: ['Context'], 30 | }, 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/LocalContract.behaviour.ts: -------------------------------------------------------------------------------- 1 | import { transpileContracts, OutputFile } from '../../../src/index'; 2 | import { artifacts } from './setup'; 3 | 4 | export function shouldTranspileToValidContract(contract: string, output: Record>): void { 5 | it(`is converted to a valid ${contract}Upgradeable contract`, (): void => { 6 | const files = transpileContracts([contract], artifacts, './contracts/'); 7 | 8 | for (const file of files) { 9 | const key = file.contracts[0]; 10 | expect(file.source).toMatchSnapshot(); 11 | expect(file.fileName).toBe(`${output[key].fileName}.sol`); 12 | expect(file.path).toBe(`./contracts/__upgradeable__/${output[key].path}Upgradeable.sol`); 13 | expect(file.contracts).toEqual(output[key].contracts); 14 | } 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/SimpleInheritance.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`SimpleInheritance contract`, (): void => { 4 | shouldTranspileToValidContract('SIC', { 5 | SIC: { 6 | path: 'SimpleInheritance', 7 | fileName: 'SimpleInheritance', 8 | contracts: ['SIC', 'SIB', 'SIA'], 9 | }, 10 | SIB: { 11 | path: 'SimpleInheritance', 12 | fileName: 'SimpleInheritance', 13 | contracts: ['SIB', 'SIA'], 14 | }, 15 | SIA: { 16 | path: 'SimpleInheritance', 17 | fileName: 'SimpleInheritance', 18 | contracts: ['SIA'], 19 | }, 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/StringConstructor.test.ts: -------------------------------------------------------------------------------- 1 | import { shouldTranspileToValidContract } from './LocalContract.behaviour'; 2 | 3 | describe(`StringConstructor contract`, (): void => { 4 | shouldTranspileToValidContract('StringConstructor', { 5 | StringConstructor: { 6 | path: 'StringConstructor', 7 | fileName: 'StringConstructor', 8 | contracts: ['StringConstructor'], 9 | }, 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/__snapshots__/ElementaryTypes.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`ElementaryTypes contract is converted to a valid ElementaryTypesUpgradeable contract 1`] = ` 4 | "pragma solidity ^0.5.0; 5 | import \\"@openzeppelin/upgrades/contracts/Initializable.sol\\"; 6 | 7 | contract ElementaryTypesUpgradeable is Initializable { 8 | function initialize() external initializer { 9 | __init(true); 10 | } 11 | 12 | function __init(bool callChain) internal { 13 | 14 | 15 | owner = address(0x123); 16 | active = true; 17 | hello = \\"hello\\"; 18 | count = -123; 19 | ucount = 123; 20 | samevar = \\"stringliteral\\"; 21 | 22 | } 23 | 24 | address public owner ; 25 | bool active ; 26 | string hello ; 27 | int count ; 28 | uint ucount ; 29 | bytes32 samevar ; 30 | } 31 | " 32 | `; 33 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/__snapshots__/ElementaryTypesWithConstructor.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`ElementaryTypesWithConstructor contract is converted to a valid ElementaryTypesWithConstructorUpgradeable contract 1`] = ` 4 | "pragma solidity ^0.5.0; 5 | import \\"@openzeppelin/upgrades/contracts/Initializable.sol\\"; 6 | 7 | contract ElementaryTypesWithConstructorUpgradeable is Initializable { 8 | function initialize() external initializer { 9 | __init(true); 10 | } 11 | 12 | function __init(bool callChain) internal { 13 | 14 | 15 | 16 | owner = address(0x123); 17 | active = true; 18 | hello = \\"hello\\"; 19 | count = -123; 20 | ucount = 123; 21 | samevar = \\"stringliteral\\"; 22 | 23 | } 24 | 25 | address public owner; 26 | bool active; 27 | string hello; 28 | int count; 29 | uint ucount; 30 | bytes32 samevar; 31 | 32 | 33 | } 34 | " 35 | `; 36 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/__snapshots__/StringConstructor.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`StringConstructor contract is converted to a valid StringConstructorUpgradeable contract 1`] = ` 4 | "pragma solidity ^0.5.0; 5 | import \\"@openzeppelin/upgrades/contracts/Initializable.sol\\"; 6 | 7 | contract StringConstructorUpgradeable is Initializable { 8 | function initialize(string calldata message) external initializer { 9 | __init(true, message); 10 | } 11 | 12 | function __init(bool callChain, string memory message) internal { 13 | 14 | 15 | 16 | 17 | 18 | } 19 | 20 | 21 | }" 22 | `; 23 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/compile.test.ts: -------------------------------------------------------------------------------- 1 | import { transpileAndSaveContracts, compileContracts } from './setup'; 2 | 3 | describe('When all the contracts transpilied and saved to contracts folder', (): void => { 4 | beforeAll( 5 | async (): Promise => { 6 | await transpileAndSaveContracts( 7 | [ 8 | 'GLDToken', 9 | 'ElementaryTypesWithConstructor', 10 | 'ElementaryTypes', 11 | 'Deep', 12 | 'SIC', 13 | 'DC', 14 | 'CIB', 15 | 'StringConstructor', 16 | ], 17 | './build/contracts/', 18 | ); 19 | }, 20 | ); 21 | it('upgradeable contracts successfully compile', async (): Promise => { 22 | jest.setTimeout(10000); 23 | await compileContracts(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/test/setup.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs-extra'; 2 | import path from 'path'; 3 | import util from 'util'; 4 | import child from 'child_process'; 5 | 6 | const exec = util.promisify(child.exec); 7 | 8 | import { transpileContracts } from '../../../src/'; 9 | 10 | export async function transpileAndSaveContracts(contracts: string[], dir: string): Promise { 11 | const artifacts = fs.readdirSync(dir).map(file => { 12 | return JSON.parse(fs.readFileSync(`${dir}${file}`).toString()); 13 | }); 14 | 15 | const output = transpileContracts(contracts, artifacts, './contracts'); 16 | 17 | for (const file of output) { 18 | await fs.ensureDir(path.dirname(file.path)); 19 | fs.writeFileSync(file.path, file.source); 20 | } 21 | } 22 | 23 | export async function compileContracts(): Promise { 24 | await exec('npm run compile:contracts'); 25 | } 26 | 27 | export const artifacts = fs.readdirSync('./build/contracts/').map(file => { 28 | return JSON.parse(fs.readFileSync(`./build/contracts/${file}`).toString()); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/transpiler/test/solc-0.5/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | } -------------------------------------------------------------------------------- /packages/transpiler/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./lib", 5 | "noEmitOnError": true, 6 | "declaration": true, 7 | "sourceMap": true, 8 | "strict": true, 9 | "allowJs": false, 10 | "lib": [ 11 | "es2019" 12 | ] 13 | }, 14 | "include": ["./src"] 15 | } 16 | -------------------------------------------------------------------------------- /scripts/check-yarn-lockfile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | git diff yarn.lock 4 | 5 | if ! git diff --exit-code yarn.lock; then 6 | echo "Changes were detected in yarn.lock file after running 'yarn install', which is not expected. Please run 'yarn install' locally and commit the changes."; 7 | exit 1; 8 | fi 9 | -------------------------------------------------------------------------------- /tests/cli/.gitignore: -------------------------------------------------------------------------------- 1 | test/.ethereum 2 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./InternalLibrary.sol"; 4 | 5 | contract Greeter { 6 | using Numbers for uint256; 7 | 8 | string public who; 9 | 10 | constructor(string memory _who) public { 11 | who = _who; 12 | } 13 | 14 | function minor() public pure returns (uint256) { 15 | return 1; 16 | } 17 | 18 | function doubles(uint256 x) public pure returns (uint256) { 19 | return x.double(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/contracts/InternalLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library Numbers { 4 | function double(uint256 self) public pure returns (uint256) { 5 | return self * 2; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/contracts/Parent.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Parent { 4 | function extendsParent() public pure returns (bool) { 5 | return true; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/contracts/SharedLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library SharedNumbers { 4 | function triple(uint256 self) public pure returns (uint256) { 5 | return self * 3; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/dependencies/mock-stdlib-1.1.0/migrations/.gitkeep -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "version": "1.1.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/truffle.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/dependencies/mock-stdlib-1.1.0/truffle.js -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.1.0/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "manifestVersion": "2", 4 | "version": "1.1.0", 5 | "contracts": ["Greeter"] 6 | } 7 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "./InternalLibrary.sol"; 4 | 5 | contract Greeter { 6 | using Numbers for uint256; 7 | 8 | string public who; 9 | 10 | constructor(string memory _who) public { 11 | who = _who; 12 | } 13 | 14 | function minor() public pure returns (uint256) { 15 | return 2; 16 | } 17 | 18 | function doubles(uint256 x) public pure returns (uint256) { 19 | return x.double(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/contracts/InternalLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library Numbers { 4 | function double(uint256 self) public pure returns (uint256) { 5 | return self * 2 + 1; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/contracts/Parent.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Parent { 4 | function extendsParent() public pure returns (bool) { 5 | return true; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/contracts/SharedLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | library SharedNumbers { 4 | function triple(uint256 self) public pure returns (uint256) { 5 | return self * 3 + 1; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/dependencies/mock-stdlib-1.2.0/migrations/.gitkeep -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "version": "1.2.0", 4 | "description": "Mock stdlib for tests in zos-cli", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "truffle test" 9 | }, 10 | "author": "santiago@zeppelin.solutions", 11 | "license": "MIT" 12 | } 13 | -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/truffle.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/dependencies/mock-stdlib-1.2.0/truffle.js -------------------------------------------------------------------------------- /tests/cli/dependencies/mock-stdlib-1.2.0/zos.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-stdlib", 3 | "manifestVersion": "2", 4 | "version": "1.2.0", 5 | "contracts": ["Greeter"] 6 | } 7 | -------------------------------------------------------------------------------- /tests/cli/test/README.md: -------------------------------------------------------------------------------- 1 | # CLI app integration test 2 | 3 | Integration tests for a ZeppelinOS CLI app project. -------------------------------------------------------------------------------- /tests/cli/test/files/GreeterWrapper.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "mock-stdlib/contracts/Greeter.sol"; 4 | 5 | contract GreeterWrapper { 6 | Greeter public greeter; 7 | 8 | constructor(Greeter _greeter) public { 9 | require(address(_greeter) != address(0)); 10 | greeter = _greeter; 11 | } 12 | 13 | function say() public view returns (string memory) { 14 | return greeter.who(); 15 | } 16 | 17 | function iteration() public view returns (uint256) { 18 | return greeter.minor(); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/cli/test/files/GreeterWrapperV2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "mock-stdlib/contracts/Greeter.sol"; 4 | import "mock-stdlib/contracts/SharedLibrary.sol"; 5 | 6 | contract GreeterWrapper { 7 | using SharedNumbers for uint256; 8 | Greeter public greeter; 9 | 10 | constructor(Greeter _greeter) public { 11 | require(address(_greeter) != address(0)); 12 | greeter = _greeter; 13 | } 14 | 15 | function say() public view returns (string memory) { 16 | return greeter.who(); 17 | } 18 | 19 | function iteration() public view returns (uint256) { 20 | return greeter.minor().triple() + 10; 21 | } 22 | } -------------------------------------------------------------------------------- /tests/cli/test/files/Samples.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "mock-stdlib/contracts/Parent.sol"; 4 | 5 | contract Foo is Parent { 6 | function say() public pure returns(string memory) { 7 | return "Foo"; 8 | } 9 | } 10 | 11 | contract Bar { 12 | function say() public pure returns(string memory) { 13 | return "Bar"; 14 | } 15 | } 16 | 17 | contract Baz { 18 | function say() public pure returns(string memory) { 19 | return "Baz"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/cli/test/files/SamplesV2.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "mock-stdlib/contracts/Parent.sol"; 4 | 5 | contract Foo is Parent { 6 | function say() public pure returns (string memory) { 7 | return "FooV2"; 8 | } 9 | } 10 | 11 | contract Bar { 12 | function say() public pure returns (string memory) { 13 | return "BarV2"; 14 | } 15 | } 16 | 17 | contract Baz { 18 | function say() public pure returns (string memory) { 19 | return "BazV2"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/cli/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tests-cli-test", 3 | "private": true, 4 | "version": "2.8.0-rc.0", 5 | "description": "Integration tests for CLI app", 6 | "author": "santiago@zeppelin.solutions", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "scripts/test.sh" 10 | }, 11 | "devDependencies": { 12 | "chai": "^4.1.2", 13 | "lodash": "^4.17.0", 14 | "mocha": "5.2.0", 15 | "truffle": "^4.1.14", 16 | "truffle-hdwallet-provider": "0.0.6" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/cli/test/scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source "../../util/test.sh" -------------------------------------------------------------------------------- /tests/cli/test/truffle.js: -------------------------------------------------------------------------------- 1 | ../workdir/truffle.js -------------------------------------------------------------------------------- /tests/cli/workdir/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .zos.session 3 | build/* 4 | node_modules 5 | zos.* 6 | contracts/* 7 | 8 | .openzeppelin/.session 9 | -------------------------------------------------------------------------------- /tests/cli/workdir/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/workdir/.gitkeep -------------------------------------------------------------------------------- /tests/cli/workdir/contracts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/workdir/contracts/.gitkeep -------------------------------------------------------------------------------- /tests/cli/workdir/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/cli/workdir/migrations/.gitkeep -------------------------------------------------------------------------------- /tests/cli/workdir/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tests-cli-workdir", 3 | "private": true, 4 | "version": "2.8.0-rc.0", 5 | "description": "CLI app project for ZeppelinOS integration test", 6 | "author": "santiago@openzeppelin.com", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@openzeppelin/upgrades": "2.8.0-rc.0", 10 | "bignumber.js": "^7.2.0", 11 | "mock-stdlib": "file:../dependencies/mock-stdlib-1.1.0", 12 | "truffle-hdwallet-provider": "0.0.6" 13 | }, 14 | "devDependencies": { 15 | "@openzeppelin/cli": "2.8.0-rc.0", 16 | "truffle": "^5.1.16" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/cli/workdir/scripts/getaccounts.js: -------------------------------------------------------------------------------- 1 | function getAccounts() { 2 | return new Promise((resolve, reject) => { 3 | web3.eth.getAccounts((err, accounts) => { 4 | if (err) reject(err); 5 | resolve(accounts); 6 | }); 7 | }); 8 | } 9 | 10 | module.exports = function(cb) { 11 | getAccounts() 12 | .then(accounts => { 13 | console.log(accounts.join(",")); 14 | cb(); 15 | }) 16 | .catch(cb); 17 | }; 18 | -------------------------------------------------------------------------------- /tests/cli/workdir/truffle.js: -------------------------------------------------------------------------------- 1 | const HDWalletProvider = require("truffle-hdwallet-provider") 2 | const mnemonic = process.env.MNEMONIC || 'canyon spice man sun shiver science endless review senior lawsuit same glimpse' 3 | 4 | module.exports = { 5 | networks: { 6 | "geth-dev": { 7 | host: 'localhost', 8 | port: 8545, 9 | network_id: '9955', 10 | gasPrice: 1e9 11 | }, 12 | "geth-dev-hdwallet": { 13 | provider: function() { 14 | return new HDWalletProvider(mnemonic, "http://localhost:8545/") 15 | }, 16 | network_id: '9955', 17 | gasPrice: 1e9 18 | }, 19 | "rinkeby-infura-hdwallet": { 20 | provider: function() { 21 | return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/") 22 | }, 23 | network_id: '4', 24 | gasPrice: 1e9 25 | } 26 | } 27 | }; -------------------------------------------------------------------------------- /tests/deploy/.gitignore: -------------------------------------------------------------------------------- 1 | /.openzeppelin 2 | /extra-networks.json 3 | /contracts/__upgradeable__ 4 | -------------------------------------------------------------------------------- /tests/deploy/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": [ 4 | "Answer", 5 | "ValueWithConstructor" 6 | ], 7 | "dependencies": {}, 8 | "name": "regular-deploys", 9 | "version": "0.1.0", 10 | "compiler": { 11 | "compilerSettings": { 12 | "optimizer": { 13 | "enabled": false, 14 | "runs": "200" 15 | } 16 | }, 17 | "typechain": { 18 | "enabled": false 19 | }, 20 | "manager": "openzeppelin", 21 | "solcVersion": "0.5.16", 22 | "artifactsDir": "build/contracts", 23 | "contractsDir": "contracts" 24 | }, 25 | "telemetryOptIn": false 26 | } 27 | -------------------------------------------------------------------------------- /tests/deploy/contracts/Answer.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Answer { 4 | function answer() public view returns (uint) { 5 | return 42; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/deploy/contracts/ValueWithConstructor.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5; 2 | 3 | contract ValueWithConstructor { 4 | uint public value; 5 | constructor (uint x, uint y) public { 6 | value = x * y; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/deploy/networks.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | const extra = fs.existsSync('extra-networks.json') 4 | ? JSON.parse(fs.readFileSync('extra-networks.json')) 5 | : {}; 6 | 7 | module.exports = { 8 | networks: { 9 | 'geth-dev': { 10 | url: 'http://localhost:8545', 11 | networkId: '9955', 12 | gasPrice: 1e9, 13 | }, 14 | ...extra 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /tests/deploy/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tests-deploy-command", 3 | "version": "2.8.0-rc.0", 4 | "scripts": { 5 | "test": "node test.js" 6 | }, 7 | "license": "MIT", 8 | "private": true, 9 | "dependencies": { 10 | "@openzeppelin/cli": "2.8.0-rc.0", 11 | "@openzeppelin/test-environment": "^0.1.3" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/kits/.gitignore: -------------------------------------------------------------------------------- 1 | test/.ethereum 2 | 3 | workdir/ 4 | !workdir/.gitkeep 5 | -------------------------------------------------------------------------------- /tests/kits/test/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '../../../.eslintrc.base.js', 4 | ], 5 | }; -------------------------------------------------------------------------------- /tests/kits/test/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | ...require("../../../.prettierrc.base.js"), 3 | }; 4 | -------------------------------------------------------------------------------- /tests/kits/test/README.md: -------------------------------------------------------------------------------- 1 | # Starter kits integration test 2 | 3 | Integration tests for Starter kits and an unpack command. -------------------------------------------------------------------------------- /tests/kits/test/counter.patch: -------------------------------------------------------------------------------- 1 | 3,4d2 2 | < // import "openzeppelin-eth/contracts/ownership/Ownable.sol"; 3 | < import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | 6c4 5 | < contract Counter is Initializable { 6 | --- 7 | > contract Counter { 8 | 11c9 9 | < function initialize(uint num) public initializer { 10 | --- 11 | > constructor(uint num) public { 12 | -------------------------------------------------------------------------------- /tests/kits/test/gsn.patch: -------------------------------------------------------------------------------- 1 | 3,4c3 2 | < import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol"; 3 | < import "@openzeppelin/upgrades/contracts/Initializable.sol"; 4 | --- 5 | > import "@openzeppelin/contracts/GSN/GSNRecipient.sol"; 6 | 6c5 7 | < contract Counter is Initializable, GSNRecipient { 8 | --- 9 | > contract Counter is GSNRecipient { 10 | 11,12c10 11 | < function initialize(uint num) public initializer { 12 | < GSNRecipient.initialize(); 13 | --- 14 | > constructor(uint num) public { 15 | -------------------------------------------------------------------------------- /tests/kits/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tests-kit-test", 3 | "private": true, 4 | "version": "2.8.0-rc.0", 5 | "description": "Integration tests for Starter kits and an unpack command", 6 | "author": "igor@zeppelin.solutions", 7 | "license": "MIT", 8 | "scripts": { 9 | "test": "scripts/test.sh" 10 | }, 11 | "devDependencies": { 12 | "@typescript-eslint/eslint-plugin": "^1.11.0", 13 | "@typescript-eslint/parser": "^1.11.0", 14 | "chai": "^4.1.2", 15 | "eslint": "^5.16.0", 16 | "eslint-config-prettier": "^6.0.0", 17 | "eslint-plugin-prettier": "^3.1.0", 18 | "lodash": "^4.17.0", 19 | "mocha": "5.2.0", 20 | "prettier": "^1.18.2", 21 | "truffle": "5.0.21", 22 | "typescript": "^3.5.2" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/kits/test/scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source "../../util/test.sh" -------------------------------------------------------------------------------- /tests/kits/workdir/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/kits/workdir/.gitkeep -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/.gitignore: -------------------------------------------------------------------------------- 1 | !build/ 2 | -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/contracts/DependencyInvalid.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract DependencyWithConstructor { 4 | uint256 public dependencyValue; 5 | constructor() public { 6 | dependencyValue = 42; 7 | } 8 | } -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/contracts/DependencyStorageMock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract DependencyStorageMock { 4 | enum MyEnum { State1, State2 } 5 | struct MyStruct { uint256 value; } 6 | } -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/contracts/Greeter.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | contract Greeter { 4 | event Greeting(string greeting); 5 | 6 | function greet(string memory who) public { 7 | emit Greeting(greeting(who)); 8 | } 9 | 10 | function greeting(string memory who) public pure returns (string memory) { 11 | return who; 12 | } 13 | 14 | function say() public pure returns (string memory) { 15 | return "hello"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/migrations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/mocks/mock-dependency/migrations/.gitkeep -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-dependency", 3 | "version": "2.8.0-rc.0", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-dependency", 3 | "version": "2.8.0-rc.0", 4 | "description": "Mock dependency for tests in zos-lib", 5 | "private": true, 6 | "author": "facundo@zeppelin.solutions", 7 | "license": "MIT" 8 | } 9 | -------------------------------------------------------------------------------- /tests/mocks/mock-dependency/truffle.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // See 3 | // to customize your Truffle configuration! 4 | }; 5 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/.gitignore: -------------------------------------------------------------------------------- 1 | !build/ 2 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/.openzeppelin/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifestVersion": "2.2", 3 | "contracts": [], 4 | "dependencies": {}, 5 | "name": "mock-solc-0.6", 6 | "version": "1.0.0", 7 | "telemetryOptIn": false, 8 | "compiler": { 9 | "manager": "openzeppelin", 10 | "solcVersion": "0.6.2", 11 | "compilerSettings": { 12 | "optimizer": { 13 | "enabled": false, 14 | "runs": "200" 15 | } 16 | }, 17 | "artifactsDir": "build/contracts", 18 | "contractsDir": "contracts", 19 | "typechain": {} 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/contracts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-sdk/7d96de7248ae2e7e81a743513ccc617a2e6bba21/tests/mocks/mock-solc-0.6/contracts/.gitkeep -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/contracts/Sample.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | contract Base { 4 | function basePure() public pure { } 5 | function basePayable() public payable { } 6 | } 7 | 8 | contract Sample is Base { 9 | uint256 public value; 10 | 11 | function samplePure(uint256 x) public pure returns (uint256) { return x; } 12 | function sampleView() public view returns (uint256) { return value; } 13 | function samplePayable() public payable { value = value + 1; } 14 | function sampleNonpayable(uint256 x) public { value = value + x; } 15 | } 16 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/contracts/initializable/Initializable.sol: -------------------------------------------------------------------------------- 1 | ../../../../../contracts/Initializable.sol -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/contracts/initializable/InitializableMock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import "./Initializable.sol"; 4 | 5 | /** 6 | * @title InitializableMock 7 | * @dev This contract is a mock to test initializable functionality 8 | */ 9 | contract InitializableMock is Initializable { 10 | 11 | bool public initializerRan; 12 | uint256 public x; 13 | 14 | function initialize() public initializer { 15 | initializerRan = true; 16 | } 17 | 18 | function initializeNested() public initializer { 19 | initialize(); 20 | } 21 | 22 | function initializeWithX(uint256 _x) public payable initializer { 23 | x = _x; 24 | } 25 | 26 | function nonInitializable(uint256 _x) public payable { 27 | x = _x; 28 | } 29 | 30 | function fail() public pure { 31 | require(false, "InitializableMock forced failure"); 32 | } 33 | 34 | function secret() private pure returns (string memory) { 35 | return 'Im secret'; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/networks.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | networks: { 3 | development: { 4 | protocol: 'http', 5 | host: 'localhost', 6 | port: 8545, 7 | gas: 5000000, 8 | gasPrice: 5e9, 9 | networkId: '*', 10 | }, 11 | }, 12 | }; 13 | -------------------------------------------------------------------------------- /tests/mocks/mock-solc-0.6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mock-solc-0.6", 3 | "version": "2.8.0-rc.0", 4 | "description": "", 5 | "main": "index.js", 6 | "private": true, 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC" 13 | } 14 | -------------------------------------------------------------------------------- /tests/util/fund.js: -------------------------------------------------------------------------------- 1 | module.exports = function(cb) { 2 | web3.eth.sendTransaction({ from: web3.eth.accounts[0], to: process.env.RECIPIENT_ACCOUNT, value: 1000e18 }, cb); 3 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "pretty": true, 5 | "disableSizeLimit": true, 6 | "module": "commonjs", 7 | "moduleResolution": "Node", 8 | "target": "es2017", 9 | "allowJs": true, 10 | "checkJs": false, 11 | "strict": false, 12 | "resolveJsonModule": true, 13 | "esModuleInterop": true, 14 | "lib": ["es2017"], 15 | "declarationMap": true 16 | }, 17 | "exclude": ["**/node_modules/*", "**/*.spec.ts"] 18 | } 19 | --------------------------------------------------------------------------------