Use cbor metadata in gas cost tests.

This commit is contained in:
chriseth
2020-07-28 23:42:22 +02:00
parent 73506e2858
commit b8b78a6982
3 changed files with 35 additions and 21 deletions
+19 -8
View File
@@ -824,6 +824,14 @@ string const& CompilerStack::metadata(string const& _contractName) const
return metadata(contract(_contractName));
}
bytes CompilerStack::cborMetadata(string const& _contractName) const
{
if (m_stackState < AnalysisPerformed)
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Analysis was not successful."));
return createCBORMetadata(contract(_contractName));
}
string const& CompilerStack::metadata(Contract const& _contract) const
{
if (m_stackState < AnalysisPerformed)
@@ -1063,10 +1071,7 @@ void CompilerStack::compileContract(
shared_ptr<Compiler> compiler = make_shared<Compiler>(m_evmVersion, m_revertStrings, m_optimiserSettings);
compiledContract.compiler = compiler;
bytes cborEncodedMetadata = createCBORMetadata(
metadata(compiledContract),
!onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)
);
bytes cborEncodedMetadata = createCBORMetadata(compiledContract);
try
{
@@ -1390,18 +1395,24 @@ private:
bytes m_data;
};
bytes CompilerStack::createCBORMetadata(string const& _metadata, bool _experimentalMode)
bytes CompilerStack::createCBORMetadata(Contract const& _contract) const
{
bool const experimentalMode = !onlySafeExperimentalFeaturesActivated(
_contract.contract->sourceUnit().annotation().experimentalFeatures
);
string meta = metadata(_contract);
MetadataCBOREncoder encoder;
if (m_metadataHash == MetadataHash::IPFS)
encoder.pushBytes("ipfs", util::ipfsHash(_metadata));
encoder.pushBytes("ipfs", util::ipfsHash(meta));
else if (m_metadataHash == MetadataHash::Bzzr1)
encoder.pushBytes("bzzr1", util::bzzr1Hash(_metadata).asBytes());
encoder.pushBytes("bzzr1", util::bzzr1Hash(meta).asBytes());
else
solAssert(m_metadataHash == MetadataHash::None, "Invalid metadata hash");
if (_experimentalMode)
if (experimentalMode)
encoder.pushBool("experimental", true);
if (m_release)
encoder.pushBytes("solc", VersionCompactBytes);
+4 -1
View File
@@ -314,6 +314,9 @@ public:
/// @returns the Contract Metadata
std::string const& metadata(std::string const& _contractName) const;
/// @returns the cbor-encoded metadata.
bytes cborMetadata(std::string const& _contractName) const;
/// @returns a JSON representing the estimated gas usage for contract creation, internal and external functions
Json::Value gasEstimates(std::string const& _contractName) const;
@@ -402,7 +405,7 @@ private:
std::string createMetadata(Contract const& _contract) const;
/// @returns the metadata CBOR for the given serialised metadata JSON.
bytes createCBORMetadata(std::string const& _metadata, bool _experimentalMode);
bytes createCBORMetadata(Contract const& _contract) const;
/// @returns the contract ABI as a JSON object.
/// This will generate the JSON object and store it in the Contract object if it is not present yet.