Skip to content

Commit

Permalink
test stake succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jun 15, 2024
1 parent 0e63a96 commit 0ccb250
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
6 changes: 1 addition & 5 deletions src/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ contract RewardsDistributor is Ownable2StepUpgradeable {

uint256 id = rewardConfigurationsIds[receiver][token];

require(
rewardConfigurations[receiver].length > 0 && id > 0,
"No reward configuration found"
);
require(id > 0, "No reward configuration found");

Check warning on line 101 in src/RewardsDistributor.sol

View workflow job for this annotation

GitHub Actions / lint

GC: Use Custom Errors instead of require statements

RewardConfiguration storage rewardConfiguration = rewardConfigurations[
receiver
Expand All @@ -121,7 +118,6 @@ contract RewardsDistributor is Ownable2StepUpgradeable {
rewardConfiguration.lastUpdate = block.timestamp;

// transfer the reward
// TODO change to safeTransfer
IERC20(token).safeTransfer(receiver, reward);
}
}
34 changes: 21 additions & 13 deletions test/unit/StakingUnitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {MockShu} from "../mocks/MockShu.sol";

contract StakingUnitTest is Test {
IStaking public staking;
MockShu public shu;

uint256 constant lockPeriod = 60 * 24 * 30 * 6; // 6 months
uint256 constant minStake = 50_000 * 1e18; // 50k
Expand All @@ -22,33 +23,27 @@ contract StakingUnitTest is Test {

function setUp() public {
// deploy mock shu
MockShu shu = new MockShu();
shu = new MockShu();

shu.mint(keyper, 1_000_000 * 1e18);

// deploy rewards distributor
address rewardsDistributor = address(new RewardsDistributor());

address rewardsDistributionProxy = address(
new TransparentUpgradeableProxy(
rewardsDistributor,
address(new RewardsDistributor()),
address(this),
""
abi.encodeWithSignature("initialize(address)", address(this))
)
);

RewardsDistributor(rewardsDistributionProxy).initialize(
address(this) // owner
);

// deploy staking
address stakingContract = address(new Staking());

address stakingProxy = address(
new TransparentUpgradeableProxy(stakingContract, address(this), "")
);

Staking(address(stakingProxy)).initialize(
Staking(stakingProxy).initialize(
address(this), // owner
address(shu),
address(rewardsDistributionProxy),
Expand All @@ -57,8 +52,18 @@ contract StakingUnitTest is Test {
);

staking = IStaking(stakingProxy);

IRewardsDistributor(rewardsDistributionProxy).addRewardConfiguration(
stakingProxy,
address(shu),
1e18
);
}

/*//////////////////////////////////////////////////////////////
HAPPY PATHS
//////////////////////////////////////////////////////////////*/

function testAddKeyper() public {
vm.expectEmit(address(staking));
emit IStaking.KeyperSet(keyper, true);
Expand All @@ -68,14 +73,17 @@ contract StakingUnitTest is Test {
function testStakeSucceed() public {
testAddKeyper();

vm.startPrank(keyper);
shu.approve(address(staking), minStake);

vm.expectEmit(true, true, true, true, address(staking));
emit IStaking.Staked(
address(this),
keyper,
minStake,
minStake, // first stake, shares == amount
lockPeriod
);
vm.prank(keyper);
staking.stake(50_000 * 1e18);

staking.stake(minStake);
}
}

0 comments on commit 0ccb250

Please sign in to comment.