title: How to limit token receiver callers to accepted token address?
body: <p>I want to create a payable token
  which includes a function <code>transferAndCall(TokenReceiver to, uint256 amount, bytes4 selector)</code>.
  By calling this function, you can transfer tokens to the <code>TokenReceiver</code> smart contract address,
  and then call <code>onTransferReceived(address from,uint tokensPaid, bytes4 selector)</code> on the receiver,
  which in turn invokes a function specified in the<code>bytes4 selector</code> on the receiver.</p>
  <p>Note that this is similar to/ inspired by <a href="https://eips.ethereum.org/EIPS/eip-1363" rel="noreferrer">ERC1363</a>.</p>
  <p>Here is a simplified version of my receivable token:</p>
  <pre><code>import &quot;@openzeppelin/contracts/token/ERC20/ERC20.sol&quot;;
  contract MeowToken is ERC20 {
    constructor() ERC20(&quot;MeowToken&quot;, &quot;MEO&quot;) {
      ERC20._mint(msg.sender, 10_000_000);
    }
    function transferAndCall(
      TokenReceiver to,
      uint256 amount,
      bytes4 selector
    ) external {
      ERC20.transfer(address(to), amount);
      to.onTransferReceived(msg.sender, amount, selector);
    }
  }
  </code></pre>
  <p>And this is a token receiver:</p>
  <pre><code>contract TokenReceiver {
    address acceptedToken;
    event PurchaseMade(address from, uint tokensPaid);
      
    modifier acceptedTokenOnly () {
      require(msg.sender == address(acceptedToken), &quot;Should be called only via the accepted token&quot;);
      _;
    }
      
    constructor(address _acceptedToken) {
      acceptedToken = _acceptedToken;
    }
      
    function onTransferReceived(
      address from,
      uint tokensPaid,
      bytes4 selector
    ) public acceptedTokenOnly {
      (bool success,) = address(this).call(abi.encodeWithSelector(selector, from, tokensPaid));
      require(success, &quot;Function call failed&quot;);
    }
  
    function purchase(address from, uint tokensPaid) public acceptedTokenOnly {
      emit PurchaseMade(from, tokensPaid);
    }
  }
  </code></pre>
  <p>I want to make sure that public functions on the receiver are <strong>only</strong> called via the payable token.
  For this reason I added <code>acceptedTokenOnly</code> modifier to both of them.
  However after adding the modifier my test began to fail:</p>
  <pre class="lang-js prettyprint-override"><code>it('Transfer Tokens and call Purchase', async () =&gt; {
      const tokenAmount = 100;
      const tx = meowToken.transferAndCall(
        tokenReceiver.address,
        tokenAmount,
        tokenReceiver.interface.getSighash('purchase'),
      );
      await expect(tx)
        .to.emit(tokenReceiver, 'PurchaseMade')
        .withArgs(deployer.address, tokenAmount);
  });
  </code></pre>
  <pre><code>1) Transfer and call
         Transfer Tokens and call Purchase:
       Error: VM Exception while processing transaction: reverted with reason string 'Function call failed'
  </code></pre>
  <p>Why does this happen?
  How to make sure the receiver's functions are invoked only by the accepted token?</p>
  <p>For reference, I am developing and testing smart contracts in Hardhat and deploying on <a href="https://developers.rsk.co/" rel="noreferrer">RSK</a>.</p>