Enhanced integration & optimized testing

This commit is contained in:
PedroCailleret
2023-02-14 18:40:02 -03:00
parent 4c8016080d
commit 8310e013f6
40 changed files with 1516 additions and 649 deletions

View File

@@ -23,19 +23,73 @@ describe("Reputation", () => {
({ 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));
// });
// });
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);
const testCases = [
{
x: 0,
expected: curve(0),
},
{
x: 500,
expected: curve(500),
},
{
x: 444444,
expected: curve(444444),
},
{
x: 988700,
expected: curve(988700),
},
{
x: Number.MAX_SAFE_INTEGER,
shouldRevert: "overflow",
},
{
x: Number.POSITIVE_INFINITY,
shouldRevert: "overflow",
},
{
x: Number.NEGATIVE_INFINITY,
shouldRevert: "overflow",
},
{
x: -1,
shouldRevert: "value out-of-bounds",
},
{
x: Number.NaN,
shouldRevert: "invalid BigNumber string",
},
];
expect(tx1).to.eq(curve(0));
expect(tx2).to.eq(curve(500));
expect(tx3).to.eq(curve(444444));
expect(tx4).to.eq(curve(988700));
for (const testCase of testCases) {
if (testCase.shouldRevert != undefined) {
await expect(reputation.limiter(testCase.x)).to.be
.rejected;
} else {
const result = await reputation.limiter(testCase.x);
expect(result).to.eq(testCase.expected).and.to.be
.ok;
}
}
});
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -19,4 +19,5 @@ export enum P2PixErrors {
MaxBalExceeded = "MaxBalExceeded",
NotInitialized = "NotInitialized",
DecOverflow = "DecOverflow",
CallFailed = "CallFailed",
}

View File

@@ -6,7 +6,9 @@ import { MerkleTree } from "merkletreejs";
import {
MockToken,
Multicall,
P2PIX,
P2PIX__factory,
Reputation,
} from "../../src/types";
@@ -17,14 +19,6 @@ export interface Deploys {
token: string;
}
// export interface Deposit {
// remaining: BigNumber;
// pixTarget: string;
// seller: string;
// token: string;
// valid: boolean;
// }
export interface Lock {
sellerKey: BigNumber;
counter: BigNumber;
@@ -38,6 +32,16 @@ export interface Lock {
token: string;
}
export interface Call {
target: string;
callData: string;
}
export interface Result {
success: boolean;
returnData: string;
}
export interface P2pixFixture {
p2pix: P2PIX;
erc20: MockToken;
@@ -49,19 +53,40 @@ export interface RepFixture {
reputation: Reputation;
}
type P2PixAndReputation = P2pixFixture & RepFixture;
export interface MtcFixture {
multicall: Multicall;
}
type P2PixAndReputation = P2pixFixture &
RepFixture &
MtcFixture;
// exported constants
export const getSignerAddrs = (
amount: number,
addrs: SignerWithAddress[],
): string[] => {
const signers: string[] = [];
const buffr = addrs.slice(0, amount);
for (let i = 0; i < amount; i++) {
signers.push(buffr[i].address);
}
return signers;
return addrs.slice(0, amount).map(({ address }) => address);
};
export const getBnFrom = (nums: number[]): BigNumber[] => {
const bns = nums.map(num => ethers.BigNumber.from(num));
return bns;
};
export const getLockData = (
addr: string,
locks: BigNumber[][],
): Call[] => {
const iface = new ethers.utils.Interface(
P2PIX__factory.abi,
);
return locks.map(lock => ({
target: addr,
callData: iface.encodeFunctionData("getLocksStatus", [
lock,
]),
}));
};
export const randomSigners = (amount: number): Signer[] => {
@@ -128,6 +153,11 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
[true],
)) as P2PIX;
const Multicall = await ethers.getContractFactory(
"Multicall",
);
const multicall = (await Multicall.deploy()) as Multicall;
const signers = await ethers.getSigners();
const whitelisted = signers.slice(0, 2);
const leaves = whitelisted.map(account =>
@@ -142,6 +172,7 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
);
return {
multicall,
reputation,
erc20,
p2pix,