Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Support contracts with the same name #1203
Browse files Browse the repository at this point in the history
  • Loading branch information
melnikaite committed Sep 11, 2019
1 parent 4577820 commit 4614d75
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"ethereumjs-util": "^6.1.0",
"find-up": "^3.0.0",
"fs-extra": "^7.0.1",
"fs-readdir-recursive": "^1.1.0",
"inquirer": "^6.4.1",
"is-url": "^1.2.4",
"lockfile": "^1.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import pick from 'lodash.pick';
import omitBy from 'lodash.omitby';
import isUndefined from 'lodash.isundefined';
import { readJsonSync, ensureDirSync, readJSON, writeJson, unlink } from 'fs-extra';
import { statSync, existsSync, readdirSync, lstatSync } from 'fs';
import { statSync, existsSync, lstatSync } from 'fs';
import readdirSync from 'fs-readdir-recursive';
import { Loggy, Contracts } from '@openzeppelin/upgrades';
import {
RawContract,
Expand Down Expand Up @@ -188,7 +189,9 @@ class SolidityProjectCompiler {
await Promise.all(
this.compilerOutput.map(async data => {
const name = data.contractName;
const buildFileName = `${this.outputDir}/${name}.json`;
const buildDirName = `${this.outputDir}/${data.sourcePath.replace(/^contracts\/(.*)$/, `$1`)}`;
ensureDirSync(buildDirName);
const buildFileName = `${buildDirName}/${name}.json`;
if (networksInfo[name]) Object.assign(data, { networks: networksInfo[name] });
await writeJson(buildFileName, data, { spaces: 2 });
}),
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/models/local/ContractManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Dependency from '../dependency/Dependency';
import ProjectFile from '../files/ProjectFile';
import ConfigManager from '../config/ConfigManager';
import path from 'path';
import readdirSync from 'fs-readdir-recursive';

export default class ContractManager {
public projectFile: ProjectFile;
Expand Down Expand Up @@ -35,7 +36,7 @@ export default class ContractManager {
const buildDir = ConfigManager.getBuildDir();
const contractsDir = Contracts.getLocalContractsDir();
if (FileSystem.exists(buildDir)) {
return FileSystem.readDir(buildDir)
return readdirSync(buildDir)
.filter(name => name.match(/\.json$/))
.map(name => FileSystem.parseJsonIfExists(`${buildDir}/${name}`))
.filter(contract => {
Expand All @@ -45,7 +46,7 @@ export default class ContractManager {
!this.isAbstractContract(contract)
);
})
.map(({ contractName }) => contractName);
.map(({ sourcePath, contractName }) => `${sourcePath.replace(/contracts\/(.*)/, `$1`)}/${contractName}`);
} else return [];
}

Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/utils/naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function toContractFullName(packageName: string, contractName: string): s
export function fromContractFullName(contractFullName: string): { contract?: string; package?: string } {
if (!contractFullName) return {};
const fragments = contractFullName.split('/');
const contractName = fragments.pop();
if (fragments.length === 0) return { contract: contractName };
else return pickBy({ contract: contractName, package: fragments.join('/') });
if (fragments.length === 2) return { contract: contractFullName };
else return pickBy({ contract: fragments.slice(1).join('/'), package: fragments[0] });
}
10 changes: 5 additions & 5 deletions packages/cli/test/commands/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('create command', function() {
itShouldParse(
'should call create script with options',
'create',
'zos create Impl --network test --init setup --args 42 --force --from 0x40',
'zos create Impl.sol/Impl --network test --init setup --args 42 --force --from 0x40',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Impl',
Expand All @@ -26,7 +26,7 @@ describe('create command', function() {
itShouldParse(
'should call create script with kind',
'create',
'zos create Impl --network test --init setup --args 42 --force --from 0x40 --minimal',
'zos create Impl.sol/Impl --network test --init setup --args 42 --force --from 0x40 --minimal',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Impl',
Expand All @@ -43,7 +43,7 @@ describe('create command', function() {
itShouldParse(
'should call create script with options',
'create',
'zos create Boolean --network test --init initialize --args false --force --from 0x40',
'zos create Boolean.sol/Boolean --network test --init initialize --args false --force --from 0x40',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Boolean',
Expand All @@ -59,7 +59,7 @@ describe('create command', function() {
itShouldParse(
'should call create script with default init method',
'create',
'zos create Impl --network test --init --args 42 --force --from 0x40',
'zos create Impl.sol/Impl --network test --init --args 42 --force --from 0x40',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Impl',
Expand All @@ -75,7 +75,7 @@ describe('create command', function() {
itShouldParse(
'should call create script with init if only args is provided',
'create',
'zos create Impl --network test --args 42 --force --from 0x40',
'zos create Impl.sol/Impl --network test --args 42 --force --from 0x40',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Impl',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/commands/create2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract('create2 command', function() {
itShouldParse(
'should call create2 script with options',
'create',
'zos create2 Impl --network test --init setup --args 42 --force --salt 10 --from 0x40 --signature 0x80',
'zos create2 Impl.sol/Impl --network test --init setup --args 42 --force --salt 10 --from 0x40 --signature 0x80',
function(create) {
create.should.have.been.calledWithExactly({
contractAlias: 'Impl',
Expand Down Expand Up @@ -41,7 +41,7 @@ contract('create2 command', function() {
itShouldParse(
'should call create2 script querying signature',
'querySignedDeployment',
'zos create2 Impl --query --init setup --args 42 --signature 0x80 --network test --salt 10 --from 0x40',
'zos create2 Impl.sol/Impl --query --init setup --args 42 --signature 0x80 --network test --salt 10 --from 0x40',
function(querySignedDeployment) {
querySignedDeployment.should.have.been.calledWithExactly({
network: 'test',
Expand Down

0 comments on commit 4614d75

Please sign in to comment.