Remove faker-js

This commit is contained in:
Arnaud 2024-09-16 14:46:06 +02:00
parent 9d8ddb951b
commit 68dec65501
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
4 changed files with 50 additions and 71 deletions

17
package-lock.json generated
View File

@ -12,7 +12,6 @@
"valibot": "^0.36.0"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/strictest": "^2.0.5",
"prettier": "^3.3.3",
"tsup": "^8.2.3",
@ -407,22 +406,6 @@
"node": ">=18"
}
},
"node_modules/@faker-js/faker": {
"version": "8.4.1",
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-8.4.1.tgz",
"integrity": "sha512-XQ3cU+Q8Uqmrbf2e0cIC/QN43sTBSC8KF12u29Mb47tWrt2hAgBXSgpZMj4Ao8Uk0iJcU99QsOCaIL8934obCg==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/fakerjs"
}
],
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0",
"npm": ">=6.14.13"
}
},
"node_modules/@isaacs/cliui": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",

View File

@ -57,7 +57,6 @@
"node": ">=20"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@tsconfig/strictest": "^2.0.5",
"prettier": "^3.3.3",
"tsup": "^8.2.3",
@ -67,4 +66,4 @@
"dependencies": {
"valibot": "^0.36.0"
}
}
}

View File

@ -1,49 +1,22 @@
import { faker } from "@faker-js/faker";
import { afterEach, assert, describe, it, vi } from "vitest";
import { Fetch } from "../fetch-safe/fetch-safe";
import { CodexMarketplace } from "./marketplace";
// function createSlot() {
// return {
// "id": faker.string.alphanumeric(64),
// "request": {
// "id": faker.string.alphanumeric(64),
// "client": faker.finance.ethereumAddress(),
// "ask":
// {
// "slots": faker.number.int({ min: 0, max: 9 }),
// "slotSize": faker.number.float({ max: 10000 }).toString(),
// "duration": faker.number.int({ max: 300000 }).toString(),
// "proofProbability": faker.number.int({ max: 9 }),
// "reward": faker.number.float({ max: 1000 }).toString(),
// "maxSlotLoss": faker.number.int({ max: 9 })
// },
// "content": {
// "cid": faker.string.alphanumeric(64),
// "por": {
// "u": faker.string.alphanumeric(16),
// "publicKey": faker.string.alphanumeric(64),
// "name": faker.string.alphanumeric(16)
// }
// },
// "expiry": faker.number.int({ min: 2, max: 59 }) + " minutes",
// "nonce": faker.string.alphanumeric(64)
// },
// "slotIndex": faker.number.int({ min: 0, max: 9 })
// }
// }
import {
randomEthereumAddress,
randomInt,
randomString,
} from "../tests/tests.util";
function createStorageRequest() {
return {
cid: faker.string.alphanumeric(64),
duration: faker.number.int({ min: 1 }),
reward: faker.number.int(),
proofProbability: faker.number.int(),
nodes: faker.number.int(),
tolerance: faker.number.int(),
expiry: faker.number.int({ min: 1 }),
collateral: faker.number.int(),
cid: randomString(64),
duration: randomInt(1, 64000),
reward: randomInt(1, 100),
proofProbability: randomInt(1, 100),
nodes: randomInt(1, 5),
tolerance: randomInt(1, 100),
expiry: randomInt(1, 100),
collateral: randomInt(1, 100),
};
}
@ -134,15 +107,15 @@ function minNumberValidationError(field: string, min: number) {
function createAvailability() {
return {
id: faker.finance.ethereumAddress(),
availabilityId: faker.finance.ethereumAddress(),
size: faker.number.int({ min: 3000, max: 300000 }),
requestId: faker.finance.ethereumAddress(),
slotIndex: faker.number.int({ min: 0, max: 9 }),
totalSize: faker.number.int({ min: 0, max: 9 }).toString(),
duration: faker.number.int({ min: 0, max: 9 }).toString(),
minPrice: faker.number.int({ min: 0, max: 9 }).toString(),
maxCollateral: faker.number.int({ min: 0, max: 9 }).toString(),
id: randomEthereumAddress(),
availabilityId: randomEthereumAddress(),
size: randomInt(3000, 300000),
requestId: randomEthereumAddress(),
slotIndex: randomInt(0, 9),
totalSize: randomInt(0, 9).toString(),
duration: randomInt(0, 9).toString(),
minPrice: randomInt(0, 9).toString(),
maxCollateral: randomInt(0, 9).toString(),
};
}
@ -284,7 +257,7 @@ describe("marketplace", () => {
it("returns an error when trying to update an availability with zero total size", async () => {
const response = await marketplace.updateAvailability({
id: faker.string.alphanumeric(64),
id: randomString(64),
totalSize: 0,
});
@ -293,7 +266,7 @@ describe("marketplace", () => {
it("returns an error when trying to update an availability with zero duration", async () => {
const response = await marketplace.updateAvailability({
id: faker.string.alphanumeric(64),
id: randomString(64),
duration: 0,
});
@ -307,7 +280,7 @@ describe("marketplace", () => {
spy.mockImplementationOnce(() => Promise.resolve({ error: false, data }));
const response = await marketplace.updateAvailability({
id: faker.string.alphanumeric(64),
id: randomString(64),
totalSize: 3000,
});

24
src/tests/tests.util.ts Normal file
View File

@ -0,0 +1,24 @@
export const randomEthereumAddress = () => {
const randomBytes = crypto.getRandomValues(new Uint8Array(20));
// Convert bytes to a hexadecimal string
const address = Array.from(randomBytes)
.map((byte) => ("0" + byte.toString(16)).slice(-2)) // Convert to hex and pad with zero
.join("");
return "0x" + address; // Prefix with '0x'
};
export const randomString = (length: number) => {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
}
return result;
};
export const randomInt = (min: number, max: number) =>
Math.floor(Math.random() * (max - min)) + min;