mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Added tests for --no-append-metadata
- Command line tests - Documented the standard json - Changelog - A Change in SolidityExecutionFramework to prevent flaky gas tests - A boost test for --no-append-metadata - Removed an outdated comment
This commit is contained in:
parent
f96e802e74
commit
d32661c0af
@ -4,6 +4,8 @@ Language Features:
|
||||
|
||||
|
||||
Compiler Features:
|
||||
* Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode.
|
||||
* Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode.
|
||||
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string.
|
||||
|
||||
|
||||
|
@ -220,6 +220,10 @@ Whereas release builds of solc use a 3 byte encoding of the version as shown
|
||||
above (one byte each for major, minor and patch version number), prerelease builds
|
||||
will instead use a complete version string including commit hash and build date.
|
||||
|
||||
The commandline flag ``--no-cbor-metadata`` can be used to skip metadata
|
||||
from getting appended at the end of the deployed bytecode. Equivalently, the
|
||||
boolean field ``settings.metadata.appendCBOR`` in Standard JSON input can be set to false.
|
||||
|
||||
.. note::
|
||||
The CBOR mapping can also contain other keys, so it is better to fully
|
||||
decode the data instead of relying on it starting with ``0xa264``.
|
||||
|
@ -323,6 +323,9 @@ Input Description
|
||||
},
|
||||
// Metadata settings (optional)
|
||||
"metadata": {
|
||||
// The CBOR metadata is appended at the end of the bytecode by default.
|
||||
// Setting this to false omits the metadata from the runtime and deploy time code.
|
||||
"appendCBOR": true,
|
||||
// Use only literal content and not URLs (false by default)
|
||||
"useLiteralContent": true,
|
||||
// Use the given hash method for the metadata hash that is appended to the bytecode.
|
||||
|
@ -345,8 +345,6 @@ public:
|
||||
Json::Value gasEstimates(std::string const& _contractName) const;
|
||||
|
||||
/// Changes the format of the metadata appended at the end of the bytecode.
|
||||
/// This is mostly a workaround to avoid bytecode and gas differences between compiler builds
|
||||
/// caused by differences in metadata. Should only be used for testing.
|
||||
void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; }
|
||||
|
||||
static MetadataFormat defaultMetadataFormat()
|
||||
|
1
test/cmdlineTests/metadata_append_standard_json/args
Normal file
1
test/cmdlineTests/metadata_append_standard_json/args
Normal file
@ -0,0 +1 @@
|
||||
--pretty-json --json-indent 4
|
28
test/cmdlineTests/metadata_append_standard_json/input.json
Normal file
28
test/cmdlineTests/metadata_append_standard_json/input.json
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
"language": "Solidity",
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;\n\ncontract test {}"
|
||||
}
|
||||
},
|
||||
"settings":
|
||||
{
|
||||
"viaIR": true,
|
||||
"optimizer": {
|
||||
"enabled": true
|
||||
},
|
||||
"metadata":
|
||||
{
|
||||
"appendCBOR": false
|
||||
},
|
||||
"outputSelection":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"test": ["evm.bytecode"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
test/cmdlineTests/metadata_append_standard_json/output.json
Normal file
30
test/cmdlineTests/metadata_append_standard_json/output.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"contracts":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"test":
|
||||
{
|
||||
"evm":
|
||||
{
|
||||
"bytecode":
|
||||
{
|
||||
"functionDebugData": {},
|
||||
"generatedSources": [],
|
||||
"linkReferences": {},
|
||||
"object": "608080604052346013576004908160198239f35b600080fdfe600080fd",
|
||||
"opcodes": "PUSH1 0x80 DUP1 PUSH1 0x40 MSTORE CALLVALUE PUSH1 0x13 JUMPI PUSH1 0x4 SWAP1 DUP2 PUSH1 0x19 DUP3 CODECOPY RETURN JUMPDEST PUSH1 0x0 DUP1 REVERT INVALID PUSH1 0x0 DUP1 REVERT ",
|
||||
"sourceMap": "60:16:0:-:0;;;;;;;;;;;;;;;;;"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"id": 0
|
||||
}
|
||||
}
|
||||
}
|
1
test/cmdlineTests/no_append_incorrect_combination/args
Normal file
1
test/cmdlineTests/no_append_incorrect_combination/args
Normal file
@ -0,0 +1 @@
|
||||
--no-cbor-metadata --metadata-hash ipfs
|
1
test/cmdlineTests/no_append_incorrect_combination/err
Normal file
1
test/cmdlineTests/no_append_incorrect_combination/err
Normal file
@ -0,0 +1 @@
|
||||
Cannot specify a metadata hashing method when --no-cbor-metadata is set.
|
1
test/cmdlineTests/no_append_incorrect_combination/exit
Normal file
1
test/cmdlineTests/no_append_incorrect_combination/exit
Normal file
@ -0,0 +1 @@
|
||||
1
|
10
test/cmdlineTests/no_append_incorrect_combination/input.sol
Normal file
10
test/cmdlineTests/no_append_incorrect_combination/input.sol
Normal file
@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >= 0.0.0;
|
||||
|
||||
contract Empty {}
|
||||
|
||||
contract C {
|
||||
function f() external returns (bytes memory, bytes memory){
|
||||
return (type(Empty).creationCode, type(Empty).runtimeCode);
|
||||
}
|
||||
}
|
1
test/cmdlineTests/no_append_metadata/args
Normal file
1
test/cmdlineTests/no_append_metadata/args
Normal file
@ -0,0 +1 @@
|
||||
--no-cbor-metadata --bin --via-ir --optimize
|
10
test/cmdlineTests/no_append_metadata/input.sol
Normal file
10
test/cmdlineTests/no_append_metadata/input.sol
Normal file
@ -0,0 +1,10 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >= 0.0.0;
|
||||
|
||||
// NOTE: The expected output would be the binary with no metadata.
|
||||
// The commandline tests would replace bytecode with metadata in it with
|
||||
// <BYTECODE REMOVED>
|
||||
// Therefore, not having that means success!
|
||||
|
||||
contract C {
|
||||
}
|
4
test/cmdlineTests/no_append_metadata/output
Normal file
4
test/cmdlineTests/no_append_metadata/output
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
======= no_append_metadata/input.sol:C =======
|
||||
Binary:
|
||||
608080604052346013576004908160198239f35b600080fdfe600080fd
|
@ -92,6 +92,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
|
||||
}
|
||||
)";
|
||||
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
|
||||
m_appendCBORMetadata = false;
|
||||
compileAndRun(sourceCode);
|
||||
|
||||
auto evmVersion = solidity::test::CommonOptions::get().evmVersion();
|
||||
|
@ -53,7 +53,7 @@ SemanticTest::SemanticTest(
|
||||
bool _enforceGasCost,
|
||||
u256 _enforceGasCostMinValue
|
||||
):
|
||||
SolidityExecutionFramework(_evmVersion, _vmPaths),
|
||||
SolidityExecutionFramework(_evmVersion, _vmPaths, false),
|
||||
EVMVersionRestrictedTestCase(_filename),
|
||||
m_sources(m_reader.sources()),
|
||||
m_lineOffset(m_reader.lineNumber()),
|
||||
|
@ -62,6 +62,9 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
|
||||
m_compiler.enableEvmBytecodeGeneration(!m_compileViaYul);
|
||||
m_compiler.enableIRGeneration(m_compileViaYul);
|
||||
m_compiler.setRevertStringBehaviour(m_revertStrings);
|
||||
if (!m_appendCBORMetadata) {
|
||||
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
|
||||
}
|
||||
m_compiler.setMetadataHash(m_metadataHash);
|
||||
if (!m_compiler.compile())
|
||||
{
|
||||
|
@ -40,8 +40,14 @@ class SolidityExecutionFramework: public solidity::test::ExecutionFramework
|
||||
|
||||
public:
|
||||
SolidityExecutionFramework(): m_showMetadata(solidity::test::CommonOptions::get().showMetadata) {}
|
||||
explicit SolidityExecutionFramework(langutil::EVMVersion _evmVersion, std::vector<boost::filesystem::path> const& _vmPaths):
|
||||
ExecutionFramework(_evmVersion, _vmPaths), m_showMetadata(solidity::test::CommonOptions::get().showMetadata)
|
||||
explicit SolidityExecutionFramework(
|
||||
langutil::EVMVersion _evmVersion,
|
||||
std::vector<boost::filesystem::path> const& _vmPaths,
|
||||
bool _appendCBORMetadata = true
|
||||
):
|
||||
ExecutionFramework(_evmVersion, _vmPaths),
|
||||
m_showMetadata(solidity::test::CommonOptions::get().showMetadata),
|
||||
m_appendCBORMetadata(_appendCBORMetadata)
|
||||
{}
|
||||
|
||||
bytes const& compileAndRunWithoutCheck(
|
||||
@ -80,6 +86,7 @@ protected:
|
||||
bool m_compileViaYul = false;
|
||||
bool m_compileToEwasm = false;
|
||||
bool m_showMetadata = false;
|
||||
bool m_appendCBORMetadata = true;
|
||||
CompilerStack::MetadataHash m_metadataHash = CompilerStack::MetadataHash::IPFS;
|
||||
RevertStrings m_revertStrings = RevertStrings::Default;
|
||||
};
|
||||
|
@ -224,6 +224,15 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(no_cbor_metadata)
|
||||
{
|
||||
vector<string> commandLine = {"solc", "--no-cbor-metadata", "contract.sol"};
|
||||
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
||||
bool assert = parsedOptions.metadata.format == CompilerStack::MetadataFormat::NoMetadata;
|
||||
|
||||
BOOST_TEST(assert);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(via_ir_options)
|
||||
{
|
||||
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);
|
||||
|
Loading…
Reference in New Issue
Block a user