@1inch/solidity-utils 2.0.11 → 2.0.14

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 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
+ ```
@@ -4,8 +4,10 @@ pragma solidity ^0.8.0;
4
4
  pragma abicoder v1;
5
5
 
6
6
  abstract contract EthReceiver {
7
+ error EthDepositRejected();
8
+
7
9
  receive() external payable {
8
10
  // solhint-disable-next-line avoid-tx-origin
9
- require(msg.sender != tx.origin, "ETH deposit rejected");
11
+ if (msg.sender == tx.origin) revert EthDepositRejected();
10
12
  }
11
13
  }
@@ -3,17 +3,13 @@
3
3
  pragma solidity ^0.8.0;
4
4
  pragma abicoder v1;
5
5
 
6
- import "@openzeppelin/contracts/utils/Strings.sol";
7
-
8
6
  contract GasChecker {
9
- using Strings for uint256;
7
+ error GasCostDiffers(uint256 expected, uint256 actual);
10
8
 
11
- modifier checkGasCost(uint256 expectedGasCost) {
9
+ modifier checkGasCost(uint256 expected) {
12
10
  uint256 gas = gasleft();
13
11
  _;
14
- gas -= gasleft();
15
- if (expectedGasCost > 0) {
16
- require (gas == expectedGasCost, string(abi.encodePacked("Gas cost differs: expected ", expectedGasCost.toString(), ", actual: ", gas.toString())));
17
- }
12
+ unchecked { gas -= gasleft(); }
13
+ if (expected > 0 && gas != expected) revert GasCostDiffers(expected, gas);
18
14
  }
19
15
  }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+ pragma abicoder v1;
5
+
6
+ abstract contract OnlyWethReceiver {
7
+ error EthDepositRejected();
8
+
9
+ // solhint-disable-next-line var-name-mixedcase
10
+ address internal immutable _WETH;
11
+
12
+ constructor(address weth) {
13
+ _WETH = weth;
14
+ }
15
+
16
+ receive() external payable {
17
+ // solhint-disable-next-line avoid-tx-origin
18
+ if (msg.sender != _WETH) revert EthDepositRejected();
19
+ }
20
+ }
@@ -5,25 +5,26 @@ pragma abicoder v1;
5
5
 
6
6
  import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
7
7
  import "./interfaces/IDaiLikePermit.sol";
8
+ import "./libraries/RevertReasonForwarder.sol";
8
9
 
9
10
  contract Permitable {
10
11
  error BadPermitLength();
11
- error PermitFailed();
12
12
 
13
13
  function _permit(address token, bytes calldata permit) internal virtual {
14
14
  if (permit.length > 0) {
15
15
  bool success;
16
- bytes memory result;
17
16
  if (permit.length == 32 * 7) {
18
17
  // solhint-disable-next-line avoid-low-level-calls
19
- (success, result) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
18
+ (success,) = token.call(abi.encodePacked(IERC20Permit.permit.selector, permit));
20
19
  } else if (permit.length == 32 * 8) {
21
20
  // solhint-disable-next-line avoid-low-level-calls
22
- (success, result) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
21
+ (success,) = token.call(abi.encodePacked(IDaiLikePermit.permit.selector, permit));
23
22
  } else {
24
23
  revert BadPermitLength();
25
24
  }
26
- if (!success) revert PermitFailed();
25
+ if (!success) {
26
+ RevertReasonForwarder.reRevert();
27
+ }
27
28
  }
28
29
  }
29
30
  }
@@ -35,33 +35,39 @@ library AddressArray {
35
35
  if (len > output.length) revert OutputArrayTooSmall();
36
36
  if (len > 0) {
37
37
  output[0] = address(uint160(lengthAndFirst));
38
- for (uint i = 1; i < len; i++) {
39
- output[i] = address(uint160(self._raw[i]));
38
+ unchecked {
39
+ for (uint i = 1; i < len; i++) {
40
+ output[i] = address(uint160(self._raw[i]));
41
+ }
40
42
  }
41
43
  }
42
44
  return output;
43
45
  }
44
46
 
45
47
  function push(Data storage self, address account) internal returns(uint256) {
46
- uint256 lengthAndFirst = self._raw[0];
47
- uint256 len = lengthAndFirst >> 160;
48
- if (len == 0) {
49
- self._raw[0] = (1 << 160) + uint160(account);
50
- }
51
- else {
52
- self._raw[0] = lengthAndFirst + (1 << 160);
53
- self._raw[len] = uint160(account);
48
+ unchecked {
49
+ uint256 lengthAndFirst = self._raw[0];
50
+ uint256 len = lengthAndFirst >> 160;
51
+ if (len == 0) {
52
+ self._raw[0] = (1 << 160) + uint160(account);
53
+ }
54
+ else {
55
+ self._raw[0] = lengthAndFirst + (1 << 160);
56
+ self._raw[len] = uint160(account);
57
+ }
58
+ return len + 1;
54
59
  }
55
- return len + 1;
56
60
  }
57
61
 
58
62
  function pop(Data storage self) internal {
59
- uint256 lengthAndFirst = self._raw[0];
60
- uint256 len = lengthAndFirst >> 160;
61
- if (len == 0) revert PopFromEmptyArray();
62
- self._raw[len - 1] = 0;
63
- if (len > 1) {
64
- self._raw[0] = lengthAndFirst - (1 << 160);
63
+ unchecked {
64
+ uint256 lengthAndFirst = self._raw[0];
65
+ uint256 len = lengthAndFirst >> 160;
66
+ if (len == 0) revert PopFromEmptyArray();
67
+ self._raw[len - 1] = 0;
68
+ if (len > 1) {
69
+ self._raw[0] = lengthAndFirst - (1 << 160);
70
+ }
65
71
  }
66
72
  }
67
73
 
@@ -39,9 +39,11 @@ library AddressSet {
39
39
  return false;
40
40
  }
41
41
  if (index < s.items.length()) {
42
- address lastItem = s.items.at(s.items.length() - 1);
43
- s.items.set(index - 1, lastItem);
44
- s.lookup[lastItem] = index;
42
+ unchecked {
43
+ address lastItem = s.items.at(s.items.length() - 1);
44
+ s.items.set(index - 1, lastItem);
45
+ s.lookup[lastItem] = index;
46
+ }
45
47
  }
46
48
  s.items.pop();
47
49
  delete s.lookup[item];
@@ -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
+ }
@@ -16,6 +16,8 @@ library RevertReasonParser {
16
16
  using StringUtil for uint256;
17
17
  using StringUtil for bytes;
18
18
 
19
+ error InvalidRevertReason();
20
+
19
21
  bytes4 constant private _ERROR_SELECTOR = bytes4(keccak256("Error(string)"));
20
22
  bytes4 constant private _PANIC_SELECTOR = bytes4(keccak256("Panic(uint256)"));
21
23
 
@@ -42,8 +44,8 @@ library RevertReasonParser {
42
44
  because of that we can't check for equality and instead check
43
45
  that string length + extra 68 bytes is less than overall data length
44
46
  */
45
- require(data.length >= 68 + bytes(reason).length, "Invalid revert reason");
46
- return string(abi.encodePacked(prefix, "Error(", reason, ")"));
47
+ if (data.length < 68 + bytes(reason).length) revert InvalidRevertReason();
48
+ return string.concat(prefix, "Error(", reason, ")");
47
49
  }
48
50
  // 36 = 4-byte selector + 32 bytes integer
49
51
  else if (selector == _PANIC_SELECTOR && data.length == 36) {
@@ -53,8 +55,8 @@ library RevertReasonParser {
53
55
  // 36 = 32 bytes data length + 4-byte selector
54
56
  code := mload(add(data, 36))
55
57
  }
56
- return string(abi.encodePacked(prefix, "Panic(", code.toHex(), ")"));
58
+ return string.concat(prefix, "Panic(", code.toHex(), ")");
57
59
  }
58
- return string(abi.encodePacked(prefix, "Unknown(", data.toHex(), ")"));
60
+ return string.concat(prefix, "Unknown(", data.toHex(), ")");
59
61
  }
60
62
  }
@@ -6,13 +6,19 @@ 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 "./RevertReasonParser.sol";
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();
17
+ error NotEnoughValue();
18
+ error FromIsNotSender();
19
+ error ToIsNotThis();
20
+ error ERC20OperationFailed();
21
+
16
22
  IERC20 private constant _ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
17
23
  IERC20 private constant _ZERO_ADDRESS = IERC20(address(0));
18
24
 
@@ -41,9 +47,9 @@ library UniERC20 {
41
47
  function uniTransferFrom(IERC20 token, address payable from, address to, uint256 amount) internal {
42
48
  if (amount > 0) {
43
49
  if (isETH(token)) {
44
- require(msg.value >= amount, "UniERC20: not enough value");
45
- require(from == msg.sender, "from is not msg.sender");
46
- require(to == address(this), "to is not this");
50
+ if (msg.value < amount) revert NotEnoughValue();
51
+ if (from != msg.sender) revert FromIsNotSender();
52
+ if (to != address(this)) revert ToIsNotThis();
47
53
  if (msg.value > amount) {
48
54
  // Return remainder if exist
49
55
  from.transfer(msg.value.sub(amount));
@@ -63,7 +69,7 @@ library UniERC20 {
63
69
  }
64
70
 
65
71
  function uniApprove(IERC20 token, address to, uint256 amount) internal {
66
- require(!isETH(token), "Approve called on ETH");
72
+ if (isETH(token)) revert ApproveCalledOnETH();
67
73
 
68
74
  // solhint-disable-next-line avoid-low-level-calls
69
75
  (bool success, bytes memory returndata) = address(token).call(abi.encodeWithSelector(token.approve.selector, to, amount));
@@ -91,7 +97,7 @@ library UniERC20 {
91
97
  if (success && data.length >= 96) {
92
98
  (uint256 offset, uint256 len) = abi.decode(data, (uint256, uint256));
93
99
  if (offset == 0x20 && len > 0 && len <= 256) {
94
- return string(abi.decode(data, (bytes)));
100
+ return abi.decode(data, (string));
95
101
  }
96
102
  }
97
103
 
@@ -103,8 +109,10 @@ library UniERC20 {
103
109
 
104
110
  if (len > 0) {
105
111
  bytes memory result = new bytes(len);
106
- for (uint i = 0; i < len; i++) {
107
- result[i] = data[i];
112
+ unchecked {
113
+ for (uint i = 0; i < len; i++) {
114
+ result[i] = data[i];
115
+ }
108
116
  }
109
117
  return string(result);
110
118
  }
@@ -117,11 +125,11 @@ library UniERC20 {
117
125
  // solhint-disable-next-line avoid-low-level-calls
118
126
  (bool success, bytes memory result) = address(token).call(data);
119
127
  if (!success) {
120
- revert(RevertReasonParser.parse(result, "Low-level call failed: "));
128
+ RevertReasonForwarder.reRevert();
121
129
  }
122
130
 
123
131
  if (result.length > 0) { // Return data is optional
124
- require(abi.decode(result, (bool)), "ERC20 operation did not succeed");
132
+ if (!abi.decode(result, (bool))) revert ERC20OperationFailed();
125
133
  }
126
134
  }
127
135
  }
package/dist/src/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
  // created from 'create-ts-index'
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
- (0, tslib_1.__exportStar)(require("./asserts"), exports);
6
- (0, tslib_1.__exportStar)(require("./permit"), exports);
7
- (0, tslib_1.__exportStar)(require("./prelude"), exports);
8
- (0, tslib_1.__exportStar)(require("./profileEVM"), exports);
9
- (0, tslib_1.__exportStar)(require("./utils"), exports);
5
+ tslib_1.__exportStar(require("./asserts"), exports);
6
+ tslib_1.__exportStar(require("./permit"), exports);
7
+ tslib_1.__exportStar(require("./prelude"), exports);
8
+ tslib_1.__exportStar(require("./profileEVM"), exports);
9
+ tslib_1.__exportStar(require("./utils"), exports);
10
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,yDAA0B;AAC1B,wDAAyB;AACzB,yDAA0B;AAC1B,4DAA6B;AAC7B,uDAAwB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,iCAAiC;;;AAEjC,oDAA0B;AAC1B,mDAAyB;AACzB,oDAA0B;AAC1B,uDAA6B;AAC7B,kDAAwB"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.should = exports.config = exports.expect = exports.assert = exports.AssertionError = exports.Assertion = exports.ether = exports.time = exports.toBN = exports.constants = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const chai_1 = (0, tslib_1.__importStar)(require("chai"));
5
+ const chai_1 = tslib_1.__importStar(require("chai"));
6
6
  Object.defineProperty(exports, "Assertion", { enumerable: true, get: function () { return chai_1.Assertion; } });
7
7
  Object.defineProperty(exports, "AssertionError", { enumerable: true, get: function () { return chai_1.AssertionError; } });
8
8
  Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return chai_1.assert; } });
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "expect", { enumerable: true, get: function () {
10
10
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return chai_1.config; } });
11
11
  Object.defineProperty(exports, "should", { enumerable: true, get: function () { return chai_1.should; } });
12
12
  require("chai-bn");
13
- const chai_as_promised_1 = (0, tslib_1.__importDefault)(require("chai-as-promised"));
13
+ const chai_as_promised_1 = tslib_1.__importDefault(require("chai-as-promised"));
14
14
  const web3_utils_1 = require("web3-utils");
15
15
  Object.defineProperty(exports, "toBN", { enumerable: true, get: function () { return web3_utils_1.toBN; } });
16
16
  chai_1.default.use(chai_as_promised_1.default);
@@ -1 +1 @@
1
- {"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":";;;;AAAA,0DAAuF;AAqCnF,0FArCW,gBAAS,OAqCX;AACT,+FAtCsB,qBAAc,OAsCtB;AACd,uFAvCsC,aAAM,OAuCtC;AACN,uFAxC8C,aAAM,OAwC9C;AACN,uFAzCsD,aAAM,OAyCtD;AACN,uFA1C8D,aAAM,OA0C9D;AAzCV,mBAAiB;AACjB,qFAA8C;AAC9C,2CAAyC;AAiBrC,qFAjBK,iBAAI,OAiBL;AAfR,cAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACzB,8DAA8D;AAC9D,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEpD,QAAA,SAAS,GAAG;IACrB,YAAY,EAAE,4CAA4C;IAC1D,WAAW,EAAE,4CAA4C;IACzD,YAAY,EAAE,oEAAoE;IAClF,WAAW,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IACjE,UAAU,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IAChE,UAAU,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC3D,CAAC;AAaE,QAAA,IAAI,GAAS,QAAQ,CAAC;AAEnC,SAAgB,KAAK,CAAE,CAAS;IAC5B,OAAO,IAAA,iBAAI,EAAC,IAAA,kBAAK,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC;AAFD,sBAEC"}
1
+ {"version":3,"file":"prelude.js","sourceRoot":"","sources":["../../src/prelude.ts"],"names":[],"mappings":";;;;AAAA,qDAAuF;AAqCnF,0FArCW,gBAAS,OAqCX;AACT,+FAtCsB,qBAAc,OAsCtB;AACd,uFAvCsC,aAAM,OAuCtC;AACN,uFAxC8C,aAAM,OAwC9C;AACN,uFAzCsD,aAAM,OAyCtD;AACN,uFA1C8D,aAAM,OA0C9D;AAzCV,mBAAiB;AACjB,gFAA8C;AAC9C,2CAAyC;AAiBrC,qFAjBK,iBAAI,OAiBL;AAfR,cAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC;AACzB,8DAA8D;AAC9D,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEpD,QAAA,SAAS,GAAG;IACrB,YAAY,EAAE,4CAA4C;IAC1D,WAAW,EAAE,4CAA4C;IACzD,YAAY,EAAE,oEAAoE;IAClF,WAAW,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IACjE,UAAU,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE;IAChE,UAAU,EAAE,IAAA,iBAAI,EAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,iBAAI,EAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC3D,CAAC;AAaE,QAAA,IAAI,GAAS,QAAQ,CAAC;AAEnC,SAAgB,KAAK,CAAE,CAAS;IAC5B,OAAO,IAAA,iBAAI,EAAC,IAAA,kBAAK,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AACnC,CAAC;AAFD,sBAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1inch/solidity-utils",
3
- "version": "2.0.11",
3
+ "version": "2.0.14",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -20,7 +20,8 @@
20
20
  "lint:ts:fix": "eslint . --fix --ext .ts",
21
21
  "lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
22
22
  "lint:sol:fix": "solhint --max-warnings 0 \"contracts/**/*.sol\" --fix",
23
- "test": "hardhat test",
23
+ "test": "hardhat test --parallel",
24
+ "test:ci": "hardhat test",
24
25
  "typecheck": "tsc --noEmit --skipLibCheck",
25
26
  "typechain": "hardhat typechain"
26
27
  },
@@ -33,44 +34,44 @@
33
34
  "chai-as-promised": "7.1.1",
34
35
  "chai-bn": "0.3.1",
35
36
  "ethereumjs-util": "7.1.4",
36
- "web3-utils": "1.7.0"
37
+ "web3-utils": "1.7.1"
37
38
  },
38
39
  "devDependencies": {
39
- "@nomiclabs/hardhat-etherscan": "3.0.1",
40
- "@nomiclabs/hardhat-truffle5": "2.0.4",
40
+ "@nomiclabs/hardhat-truffle5": "2.0.5",
41
41
  "@nomiclabs/hardhat-web3": "2.0.0",
42
- "@typechain/hardhat": "4.0.0",
42
+ "@typechain/hardhat": "6.0.0",
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
46
  "@types/mocha": "9.1.0",
47
- "@types/node": "17.0.18",
48
- "@typescript-eslint/eslint-plugin": "5.12.0",
49
- "@typescript-eslint/parser": "5.12.0",
47
+ "@types/node": "17.0.23",
48
+ "@typescript-eslint/eslint-plugin": "5.18.0",
49
+ "@typescript-eslint/parser": "5.18.0",
50
+ "acquit": "1.2.1",
51
+ "commander": "^9.1.0",
50
52
  "create-ts-index": "^1.14.0",
51
53
  "cross-spawn": "7.0.3",
52
54
  "dotenv": "16.0.0",
53
- "eslint": "8.9.0",
55
+ "eslint": "8.12.0",
54
56
  "eslint-config-standard": "16.0.3",
55
- "eslint-plugin-import": "2.25.4",
57
+ "eslint-plugin-import": "2.26.0",
56
58
  "eslint-plugin-node": "11.1.0",
57
59
  "eslint-plugin-promise": "6.0.0",
58
60
  "eslint-plugin-standard": "5.0.0",
59
61
  "eslint-plugin-typescript": "0.14.0",
60
- "hardhat": "2.8.4",
61
- "hardhat-deploy": "0.10.5",
62
+ "hardhat": "2.9.3",
62
63
  "hardhat-gas-reporter": "1.0.8",
63
64
  "rimraf": "3.0.2",
64
65
  "shx": "0.3.4",
65
- "solc": "0.8.11",
66
66
  "solhint": "3.3.7",
67
67
  "solidity-coverage": "0.7.20",
68
- "ts-node": "10.5.0",
68
+ "ts-node": "10.7.0",
69
69
  "typechain": "7.0.0",
70
- "typescript": "4.5.5"
70
+ "typescript": "4.6.3"
71
71
  },
72
72
  "bin": {
73
- "solidity-utils-docify": "utils/docify.utils.js"
73
+ "solidity-utils-docify": "utils/docify.utils.js",
74
+ "test-docgen": "utils/test-docgen.js"
74
75
  },
75
76
  "bugs": {
76
77
  "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
+ }