Skip to content

Commit 3c63be5

Browse files
authored
Merge pull request #10037 from ethereum/enableYultests
Enable some more Yul tests.
2 parents 447744e + 837dd00 commit 3c63be5

File tree

1 file changed

+110
-78
lines changed

1 file changed

+110
-78
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 110 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -622,27 +622,30 @@ BOOST_AUTO_TEST_CASE(for_loop_break_continue)
622622
}
623623
}
624624
)";
625-
compileAndRun(sourceCode);
625+
ALSO_VIA_YUL(
626+
DISABLE_EWASM_TESTRUN()
627+
compileAndRun(sourceCode);
626628

627-
auto breakContinue = [](u256 const& n) -> u256
628-
{
629-
u256 i = 1;
630-
u256 k = 0;
631-
for (i *= 5; k < n; i *= 7)
629+
auto breakContinue = [](u256 const& n) -> u256
632630
{
633-
k++;
634-
i += 4;
635-
if (n % 3 == 0)
636-
break;
637-
i += 9;
638-
if (n % 2 == 0)
639-
continue;
640-
i += 19;
641-
}
642-
return i;
643-
};
631+
u256 i = 1;
632+
u256 k = 0;
633+
for (i *= 5; k < n; i *= 7)
634+
{
635+
k++;
636+
i += 4;
637+
if (n % 3 == 0)
638+
break;
639+
i += 9;
640+
if (n % 2 == 0)
641+
continue;
642+
i += 19;
643+
}
644+
return i;
645+
};
644646

645-
testContractAgainstCppOnRange("f(uint256)", breakContinue, 0, 10);
647+
testContractAgainstCppOnRange("f(uint256)", breakContinue, 0, 10);
648+
);
646649
}
647650

648651
BOOST_AUTO_TEST_CASE(calling_other_functions)
@@ -663,8 +666,6 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
663666
}
664667
}
665668
)";
666-
compileAndRun(sourceCode);
667-
668669
auto evenStep_cpp = [](u256 const& n) -> u256
669670
{
670671
return n / 2;
@@ -687,12 +688,16 @@ BOOST_AUTO_TEST_CASE(calling_other_functions)
687688
}
688689
return y;
689690
};
691+
ALSO_VIA_YUL(
692+
DISABLE_EWASM_TESTRUN()
693+
compileAndRun(sourceCode);
690694

691-
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(0));
692-
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(1));
693-
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(2));
694-
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(8));
695-
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(127));
695+
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(0));
696+
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(1));
697+
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(2));
698+
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(8));
699+
testContractAgainstCpp("run(uint256)", collatz_cpp, u256(127));
700+
)
696701
}
697702

698703
BOOST_AUTO_TEST_CASE(many_local_variables)
@@ -706,18 +711,18 @@ BOOST_AUTO_TEST_CASE(many_local_variables)
706711
}
707712
}
708713
)";
714+
auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
715+
{
716+
u256 a = 0x1;
717+
u256 b = 0x10;
718+
u256 c = 0x100;
719+
u256 y = a + b + c + x1 + x2 + x3;
720+
return y + b + x2;
721+
};
709722
ALSO_VIA_YUL(
710723
DISABLE_EWASM_TESTRUN()
711724

712725
compileAndRun(sourceCode);
713-
auto f = [](u256 const& x1, u256 const& x2, u256 const& x3) -> u256
714-
{
715-
u256 a = 0x1;
716-
u256 b = 0x10;
717-
u256 c = 0x100;
718-
u256 y = a + b + c + x1 + x2 + x3;
719-
return y + b + x2;
720-
};
721726
testContractAgainstCpp("run(uint256,uint256,uint256)", f, u256(0x1000), u256(0x10000), u256(0x100000));
722727
)
723728
}
@@ -823,12 +828,15 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
823828
}
824829
}
825830
)";
826-
compileAndRun(sourceCode);
827-
auto small_signed_types_cpp = []() -> u256
828-
{
829-
return -int32_t(10) * -int64_t(20);
830-
};
831-
testContractAgainstCpp("run()", small_signed_types_cpp);
831+
ALSO_VIA_YUL(
832+
DISABLE_EWASM_TESTRUN()
833+
compileAndRun(sourceCode);
834+
auto small_signed_types_cpp = []() -> u256
835+
{
836+
return -int32_t(10) * -int64_t(20);
837+
};
838+
testContractAgainstCpp("run()", small_signed_types_cpp);
839+
);
832840
}
833841

834842
BOOST_AUTO_TEST_CASE(compound_assign)
@@ -1154,10 +1162,13 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
11541162
}
11551163
}
11561164
)";
1157-
compileAndRun(code, 0, "C");
1158-
bytes result = callContractFunction("f()");
1159-
BOOST_REQUIRE_EQUAL(result.size(), 32);
1160-
BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0);
1165+
ALSO_VIA_YUL(
1166+
DISABLE_EWASM_TESTRUN()
1167+
compileAndRun(code, 0, "C");
1168+
bytes result = callContractFunction("f()");
1169+
BOOST_REQUIRE_EQUAL(result.size(), 32);
1170+
BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0);
1171+
)
11611172
}
11621173

11631174
BOOST_AUTO_TEST_CASE(log0)
@@ -1325,14 +1336,17 @@ BOOST_AUTO_TEST_CASE(keccak256)
13251336
}
13261337
}
13271338
)";
1328-
compileAndRun(sourceCode);
1329-
auto f = [&](u256 const& _x) -> u256
1330-
{
1331-
return util::keccak256(toBigEndian(_x));
1332-
};
1333-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1334-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1335-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1339+
ALSO_VIA_YUL(
1340+
DISABLE_EWASM_TESTRUN()
1341+
compileAndRun(sourceCode);
1342+
auto f = [&](u256 const& _x) -> u256
1343+
{
1344+
return util::keccak256(toBigEndian(_x));
1345+
};
1346+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1347+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1348+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1349+
);
13361350
}
13371351

13381352
BOOST_AUTO_TEST_CASE(sha256)
@@ -1344,7 +1358,6 @@ BOOST_AUTO_TEST_CASE(sha256)
13441358
}
13451359
}
13461360
)";
1347-
compileAndRun(sourceCode);
13481361
auto f = [&](u256 const& _x) -> bytes
13491362
{
13501363
if (_x == u256(4))
@@ -1355,9 +1368,13 @@ BOOST_AUTO_TEST_CASE(sha256)
13551368
return fromHex("af9613760f72635fbdb44a5a0a63c39f12af30f950a6ee5c971be188e89c4051");
13561369
return fromHex("");
13571370
};
1358-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1359-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1360-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1371+
ALSO_VIA_YUL(
1372+
DISABLE_EWASM_TESTRUN()
1373+
compileAndRun(sourceCode);
1374+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1375+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1376+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1377+
)
13611378
}
13621379

13631380
BOOST_AUTO_TEST_CASE(ripemd)
@@ -1369,7 +1386,6 @@ BOOST_AUTO_TEST_CASE(ripemd)
13691386
}
13701387
}
13711388
)";
1372-
compileAndRun(sourceCode);
13731389
auto f = [&](u256 const& _x) -> bytes
13741390
{
13751391
if (_x == u256(4))
@@ -1380,9 +1396,13 @@ BOOST_AUTO_TEST_CASE(ripemd)
13801396
return fromHex("1cf4e77f5966e13e109703cd8a0df7ceda7f3dc3000000000000000000000000");
13811397
return fromHex("");
13821398
};
1383-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1384-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1385-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1399+
ALSO_VIA_YUL(
1400+
DISABLE_EWASM_TESTRUN()
1401+
compileAndRun(sourceCode);
1402+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1403+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1404+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1405+
)
13861406
}
13871407

13881408
BOOST_AUTO_TEST_CASE(packed_keccak256)
@@ -1396,7 +1416,6 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
13961416
}
13971417
}
13981418
)";
1399-
compileAndRun(sourceCode);
14001419
auto f = [&](u256 const& _x) -> u256
14011420
{
14021421
return util::keccak256(
@@ -1407,9 +1426,13 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
14071426
toBigEndian(u256(256))
14081427
);
14091428
};
1410-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1411-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1412-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1429+
ALSO_VIA_YUL(
1430+
DISABLE_EWASM_TESTRUN()
1431+
compileAndRun(sourceCode);
1432+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1433+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1434+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1435+
)
14131436
}
14141437

14151438
BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
@@ -1428,13 +1451,16 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
14281451
}
14291452
}
14301453
)";
1431-
compileAndRun(sourceCode);
1432-
// Strangely, arrays are encoded with intra-element padding.
1433-
ABI_CHECK(callContractFunction("f()"), encodeArgs(
1434-
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
1435-
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
1436-
util::keccak256(fromHex(m_contractAddress.hex() + "26121ff0"))
1437-
));
1454+
ALSO_VIA_YUL(
1455+
DISABLE_EWASM_TESTRUN()
1456+
compileAndRun(sourceCode);
1457+
// Strangely, arrays are encoded with intra-element padding.
1458+
ABI_CHECK(callContractFunction("f()"), encodeArgs(
1459+
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
1460+
util::keccak256(encodeArgs(u256("0xfffffffffffffffffffffffffffffe"), u256("0xfffffffffffffffffffffffffffffd"), u256("0xfffffffffffffffffffffffffffffc"))),
1461+
util::keccak256(fromHex(m_contractAddress.hex() + "26121ff0"))
1462+
));
1463+
)
14381464
}
14391465

14401466
BOOST_AUTO_TEST_CASE(packed_sha256)
@@ -1448,7 +1474,6 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
14481474
}
14491475
}
14501476
)";
1451-
compileAndRun(sourceCode);
14521477
auto f = [&](u256 const& _x) -> bytes
14531478
{
14541479
if (_x == u256(4))
@@ -1459,9 +1484,13 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
14591484
return fromHex("f14def4d07cd185ddd8b10a81b2238326196a38867e6e6adbcc956dc913488c7");
14601485
return fromHex("");
14611486
};
1462-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1463-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1464-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1487+
ALSO_VIA_YUL(
1488+
DISABLE_EWASM_TESTRUN()
1489+
compileAndRun(sourceCode);
1490+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1491+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1492+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1493+
)
14651494
}
14661495

14671496
BOOST_AUTO_TEST_CASE(packed_ripemd160)
@@ -1475,7 +1504,6 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
14751504
}
14761505
}
14771506
)";
1478-
compileAndRun(sourceCode);
14791507
auto f = [&](u256 const& _x) -> bytes
14801508
{
14811509
if (_x == u256(4))
@@ -1486,9 +1514,13 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
14861514
return fromHex("c0a2e4b1f3ff766a9a0089e7a410391730872495000000000000000000000000");
14871515
return fromHex("");
14881516
};
1489-
testContractAgainstCpp("a(bytes32)", f, u256(4));
1490-
testContractAgainstCpp("a(bytes32)", f, u256(5));
1491-
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1517+
ALSO_VIA_YUL(
1518+
DISABLE_EWASM_TESTRUN()
1519+
compileAndRun(sourceCode);
1520+
testContractAgainstCpp("a(bytes32)", f, u256(4));
1521+
testContractAgainstCpp("a(bytes32)", f, u256(5));
1522+
testContractAgainstCpp("a(bytes32)", f, u256(-1));
1523+
)
14921524
}
14931525

14941526
BOOST_AUTO_TEST_CASE(inter_contract_calls)

0 commit comments

Comments
 (0)