Skip to content

Commit 2d3bd91

Browse files
authored
Merge pull request #8203 from ethereum/extract-tests
Extract some semantic tests
2 parents 0dd398e + 1027f6f commit 2d3bd91

File tree

4 files changed

+64
-82
lines changed

4 files changed

+64
-82
lines changed

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -784,26 +784,6 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
784784
testContractAgainstCpp("run()", small_signed_types_cpp);
785785
}
786786

787-
BOOST_AUTO_TEST_CASE(strings)
788-
{
789-
char const* sourceCode = R"(
790-
contract test {
791-
function fixedBytes() public returns(bytes32 ret) {
792-
return "abc\x00\xff__";
793-
}
794-
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
795-
oneRet = one;
796-
large = small;
797-
}
798-
}
799-
)";
800-
ALSO_VIA_YUL(
801-
compileAndRun(sourceCode);
802-
ABI_CHECK(callContractFunction("fixedBytes()"), encodeArgs(string("abc\0\xff__", 7)));
803-
ABI_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true), encodeArgs(string("\0\x2", 2), true));
804-
)
805-
}
806-
807787
BOOST_AUTO_TEST_CASE(compound_assign)
808788
{
809789
char const* sourceCode = R"(
@@ -843,40 +823,6 @@ BOOST_AUTO_TEST_CASE(compound_assign)
843823
)
844824
}
845825

846-
BOOST_AUTO_TEST_CASE(simple_mapping)
847-
{
848-
char const* sourceCode = R"(
849-
contract test {
850-
mapping(uint8 => uint8) table;
851-
function get(uint8 k) public returns (uint8 v) {
852-
return table[k];
853-
}
854-
function set(uint8 k, uint8 v) public {
855-
table[k] = v;
856-
}
857-
}
858-
)";
859-
860-
ALSO_VIA_YUL(
861-
compileAndRun(sourceCode);
862-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0)), encodeArgs(uint8_t(0x00)));
863-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x00)));
864-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
865-
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0xa1));
866-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0x00)));
867-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
868-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
869-
callContractFunction("set(uint8,uint8)", uint8_t(0x00), uint8_t(0xef));
870-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
871-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
872-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
873-
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0x05));
874-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
875-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x05)));
876-
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
877-
)
878-
}
879-
880826
BOOST_AUTO_TEST_CASE(mapping_state)
881827
{
882828
char const* sourceCode = R"(
@@ -1057,34 +1003,6 @@ BOOST_AUTO_TEST_CASE(constructor)
10571003
)
10581004
}
10591005

1060-
BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
1061-
{
1062-
char const* sourceCode = R"(
1063-
contract test {
1064-
uint256 public data;
1065-
bytes6 public name;
1066-
bytes32 public a_hash;
1067-
address public an_address;
1068-
constructor() public {
1069-
data = 8;
1070-
name = "Celina";
1071-
a_hash = keccak256("\x7b");
1072-
an_address = address(0x1337);
1073-
super_secret_data = 42;
1074-
}
1075-
uint256 super_secret_data;
1076-
}
1077-
)";
1078-
ALSO_VIA_YUL(
1079-
compileAndRun(sourceCode);
1080-
ABI_CHECK(callContractFunction("data()"), encodeArgs(8));
1081-
ABI_CHECK(callContractFunction("name()"), encodeArgs("Celina"));
1082-
ABI_CHECK(callContractFunction("a_hash()"), encodeArgs(util::keccak256(bytes(1, 0x7b))));
1083-
ABI_CHECK(callContractFunction("an_address()"), encodeArgs(util::toBigEndian(u160(0x1337))));
1084-
ABI_CHECK(callContractFunction("super_secret_data()"), bytes());
1085-
);
1086-
}
1087-
10881006
BOOST_AUTO_TEST_CASE(balance)
10891007
{
10901008
char const* sourceCode = R"(
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
contract test {
2+
uint256 public data;
3+
bytes6 public name;
4+
bytes32 public a_hash;
5+
address public an_address;
6+
constructor() public {
7+
data = 8;
8+
name = "Celina";
9+
a_hash = keccak256("\x7b");
10+
an_address = address(0x1337);
11+
super_secret_data = 42;
12+
}
13+
uint256 super_secret_data;
14+
}
15+
// ====
16+
// compileViaYul: also
17+
// ----
18+
// data() -> 8
19+
// name() -> "Celina"
20+
// a_hash() -> 0xa91eddf639b0b768929589c1a9fd21dcb0107199bdd82e55c5348018a1572f52
21+
// an_address() -> 0x1337
22+
// super_secret_data() -> FAILURE
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
contract test {
2+
mapping(uint8 => uint8) table;
3+
function get(uint8 k) public returns (uint8 v) {
4+
return table[k];
5+
}
6+
function set(uint8 k, uint8 v) public {
7+
table[k] = v;
8+
}
9+
}
10+
// ====
11+
// compileViaYul: also
12+
// ----
13+
// get(uint8): 0 -> 0
14+
// get(uint8): 0x01 -> 0
15+
// get(uint8): 0xa7 -> 0
16+
// set(uint8,uint8): 0x01, 0xa1 ->
17+
// get(uint8): 0 -> 0
18+
// get(uint8): 0x01 -> 0xa1
19+
// get(uint8): 0xa7 -> 0
20+
// set(uint8,uint8): 0x00, 0xef ->
21+
// get(uint8): 0 -> 0xef
22+
// get(uint8): 0x01 -> 0xa1
23+
// get(uint8): 0xa7 -> 0
24+
// set(uint8,uint8): 0x01, 0x05 ->
25+
// get(uint8): 0 -> 0xef
26+
// get(uint8): 0x01 -> 0x05
27+
// get(uint8): 0xa7 -> 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract test {
2+
function fixedBytes() public returns(bytes32 ret) {
3+
return "abc\x00\xff__";
4+
}
5+
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
6+
oneRet = one;
7+
large = small;
8+
}
9+
}
10+
11+
// ====
12+
// compileViaYul: also
13+
// ----
14+
// fixedBytes() -> "abc\0\xff__"
15+
// pipeThrough(bytes2, bool): "\0\x02", true -> "\0\x2", true

0 commit comments

Comments
 (0)