Throw an error if contract file doesn't contain the contract with the same name

This commit is contained in:
Leonid Logvinov
2018-03-15 16:30:18 +01:00
parent 3c36135d6c
commit 8fd705d2af

View File

@@ -228,6 +228,11 @@ export class Compiler {
}
const contractName = path.basename(fileName, constants.SOLIDITY_FILE_EXTENSION);
const contractIdentifier = `${fileName}:${contractName}`;
if (_.isUndefined(compiled.contracts[contractIdentifier])) {
throw new Error(
`Contract ${contractName} not found in ${fileName}. Please make sure your contract has the same name as a file`,
);
}
const abi: Web3.ContractAbi = JSON.parse(compiled.contracts[contractIdentifier].interface);
const bytecode = `0x${compiled.contracts[contractIdentifier].bytecode}`;
const runtimeBytecode = `0x${compiled.contracts[contractIdentifier].runtimeBytecode}`;