ERc20 balance is not update when using proxy

35 views Asked by At

I am try to test the code in this page. : https://medium.com/@solidity101/100daysofsolidity-057-supercharge-your-smart-contract-deployments-with-proxy-pattern-604659d2117d

But the balance is not update , is there any error in this page ? or it is normal that the balance is not update because the proxy don't have storage variable ?

The proxy code

// Proxy contract - Proxy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Proxy {
 address public implementation;
constructor(address _implementation) {
 implementation = _implementation;
 }
fallback() external payable {
 address _impl = implementation;
 assembly {
 calldatacopy(0, 0, calldatasize())
 let result := delegatecall(gas(), _impl, 0, calldatasize(), 0, 0)
 returndatacopy(0, 0, returndatasize())
 switch result
 case 0 { revert(0, returndatasize()) }
 default { return(0, returndatasize()) }
 }
 }
}

ERC20 code

import "openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20Token is ERC20 {
    constructor() ERC20("GRYDL", "GRD") {
        _mint(msg.sender, 100 ether);
    }
}

and the test

const Proxy = artifacts.require("Proxy");
const ERC20Token = artifacts.require("ERC20Token");
module.exports = async function (deployer) {
 await deployer.deploy(ERC20Token, "MyToken", "MTK");
 const erc20Token = await ERC20Token.deployed();
 await deployer.deploy(Proxy, erc20Token.address);
};

// JavaScript code for interacting with the Proxy contract
const Proxy = artifacts.require("Proxy");
const ERC20Token = artifacts.require("ERC20Token");
module.exports = async function (deployer) {
 const proxy = await Proxy.deployed();
 const erc20Token = await ERC20Token.at(proxy.address);
// Perform ERC20 token transfers using the Proxy
 const recipient = "0x1234567890123456789012345678901234567890";
 const amount = 100;
 await erc20Token.transfer(recipient, amount);
// Check the balance of the recipient
 const recipientBalance = await erc20Token.balanceOf(recipient);
 console.log("Recipient Balance:", recipientBalance.toString());
};
0

There are 0 answers