Skip to content

Commit a5eb384

Browse files
committed
Special treatment for differences between encoders.
1 parent 5bbd65c commit a5eb384

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

test/libsolidity/ABIDecoderTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(enums)
8686
}
8787
}
8888
)";
89-
bool newDecoder = false;
89+
bool newDecoder = dev::test::Options::get().useABIEncoderV2;
9090
BOTH_ENCODERS(
9191
compileAndRun(sourceCode);
9292
ABI_CHECK(callContractFunction("f(uint8)", 0), encodeArgs(u256(0)));

test/libsolidity/ABIEncoderTests.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
164164
}
165165
)";
166166

167-
compileAndRun(sourceCode);
168-
callContractFunction("f()");
169-
// The old encoder does not clean array elements.
170-
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000")));
167+
if (!dev::test::Options::get().useABIEncoderV2)
168+
{
169+
compileAndRun(sourceCode);
170+
callContractFunction("f()");
171+
// The old encoder does not clean array elements.
172+
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000")));
173+
}
171174

172175
compileAndRun(NewEncoderPragma + sourceCode);
173176
callContractFunction("f()");

test/libsolidity/GasCosts.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ BOOST_AUTO_TEST_CASE(string_storage)
7070

7171
if (Options::get().evmVersion() <= EVMVersion::byzantium())
7272
CHECK_GAS(134435, 130591, 100);
73+
else if (Options::get().useABIEncoderV2)
74+
CHECK_GAS(151819, 142753, 100);
7375
else
7476
CHECK_GAS(127225, 124873, 100);
7577
if (Options::get().evmVersion() >= EVMVersion::byzantium())
7678
{
7779
callContractFunction("f()");
7880
if (Options::get().evmVersion() == EVMVersion::byzantium())
7981
CHECK_GAS(21551, 21526, 20);
82+
else if (Options::get().useABIEncoderV2)
83+
CHECK_GAS(21713, 21635, 20);
8084
else
8185
CHECK_GAS(21546, 21526, 20);
8286
}

test/libsolidity/GasMeter.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,14 @@ class GasMeterTestFramework: public SolidityExecutionFramework
7373
// costs for transaction
7474
gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);
7575

76-
BOOST_REQUIRE(!gas.isInfinite);
77-
BOOST_CHECK_LE(m_gasUsed, gas.value);
78-
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
76+
// Skip the tests when we force ABIEncoderV2. We should enable this again
77+
// once the yul optimizer is activated.
78+
if (!dev::test::Options::get().useABIEncoderV2)
79+
{
80+
BOOST_REQUIRE(!gas.isInfinite);
81+
BOOST_CHECK_LE(m_gasUsed, gas.value);
82+
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
83+
}
7984
}
8085

8186
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
@@ -97,9 +102,14 @@ class GasMeterTestFramework: public SolidityExecutionFramework
97102
*m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
98103
_sig
99104
);
100-
BOOST_REQUIRE(!gas.isInfinite);
101-
BOOST_CHECK_LE(m_gasUsed, gas.value);
102-
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
105+
// Skip the tests when we force ABIEncoderV2. We should enable this again
106+
// once the yul optimizer is activated.
107+
if (!dev::test::Options::get().useABIEncoderV2)
108+
{
109+
BOOST_REQUIRE(!gas.isInfinite);
110+
BOOST_CHECK_LE(m_gasUsed, gas.value);
111+
BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed);
112+
}
103113
}
104114

105115
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14317,12 +14317,17 @@ BOOST_AUTO_TEST_CASE(abi_encode_empty_string)
1431714317
}
1431814318
}
1431914319
)";
14320+
1432014321
compileAndRun(sourceCode, 0, "C");
14321-
ABI_CHECK(callContractFunction("f()"), encodeArgs(
14322-
0x40, 0xc0,
14323-
0x60, 0x20, 0x00, 0x00,
14324-
0x00
14325-
));
14322+
if (!dev::test::Options::get().useABIEncoderV2)
14323+
{
14324+
// ABI Encoder V2 has slightly different padding, tested below.
14325+
ABI_CHECK(callContractFunction("f()"), encodeArgs(
14326+
0x40, 0xc0,
14327+
0x60, 0x20, 0x00, 0x00,
14328+
0x00
14329+
));
14330+
}
1432614331
}
1432714332

1432814333
BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2)

0 commit comments

Comments
 (0)