This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate constructors in ancestor contracts
Fixes #1332
- Loading branch information
1 parent
1025c22
commit 5718f16
Showing
10 changed files
with
105 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
// TS-TODO: Web3 typings? | ||
export function hasConstructor(contract: any): boolean { | ||
return !!contract.schema.abi.find(fn => fn.type === 'constructor'); | ||
import Contract from '../artifacts/Contract'; | ||
import { BuildArtifacts } from '..'; | ||
import ContractAST, { ContractDefinitionFilter } from '../utils/ContractAST'; | ||
import { Artifact } from '../artifacts/BuildArtifacts'; | ||
|
||
export function hasConstructor(contract: Contract, buildArtifacts: BuildArtifacts): boolean { | ||
if (hasConstructorInABI(contract.schema)) return true; | ||
|
||
const baseContracts = new ContractAST(contract, buildArtifacts, ContractDefinitionFilter) | ||
.getLinearizedBaseContracts() | ||
.map(node => buildArtifacts.getArtifactByName(node.name)); | ||
|
||
const baseContractsWithConstructors = baseContracts.filter(hasConstructorInABI); | ||
return baseContractsWithConstructors.length > 0; | ||
} | ||
|
||
function hasConstructorInABI(contract: Artifact): boolean { | ||
return !!contract.abi.find(fn => fn.type === 'constructor'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/lib/test/mocks/mock-dependency/contracts/DependencyInvalid.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract DependencyWithConstructor { | ||
uint256 public dependencyValue; | ||
constructor() public { | ||
dependencyValue = 42; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters