ERC-20 Staking Vault

Stake STK · earn more STK · ReentrancyGuard · 6 Hardhat tests

Contract overview

Lab 6 / 6 Hardhat passing Solidity 0.8.20 Local network only

Two contracts:

Rewards accrue at a per-second rate the owner sets with setRewardRate. Guards:

How this staking vault works

How the tests work

Run on the author’s machine with Hardhat’s local network (no wallet, no public RPC):

npm install
npx hardhat test

Evidence re-ran 2026-09-09 (ET): 6 passing, 0 failing (~3s). Exit code 0. No private key used. No testnet or mainnet transaction.

Hardhat test results for staking vault

What each of the 6 tests checks

TestResult
Stake records the balance before the transfer returnspass
Withdraw above staked amount revertspass
Withdraw returns principalpass
Rewards accrue after 100 seconds (~100 tokens at 1 token/s)pass
Two equal stakers earn about the samepass
Non-owner cannot change rewardRatepass

Source layout: test/StakingVault.js · JSON evidence in repo results/tests.json.

Links

Open GitHub repo Back to labs index

Author: Harsha Nandhan Reddy Gajulapalli · MIT · harshanandhanreddy820@gmail.com