From 5c042e2e592ff52542224f61d181c109d15e4573 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 12 Mar 2015 17:31:39 +0100 Subject: [PATCH] Small FixedBytes type fixes - Integer Constant is explicitly convertible to FixedBytes, so using that in the tests --- libsolidity/Types.cpp | 7 ++----- test/SolidityEndToEndTest.cpp | 16 +++++++--------- test/SolidityNameAndTypeResolution.cpp | 1 + 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 22e9dfb81..bd55e2a8b 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -191,13 +191,10 @@ TypePointer IntegerType::unaryOperatorResult(Token::Value _operator) const // no further unary operators for addresses else if (isAddress()) return TypePointer(); - // "~" is ok for all other types - else if (_operator == Token::BitNot) - return shared_from_this(); // for non-address integers, we allow +, -, ++ and -- else if (_operator == Token::Add || _operator == Token::Sub || _operator == Token::Inc || _operator == Token::Dec || - _operator == Token::After) + _operator == Token::After || _operator == Token::BitNot) return shared_from_this(); else return TypePointer(); @@ -1154,7 +1151,7 @@ MagicType::MagicType(MagicType::Kind _kind): case Kind::Block: m_members = MemberList({{"coinbase", make_shared(0, IntegerType::Modifier::Address)}, {"timestamp", make_shared(256)}, - {"blockhash", make_shared(strings{"uint"}, strings{"bytes"}, FunctionType::Location::BlockHash)}, + {"blockhash", make_shared(strings{"uint"}, strings{"bytes32"}, FunctionType::Location::BlockHash)}, {"difficulty", make_shared(256)}, {"number", make_shared(256)}, {"gaslimit", make_shared(256)}}); diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index 5f95709c5..2f965849b 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -1182,14 +1182,12 @@ BOOST_AUTO_TEST_CASE(send_ether) BOOST_CHECK(callContractFunction("a(address,uint256)", address, amount) == encodeArgs(1)); BOOST_CHECK_EQUAL(m_state.balance(address), amount); } -// TODO: Note that these tests should actually be -// simply converting integer constant to bytes32. This conversion is not there -// yet. When it's implemented DO change the tests too + BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = "contract test {\n" " function a() {\n" - " log0(bytes32(1));\n" + " log0(1);\n" " }\n" "}\n"; compileAndRun(sourceCode); @@ -1204,7 +1202,7 @@ BOOST_AUTO_TEST_CASE(log1) { char const* sourceCode = "contract test {\n" " function a() {\n" - " log1(bytes32(1), bytes32(2));\n" + " log1(1, 2);\n" " }\n" "}\n"; compileAndRun(sourceCode); @@ -1220,7 +1218,7 @@ BOOST_AUTO_TEST_CASE(log2) { char const* sourceCode = "contract test {\n" " function a() {\n" - " log2(bytes32(1), bytes32(2), bytes32(3));\n" + " log2(1, 2, 3);\n" " }\n" "}\n"; compileAndRun(sourceCode); @@ -1237,7 +1235,7 @@ BOOST_AUTO_TEST_CASE(log3) { char const* sourceCode = "contract test {\n" " function a() {\n" - " log3(bytes32(1), bytes32(2), bytes32(3), bytes32(4));\n" + " log3(1, 2, 3, 4);\n" " }\n" "}\n"; compileAndRun(sourceCode); @@ -1254,7 +1252,7 @@ BOOST_AUTO_TEST_CASE(log4) { char const* sourceCode = "contract test {\n" " function a() {\n" - " log4(bytes32(1), bytes32(2), bytes32(3), bytes32(4), bytes32(5));\n" + " log4(1, 2, 3, 4, 5);\n" " }\n" "}\n"; compileAndRun(sourceCode); @@ -1271,7 +1269,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor) { char const* sourceCode = "contract test {\n" " function test() {\n" - " log1(bytes32(1), bytes32(2));\n" + " log1(1, 2);\n" " }\n" "}\n"; compileAndRun(sourceCode); diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index 99a1a8bcb..a310800f7 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -1358,6 +1358,7 @@ BOOST_AUTO_TEST_CASE(test_fromElementaryTypeName) BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt248) == *make_shared(248, IntegerType::Modifier::Unsigned)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::UInt256) == *make_shared(256, IntegerType::Modifier::Unsigned)); + BOOST_CHECK(*Type::fromElementaryTypeName(Token::Byte) == *make_shared(1)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes0) == *make_shared(0)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes1) == *make_shared(1)); BOOST_CHECK(*Type::fromElementaryTypeName(Token::Bytes2) == *make_shared(2));