@1inch/solidity-utils 2.0.12 → 2.0.15
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 +93 -0
- package/contracts/libraries/RevertReasonForwarder.sol +14 -0
- package/contracts/libraries/SafeERC20.sol +122 -0
- package/contracts/libraries/UniERC20.sol +6 -4
- package/dist/src/permit.d.ts +2 -1
- package/dist/src/permit.js +2 -1
- package/dist/src/permit.js.map +1 -1
- package/package.json +9 -4
- package/utils/acquit-markdown.js +53 -0
- package/utils/test-docgen.js +117 -0
- package/contracts/Permitable.sol +0 -34
package/README.md
CHANGED
|
@@ -64,3 +64,96 @@ Add to `package.json` file solidity compiler version and shortcut to run command
|
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
...
|
|
67
|
+
|
|
68
|
+
#### Test documentation generator (test-docgen)
|
|
69
|
+
Script generates documentation for tests in markdown format.
|
|
70
|
+
Give descriptions for `describe` and `it` sections and build documentation using these descriptions.
|
|
71
|
+
|
|
72
|
+
##### Example
|
|
73
|
+
Test described as shown below
|
|
74
|
+
|
|
75
|
+
```JavaScript
|
|
76
|
+
// Test suite
|
|
77
|
+
describe('My feature', function() {
|
|
78
|
+
// Nested test suite
|
|
79
|
+
describe("My subfeature", function() {
|
|
80
|
+
/*
|
|
81
|
+
**Test case 1**
|
|
82
|
+
Test case should work
|
|
83
|
+
*/
|
|
84
|
+
it("My case", function() {
|
|
85
|
+
// code here
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
will generated the following output
|
|
91
|
+
```Markdown
|
|
92
|
+
|
|
93
|
+
# My feature
|
|
94
|
+
|
|
95
|
+
Test suite
|
|
96
|
+
|
|
97
|
+
## My subfeature
|
|
98
|
+
|
|
99
|
+
Nested test suite
|
|
100
|
+
|
|
101
|
+
### My case
|
|
102
|
+
|
|
103
|
+
**Test case 1**
|
|
104
|
+
Test case should work
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
##### Installation
|
|
108
|
+
- Before use install documentation parser
|
|
109
|
+
```
|
|
110
|
+
yarn add acquit --dev
|
|
111
|
+
```
|
|
112
|
+
- Optionally configure script for default usage. Add to `script` section in `package.json`
|
|
113
|
+
```
|
|
114
|
+
"test:docs": "npx test-docgen"
|
|
115
|
+
```
|
|
116
|
+
- Optionally configure script for generating test list only. Add to `script` section in `package.json`
|
|
117
|
+
```
|
|
118
|
+
"test:docs": "npx test-docgen -l"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
##### Usage
|
|
122
|
+
If script configured
|
|
123
|
+
```
|
|
124
|
+
yarn test:docs
|
|
125
|
+
```
|
|
126
|
+
or
|
|
127
|
+
```
|
|
128
|
+
npx test-docgen
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Available parameters
|
|
132
|
+
```
|
|
133
|
+
Options:
|
|
134
|
+
-i, --input <input> tests directory (default: "test")
|
|
135
|
+
-x, --exclude [exclude] exclude directories and files. omit argument to exclude all subdirectories (default: false)
|
|
136
|
+
-o, --output <output> file to write output (default: "TESTS.md")
|
|
137
|
+
-c, --code include code (default: false)
|
|
138
|
+
-l, --list list tests only, do not include description (default: false)
|
|
139
|
+
-d, --debug debug mode (default: false)
|
|
140
|
+
-h, --help display help for command
|
|
141
|
+
```
|
|
142
|
+
##### Examples
|
|
143
|
+
Generate docs with default input and output
|
|
144
|
+
```
|
|
145
|
+
npx test-docgen
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Generate docs for files in folders `tests/mocks` and `tests/utils`
|
|
149
|
+
```
|
|
150
|
+
npx test-docgen -i "tests/mocks;tests/utils"
|
|
151
|
+
```
|
|
152
|
+
Exclude from docs file `test/mock-exclude.js` and `test/utils folder`
|
|
153
|
+
```
|
|
154
|
+
npx test-docgen -x "tests/mock-exclude.js;tests/utils"
|
|
155
|
+
```
|
|
156
|
+
Generate list of tests only
|
|
157
|
+
```
|
|
158
|
+
npx test-docgen -l
|
|
159
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
pragma abicoder v1;
|
|
5
|
+
|
|
6
|
+
library RevertReasonForwarder {
|
|
7
|
+
function reRevert() internal pure {
|
|
8
|
+
// bubble up revert reason from latest external call
|
|
9
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
10
|
+
returndatacopy(0, 0, returndatasize())
|
|
11
|
+
revert(0, returndatasize())
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
|
|
5
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
|
|
7
|
+
import "../interfaces/IDaiLikePermit.sol";
|
|
8
|
+
import "../libraries/RevertReasonForwarder.sol";
|
|
9
|
+
|
|
10
|
+
library SafeERC20 {
|
|
11
|
+
error SafeTransferFailed();
|
|
12
|
+
error SafeTransferFromFailed();
|
|
13
|
+
error ForceApproveFailed();
|
|
14
|
+
error SafeIncreaseAllowanceFailed();
|
|
15
|
+
error SafeDecreaseAllowanceFailed();
|
|
16
|
+
error SafePermitBadLength();
|
|
17
|
+
|
|
18
|
+
// Ensures method do not revert or return boolean `true`, admits call to non-smart-contract
|
|
19
|
+
function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
|
|
20
|
+
bytes4 selector = token.transferFrom.selector;
|
|
21
|
+
bool success;
|
|
22
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
23
|
+
let data := mload(0x40)
|
|
24
|
+
mstore(0x40, add(data, 100))
|
|
25
|
+
|
|
26
|
+
mstore(data, selector)
|
|
27
|
+
mstore(add(data, 0x04), from)
|
|
28
|
+
mstore(add(data, 0x24), to)
|
|
29
|
+
mstore(add(data, 0x44), amount)
|
|
30
|
+
let status := call(gas(), token, 0, data, 100, 0x0, 0x20)
|
|
31
|
+
success := and(status, or(iszero(returndatasize()), and(gt(returndatasize(), 31), eq(mload(0), 1))))
|
|
32
|
+
}
|
|
33
|
+
if (!success) {
|
|
34
|
+
revert SafeTransferFromFailed();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Ensures method do not revert or return boolean `true`, admits call to non-smart-contract
|
|
39
|
+
function safeTransfer(IERC20 token, address to, uint256 value) internal {
|
|
40
|
+
if (!_makeCall(token, token.transfer.selector, to, value)) {
|
|
41
|
+
revert SafeTransferFailed();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// If `approve(from, to, amount)` fails, try to `approve(from, to, 0)` before retry
|
|
46
|
+
function forceApprove(IERC20 token, address spender, uint256 value) internal {
|
|
47
|
+
if (!_makeCall(token, token.approve.selector, spender, value)) {
|
|
48
|
+
if (!_makeCall(token, token.approve.selector, spender, 0) ||
|
|
49
|
+
!_makeCall(token, token.approve.selector, spender, value))
|
|
50
|
+
{
|
|
51
|
+
revert ForceApproveFailed();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
|
|
57
|
+
uint256 allowance = token.allowance(address(this), spender);
|
|
58
|
+
if (value > type(uint256).max - allowance) revert SafeIncreaseAllowanceFailed();
|
|
59
|
+
forceApprove(token, spender, allowance + value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
|
|
63
|
+
uint256 allowance = token.allowance(address(this), spender);
|
|
64
|
+
if (value > allowance) revert SafeDecreaseAllowanceFailed();
|
|
65
|
+
forceApprove(token, spender, allowance - value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function safePermit(IERC20 token, bytes calldata permit) internal {
|
|
69
|
+
bool success;
|
|
70
|
+
if (permit.length == 32 * 7) {
|
|
71
|
+
// solhint-disable-next-line avoid-low-level-calls
|
|
72
|
+
success = _makeCalldataCall(token, IERC20Permit.permit.selector, permit);
|
|
73
|
+
} else if (permit.length == 32 * 8) {
|
|
74
|
+
// solhint-disable-next-line avoid-low-level-calls
|
|
75
|
+
success = _makeCalldataCall(token, IDaiLikePermit.permit.selector, permit);
|
|
76
|
+
} else {
|
|
77
|
+
revert SafePermitBadLength();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!success) {
|
|
81
|
+
RevertReasonForwarder.reRevert();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function _makeCall(IERC20 token, bytes4 selector, address to, uint256 amount) private returns(bool done) {
|
|
86
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
87
|
+
let data := mload(0x40)
|
|
88
|
+
mstore(0x40, add(data, 68))
|
|
89
|
+
|
|
90
|
+
mstore(data, selector)
|
|
91
|
+
mstore(add(data, 0x04), to)
|
|
92
|
+
mstore(add(data, 0x24), amount)
|
|
93
|
+
let success := call(gas(), token, 0, data, 68, 0x0, 0x20)
|
|
94
|
+
done := and(
|
|
95
|
+
success,
|
|
96
|
+
or(
|
|
97
|
+
iszero(returndatasize()),
|
|
98
|
+
and(gt(returndatasize(), 31), eq(mload(0), 1))
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function _makeCalldataCall(IERC20 token, bytes4 selector, bytes calldata args) private returns(bool done) {
|
|
105
|
+
assembly { // solhint-disable-line no-inline-assembly
|
|
106
|
+
let len := add(4, args.length)
|
|
107
|
+
let data := mload(0x40)
|
|
108
|
+
mstore(0x40, add(data, len))
|
|
109
|
+
|
|
110
|
+
mstore(data, selector)
|
|
111
|
+
calldatacopy(add(data, 0x04), args.offset, args.length)
|
|
112
|
+
let success := call(gas(), token, 0, data, len, 0x0, 0x20)
|
|
113
|
+
done := and(
|
|
114
|
+
success,
|
|
115
|
+
or(
|
|
116
|
+
iszero(returndatasize()),
|
|
117
|
+
and(gt(returndatasize(), 31), eq(mload(0), 1))
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -6,16 +6,18 @@ pragma abicoder v1;
|
|
|
6
6
|
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
|
7
7
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
8
8
|
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
9
|
-
import "./
|
|
9
|
+
import "./RevertReasonForwarder.sol";
|
|
10
10
|
import "./StringUtil.sol";
|
|
11
11
|
|
|
12
12
|
library UniERC20 {
|
|
13
13
|
using SafeMath for uint256;
|
|
14
14
|
using SafeERC20 for IERC20;
|
|
15
15
|
|
|
16
|
+
error ApproveCalledOnETH();
|
|
16
17
|
error NotEnoughValue();
|
|
17
18
|
error FromIsNotSender();
|
|
18
19
|
error ToIsNotThis();
|
|
20
|
+
error ERC20OperationFailed();
|
|
19
21
|
|
|
20
22
|
IERC20 private constant _ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
|
21
23
|
IERC20 private constant _ZERO_ADDRESS = IERC20(address(0));
|
|
@@ -67,7 +69,7 @@ library UniERC20 {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
function uniApprove(IERC20 token, address to, uint256 amount) internal {
|
|
70
|
-
|
|
72
|
+
if (isETH(token)) revert ApproveCalledOnETH();
|
|
71
73
|
|
|
72
74
|
// solhint-disable-next-line avoid-low-level-calls
|
|
73
75
|
(bool success, bytes memory returndata) = address(token).call(abi.encodeWithSelector(token.approve.selector, to, amount));
|
|
@@ -123,11 +125,11 @@ library UniERC20 {
|
|
|
123
125
|
// solhint-disable-next-line avoid-low-level-calls
|
|
124
126
|
(bool success, bytes memory result) = address(token).call(data);
|
|
125
127
|
if (!success) {
|
|
126
|
-
|
|
128
|
+
RevertReasonForwarder.reRevert();
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
if (result.length > 0) { // Return data is optional
|
|
130
|
-
|
|
132
|
+
if (!abi.decode(result, (bool))) revert ERC20OperationFailed();
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
}
|
package/dist/src/permit.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { MessageTypes, SignTypedDataVersion, TypedMessage } from '@metamask/eth-sig-util';
|
|
2
3
|
import { Token } from './utils';
|
|
3
4
|
export declare const TypedDataVersion = SignTypedDataVersion.V4;
|
|
@@ -73,7 +74,7 @@ export interface PermittableToken extends Token {
|
|
|
73
74
|
nonces(owner: string, txDetails?: Truffle.TransactionDetails): Promise<BN>;
|
|
74
75
|
name(txDetails?: Truffle.TransactionDetails): Promise<string>;
|
|
75
76
|
}
|
|
76
|
-
export declare function signWithPk<T extends MessageTypes>(privateKey: string, data: TypedMessage<T>): string;
|
|
77
|
+
export declare function signWithPk<T extends MessageTypes>(privateKey: Buffer | string, data: TypedMessage<T>): string;
|
|
77
78
|
export declare function getPermit(owner: string, ownerPrivateKey: string, permitContract: PermittableToken, tokenVersion: string, chainId: number, spender: string, value: string, deadline?: string): Promise<string>;
|
|
78
79
|
export declare function getPermitLikeDai(holder: string, holderPrivateKey: string, permitContract: PermittableToken, tokenVersion: string, chainId: number, spender: string, allowed: boolean, expiry?: string): Promise<string>;
|
|
79
80
|
export declare function withTarget(target: BN | string, data: BN | string): string;
|
package/dist/src/permit.js
CHANGED
|
@@ -62,7 +62,8 @@ function buildDataLikeDai(name, version, chainId, verifyingContract, holder, spe
|
|
|
62
62
|
}
|
|
63
63
|
exports.buildDataLikeDai = buildDataLikeDai;
|
|
64
64
|
function signWithPk(privateKey, data) {
|
|
65
|
-
|
|
65
|
+
const buffer = Buffer.isBuffer(privateKey) ? privateKey : Buffer.from(trim0x(privateKey), 'hex');
|
|
66
|
+
return (0, eth_sig_util_1.signTypedData)({ privateKey: buffer, data, version: exports.TypedDataVersion });
|
|
66
67
|
}
|
|
67
68
|
exports.signWithPk = signWithPk;
|
|
68
69
|
/*
|
package/dist/src/permit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permit.js","sourceRoot":"","sources":["../../src/permit.ts"],"names":[],"mappings":";;;AAAA,yDAAyH;AACzH,qDAA6C;AAE7C,uCAAsC;AAGzB,QAAA,gBAAgB,GAAG,mCAAoB,CAAC,EAAE,CAAC;AAC3C,QAAA,eAAe,GAAG,mBAAS,CAAC,WAAW,CAAC;AAExC,QAAA,YAAY,GAAG;IACxB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;CACjD,CAAC;AAEW,QAAA,MAAM,GAAG;IAClB,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;IAClC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;CACxC,CAAC;AAEW,QAAA,aAAa,GAAG;IACzB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IAC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AAC,IAAI,EAAE,CAAC;IACzC,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IACvI,MAAM,SAAS,GAAG,UAAU,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAA,4BAAU,EAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACxH,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACnC,CAAC;AAjBD,4CAiBC;AAED,SAAgB,UAAU,CAAE,MAAmB,EAAE,IAAiB;IAC9D,OAAO,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAFD,gCAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1inch/solidity-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"main": "dist/src/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"repository": {
|
|
@@ -43,11 +43,15 @@
|
|
|
43
43
|
"@typechain/truffle-v5": "7.0.0",
|
|
44
44
|
"@types/chai": "4.3.0",
|
|
45
45
|
"@types/chai-as-promised": "7.1.5",
|
|
46
|
+
"@types/eth-sig-util": "2.1.1",
|
|
47
|
+
"@types/ethereumjs-util": "6.1.0",
|
|
46
48
|
"@types/mocha": "9.1.0",
|
|
47
49
|
"@types/node": "17.0.23",
|
|
48
50
|
"@typescript-eslint/eslint-plugin": "5.18.0",
|
|
49
51
|
"@typescript-eslint/parser": "5.18.0",
|
|
50
|
-
"
|
|
52
|
+
"acquit": "1.2.1",
|
|
53
|
+
"commander": "9.3.0",
|
|
54
|
+
"create-ts-index": "1.14.0",
|
|
51
55
|
"cross-spawn": "7.0.3",
|
|
52
56
|
"dotenv": "16.0.0",
|
|
53
57
|
"eslint": "8.12.0",
|
|
@@ -56,7 +60,7 @@
|
|
|
56
60
|
"eslint-plugin-node": "11.1.0",
|
|
57
61
|
"eslint-plugin-promise": "6.0.0",
|
|
58
62
|
"eslint-plugin-standard": "5.0.0",
|
|
59
|
-
"
|
|
63
|
+
"ethereumjs-wallet": "1.0.2",
|
|
60
64
|
"hardhat": "2.9.3",
|
|
61
65
|
"hardhat-gas-reporter": "1.0.8",
|
|
62
66
|
"rimraf": "3.0.2",
|
|
@@ -68,7 +72,8 @@
|
|
|
68
72
|
"typescript": "4.6.3"
|
|
69
73
|
},
|
|
70
74
|
"bin": {
|
|
71
|
-
"solidity-utils-docify": "utils/docify.utils.js"
|
|
75
|
+
"solidity-utils-docify": "utils/docify.utils.js",
|
|
76
|
+
"test-docgen": "utils/test-docgen.js"
|
|
72
77
|
},
|
|
73
78
|
"bugs": {
|
|
74
79
|
"url": "https://github.com/1inch/solidity-utils/issues"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = plugin;
|
|
4
|
+
|
|
5
|
+
function plugin(instance, options) {
|
|
6
|
+
if (instance) {
|
|
7
|
+
instance.output(markdown(options, instance));
|
|
8
|
+
} else {
|
|
9
|
+
const acquit = require('acquit');
|
|
10
|
+
acquit.output(markdown(options, acquit));
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
plugin.markdown = markdown;
|
|
15
|
+
|
|
16
|
+
function markdown(options, acquit) {
|
|
17
|
+
return function(res) {
|
|
18
|
+
return recurse(res, 0, options, acquit);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function recurse(blocks, level, options, acquit) {
|
|
23
|
+
var str = '';
|
|
24
|
+
var hashes = getHashes(level + 1);
|
|
25
|
+
for (var i = 0; i < blocks.length; ++i) {
|
|
26
|
+
if (blocks[i].contents) {
|
|
27
|
+
str += hashes + ' ' + (blocks[i].type === 'it' ? (!options || !options.it ? 'It ': '') : '') +
|
|
28
|
+
blocks[i].contents;
|
|
29
|
+
}
|
|
30
|
+
str += '\n\n';
|
|
31
|
+
for (var j = 0; j < blocks[i].comments.length; ++j) {
|
|
32
|
+
str += acquit.trimEachLine(blocks[i].comments[j]);
|
|
33
|
+
str += '\n\n';
|
|
34
|
+
}
|
|
35
|
+
if (blocks[i].type === 'describe') {
|
|
36
|
+
str += recurse(blocks[i].blocks, level + 1, options, acquit);
|
|
37
|
+
} else if (blocks[i].code.trim() && options.code) {
|
|
38
|
+
str += ['```javascript', blocks[i].code, '```'].join('\n');
|
|
39
|
+
}
|
|
40
|
+
if (i + 1 < blocks.length) {
|
|
41
|
+
str += '\n\n';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return str;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getHashes(level) {
|
|
48
|
+
var str = '';
|
|
49
|
+
for (var i = 0; i < level; ++i) {
|
|
50
|
+
str += '#';
|
|
51
|
+
}
|
|
52
|
+
return str;
|
|
53
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const commander = require('commander');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const program = new commander.Command();
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
program
|
|
10
|
+
.option('-i, --input <input>', 'tests directory', 'test')
|
|
11
|
+
.option('-x, --exclude [exclude]', 'exclude directories and files. omit argument to exclude all subdirectories', false)
|
|
12
|
+
.option('-o, --output <output>', 'file to write output', 'TESTS.md')
|
|
13
|
+
.option('-c, --code', 'include code', false)
|
|
14
|
+
.option('-l, --list', 'list tests only, do not include description', false)
|
|
15
|
+
.option('-d, --debug', 'debug mode', false);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
program.parse(process.argv);
|
|
19
|
+
|
|
20
|
+
const options = program.opts();
|
|
21
|
+
const debugMode = options.debug;
|
|
22
|
+
const includeCode = options.code ? true : false;
|
|
23
|
+
const listOnly = options.list ? true : false;
|
|
24
|
+
const includeSubs = !(options.exclude === true);
|
|
25
|
+
const inputDir = options.input.split(';');
|
|
26
|
+
const outputFile = options.output;
|
|
27
|
+
const excludeDirs = (typeof options.exclude == 'boolean') ? [] : options.exclude.split(';');
|
|
28
|
+
|
|
29
|
+
if (debugMode){
|
|
30
|
+
console.log('----- DEBUG MODE -----');
|
|
31
|
+
console.log('options:', options);
|
|
32
|
+
console.log();
|
|
33
|
+
console.log('parsed options:');
|
|
34
|
+
console.log(
|
|
35
|
+
' includeCode:', includeCode,
|
|
36
|
+
'\n listOnly:', listOnly,
|
|
37
|
+
'\n inputDir:', inputDir,
|
|
38
|
+
'\n outputFile:', outputFile,
|
|
39
|
+
'\n includeSubs:', includeSubs,
|
|
40
|
+
'\n excludeDirs:', excludeDirs,
|
|
41
|
+
'\n debugMode:', debugMode
|
|
42
|
+
);
|
|
43
|
+
console.log('\nRemaining arguments: ', program.args);
|
|
44
|
+
console.log('\nFiles and directories found:');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let files = [];
|
|
48
|
+
function throughDirectory (directory, includeSubs, excludeDirs) {
|
|
49
|
+
if (!fs.existsSync(directory)) {
|
|
50
|
+
console.log('WARNING! Directory does not exist:', directory, '=> skipped');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fs.readdirSync(directory).forEach(file => {
|
|
55
|
+
const absolute = path.join(directory, file);
|
|
56
|
+
if (debugMode) console.log(absolute);
|
|
57
|
+
if (!excludeDirs.includes(absolute)) {
|
|
58
|
+
if (fs.statSync(absolute).isDirectory()){
|
|
59
|
+
if (includeSubs) throughDirectory(absolute, includeSubs, excludeDirs);
|
|
60
|
+
}
|
|
61
|
+
else files.push(absolute);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
inputDir.forEach(dir => {
|
|
67
|
+
throughDirectory(dir, includeSubs, excludeDirs);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (debugMode) console.log('\nfiles:', files);
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
//Script
|
|
75
|
+
const acquitMd = require('acquit')();
|
|
76
|
+
const acquitJson = require('acquit')();
|
|
77
|
+
require('./acquit-markdown.js')(acquitMd, { code: includeCode, it: true });
|
|
78
|
+
|
|
79
|
+
const legend = {};
|
|
80
|
+
let content;
|
|
81
|
+
let markdown = '';
|
|
82
|
+
let legendMd = '';
|
|
83
|
+
|
|
84
|
+
if (debugMode) console.log('\nFiles processed:');
|
|
85
|
+
files.forEach((file) => {
|
|
86
|
+
content = fs.readFileSync(file).toString();
|
|
87
|
+
legend.blocks = acquitJson.parse(content);
|
|
88
|
+
legend.contents = file;
|
|
89
|
+
legendMd += buildLegend(legend, 1, listOnly);
|
|
90
|
+
markdown += acquitMd.parse(content).toString();
|
|
91
|
+
markdown += '\n';
|
|
92
|
+
if (debugMode) console.log(' ', file, '=> done');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
content = listOnly ? legendMd : legendMd + markdown;
|
|
96
|
+
|
|
97
|
+
fs.writeFileSync(outputFile, content);
|
|
98
|
+
console.log('done');
|
|
99
|
+
|
|
100
|
+
function buildLegend (block, depth, listOnly) {
|
|
101
|
+
// console.log(depth, block.contents);
|
|
102
|
+
const url = (block.contents == null)
|
|
103
|
+
? ''
|
|
104
|
+
: block.contents.toLowerCase().trim()
|
|
105
|
+
.split(' ').join('-')
|
|
106
|
+
.split(/,|\+|\/|:|\(|\)/).join('')
|
|
107
|
+
.replace('--', '-');
|
|
108
|
+
let legend = listOnly
|
|
109
|
+
? Array(depth).join(' ') + '* ' + block.contents + '\n'
|
|
110
|
+
: Array(depth).join(' ') + '* [' + block.contents + '](#' + url + ')\n';
|
|
111
|
+
if (block.blocks) {
|
|
112
|
+
legend += block.blocks.map(function (child) {
|
|
113
|
+
return buildLegend(child, depth + 1, listOnly);
|
|
114
|
+
}).join('');
|
|
115
|
+
}
|
|
116
|
+
return legend;
|
|
117
|
+
}
|
package/contracts/Permitable.sol
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.0;
|
|
4
|
-
pragma abicoder v1;
|
|
5
|
-
|
|
6
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
|
|
7
|
-
import "./interfaces/IDaiLikePermit.sol";
|
|
8
|
-
|
|
9
|
-
contract Permitable {
|
|
10
|
-
error BadPermitLength();
|
|
11
|
-
|
|
12
|
-
function _permit(address token, bytes calldata permit) internal virtual {
|
|
13
|
-
if (permit.length > 0) {
|
|
14
|
-
bool success;
|
|
15
|
-
bytes memory result;
|
|
16
|
-
if (permit.length == 32 * 7) {
|
|
17
|
-
// solhint-disable-next-line avoid-low-level-calls
|
|
18
|
-
(success, result) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
|
|
19
|
-
} else if (permit.length == 32 * 8) {
|
|
20
|
-
// solhint-disable-next-line avoid-low-level-calls
|
|
21
|
-
(success, result) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
|
|
22
|
-
} else {
|
|
23
|
-
revert BadPermitLength();
|
|
24
|
-
}
|
|
25
|
-
if (!success) {
|
|
26
|
-
// bubble up revert reason from permit call
|
|
27
|
-
assembly { // solhint-disable-line no-inline-assembly
|
|
28
|
-
returndatacopy(0, 0, returndatasize())
|
|
29
|
-
revert(0, returndatasize())
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|