Skip to content

Commit

Permalink
setup unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Nov 12, 2024
1 parent e11141c commit 2385cc1
Show file tree
Hide file tree
Showing 12 changed files with 1,343 additions and 1,456 deletions.
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"func-visibility": ["warn", { "ignoreConstructors": true }],
"reason-string": ["warn", { "maxLength": 64 }],
"not-rely-on-time": "off",
"max-states-count": ["warn", 17]
"max-states-count": ["warn", 17],
"custom-errors": "off"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"prettier": "prettier --config .prettierrc --write \"**/*.{js,json,md,sol,ts}\"",
"prettier:list-different": "prettier --config .prettierrc --list-different \"**/*.{js,json,md,sol,ts}\"",
"profile": "REPORT_GAS=true yarn hardhat test test/*.ts test/**/*.ts",
"test": "yarn hardhat test test/*.ts test/**/*.ts"
"test": "yarn hardhat test test/*.ts"
},
"dependencies": {
"@openzeppelin/contracts": "5.1.0",
Expand Down
125 changes: 0 additions & 125 deletions test/helper.js

This file was deleted.

92 changes: 92 additions & 0 deletions test/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { ethers } from "hardhat";
import { promisify } from "util";
import { expect } from "chai";

const AMPL_DECIMALS = 9;

function $AMPL(x: number) {
return ethers.parseUnits(x.toFixed(AMPL_DECIMALS), AMPL_DECIMALS);
}

// Perc has to be a whole number
async function invokeRebase(ampl, perc) {
await ampl.rebase(1, ((await ampl.totalSupply()) * BigInt(perc)) / 100n);
}

function checkAmplAprox(x, y) {
checkAprox(x, $AMPL(y), BigInt(10 ** 7));
}

function checkSharesAprox(x, y) {
checkAprox(x, y, BigInt(10 ** 12));
}

function checkAprox(x, y, delta_) {
const delta = BigInt(delta_);
const upper = y + delta;
const lower = y - delta;
expect(x).to.gte(lower).to.lte(upper);
}

export const TimeHelpers = {
secondsFromNow: async (secondsFromNow: number): Promise<number> => {
return (await TimeHelpers.currentTime()) + secondsFromNow;
},

moveClock: async (seconds: number): Promise<void> => {
await hre.network.provider.send("evm_increaseTime", [seconds]);
},

advanceBlock: async () => {
await hre.network.provider.send("evm_mine");
},

increaseTime: async (seconds: number): Promise<void> => {
await hre.network.provider.send("evm_increaseTime", [seconds]);
await hre.network.provider.send("evm_mine");
},

setNextBlockTimestamp: async (timestamp: number): Promise<void> => {
await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp]);
await hre.network.provider.send("evm_mine");
},

currentTime: async (): Promise<number> => {
const res = await hre.network.provider.send("eth_getBlockByNumber", [
"latest",
false,
]);
const timestamp = parseInt(res.timestamp, 16);
return timestamp;
},
};

async function printMethodOutput(r) {
console.log(r.logs);
}

async function printStatus(dist) {
console.log("Total Locked: ", await dist.totalLocked.staticCall().toString());
console.log("Total UnLocked: ", await dist.totalUnlocked.staticCall().toString());
const c = (await dist.unlockScheduleCount.staticCall()).toNumber();
console.log(await dist.unlockScheduleCount.staticCall().toString());

for (let i = 0; i < c; i++) {
console.log(await dist.unlockSchedules.staticCall(i).toString());
}
// await dist.totalLocked.staticCall()
// await dist.totalUnlocked.staticCall()
// await dist.unlockScheduleCount.staticCall()
// dist.updateAccounting.staticCall() // and all the logs
// dist.unlockSchedules.staticCall(1)
}

module.exports = {
checkAmplAprox,
checkSharesAprox,
invokeRebase,
$AMPL,
TimeHelpers,
printMethodOutput,
printStatus,
};
Loading

0 comments on commit 2385cc1

Please sign in to comment.