From c6ad99c3b13e68dbeae5889d2c5ae7c98c499c72 Mon Sep 17 00:00:00 2001 From: wechman Date: Mon, 1 Aug 2022 09:07:28 +0200 Subject: [PATCH] Add FunctionCallGraph unit tests for user defined operators --- .../analysis/FunctionCallGraph.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/libsolidity/analysis/FunctionCallGraph.cpp b/test/libsolidity/analysis/FunctionCallGraph.cpp index 7b67aeb44..624d50fb3 100644 --- a/test/libsolidity/analysis/FunctionCallGraph.cpp +++ b/test/libsolidity/analysis/FunctionCallGraph.cpp @@ -1702,6 +1702,72 @@ BOOST_AUTO_TEST_CASE(using_for) checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges); } +BOOST_AUTO_TEST_CASE(user_defined_binary_operator) +{ + unique_ptr compilerStack = parseAndAnalyzeContracts(R"( + type Int is int128; + using {add as +} for Int; + + function add(Int, Int) returns (Int) { + return Int.wrap(0); + } + + contract C { + function test() public { + Int.wrap(0) + Int.wrap(1); + } + } + )"s); + tuple graphs = collectGraphs(*compilerStack); + + map expectedCreationEdges = { + {"C", {}}, + }; + + map expectedDeployedEdges = { + {"C", { + {"Entry", "function C.test()"}, + {"function C.test()", "function add(Int,Int)"}, + }}, + }; + + checkCallGraphExpectations(get<0>(graphs), expectedCreationEdges); + checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges); +} + +BOOST_AUTO_TEST_CASE(user_defined_unary_operator) +{ + unique_ptr compilerStack = parseAndAnalyzeContracts(R"( + type Int is int128; + using {sub as -} for Int; + + function sub(Int) returns (Int) { + return Int.wrap(0); + } + + contract C { + function test() public { + -Int.wrap(1); + } + } + )"s); + tuple graphs = collectGraphs(*compilerStack); + + map expectedCreationEdges = { + {"C", {}}, + }; + + map expectedDeployedEdges = { + {"C", { + {"Entry", "function C.test()"}, + {"function C.test()", "function sub(Int)"}, + }}, + }; + + checkCallGraphExpectations(get<0>(graphs), expectedCreationEdges); + checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges); +} + BOOST_AUTO_TEST_CASE(getters) { unique_ptr compilerStack = parseAndAnalyzeContracts(R"(