mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Special treatment for differences between ABI encoders.
This commit is contained in:
parent
5bbd65c5ca
commit
8ace2c5b11
@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(enums)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
bool newDecoder = false;
|
bool newDecoder = dev::test::Options::get().useABIEncoderV2;
|
||||||
BOTH_ENCODERS(
|
BOTH_ENCODERS(
|
||||||
compileAndRun(sourceCode);
|
compileAndRun(sourceCode);
|
||||||
ABI_CHECK(callContractFunction("f(uint8)", 0), encodeArgs(u256(0)));
|
ABI_CHECK(callContractFunction("f(uint8)", 0), encodeArgs(u256(0)));
|
||||||
|
@ -164,10 +164,13 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
compileAndRun(sourceCode);
|
if (!dev::test::Options::get().useABIEncoderV2)
|
||||||
callContractFunction("f()");
|
{
|
||||||
// The old encoder does not clean array elements.
|
compileAndRun(sourceCode);
|
||||||
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000")));
|
callContractFunction("f()");
|
||||||
|
// The old encoder does not clean array elements.
|
||||||
|
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000")));
|
||||||
|
}
|
||||||
|
|
||||||
compileAndRun(NewEncoderPragma + sourceCode);
|
compileAndRun(NewEncoderPragma + sourceCode);
|
||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
|
@ -70,6 +70,9 @@ BOOST_AUTO_TEST_CASE(string_storage)
|
|||||||
|
|
||||||
if (Options::get().evmVersion() <= EVMVersion::byzantium())
|
if (Options::get().evmVersion() <= EVMVersion::byzantium())
|
||||||
CHECK_GAS(134435, 130591, 100);
|
CHECK_GAS(134435, 130591, 100);
|
||||||
|
// This is only correct on >=Constantinople.
|
||||||
|
else if (Options::get().useABIEncoderV2)
|
||||||
|
CHECK_GAS(151819, 142753, 100);
|
||||||
else
|
else
|
||||||
CHECK_GAS(127225, 124873, 100);
|
CHECK_GAS(127225, 124873, 100);
|
||||||
if (Options::get().evmVersion() >= EVMVersion::byzantium())
|
if (Options::get().evmVersion() >= EVMVersion::byzantium())
|
||||||
@ -77,6 +80,9 @@ BOOST_AUTO_TEST_CASE(string_storage)
|
|||||||
callContractFunction("f()");
|
callContractFunction("f()");
|
||||||
if (Options::get().evmVersion() == EVMVersion::byzantium())
|
if (Options::get().evmVersion() == EVMVersion::byzantium())
|
||||||
CHECK_GAS(21551, 21526, 20);
|
CHECK_GAS(21551, 21526, 20);
|
||||||
|
// This is only correct on >=Constantinople.
|
||||||
|
else if (Options::get().useABIEncoderV2)
|
||||||
|
CHECK_GAS(21713, 21635, 20);
|
||||||
else
|
else
|
||||||
CHECK_GAS(21546, 21526, 20);
|
CHECK_GAS(21546, 21526, 20);
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,14 @@ public:
|
|||||||
// costs for transaction
|
// costs for transaction
|
||||||
gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);
|
gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);
|
||||||
|
|
||||||
BOOST_REQUIRE(!gas.isInfinite);
|
// Skip the tests when we force ABIEncoderV2.
|
||||||
BOOST_CHECK_LE(m_gasUsed, gas.value);
|
// TODO: We should enable this again once the yul optimizer is activated.
|
||||||
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
|
if (!dev::test::Options::get().useABIEncoderV2)
|
||||||
|
{
|
||||||
|
BOOST_REQUIRE(!gas.isInfinite);
|
||||||
|
BOOST_CHECK_LE(m_gasUsed, gas.value);
|
||||||
|
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
|
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
|
||||||
@ -97,9 +102,14 @@ public:
|
|||||||
*m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
|
*m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
|
||||||
_sig
|
_sig
|
||||||
);
|
);
|
||||||
BOOST_REQUIRE(!gas.isInfinite);
|
// Skip the tests when we force ABIEncoderV2.
|
||||||
BOOST_CHECK_LE(m_gasUsed, gas.value);
|
// TODO: We should enable this again once the yul optimizer is activated.
|
||||||
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
|
if (!dev::test::Options::get().useABIEncoderV2)
|
||||||
|
{
|
||||||
|
BOOST_REQUIRE(!gas.isInfinite);
|
||||||
|
BOOST_CHECK_LE(m_gasUsed, gas.value);
|
||||||
|
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)
|
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)
|
||||||
|
@ -14317,12 +14317,17 @@ BOOST_AUTO_TEST_CASE(abi_encode_empty_string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
compileAndRun(sourceCode, 0, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
ABI_CHECK(callContractFunction("f()"), encodeArgs(
|
if (!dev::test::Options::get().useABIEncoderV2)
|
||||||
0x40, 0xc0,
|
{
|
||||||
0x60, 0x20, 0x00, 0x00,
|
// ABI Encoder V2 has slightly different padding, tested below.
|
||||||
0x00
|
ABI_CHECK(callContractFunction("f()"), encodeArgs(
|
||||||
));
|
0x40, 0xc0,
|
||||||
|
0x60, 0x20, 0x00, 0x00,
|
||||||
|
0x00
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2)
|
BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2)
|
||||||
|
Loading…
Reference in New Issue
Block a user