Skip to content

Commit

Permalink
CLI: Fix ambiguous name error when passing in fully qualified contrac…
Browse files Browse the repository at this point in the history
…t names (#944)
  • Loading branch information
ericglau authored Dec 14, 2023
1 parent 6a89da4 commit f008ac4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- CLI: Fix ambiguous name error when passing in fully qualified contract names. ([#944](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/944))

## 1.32.0 (2023-12-11)

- Support deploying proxies from OpenZeppelin Contracts 5.0. ([#919](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/919))
Expand Down
24 changes: 24 additions & 0 deletions packages/core/src/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,27 @@ test('validate - single contract - ok', async t => {
const output = (await execAsync(`${CLI} validate ${temp} --contract Annotation`)).stdout;
t.snapshot(output);
});

test('validate - fully qualified version of ambiguous contract name', async t => {
const temp = await getTempDir(t);
const buildInfo = await artifacts.getBuildInfo(`contracts/test/ValidationsSameNameSafe.sol:SameName`);
await fs.writeFile(path.join(temp, 'validate.json'), JSON.stringify(buildInfo));

const output = (
await execAsync(`${CLI} validate ${temp} --contract contracts/test/ValidationsSameNameSafe.sol:SameName`)
).stdout;
t.snapshot(output);
});

test('validate - references fully qualified version of ambiguous contract name', async t => {
const temp = await getTempDir(t);
const buildInfo = await artifacts.getBuildInfo(`contracts/test/ValidationsSameNameSafe.sol:SameName`);
await fs.writeFile(path.join(temp, 'validate.json'), JSON.stringify(buildInfo));

const output = (
await execAsync(
`${CLI} validate ${temp} --contract contracts/test/ValidationsSameNameSafe.sol:SameName --reference contracts/test/ValidationsSameNameUnsafe.sol:SameName`,
)
).stdout;
t.snapshot(output);
});
18 changes: 18 additions & 0 deletions packages/core/src/cli/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,21 @@ Generated by [AVA](https://avajs.dev).
SUCCESS␊
`

## validate - fully qualified version of ambiguous contract name

> Snapshot 1
` ✔ contracts/test/ValidationsSameNameSafe.sol:SameName␊
SUCCESS␊
`

## validate - references fully qualified version of ambiguous contract name

> Snapshot 1
` ✔ contracts/test/ValidationsSameNameSafe.sol:SameName (upgrades from contracts/test/ValidationsSameNameUnsafe.sol:SameName)␊
SUCCESS␊
`
Binary file modified packages/core/src/cli/cli.test.ts.snap
Binary file not shown.
4 changes: 2 additions & 2 deletions packages/core/src/cli/validate/contract-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getUpgradeableContractReport(
): UpgradeableContractReport | undefined {
let version;
try {
version = getContractVersion(contract.validationData, contract.name);
version = getContractVersion(contract.validationData, contract.fullyQualifiedName);
} catch (e: any) {
if (e.message.endsWith('is abstract')) {
// Skip abstract upgradeable contracts - they will be validated as part of their caller contracts
Expand All @@ -126,7 +126,7 @@ function getUpgradeableContractReport(
if (opts.unsafeSkipStorageCheck !== true && referenceContract !== undefined) {
const layout = getStorageLayout(contract.validationData, version);

const referenceVersion = getContractVersion(referenceContract.validationData, referenceContract.name);
const referenceVersion = getContractVersion(referenceContract.validationData, referenceContract.fullyQualifiedName);
const referenceLayout = getStorageLayout(referenceContract.validationData, referenceVersion);

reference = referenceContract.fullyQualifiedName;
Expand Down

0 comments on commit f008ac4

Please sign in to comment.