mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add inline assembly test for sha3/keccak256
This commit is contained in:
parent
524a52660d
commit
dcb7c51920
@ -481,6 +481,14 @@ BOOST_AUTO_TEST_CASE(revert)
|
|||||||
BOOST_CHECK(successAssemble("{ revert(0, 0) }"));
|
BOOST_CHECK(successAssemble("{ revert(0, 0) }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(keccak256)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(successAssemble("{ 0 0 keccak256 pop }"));
|
||||||
|
BOOST_CHECK(successAssemble("{ pop(keccak256(0, 0)) }"));
|
||||||
|
BOOST_CHECK(successAssemble("{ 0 0 sha3 pop }"));
|
||||||
|
BOOST_CHECK(successAssemble("{ pop(sha3(0, 0)) }"));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -9338,6 +9338,45 @@ BOOST_AUTO_TEST_CASE(interface)
|
|||||||
BOOST_CHECK(callContractFunction("f(address)", recipient) == encodeArgs(true));
|
BOOST_CHECK(callContractFunction("f(address)", recipient) == encodeArgs(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(keccak256_assembly)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
function f() returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
ret := keccak256(0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function g() returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
0
|
||||||
|
0
|
||||||
|
keccak256
|
||||||
|
=: ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function h() returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
ret := sha3(0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function i() returns (bytes32 ret) {
|
||||||
|
assembly {
|
||||||
|
0
|
||||||
|
0
|
||||||
|
sha3
|
||||||
|
=: ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "C");
|
||||||
|
BOOST_CHECK(callContractFunction("f()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
|
BOOST_CHECK(callContractFunction("g()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
|
BOOST_CHECK(callContractFunction("h()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
|
BOOST_CHECK(callContractFunction("i()") == fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user