github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata-istanbul/write-protection-002.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity ^0.6.6;
     3  
     4  // NOTE: Deploy this contract first
     5  contract B {
     6      // NOTE: storage layout must be the same as contract A
     7      uint public num;
     8      address public sender;
     9      uint public value;
    10      event Done();
    11  
    12      function setVars(uint _num) public payable {
    13          num = _num;
    14          sender = msg.sender;
    15          value = msg.value;
    16          emit Done();
    17      }
    18  }
    19  
    20  contract A {
    21      uint public num;
    22      address public sender;
    23      uint public value;
    24      address private c;
    25      mapping(uint => uint) private _a;
    26      event Success(bool);
    27  
    28      function make() public {
    29          c = address(new B());
    30          _a[1] = 1;
    31          _a[2] = 2;
    32          _a[3] = 3;
    33      }
    34  
    35      function setVars(address _contract, uint _num) public returns (uint256) {
    36          if (_contract == address(0)) {
    37              _contract = c;
    38          }
    39          delete _a[1];
    40          (bool success, bytes memory _) = _contract.staticcall(
    41              abi.encodeWithSignature("setVars(uint256)", _num)
    42          );
    43          emit Success(success);
    44  
    45          return 1;
    46      }
    47  }