mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Extract some semantic tests
This commit is contained in:
parent
cebca57ac2
commit
1027f6f78f
@ -784,26 +784,6 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
testContractAgainstCpp("run()", small_signed_types_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(strings)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function fixedBytes() public returns(bytes32 ret) {
|
||||
return "abc\x00\xff__";
|
||||
}
|
||||
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
|
||||
oneRet = one;
|
||||
large = small;
|
||||
}
|
||||
}
|
||||
)";
|
||||
ALSO_VIA_YUL(
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("fixedBytes()"), encodeArgs(string("abc\0\xff__", 7)));
|
||||
ABI_CHECK(callContractFunction("pipeThrough(bytes2,bool)", string("\0\x02", 2), true), encodeArgs(string("\0\x2", 2), true));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compound_assign)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
@ -843,40 +823,6 @@ BOOST_AUTO_TEST_CASE(compound_assign)
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(simple_mapping)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
mapping(uint8 => uint8) table;
|
||||
function get(uint8 k) public returns (uint8 v) {
|
||||
return table[k];
|
||||
}
|
||||
function set(uint8 k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
ALSO_VIA_YUL(
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0)), encodeArgs(uint8_t(0x00)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x00)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
|
||||
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0xa1));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0x00)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
|
||||
callContractFunction("set(uint8,uint8)", uint8_t(0x00), uint8_t(0xef));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0xa1)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
|
||||
callContractFunction("set(uint8,uint8)", uint8_t(0x01), uint8_t(0x05));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x00)), encodeArgs(uint8_t(0xef)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0x01)), encodeArgs(uint8_t(0x05)));
|
||||
ABI_CHECK(callContractFunction("get(uint8)", uint8_t(0xa7)), encodeArgs(uint8_t(0x00)));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(mapping_state)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
@ -1057,34 +1003,6 @@ BOOST_AUTO_TEST_CASE(constructor)
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_elementary_accessors)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
uint256 public data;
|
||||
bytes6 public name;
|
||||
bytes32 public a_hash;
|
||||
address public an_address;
|
||||
constructor() public {
|
||||
data = 8;
|
||||
name = "Celina";
|
||||
a_hash = keccak256("\x7b");
|
||||
an_address = address(0x1337);
|
||||
super_secret_data = 42;
|
||||
}
|
||||
uint256 super_secret_data;
|
||||
}
|
||||
)";
|
||||
ALSO_VIA_YUL(
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("data()"), encodeArgs(8));
|
||||
ABI_CHECK(callContractFunction("name()"), encodeArgs("Celina"));
|
||||
ABI_CHECK(callContractFunction("a_hash()"), encodeArgs(util::keccak256(bytes(1, 0x7b))));
|
||||
ABI_CHECK(callContractFunction("an_address()"), encodeArgs(util::toBigEndian(u160(0x1337))));
|
||||
ABI_CHECK(callContractFunction("super_secret_data()"), bytes());
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(balance)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
|
@ -0,0 +1,22 @@
|
||||
contract test {
|
||||
uint256 public data;
|
||||
bytes6 public name;
|
||||
bytes32 public a_hash;
|
||||
address public an_address;
|
||||
constructor() public {
|
||||
data = 8;
|
||||
name = "Celina";
|
||||
a_hash = keccak256("\x7b");
|
||||
an_address = address(0x1337);
|
||||
super_secret_data = 42;
|
||||
}
|
||||
uint256 super_secret_data;
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// data() -> 8
|
||||
// name() -> "Celina"
|
||||
// a_hash() -> 0xa91eddf639b0b768929589c1a9fd21dcb0107199bdd82e55c5348018a1572f52
|
||||
// an_address() -> 0x1337
|
||||
// super_secret_data() -> FAILURE
|
27
test/libsolidity/semanticTests/types/mapping_simple.sol
Normal file
27
test/libsolidity/semanticTests/types/mapping_simple.sol
Normal file
@ -0,0 +1,27 @@
|
||||
contract test {
|
||||
mapping(uint8 => uint8) table;
|
||||
function get(uint8 k) public returns (uint8 v) {
|
||||
return table[k];
|
||||
}
|
||||
function set(uint8 k, uint8 v) public {
|
||||
table[k] = v;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0
|
||||
// get(uint8): 0xa7 -> 0
|
||||
// set(uint8,uint8): 0x01, 0xa1 ->
|
||||
// get(uint8): 0 -> 0
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> 0
|
||||
// set(uint8,uint8): 0x00, 0xef ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0xa1
|
||||
// get(uint8): 0xa7 -> 0
|
||||
// set(uint8,uint8): 0x01, 0x05 ->
|
||||
// get(uint8): 0 -> 0xef
|
||||
// get(uint8): 0x01 -> 0x05
|
||||
// get(uint8): 0xa7 -> 0
|
15
test/libsolidity/semanticTests/types/strings.sol
Normal file
15
test/libsolidity/semanticTests/types/strings.sol
Normal file
@ -0,0 +1,15 @@
|
||||
contract test {
|
||||
function fixedBytes() public returns(bytes32 ret) {
|
||||
return "abc\x00\xff__";
|
||||
}
|
||||
function pipeThrough(bytes2 small, bool one) public returns(bytes16 large, bool oneRet) {
|
||||
oneRet = one;
|
||||
large = small;
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// fixedBytes() -> "abc\0\xff__"
|
||||
// pipeThrough(bytes2, bool): "\0\x02", true -> "\0\x2", true
|
Loading…
Reference in New Issue
Block a user