diff --git a/packages/core/src/cli/validate/find-contract.test.ts b/packages/core/src/cli/validate/find-contract.test.ts index df236a625..3ec83e06c 100644 --- a/packages/core/src/cli/validate/find-contract.test.ts +++ b/packages/core/src/cli/validate/find-contract.test.ts @@ -8,7 +8,7 @@ test('fully qualified - match', async t => { fullyQualifiedName: 'contracts/MyContract.sol:Foo', }; - t.true(isMatch('contracts/MyContract.sol:Foo', sourceContract as any)); + t.true(isMatch('contracts/MyContract.sol:Foo', sourceContract)); }); test('fully qualified without folder - match', async t => { @@ -17,7 +17,7 @@ test('fully qualified without folder - match', async t => { fullyQualifiedName: 'MyContract.sol:Foo', }; - t.true(isMatch('MyContract.sol:Foo', sourceContract as any)); + t.true(isMatch('MyContract.sol:Foo', sourceContract)); }); test('short name - match', async t => { @@ -26,7 +26,7 @@ test('short name - match', async t => { fullyQualifiedName: 'contracts/MyContract.sol:Foo', }; - t.true(isMatch('Foo', sourceContract as any)); + t.true(isMatch('Foo', sourceContract)); }); test('short name - match without folder', async t => { @@ -35,7 +35,7 @@ test('short name - match without folder', async t => { fullyQualifiedName: 'MyContract.sol:Foo', }; - t.true(isMatch('Foo', sourceContract as any)); + t.true(isMatch('Foo', sourceContract)); }); test('short name with .sol - no match', async t => { @@ -44,8 +44,8 @@ test('short name with .sol - no match', async t => { fullyQualifiedName: 'contracts/MyContract.sol:Foo', }; - t.false(isMatch('MyContract.sol', sourceContract as any)); - t.false(isMatch('Foo.sol', sourceContract as any)); + t.false(isMatch('MyContract.sol', sourceContract)); + t.false(isMatch('Foo.sol', sourceContract)); }); test('short name with .sol - match', async t => { @@ -54,7 +54,7 @@ test('short name with .sol - match', async t => { fullyQualifiedName: 'contracts/Foo.sol:Foo', }; - t.true(isMatch('Foo.sol', sourceContract as any)); + t.true(isMatch('Foo.sol', sourceContract)); }); test('short name with .sol - match without folder', async t => { @@ -63,5 +63,5 @@ test('short name with .sol - match without folder', async t => { fullyQualifiedName: 'Foo.sol:Foo', }; - t.true(isMatch('Foo.sol', sourceContract as any)); + t.true(isMatch('Foo.sol', sourceContract)); }); diff --git a/packages/core/src/cli/validate/find-contract.ts b/packages/core/src/cli/validate/find-contract.ts index 93e941eed..1f1674c90 100644 --- a/packages/core/src/cli/validate/find-contract.ts +++ b/packages/core/src/cli/validate/find-contract.ts @@ -43,7 +43,9 @@ export function findContract(contractName: string, origin: SourceContract | unde } } -export function isMatch(contractName: string, contract: SourceContract) { +type SourceContractIdentifier = Pick; + +export function isMatch(contractName: string, contract: SourceContractIdentifier) { return ( contract.fullyQualifiedName === contractName || // contracts/MyContract.sol:MyContract contract.name === contractName || // MyContract @@ -52,7 +54,7 @@ export function isMatch(contractName: string, contract: SourceContract) { ); } -function matchesDotSolAndName(contractName: string, contract: SourceContract) { +function matchesDotSolAndName(contractName: string, contract: SourceContractIdentifier) { if (contractName.includes('.sol:')) { const [fileWithoutExtension, name] = contractName.split('.sol:'); return matchesFullyQualifiedName(fileWithoutExtension, name, contract); @@ -61,7 +63,7 @@ function matchesDotSolAndName(contractName: string, contract: SourceContract) { } } -function matchesDotSol(contractName: string, contract: SourceContract) { +function matchesDotSol(contractName: string, contract: SourceContractIdentifier) { if (contractName.endsWith('.sol')) { const name = contractName.slice(0, contractName.length - 4); return matchesFullyQualifiedName(name, name, contract); @@ -70,7 +72,7 @@ function matchesDotSol(contractName: string, contract: SourceContract) { } } -function matchesFullyQualifiedName(fileNameWithoutExtension: string, name: string, contract: SourceContract) { +function matchesFullyQualifiedName(fileNameWithoutExtension: string, name: string, contract: SourceContractIdentifier) { const lastSlash = contract.fullyQualifiedName.lastIndexOf('/'); const fullyQualifiedWithoutPath = lastSlash >= 0 ? contract.fullyQualifiedName.slice(lastSlash + 1) : contract.fullyQualifiedName;