test: 🚧 Added fixtures for new test schema
This commit is contained in:
@@ -8,4 +8,5 @@ export enum P2PixErrors {
|
||||
AlreadyReleased = "AlreadyReleased",
|
||||
TxAlreadyUsed = "TxAlreadyUsed",
|
||||
InvalidSigner = "InvalidSigner",
|
||||
}
|
||||
UNAUTHORIZED = "UNAUTHORIZED",
|
||||
}
|
||||
|
||||
82
test/utils/fixtures.ts
Normal file
82
test/utils/fixtures.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||
import { Signer } from "ethers";
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
// import keccak256 from "keccak256";
|
||||
// import { MerkleTree } from "merkletreejs";
|
||||
import {
|
||||
MockToken,
|
||||
P2PIX,
|
||||
Reputation,
|
||||
} from "../../src/types";
|
||||
|
||||
// exported interfaces
|
||||
export interface P2pixFixture {
|
||||
p2pix: P2PIX;
|
||||
reputation: Reputation;
|
||||
erc20: MockToken;
|
||||
// proof: string[];
|
||||
// wrongProof: string[];
|
||||
// merkleRoot: string;
|
||||
}
|
||||
|
||||
// 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;
|
||||
};
|
||||
export const randomSigners = (amount: number): Signer[] => {
|
||||
const signers: Signer[] = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
signers.push(ethers.Wallet.createRandom());
|
||||
}
|
||||
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(
|
||||
addr.substr(2).padStart(32 * 2, 0),
|
||||
"hex",
|
||||
);
|
||||
};
|
||||
|
||||
// exported async functions
|
||||
export async function p2pixFixture(): Promise<P2pixFixture> {
|
||||
const validSigners = getSignerAddrs(
|
||||
2,
|
||||
await ethers.getSigners(),
|
||||
);
|
||||
|
||||
const Reputation = await ethers.getContractFactory(
|
||||
"Reputation",
|
||||
);
|
||||
const reputation =
|
||||
(await Reputation.deploy()) as Reputation;
|
||||
|
||||
const ERC20 = await ethers.getContractFactory("MockToken");
|
||||
const erc20 = (await ERC20.deploy(
|
||||
ethers.utils.parseEther("20000000"), // 20M
|
||||
)) as MockToken;
|
||||
|
||||
const P2PIX = await ethers.getContractFactory("P2PIX");
|
||||
const p2pix = (await P2PIX.deploy(
|
||||
4,
|
||||
validSigners,
|
||||
reputation.address,
|
||||
[erc20.address],
|
||||
[true],
|
||||
)) as P2PIX;
|
||||
|
||||
return { reputation, erc20, p2pix };
|
||||
}
|
||||
Reference in New Issue
Block a user