Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "coverage",
"problemMatcher": [],
"group": "test",
"label": "npm: coverage",
"detail": "npx hardhat coverage"
},
{
"type": "npm",
"script": "vscode-audit",
"problemMatcher": [],
"group": "build",
"label": "npm: vscode-audit",
"detail": "npx hardhat audit --format json"
},
{
"type": "npm",
"script": "deploy-tron",
"problemMatcher": [],
"group": "build",
"label": "npm: deploy-tron",
"detail": "npx hardhat --network tron deploy --tags lumi"
}
]
}
35 changes: 33 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const settings = {
const config: HardhatUserConfig = {
solidity: {
compilers: [
{ version: '0.8.23', settings }, // current solc version 1
{ version: '0.8.22', settings }, // current solc version 2, you should set the same settings for all solc versions required .
{ version: '0.8.25', settings }, // current solc version 1
],
},
vyper: {
Expand Down Expand Up @@ -57,6 +56,38 @@ const config: HardhatUserConfig = {
default: 0, // here this will by default take the first account as deployer
},
},
llm: {
defaultProvider: 'azure_openai',
// promptTemplate:
// 'As a world-class smart contract auditor, please perform a detailed security review of the following {language} code from the file "{contractName}". Focus especially on re-entrancy, integer overflows, and access control issues.',
providers: {
openai: {
apiKey: `${process.env.OPENAI_API_KEY}`,
model: 'gpt-4o',
},
azure_openai: {
apiKey: `${process.env.OPENAI_API_KEY}`,
endpoint: `${process.env.OPENAI_ENDPOINT}`,
deploymentName: `${process.env.OPENAI_DEPLOYMENT}`,
apiVersion: `${process.env.OPENAI_API_VERSION}`,
model: 'gpt-4o',
},
gemini: {
apiKey: `${process.env.GEMINI_API_KEY}`,
model: 'gemini-2.5-pro',
},
qwen: {
apiKey: `${process.env.QWEN_API_KEY}`,
model: 'qwen-turbo',
baseURL: `${process.env.QWEN_BASE_URL}`,
},
deepseek: {
apiKey: `${process.env.DEEPSEEK_API_KEY}`,
model: 'deepseek-coder',
baseURL: `${process.env.DEEPSEEK_BASE_URL}`,
},
},
},
};

export default config;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@nomicfoundation/hardhat-foundry": "^1.1.3",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomiclabs/hardhat-vyper": "^3.0.8",
"@sun-protocol/sunhat": "1.0.0",
"@sun-protocol/sunhat": "1.2.0",
"hardhat": "^2.23.0"
},
"scripts": {
Expand All @@ -13,6 +13,9 @@
"compile": "hardhat compile --verbose --force",
"clean": "hardhat clean",
"test": "hardhat test",
"audit": "npx hardhat audit",
"vscode-audit": "npx hardhat audit --format json",
"coverage": "npx hardhat coverage",
"init-foundry": "npx hardhat init-foundry",
"test-foundry": "forge test -vvv",
"compile-tron": "hardhat compile --network tron --verbose --force",
Expand Down
3 changes: 2 additions & 1 deletion test/Lock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ contract TokenTest is Test {
vm.warp(86401);
vm.prank(owner);
l.withdraw();
vm.breakpoint("a");
assertEq(owner.balance, 100 ether);
assertEq(address(l).balance, 0);
assertEq(address(l).balance, 0);
}
}
64 changes: 32 additions & 32 deletions test/Lock.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
time,
loadFixture,
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
import { expect } from "chai";
import hre from "hardhat";
} from '@nomicfoundation/hardhat-toolbox/network-helpers';
import { anyValue } from '@nomicfoundation/hardhat-chai-matchers/withArgs';
import { expect } from 'chai';
import hre from 'hardhat';

describe("Lock", function () {
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.
Expand All @@ -20,72 +20,72 @@ describe("Lock", function () {
// Contracts are deployed using the first signer/account by default
const [owner, otherAccount] = await hre.ethers.getSigners();

const Lock = await hre.ethers.getContractFactory("Lock");
const Lock = await hre.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 () {
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 () {
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 () {
it('Should receive and store the funds to lock', async function () {
const { lock, lockedAmount } = await loadFixture(
deployOneYearLockFixture
deployOneYearLockFixture,
);

expect(await hre.ethers.provider.getBalance(lock.target)).to.equal(
lockedAmount
lockedAmount,
);
});

it("Should fail if the unlockTime is not in the future", async function () {
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 hre.ethers.getContractFactory("Lock");
const Lock = await hre.ethers.getContractFactory('Lock');
await expect(Lock.deploy(latestTime, { value: 1 })).to.be.revertedWith(
"Unlock time should be in the future"
'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 () {
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"
"You can't withdraw yet",
);
});

it("Should revert with the right error if called from another account", async function () {
it('Should revert with the right error if called from another account', async function () {
const { lock, unlockTime, otherAccount } = await loadFixture(
deployOneYearLockFixture
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"
"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
deployOneYearLockFixture,
);

// Transactions are sent using the first signer by default
Expand All @@ -95,31 +95,31 @@ describe("Lock", function () {
});
});

describe("Events", function () {
it("Should emit an event on withdrawals", async function () {
describe('Events', function () {
it('Should emit an event on withdrawals', async function () {
const { lock, unlockTime, lockedAmount } = await loadFixture(
deployOneYearLockFixture
deployOneYearLockFixture,
);

await time.increaseTo(unlockTime);

await expect(lock.withdraw())
.to.emit(lock, "Withdrawal")
.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 () {
describe('Transfers', function () {
it('Should transfer the funds to the owner', async function () {
const { lock, unlockTime, lockedAmount, owner } = await loadFixture(
deployOneYearLockFixture
deployOneYearLockFixture,
);

await time.increaseTo(unlockTime);

await expect(lock.withdraw()).to.changeEtherBalances(
[owner, lock],
[lockedAmount, -lockedAmount]
[lockedAmount, -lockedAmount],
);
});
});
Expand Down