-
I am writing a stake function and testing with forge. Please see code below: function stake(uint256 _tokenId) public nonReentrant {
require(stakedNft.ownerOf(_tokenId) == msg.sender, "You don't own this token.");
if(stakers[msg.sender].amountStaked > 0) {
uint256 rewards = calculateRewards(msg.sender);
stakers[msg.sender].unclaimedRewards += rewards;
}
//stakedNft.approve(address(this), _tokenId);
//this.onERC721Received(address(this), msg.sender, _tokenId, "");
stakedNft.safeTransferFrom(msg.sender, address(this), _tokenId);
StakedToken memory stakedToken = StakedToken(msg.sender, _tokenId);
stakers[msg.sender].stakedTokens.push(stakedToken);
stakers[msg.sender].amountStaked++;
stakerAddress[_tokenId] = msg.sender;
stakers[msg.sender].timeOfLastUpdate = block.timestamp;
} TEST: // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/DPDepositor.sol";
contract DPDepositorTest is Test {
DPDepositor depositor;
IERC20 immutable CeoTokenTest = IERC20(0x5FbDB2315678afecb367f032d93F642f64180aa3);
IERC721 immutable dpGenOne = IERC721(0xede855ceD3e5A59Aaa267aBdDdB0dB21CCFE5072);
address public owner = /*[FAKEADDRESS]*/;
function setUp() public {
depositor = new DPDepositor(CeoTokenTest,dpGenOne);
}
function testPepeHolderCanStake() public {
vm.prank(owner);
depositor.stake(780);
}
} The problem i'm getting is that my function works all the way until I hit The reason I think that might be the case is that according to openzeppelin the Thanks for the assistance here! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Figured it out. Had to add vm.startPrank(owner);
dpGenOne.setApprovalForAll(address(depositor), true); In the test function. All good, thanks! |
Beta Was this translation helpful? Give feedback.
Figured it out. Had to add
In the test function. All good, thanks!