diff --git a/contracts/ApplicationManager.sol b/contracts/ApplicationManager.sol index c8046d3..f526bb2 100644 --- a/contracts/ApplicationManager.sol +++ b/contracts/ApplicationManager.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.24; +pragma solidity 0.8.25; import {IApplicationManager} from "./IApplicationManager.sol"; diff --git a/contracts/IApplicationManager.sol b/contracts/IApplicationManager.sol index b347cb5..b61563f 100644 --- a/contracts/IApplicationManager.sol +++ b/contracts/IApplicationManager.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.24; +pragma solidity 0.8.25; interface IApplicationManager { struct Application { diff --git a/contracts/Lock.sol b/contracts/Lock.sol deleted file mode 100644 index 1efbef3..0000000 --- a/contracts/Lock.sol +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.24; - -// Uncomment this line to use console.log -// import "hardhat/console.sol"; - -contract Lock { - uint public unlockTime; - address payable public owner; - - event Withdrawal(uint amount, uint when); - - constructor(uint _unlockTime) payable { - require( - block.timestamp < _unlockTime, - "Unlock time should be in the future" - ); - - unlockTime = _unlockTime; - owner = payable(msg.sender); - } - - function withdraw() public { - // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal - // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); - - require(block.timestamp >= unlockTime, "You can't withdraw yet"); - require(msg.sender == owner, "You aren't the owner"); - - emit Withdrawal(address(this).balance, block.timestamp); - - owner.transfer(address(this).balance); - } -} diff --git a/hardhat.config.ts b/hardhat.config.ts index e9dd2db..b52395c 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -3,7 +3,7 @@ import "@nomicfoundation/hardhat-toolbox-viem"; import "@nomiclabs/hardhat-solhint"; const config: HardhatUserConfig = { - solidity: "0.8.24", + solidity: "0.8.25", }; export default config; diff --git a/test/Lock.ts b/test/Lock.ts deleted file mode 100644 index 5a81076..0000000 --- a/test/Lock.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { - loadFixture, - time, -} from "@nomicfoundation/hardhat-toolbox-viem/network-helpers"; -import { expect } from "chai"; -import hre from "hardhat"; -import { getAddress, parseGwei } from "viem"; - -describe("Lock", () => { - // We define a fixture to reuse the same setup in every test. - // We use loadFixture to run this setup once, snapshot that state, - // and reset Hardhat Network to that snapshot in every test. - async function deployOneYearLockFixture() { - const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60; - - const lockedAmount = parseGwei("1"); - const unlockTime = BigInt((await time.latest()) + ONE_YEAR_IN_SECS); - - // Contracts are deployed using the first signer/account by default - const [owner, otherAccount] = await hre.viem.getWalletClients(); - - const lock = await hre.viem.deployContract("Lock", [unlockTime], { - value: lockedAmount, - }); - - const publicClient = await hre.viem.getPublicClient(); - - return { - lock, - unlockTime, - lockedAmount, - owner, - otherAccount, - publicClient, - }; - } - - describe("Deployment", () => { - it("Should set the right unlockTime", async () => { - const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture); - - expect(await lock.read.unlockTime()).to.equal(unlockTime); - }); - - it("Should set the right owner", async () => { - const { lock, owner } = await loadFixture(deployOneYearLockFixture); - - expect(await lock.read.owner()).to.equal( - getAddress(owner.account.address), - ); - }); - - it("Should receive and store the funds to lock", async () => { - const { lock, lockedAmount, publicClient } = await loadFixture( - deployOneYearLockFixture, - ); - - expect( - await publicClient.getBalance({ - address: lock.address, - }), - ).to.equal(lockedAmount); - }); - - it("Should fail if the unlockTime is not in the future", async () => { - // We don't use the fixture here because we want a different deployment - const latestTime = BigInt(await time.latest()); - await expect( - hre.viem.deployContract("Lock", [latestTime], { - value: 1n, - }), - ).to.be.rejectedWith("Unlock time should be in the future"); - }); - }); - - describe("Withdrawals", () => { - describe("Validations", () => { - it("Should revert with the right error if called too soon", async () => { - const { lock } = await loadFixture(deployOneYearLockFixture); - - await expect(lock.write.withdraw()).to.be.rejectedWith( - "You can't withdraw yet", - ); - }); - - it("Should revert with the right error if called from another account", async () => { - const { lock, unlockTime, otherAccount } = await loadFixture( - deployOneYearLockFixture, - ); - - // We can increase the time in Hardhat Network - await time.increaseTo(unlockTime); - - // We retrieve the contract with a different account to send a transaction - const lockAsOtherAccount = await hre.viem.getContractAt( - "Lock", - lock.address, - { client: { wallet: otherAccount } }, - ); - await expect(lockAsOtherAccount.write.withdraw()).to.be.rejectedWith( - "You aren't the owner", - ); - }); - - it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async () => { - const { lock, unlockTime } = await loadFixture( - deployOneYearLockFixture, - ); - - // Transactions are sent using the first signer by default - await time.increaseTo(unlockTime); - - await expect(lock.write.withdraw()).to.be.fulfilled; - }); - }); - - describe("Events", () => { - it("Should emit an event on withdrawals", async () => { - const { lock, unlockTime, lockedAmount, publicClient } = - await loadFixture(deployOneYearLockFixture); - - await time.increaseTo(unlockTime); - - const hash = await lock.write.withdraw(); - await publicClient.waitForTransactionReceipt({ hash }); - - // get the withdrawal events in the latest block - const withdrawalEvents = await lock.getEvents.Withdrawal(); - expect(withdrawalEvents).to.have.lengthOf(1); - expect(withdrawalEvents[0].args.amount).to.equal(lockedAmount); - }); - }); - }); -});