@morpho-org/morpho-test 1.0.0-integ-650.0
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.
- package/README.md +39 -0
- package/lib/asserts.d.ts +3 -0
- package/lib/asserts.js +13 -0
- package/lib/chai.d.ts +12 -0
- package/lib/chai.js +120 -0
- package/lib/fixtures.d.ts +1 -0
- package/lib/fixtures.js +10 -0
- package/lib/hardhat.d.ts +17 -0
- package/lib/hardhat.js +62 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +20 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @morpho-org/morpho-test
|
|
2
|
+
|
|
3
|
+
[![npm package][npm-img]][npm-url]
|
|
4
|
+
[![Downloads][downloads-img]][downloads-url]
|
|
5
|
+
|
|
6
|
+
Lightweight developer package that includes helpers to run hardhat and jest tests.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @morpho-org/morpho-test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add @morpho-org/morpho-test
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### jest
|
|
23
|
+
|
|
24
|
+
When running a jest test suite, you may encounter the following error:
|
|
25
|
+
|
|
26
|
+
```log
|
|
27
|
+
node:internal/modules/esm/utils:211
|
|
28
|
+
throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG();
|
|
29
|
+
^
|
|
30
|
+
|
|
31
|
+
TypeError: A dynamic import callback was invoked without --experimental-vm-modules
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To fix this, [run jest using experimental VM modules](https://jestjs.io/docs/ecmascript-modules).
|
|
35
|
+
|
|
36
|
+
[downloads-img]: https://img.shields.io/npm/dt/@morpho-org/morpho-test
|
|
37
|
+
[downloads-url]: https://www.npmtrends.com/@morpho-org/morpho-test
|
|
38
|
+
[npm-img]: https://img.shields.io/npm/v/@morpho-org/morpho-test
|
|
39
|
+
[npm-url]: https://www.npmjs.com/package/@morpho-org/morpho-test
|
package/lib/asserts.d.ts
ADDED
|
@@ -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
package/lib/chai.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
const sinon_chai_1 = __importDefault(require("sinon-chai"));
|
|
31
|
+
chai_1.default.use(sinon_chai_1.default);
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
|
|
34
|
+
BigInt.prototype.toJSON = function () {
|
|
35
|
+
return this.toString();
|
|
36
|
+
};
|
|
37
|
+
const ANY = new String("[any value]");
|
|
38
|
+
const ANYTHING = new String("[any defined value]");
|
|
39
|
+
const NUMBER = new String("[any number]");
|
|
40
|
+
const STRING = new String("[any string]");
|
|
41
|
+
const BIGINT = new String("[any bigint]");
|
|
42
|
+
Object.defineProperty(chai_1.default.expect, "any", {
|
|
43
|
+
get: function () {
|
|
44
|
+
return ANY;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(chai_1.default.expect, "anything", {
|
|
48
|
+
get: function () {
|
|
49
|
+
return ANYTHING;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(chai_1.default.expect, "number", {
|
|
53
|
+
get: function () {
|
|
54
|
+
return NUMBER;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(chai_1.default.expect, "string", {
|
|
58
|
+
get: function () {
|
|
59
|
+
return STRING;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(chai_1.default.expect, "bigint", {
|
|
63
|
+
get: function () {
|
|
64
|
+
return BIGINT;
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
function customEqual(obj1, obj2) {
|
|
68
|
+
if (Object(obj1) !== obj1 || Object(obj2) !== obj2) {
|
|
69
|
+
return obj1 === obj2;
|
|
70
|
+
}
|
|
71
|
+
const keys1 = Object.keys(obj1);
|
|
72
|
+
const keys2 = Object.keys(obj2);
|
|
73
|
+
if (keys1.length !== keys2.length) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
for (let key of keys1) {
|
|
77
|
+
switch (obj2[key]) {
|
|
78
|
+
case ANY: {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case ANYTHING: {
|
|
82
|
+
if (obj1[key] == undefined)
|
|
83
|
+
return false;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case STRING: {
|
|
87
|
+
if (typeof obj1[key] !== "string")
|
|
88
|
+
return false;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case NUMBER: {
|
|
92
|
+
if (typeof obj1[key] !== "number")
|
|
93
|
+
return false;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case BIGINT: {
|
|
97
|
+
if (typeof obj1[key] !== "bigint")
|
|
98
|
+
return false;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
default: {
|
|
102
|
+
if (!customEqual(obj1[key], obj2[key]))
|
|
103
|
+
return false;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
chai_1.Assertion.overwriteMethod("eql", function (_super) {
|
|
111
|
+
return function (arg) {
|
|
112
|
+
if (typeof arg === "object" && typeof this._obj === "object") {
|
|
113
|
+
const result = customEqual(this._obj, arg);
|
|
114
|
+
this.assert(result, "expected #{this} to deeply equal #{exp}", "expected #{this} not to deeply equal #{exp}", arg, this._obj);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
_super.apply(this, arguments);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createRandomAddress: () => string;
|
package/lib/fixtures.js
ADDED
|
@@ -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;
|
package/lib/hardhat.d.ts
ADDED
|
@@ -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,62 @@
|
|
|
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 { network } = require("hardhat");
|
|
41
|
+
let snapshot;
|
|
42
|
+
before(async () => {
|
|
43
|
+
const blockNumber = await network.provider.send("eth_blockNumber");
|
|
44
|
+
const block = await network.provider.send("eth_getBlockByNumber", [
|
|
45
|
+
blockNumber,
|
|
46
|
+
false,
|
|
47
|
+
]);
|
|
48
|
+
await onBefore?.(block);
|
|
49
|
+
snapshot = await (0, hardhat_network_helpers_1.takeSnapshot)();
|
|
50
|
+
});
|
|
51
|
+
const dataObserver = { next: sinon_1.default.spy(), error: sinon_1.default.spy() };
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await snapshot.restore();
|
|
54
|
+
dataObserver.next.resetHistory();
|
|
55
|
+
dataObserver.error.resetHistory();
|
|
56
|
+
});
|
|
57
|
+
after(async () => {
|
|
58
|
+
await (0, exports.reset)();
|
|
59
|
+
});
|
|
60
|
+
return dataObserver;
|
|
61
|
+
};
|
|
62
|
+
exports.setUp = setUp;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
require("./chai");
|
|
18
|
+
__exportStar(require("./asserts"), exports);
|
|
19
|
+
__exportStar(require("./fixtures"), exports);
|
|
20
|
+
__exportStar(require("./hardhat"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@morpho-org/morpho-test",
|
|
3
|
+
"version": "1.0.0-integ-650.0",
|
|
4
|
+
"main": "lib/index.js",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib"
|
|
7
|
+
],
|
|
8
|
+
"author": "Morpho Association <contact@morpho.org>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prepublish": "yarn build",
|
|
12
|
+
"build": "tsc --build tsconfig.build.json",
|
|
13
|
+
"test": "jest"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.4",
|
|
17
|
+
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
|
|
18
|
+
"@types/chai": "^4.3.17",
|
|
19
|
+
"@types/jest": "^29.5.12",
|
|
20
|
+
"@types/mocha": "^10.0.6",
|
|
21
|
+
"@types/node": "^22.1.0",
|
|
22
|
+
"@types/sinon": "^17.0.3",
|
|
23
|
+
"@types/sinon-chai": "^3.2.12",
|
|
24
|
+
"chai": "^4.5.0",
|
|
25
|
+
"dotenv": "^16.3.1",
|
|
26
|
+
"ethers": "^6.13.2",
|
|
27
|
+
"hardhat": "^2.20.1",
|
|
28
|
+
"mocha": "^10.4.0",
|
|
29
|
+
"sinon": "^19.0.2",
|
|
30
|
+
"sinon-chai": "^3.7.0",
|
|
31
|
+
"typescript": "^5.4.5"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
|
35
|
+
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
|
36
|
+
"chai": "^4.3.0",
|
|
37
|
+
"ethers": "^6.0.0",
|
|
38
|
+
"hardhat": "^2.20.0",
|
|
39
|
+
"sinon": "^19.0.2",
|
|
40
|
+
"sinon-chai": "^3.7.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "dcbf95368923403757853f60b8380ee861273562"
|
|
46
|
+
}
|