fix: reputation curve fixed
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import "@nomicfoundation/hardhat-chai-matchers";
|
||||
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { expect } from "chai";
|
||||
import { ethers, network } from "hardhat";
|
||||
|
||||
import { Reputation } from "../src/types";
|
||||
import { curve, repFixture } from "./utils/fixtures";
|
||||
|
||||
describe("Reputation", () => {
|
||||
// contract deployer/admin
|
||||
let owner: SignerWithAddress;
|
||||
// Reputation Interface instance;
|
||||
let reputation: Reputation;
|
||||
|
||||
before("Set signers and reset network", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
[owner] = await (ethers as any).getSigners();
|
||||
|
||||
await network.provider.send("hardhat_reset");
|
||||
});
|
||||
beforeEach("Load deployment fixtures", async () => {
|
||||
({ reputation } = await loadFixture(repFixture));
|
||||
});
|
||||
|
||||
describe("Limiter", async () => {
|
||||
it("Curve reliability", async () => {
|
||||
const tx1 = await reputation.connect(owner).limiter(0);
|
||||
const tx2 = await reputation.limiter(500);
|
||||
const tx3 = await reputation
|
||||
.connect(owner)
|
||||
.limiter(444444);
|
||||
const tx4 = await reputation.limiter(988700);
|
||||
|
||||
expect(tx1).to.eq(curve(0));
|
||||
expect(tx2).to.eq(curve(500));
|
||||
expect(tx3).to.eq(curve(444444));
|
||||
expect(tx4).to.eq(curve(988700));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -235,7 +235,7 @@ describe("P2PIX", () => {
|
||||
});
|
||||
});
|
||||
describe("Deposit", async () => {
|
||||
// it ("should revert if ERC20 is not alloed")
|
||||
// it("should revert if ERC20 is not allowed", async () => {
|
||||
// it ("should revert if deposit already exists")
|
||||
// it ("should create deposit, update storage and emit event")
|
||||
// it ("should create multiple deposits") - EDGE CASE TEST
|
||||
|
||||
@@ -13,13 +13,18 @@ import {
|
||||
// exported interfaces
|
||||
export interface P2pixFixture {
|
||||
p2pix: P2PIX;
|
||||
reputation: Reputation;
|
||||
erc20: MockToken;
|
||||
// proof: string[];
|
||||
// wrongProof: string[];
|
||||
// merkleRoot: string;
|
||||
}
|
||||
|
||||
export interface RepFixture {
|
||||
reputation: Reputation;
|
||||
}
|
||||
|
||||
type P2PixAndReputation = P2pixFixture & RepFixture;
|
||||
|
||||
// exported constants
|
||||
export const getSignerAddrs = (
|
||||
amount: number,
|
||||
@@ -32,6 +37,7 @@ export const getSignerAddrs = (
|
||||
}
|
||||
return signers;
|
||||
};
|
||||
|
||||
export const randomSigners = (amount: number): Signer[] => {
|
||||
const signers: Signer[] = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
@@ -39,10 +45,12 @@ export const randomSigners = (amount: number): Signer[] => {
|
||||
}
|
||||
return signers;
|
||||
};
|
||||
|
||||
export const getError = (Error: string) =>
|
||||
ethers.utils
|
||||
.keccak256(ethers.utils.toUtf8Bytes(Error))
|
||||
.slice(0, 10);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const padBuffer = (addr: any) => {
|
||||
return Buffer.from(
|
||||
@@ -51,8 +59,24 @@ export const padBuffer = (addr: any) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const curve = (x: number): number => {
|
||||
return Math.round(
|
||||
1 + (10 ** 6 * x) / Math.sqrt(2.5 * 10 ** 11 + x * x),
|
||||
);
|
||||
};
|
||||
|
||||
// exported async functions
|
||||
export async function p2pixFixture(): Promise<P2pixFixture> {
|
||||
export async function repFixture(): Promise<RepFixture> {
|
||||
const Reputation = await ethers.getContractFactory(
|
||||
"Reputation",
|
||||
);
|
||||
const reputation =
|
||||
(await Reputation.deploy()) as Reputation;
|
||||
|
||||
return { reputation };
|
||||
}
|
||||
|
||||
export async function p2pixFixture(): Promise<P2PixAndReputation> {
|
||||
const validSigners = getSignerAddrs(
|
||||
2,
|
||||
await ethers.getSigners(),
|
||||
|
||||
Reference in New Issue
Block a user