CRYPTO NEWS

testing in hardhat delegatecall returns invalid values

I’m trying to test if the delegatecall works fine, but I got an unwanted result.

contract CallerContract{     uint256 public value;     address public sender;     string  public name;          constructor() payable{        }          function testDelegateCall(string memory _name, TargetContractDelegate tc) public payable{         value  = msg.value;         sender = msg.sender;         name   = _name;         (bool success, bytes memory data) = payable(address(tc)).delegatecall(             abi.encodeWithSelector(TargetContractDelegate.targetFunction.selector, "Some Name")             );     }      }  contract TargetContractDelegate{     uint256 public value;     address public sender;     string  public name;            function targetFunction(string memory _nameTarget) public payable{         value       = msg.value;         sender      = msg.sender;         name        = _nameTarget;     }      function getValues() public view returns(string memory, address, uint) {         return (name, sender, value);     } } 

and my test file:

describe("Delegate Contract Testing...n", function () {          async function deployTokenFixture() {          const [deployer] = await ethers.getSigners();          const CallerContract = await ethers.getContractFactory("CallerContract");         const callercontract = await CallerContract.deploy();         await callercontract.deployed();                  const TargetContractDelegate = await ethers.getContractFactory("TargetContractDelegate");         const targetcontract = await TargetContractDelegate.deploy();         await targetcontract.deployed();                 return {              CallerContract,             callercontract,              TargetContractDelegate,              targetcontract,              deployer         }     }      describe("Deployment", function() {                   it("can call the target function a pass args", async function() {             const { callercontract, targetcontract, deployer } = await loadFixture(deployTokenFixture);              const tx = await callercontract.testDelegateCall(                 "Mensaje", targetcontract.address                 );              console.log('==========================')             //console.log(tx);              const l = await targetcontract.getValues();             console.log(l);         });     }); }); 

the console returns with:

[   '',   '0x0000000000000000000000000000000000000000',   BigNumber { value: "0" } ] 

testing in hardhat delegatecall returns invalid values

Shopping cart
There are no products in the cart!
Continue shopping
0