From 8566d523be41e1c11403f656eca6ad6ff030cca4 Mon Sep 17 00:00:00 2001 From: Haofan Zheng Date: Thu, 24 Aug 2023 17:33:48 -0700 Subject: [PATCH] Added test of gas cost on map del --- tests/BasicActionGasCost.sol | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/BasicActionGasCost.sol b/tests/BasicActionGasCost.sol index 9f96460..67eaa93 100644 --- a/tests/BasicActionGasCost.sol +++ b/tests/BasicActionGasCost.sol @@ -19,10 +19,13 @@ contract BasicActionGasCost { address m_subAddr = address(0); bool m_someBool = false; mapping(address => bool) m_someMap; + address m_someAddr = 0x0000000000000000000000000000000000000000; constructor() { GasEvalSubscriber sub = new GasEvalSubscriber(); m_subAddr = address(sub); + + m_someMap[m_someAddr] = true; } function eval() external { @@ -32,6 +35,7 @@ contract BasicActionGasCost { uint256 gasUsed = 0; bool someBool = !m_someBool; address someAddr = msg.sender; + address someAddr2 = m_someAddr; gasStart = gasleft(); GasEvalSubscriber(m_subAddr).onNotify(data); @@ -47,5 +51,13 @@ contract BasicActionGasCost { m_someMap[someAddr] = someBool; gasUsed = gasStart - gasleft(); emit LogGasCost(3, gasUsed); + + gasStart = gasleft(); + delete m_someMap[someAddr2]; + gasUsed = gasStart - gasleft(); + emit LogGasCost(4, gasUsed); + + m_someBool = false; + m_someMap[someAddr2] = true; } }