...
This commit is contained in:
parent
c749e1cd0d
commit
be8cd8310a
37
.gitignore
vendored
37
.gitignore
vendored
@ -4,4 +4,39 @@
|
||||
node_modules
|
||||
logs/
|
||||
dist/
|
||||
tests_output/
|
||||
tests_output/
|
||||
node_modules
|
||||
.env
|
||||
coverage
|
||||
coverage.json
|
||||
typechain
|
||||
typechain-types
|
||||
|
||||
# Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
||||
|
||||
node_modules
|
||||
.env
|
||||
coverage
|
||||
coverage.json
|
||||
typechain
|
||||
typechain-types
|
||||
|
||||
# Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
||||
|
||||
node_modules
|
||||
.env
|
||||
coverage
|
||||
coverage.json
|
||||
typechain
|
||||
typechain-types
|
||||
|
||||
# Hardhat files
|
||||
cache
|
||||
artifacts
|
||||
|
||||
|
29
README.md
29
README.md
@ -1,24 +1,13 @@
|
||||
# gamesns
|
||||
# Sample Hardhat Project
|
||||
|
||||
## Project setup
|
||||
```
|
||||
npm install
|
||||
```
|
||||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
npm run serve
|
||||
```
|
||||
Try running some of the following tasks:
|
||||
|
||||
### Compiles and minifies for production
|
||||
```shell
|
||||
npx hardhat help
|
||||
npx hardhat test
|
||||
REPORT_GAS=true npx hardhat test
|
||||
npx hardhat node
|
||||
npx hardhat run scripts/deploy.js
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
```
|
||||
npm run lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
||||
|
34
contracts/Lock.sol
Normal file
34
contracts/Lock.sol
Normal file
@ -0,0 +1,34 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.9;
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
6
hardhat.config.js
Normal file
6
hardhat.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
require("@nomicfoundation/hardhat-toolbox");
|
||||
|
||||
/** @type import('hardhat/config').HardhatUserConfig */
|
||||
module.exports = {
|
||||
solidity: "0.8.17",
|
||||
};
|
14630
package-lock.json
generated
14630
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -13,8 +13,6 @@
|
||||
"coverage": "vitest run --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.2.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.3",
|
||||
"@vueuse/core": "^9.6.0",
|
||||
"@vueuse/motion": "^2.0.0-beta.12",
|
||||
"@walletconnect/web3-provider": "^1.7.1",
|
||||
@ -22,13 +20,9 @@
|
||||
"ant-design-vue": "^3.2.13",
|
||||
"axios": "^1.2.0",
|
||||
"buffer": "^6.0.3",
|
||||
"chai": "^4.3.7",
|
||||
"core-js": "^3.8.3",
|
||||
"css-vars-ponyfill": "^2.4.8",
|
||||
"ethereum-waffle": "^3.4.4",
|
||||
"ethers": "^5.7.2",
|
||||
"gsap": "^3.11.3",
|
||||
"hardhat": "^2.12.6",
|
||||
"motion": "^10.14.3",
|
||||
"pinia": "^2.0.23",
|
||||
"process": "^0.11.10",
|
||||
@ -42,14 +36,23 @@
|
||||
"@emotion/is-prop-valid": "^1.2.0",
|
||||
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
||||
"@nightwatch/vue": "^0.4.1",
|
||||
"@nomicfoundation/hardhat-chai-matchers": "^1.0.5",
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.1",
|
||||
"@nomiclabs/hardhat-ethers": "^2.2.2",
|
||||
"@rollup/plugin-alias": "^4.0.2",
|
||||
"@vitejs/plugin-vue": "^3.2.0",
|
||||
"@vue/test-utils": "^2.0.0-rc.18",
|
||||
"browserify-zlib": "^0.2.0",
|
||||
"chai": "^4.3.7",
|
||||
"chromedriver": "^109.0.0",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"d3": "^7.6.1",
|
||||
"eslint-plugin-vue": "^9.9.0",
|
||||
"ethers": "^5.7.2",
|
||||
"geckodriver": "^3.2.0",
|
||||
"hardhat": "^2.12.6",
|
||||
"js-cookie": "^3.0.1",
|
||||
"lodash": "^4.17.21",
|
||||
"nightwatch": "^2.6.10",
|
||||
"rollup-plugin-polyfill-node": "^0.11.0",
|
||||
"sass": "^1.56.1",
|
||||
|
31
scripts/deploy.js
Normal file
31
scripts/deploy.js
Normal file
@ -0,0 +1,31 @@
|
||||
// We require the Hardhat Runtime Environment explicitly here. This is optional
|
||||
// but useful for running the script in a standalone fashion through `node <script>`.
|
||||
//
|
||||
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
|
||||
// will compile your contracts, add the Hardhat Runtime Environment's members to the
|
||||
// global scope, and execute the script.
|
||||
const hre = require("hardhat");
|
||||
|
||||
async function main() {
|
||||
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
|
||||
const ONE_YEAR_IN_SECS = 365 * 24 * 60 * 60;
|
||||
const unlockTime = currentTimestampInSeconds + ONE_YEAR_IN_SECS;
|
||||
|
||||
const lockedAmount = hre.ethers.utils.parseEther("1");
|
||||
|
||||
const Lock = await hre.ethers.getContractFactory("Lock");
|
||||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
||||
|
||||
await lock.deployed();
|
||||
|
||||
console.log(
|
||||
`Lock with 1 ETH and unlock timestamp ${unlockTime} deployed to ${lock.address}`
|
||||
);
|
||||
}
|
||||
|
||||
// We recommend this pattern to be able to use async/await everywhere
|
||||
// and properly handle errors.
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
126
test/Lock.js
Normal file
126
test/Lock.js
Normal file
@ -0,0 +1,126 @@
|
||||
const {
|
||||
time,
|
||||
loadFixture,
|
||||
} = require("@nomicfoundation/hardhat-network-helpers");
|
||||
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
|
||||
const { expect } = require("chai");
|
||||
|
||||
describe("Lock", function () {
|
||||
// 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 ONE_GWEI = 1_000_000_000;
|
||||
|
||||
const lockedAmount = ONE_GWEI;
|
||||
const unlockTime = (await time.latest()) + ONE_YEAR_IN_SECS;
|
||||
|
||||
// Contracts are deployed using the first signer/account by default
|
||||
const [owner, otherAccount] = await ethers.getSigners();
|
||||
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
const lock = await Lock.deploy(unlockTime, { value: lockedAmount });
|
||||
|
||||
return { lock, unlockTime, lockedAmount, owner, otherAccount };
|
||||
}
|
||||
|
||||
describe("Deployment", function () {
|
||||
it("Should set the right unlockTime", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.unlockTime()).to.equal(unlockTime);
|
||||
});
|
||||
|
||||
it("Should set the right owner", async function () {
|
||||
const { lock, owner } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
expect(await lock.owner()).to.equal(owner.address);
|
||||
});
|
||||
|
||||
it("Should receive and store the funds to lock", async function () {
|
||||
const { lock, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture
|
||||
);
|
||||
|
||||
expect(await ethers.provider.getBalance(lock.address)).to.equal(
|
||||
lockedAmount
|
||||
);
|
||||
});
|
||||
|
||||
it("Should fail if the unlockTime is not in the future", async function () {
|
||||
// We don't use the fixture here because we want a different deployment
|
||||
const latestTime = await time.latest();
|
||||
const Lock = await ethers.getContractFactory("Lock");
|
||||
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
|
||||
"Unlock time should be in the future"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Withdrawals", function () {
|
||||
describe("Validations", function () {
|
||||
it("Should revert with the right error if called too soon", async function () {
|
||||
const { lock } = await loadFixture(deployOneYearLockFixture);
|
||||
|
||||
await expect(lock.withdraw()).to.be.revertedWith(
|
||||
"You can't withdraw yet"
|
||||
);
|
||||
});
|
||||
|
||||
it("Should revert with the right error if called from another account", async function () {
|
||||
const { lock, unlockTime, otherAccount } = await loadFixture(
|
||||
deployOneYearLockFixture
|
||||
);
|
||||
|
||||
// We can increase the time in Hardhat Network
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
// We use lock.connect() to send a transaction from another account
|
||||
await expect(lock.connect(otherAccount).withdraw()).to.be.revertedWith(
|
||||
"You aren't the owner"
|
||||
);
|
||||
});
|
||||
|
||||
it("Shouldn't fail if the unlockTime has arrived and the owner calls it", async function () {
|
||||
const { lock, unlockTime } = await loadFixture(
|
||||
deployOneYearLockFixture
|
||||
);
|
||||
|
||||
// Transactions are sent using the first signer by default
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).not.to.be.reverted;
|
||||
});
|
||||
});
|
||||
|
||||
describe("Events", function () {
|
||||
it("Should emit an event on withdrawals", async function () {
|
||||
const { lock, unlockTime, lockedAmount } = await loadFixture(
|
||||
deployOneYearLockFixture
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw())
|
||||
.to.emit(lock, "Withdrawal")
|
||||
.withArgs(lockedAmount, anyValue); // We accept any value as `when` arg
|
||||
});
|
||||
});
|
||||
|
||||
describe("Transfers", function () {
|
||||
it("Should transfer the funds to the owner", async function () {
|
||||
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
|
||||
deployOneYearLockFixture
|
||||
);
|
||||
|
||||
await time.increaseTo(unlockTime);
|
||||
|
||||
await expect(lock.withdraw()).to.changeEtherBalances(
|
||||
[owner, lock],
|
||||
[lockedAmount, -lockedAmount]
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -1,13 +0,0 @@
|
||||
describe('New Helloworld Commponent test', function() {
|
||||
it('check if the component has ben mounted', async(browser) =>
|
||||
{
|
||||
browser.mountComponent('/src/views/AboutView.vue', {
|
||||
props: {
|
||||
msg:"Welcome to Your Vue.js App"
|
||||
},
|
||||
plugins: {
|
||||
router: '/src/router/index.js'
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
@ -4,7 +4,7 @@
|
||||
"module": "esnext",
|
||||
"baseUrl": "./",
|
||||
"moduleResolution": "node",
|
||||
"allowJS": true,
|
||||
"allowJs": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import nightwatchzPlugin from 'vite-plugin-nightwatch'
|
||||
import nightwatchPlugin from 'vite-plugin-nightwatch'
|
||||
import path from 'path'
|
||||
// import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
|
||||
// import requireTransform from 'vite-plugin-require-transform';
|
||||
@ -13,9 +13,7 @@ export default defineConfig({
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
nightwatchzPlugin({
|
||||
componentType: 'vue'
|
||||
}),
|
||||
nightwatchPlugin(),
|
||||
Components({}),
|
||||
// requireTransform({
|
||||
// fileRegex:/.ts$|.tsx$|.vue$/
|
||||
|
Loading…
x
Reference in New Issue
Block a user