@morpho-org/morpho-test 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export declare const assertApproxEqAbs: (actual: bigint, expected: bigint, tolerance?: bigint, message?: string) => Chai.Assertion;
2
+ export declare const assertApproxEqRel: (actual: bigint, expected: bigint, tolerance?: bigint, message?: string) => Chai.Assertion;
3
+ export declare const assertEq: (actual: bigint, expected: bigint) => Chai.Assertion;
package/lib/asserts.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertEq = exports.assertApproxEqRel = exports.assertApproxEqAbs = void 0;
4
+ const chai_1 = require("chai");
5
+ const ethers_1 = require("ethers");
6
+ const assertApproxEqAbs = (actual, expected, tolerance = 0n, message) => (0, chai_1.expect)(actual >= expected ? actual - expected : expected - actual).to.be.lessThanOrEqual(
7
+ // @ts-ignore
8
+ tolerance, message);
9
+ exports.assertApproxEqAbs = assertApproxEqAbs;
10
+ const assertApproxEqRel = (actual, expected, tolerance = 0n, message) => (0, exports.assertApproxEqAbs)(actual, expected, (expected * tolerance) / (0, ethers_1.parseEther)("1"), message);
11
+ exports.assertApproxEqRel = assertApproxEqRel;
12
+ const assertEq = (actual, expected) => (0, exports.assertApproxEqAbs)(actual, expected, 0n);
13
+ exports.assertEq = assertEq;
package/lib/chai.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import "chai-as-promised";
2
+ declare global {
3
+ namespace Chai {
4
+ interface ExpectStatic {
5
+ any: any;
6
+ anything: any;
7
+ number: any;
8
+ string: any;
9
+ bigint: any;
10
+ }
11
+ }
12
+ }
package/lib/chai.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const chai_1 = __importStar(require("chai"));
30
+ require("chai-as-promised");
31
+ const chai_exclude_1 = __importDefault(require("chai-exclude"));
32
+ const sinon_chai_1 = __importDefault(require("sinon-chai"));
33
+ chai_1.default.use(sinon_chai_1.default);
34
+ chai_1.default.use(chai_exclude_1.default);
35
+ // @ts-ignore
36
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
37
+ BigInt.prototype.toJSON = function () {
38
+ return this.toString();
39
+ };
40
+ const ANY = new String("[any value]");
41
+ const ANYTHING = new String("[any defined value]");
42
+ const NUMBER = new String("[any number]");
43
+ const STRING = new String("[any string]");
44
+ const BIGINT = new String("[any bigint]");
45
+ Object.defineProperty(chai_1.default.expect, "any", {
46
+ get: function () {
47
+ return ANY;
48
+ },
49
+ });
50
+ Object.defineProperty(chai_1.default.expect, "anything", {
51
+ get: function () {
52
+ return ANYTHING;
53
+ },
54
+ });
55
+ Object.defineProperty(chai_1.default.expect, "number", {
56
+ get: function () {
57
+ return NUMBER;
58
+ },
59
+ });
60
+ Object.defineProperty(chai_1.default.expect, "string", {
61
+ get: function () {
62
+ return STRING;
63
+ },
64
+ });
65
+ Object.defineProperty(chai_1.default.expect, "bigint", {
66
+ get: function () {
67
+ return BIGINT;
68
+ },
69
+ });
70
+ function customEqual(obj1, obj2) {
71
+ if (Object(obj1) !== obj1 || Object(obj2) !== obj2) {
72
+ return obj1 === obj2;
73
+ }
74
+ const keys1 = Object.keys(obj1);
75
+ const keys2 = Object.keys(obj2);
76
+ if (keys1.length !== keys2.length) {
77
+ return false;
78
+ }
79
+ for (let key of keys1) {
80
+ switch (obj2[key]) {
81
+ case ANY: {
82
+ break;
83
+ }
84
+ case ANYTHING: {
85
+ if (obj1[key] == undefined)
86
+ return false;
87
+ break;
88
+ }
89
+ case STRING: {
90
+ if (typeof obj1[key] !== "string")
91
+ return false;
92
+ break;
93
+ }
94
+ case NUMBER: {
95
+ if (typeof obj1[key] !== "number")
96
+ return false;
97
+ break;
98
+ }
99
+ case BIGINT: {
100
+ if (typeof obj1[key] !== "bigint")
101
+ return false;
102
+ break;
103
+ }
104
+ default: {
105
+ if (!customEqual(obj1[key], obj2[key]))
106
+ return false;
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ return true;
112
+ }
113
+ chai_1.Assertion.overwriteMethod("eql", function (_super) {
114
+ return function (arg) {
115
+ if (typeof arg === "object" && typeof this._obj === "object") {
116
+ const result = customEqual(this._obj, arg);
117
+ this.assert(result, "expected #{this} to deeply equal #{exp}", "expected #{this} not to deeply equal #{exp}", arg, this._obj);
118
+ }
119
+ else {
120
+ _super.apply(this, arguments);
121
+ }
122
+ };
123
+ });
@@ -0,0 +1 @@
1
+ export declare const createRandomAddress: () => string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRandomAddress = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const createRandomAddress = () => (0, ethers_1.getAddress)("0x" +
6
+ new Array(40)
7
+ .fill(0)
8
+ .map(() => Math.floor(Math.random() * 16).toString(16))
9
+ .join(""));
10
+ exports.createRandomAddress = createRandomAddress;
@@ -0,0 +1,17 @@
1
+ import { Block } from "ethers";
2
+ import sinon from "sinon";
3
+ export declare const mine: (blocks?: number, options?: {
4
+ interval?: number;
5
+ }, emit?: boolean) => Promise<void>;
6
+ export declare const reset: ({ url, blockNumber, }?: {
7
+ url?: string | null;
8
+ blockNumber?: number;
9
+ }) => Promise<void>;
10
+ export declare const resetAfterEach: (forking?: {
11
+ url?: string | null;
12
+ blockNumber?: number;
13
+ }) => void;
14
+ export declare const setUp: (onBefore?: (block: Block) => void) => {
15
+ next: sinon.SinonSpy<any[], any>;
16
+ error: sinon.SinonSpy<any[], any>;
17
+ };
package/lib/hardhat.js ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setUp = exports.resetAfterEach = exports.reset = exports.mine = void 0;
7
+ const sinon_1 = __importDefault(require("sinon"));
8
+ const hardhat_network_helpers_1 = require("@nomicfoundation/hardhat-network-helpers");
9
+ try {
10
+ import("@nomicfoundation/hardhat-ethers");
11
+ const { ethers } = require("hardhat");
12
+ Object.defineProperty(ethers.provider, "_networkName", {
13
+ value: "mainnet",
14
+ });
15
+ }
16
+ catch { }
17
+ const mine = async (blocks = 1, options = {}, emit = true) => {
18
+ const { ethers } = require("hardhat");
19
+ await (0, hardhat_network_helpers_1.mine)(blocks, options);
20
+ if (emit)
21
+ await ethers.provider.emit("block", await ethers.provider.getBlockNumber());
22
+ };
23
+ exports.mine = mine;
24
+ const reset = ({ url, blockNumber, } = {}) => {
25
+ if (url === null)
26
+ return (0, hardhat_network_helpers_1.reset)();
27
+ const { config } = require("hardhat");
28
+ url ??= config.networks.hardhat.forking?.url;
29
+ blockNumber ??= config.networks.hardhat.forking?.blockNumber;
30
+ return (0, hardhat_network_helpers_1.reset)(url, blockNumber);
31
+ };
32
+ exports.reset = reset;
33
+ const resetAfterEach = (forking) => {
34
+ afterEach(async () => {
35
+ await (0, exports.reset)(forking);
36
+ });
37
+ };
38
+ exports.resetAfterEach = resetAfterEach;
39
+ const setUp = (onBefore) => {
40
+ const { ethers } = require("hardhat");
41
+ let snapshot;
42
+ before(async () => {
43
+ const block = await ethers.provider.getBlock("latest", false);
44
+ await onBefore?.(block);
45
+ snapshot = await (0, hardhat_network_helpers_1.takeSnapshot)();
46
+ });
47
+ const dataObserver = { next: sinon_1.default.spy(), error: sinon_1.default.spy() };
48
+ afterEach(async () => {
49
+ await snapshot.restore();
50
+ dataObserver.next.resetHistory();
51
+ dataObserver.error.resetHistory();
52
+ });
53
+ after(async () => {
54
+ await (0, exports.reset)();
55
+ });
56
+ return dataObserver;
57
+ };
58
+ exports.setUp = setUp;
@@ -1,5 +1,4 @@
1
1
  import "./chai";
2
-
3
2
  export * from "./asserts";
4
3
  export * from "./fixtures";
5
4
  export * from "./hardhat";
package/package.json CHANGED
@@ -1,19 +1,16 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-test",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "lib/index.js",
5
5
  "files": [
6
- "src"
6
+ "lib"
7
7
  ],
8
8
  "author": "Morpho Association <contact@morpho.org>",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "prepublish": "yarn build",
12
- "add:morpho-test": "yarn add",
13
12
  "build": "tsc --build tsconfig.build.json",
14
- "build:morpho-test": "yarn build",
15
- "test": "jest",
16
- "test:morpho-test": "yarn test"
13
+ "test": "jest"
17
14
  },
18
15
  "dependencies": {
19
16
  "@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
@@ -23,13 +20,12 @@
23
20
  "chai-as-promised": "^7.1.2",
24
21
  "chai-exclude": "^2.1.0",
25
22
  "ethers": "^6.12.1",
26
- "ethers-types": "^3.16.0",
27
- "hardhat": "^2.20.1",
28
- "hardhat-deal": "^3.0.4",
29
- "hardhat-tracer": "^2.8.2",
23
+ "ethers-types": "^3.17.1",
24
+ "hardhat": "2.20.1",
25
+ "hardhat-deal": "^3.1.0",
26
+ "hardhat-tracer": "^3.0.1",
30
27
  "jest": "^29.6.2",
31
- "rxjs": "^7.8.1",
32
- "sinon": "^17.0.1",
28
+ "sinon": "^18.0.0",
33
29
  "sinon-chai": "^3.7.0"
34
30
  },
35
31
  "devDependencies": {
@@ -46,19 +42,8 @@
46
42
  "ts-node": "^10.9.2",
47
43
  "typescript": "^5.4.5"
48
44
  },
49
- "peerDependencies": {
50
- "rxjs": "^7.8.1"
51
- },
52
- "peerDependenciesMeta": {
53
- "rxjs": {
54
- "optional": true
55
- }
56
- },
57
45
  "publishConfig": {
58
- "access": "public",
59
- "files": [
60
- "lib"
61
- ]
46
+ "access": "public"
62
47
  },
63
48
  "jest": {
64
49
  "verbose": true,
@@ -79,5 +64,5 @@
79
64
  ],
80
65
  "preset": "ts-jest"
81
66
  },
82
- "gitHead": "6543ef5906fe8315fc6af0dc16ad64f60dd95831"
67
+ "gitHead": "cc64e88993808eb357c59e27501e4d05bd868e5b"
83
68
  }
package/src/asserts.ts DELETED
@@ -1,32 +0,0 @@
1
- import { expect } from "chai";
2
- import { parseEther } from "ethers";
3
-
4
- export const assertApproxEqAbs = (
5
- actual: bigint,
6
- expected: bigint,
7
- tolerance = 0n,
8
- message?: string
9
- ) =>
10
- expect(
11
- actual >= expected ? actual - expected : expected - actual
12
- ).to.be.lessThanOrEqual(
13
- // @ts-ignore
14
- tolerance,
15
- message
16
- );
17
-
18
- export const assertApproxEqRel = (
19
- actual: bigint,
20
- expected: bigint,
21
- tolerance = 0n,
22
- message?: string
23
- ) =>
24
- assertApproxEqAbs(
25
- actual,
26
- expected,
27
- (expected * tolerance) / parseEther("1"),
28
- message
29
- );
30
-
31
- export const assertEq = (actual: bigint, expected: bigint) =>
32
- assertApproxEqAbs(actual, expected, 0n);
package/src/chai.ts DELETED
@@ -1,118 +0,0 @@
1
- import chai, { Assertion } from "chai";
2
- import "chai-as-promised";
3
- import chaiExclude from "chai-exclude";
4
- import sinonChai from "sinon-chai";
5
-
6
- chai.use(sinonChai);
7
- chai.use(chaiExclude);
8
-
9
- // @ts-ignore
10
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
11
- BigInt.prototype.toJSON = function () {
12
- return this.toString();
13
- };
14
-
15
- // Extend Chai's Assertion interface to include the custom method
16
- declare global {
17
- namespace Chai {
18
- interface ExpectStatic {
19
- any: any;
20
- anything: any;
21
- number: any;
22
- string: any;
23
- bigint: any;
24
- }
25
- }
26
- }
27
-
28
- const ANY = new String("[any value]");
29
- const ANYTHING = new String("[any defined value]");
30
- const NUMBER = new String("[any number]");
31
- const STRING = new String("[any string]");
32
- const BIGINT = new String("[any bigint]");
33
-
34
- Object.defineProperty(chai.expect, "any", {
35
- get: function () {
36
- return ANY;
37
- },
38
- });
39
- Object.defineProperty(chai.expect, "anything", {
40
- get: function () {
41
- return ANYTHING;
42
- },
43
- });
44
- Object.defineProperty(chai.expect, "number", {
45
- get: function () {
46
- return NUMBER;
47
- },
48
- });
49
- Object.defineProperty(chai.expect, "string", {
50
- get: function () {
51
- return STRING;
52
- },
53
- });
54
- Object.defineProperty(chai.expect, "bigint", {
55
- get: function () {
56
- return BIGINT;
57
- },
58
- });
59
-
60
- function customEqual(obj1: any, obj2: any): boolean {
61
- if (Object(obj1) !== obj1 || Object(obj2) !== obj2) {
62
- return obj1 === obj2;
63
- }
64
-
65
- const keys1 = Object.keys(obj1);
66
- const keys2 = Object.keys(obj2);
67
-
68
- if (keys1.length !== keys2.length) {
69
- return false;
70
- }
71
-
72
- for (let key of keys1) {
73
- switch (obj2[key]) {
74
- case ANY: {
75
- break;
76
- }
77
- case ANYTHING: {
78
- if (obj1[key] == undefined) return false;
79
- break;
80
- }
81
- case STRING: {
82
- if (typeof obj1[key] !== "string") return false;
83
- break;
84
- }
85
- case NUMBER: {
86
- if (typeof obj1[key] !== "number") return false;
87
- break;
88
- }
89
- case BIGINT: {
90
- if (typeof obj1[key] !== "bigint") return false;
91
- break;
92
- }
93
- default: {
94
- if (!customEqual(obj1[key], obj2[key])) return false;
95
- break;
96
- }
97
- }
98
- }
99
-
100
- return true;
101
- }
102
-
103
- Assertion.overwriteMethod("eql", function (_super) {
104
- return function (this: Chai.AssertionStatic, arg: any) {
105
- if (typeof arg === "object" && typeof this._obj === "object") {
106
- const result = customEqual(this._obj, arg);
107
- this.assert(
108
- result,
109
- "expected #{this} to deeply equal #{exp}",
110
- "expected #{this} not to deeply equal #{exp}",
111
- arg,
112
- this._obj
113
- );
114
- } else {
115
- _super.apply(this, arguments);
116
- }
117
- };
118
- });
package/src/fixtures.ts DELETED
@@ -1,10 +0,0 @@
1
- import { getAddress } from "ethers";
2
-
3
- export const createRandomAddress = () =>
4
- getAddress(
5
- "0x" +
6
- new Array(40)
7
- .fill(0)
8
- .map(() => Math.floor(Math.random() * 16).toString(16))
9
- .join("")
10
- );
package/src/hardhat.ts DELETED
@@ -1,88 +0,0 @@
1
- import { Block } from "ethers";
2
- import { HardhatRuntimeEnvironment } from "hardhat/types";
3
- import sinon from "sinon";
4
-
5
- import {
6
- SnapshotRestorer,
7
- mine as hardhatMine,
8
- reset as hardhatReset,
9
- takeSnapshot,
10
- } from "@nomicfoundation/hardhat-network-helpers";
11
-
12
- try {
13
- import("@nomicfoundation/hardhat-ethers");
14
-
15
- const { ethers } = require("hardhat") as HardhatRuntimeEnvironment;
16
-
17
- Object.defineProperty(ethers.provider, "_networkName", {
18
- value: "mainnet",
19
- });
20
- } catch {}
21
-
22
- export const mine = async (
23
- blocks = 1,
24
- options: { interval?: number } = {},
25
- emit = true
26
- ) => {
27
- const { ethers } = require("hardhat") as HardhatRuntimeEnvironment;
28
-
29
- await hardhatMine(blocks, options);
30
-
31
- if (emit)
32
- await ethers.provider.emit("block", await ethers.provider.getBlockNumber());
33
- };
34
-
35
- export const reset = ({
36
- url,
37
- blockNumber,
38
- }: {
39
- url?: string | null;
40
- blockNumber?: number;
41
- } = {}) => {
42
- if (url === null) return hardhatReset();
43
-
44
- const { config } = require("hardhat") as HardhatRuntimeEnvironment;
45
-
46
- url ??= config.networks.hardhat.forking?.url;
47
- blockNumber ??= config.networks.hardhat.forking?.blockNumber;
48
-
49
- return hardhatReset(url, blockNumber);
50
- };
51
-
52
- export const resetAfterEach = (forking?: {
53
- url?: string | null;
54
- blockNumber?: number;
55
- }) => {
56
- afterEach(async () => {
57
- await reset(forking);
58
- });
59
- };
60
-
61
- export const setUp = (onBefore?: (block: Block) => void) => {
62
- const { ethers } = require("hardhat") as HardhatRuntimeEnvironment;
63
-
64
- let snapshot: SnapshotRestorer;
65
-
66
- before(async () => {
67
- const block = await ethers.provider.getBlock("latest", false);
68
-
69
- await onBefore?.(block!);
70
-
71
- snapshot = await takeSnapshot();
72
- });
73
-
74
- const dataObserver = { next: sinon.spy(), error: sinon.spy() };
75
-
76
- afterEach(async () => {
77
- await snapshot.restore();
78
-
79
- dataObserver.next.resetHistory();
80
- dataObserver.error.resetHistory();
81
- });
82
-
83
- after(async () => {
84
- await reset();
85
- });
86
-
87
- return dataObserver;
88
- };