fmt.sol 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. pragma solidity ^0.5.2;
  2. // forgefmt: disable-next-line
  3. pragma solidity ^0.5.2;
  4. import {
  5. symbol1 as alias1,
  6. symbol2 as alias2,
  7. symbol3 as alias3,
  8. symbol4
  9. } from "File2.sol";
  10. // forgefmt: disable-next-line
  11. import {symbol1 as alias1, symbol2 as alias2, symbol3 as alias3, symbol4} from 'File2.sol';
  12. enum States {
  13. State1,
  14. State2,
  15. State3,
  16. State4,
  17. State5,
  18. State6,
  19. State7,
  20. State8,
  21. State9
  22. }
  23. // forgefmt: disable-next-line
  24. enum States { State1, State2, State3, State4, State5, State6, State7, State8, State9 }
  25. // forgefmt: disable-next-line
  26. bytes32 constant private BYTES = 0x035aff83d86937d35b32e04f0ddc6ff469290eef2f1b692d8a815c89404d4749;
  27. // forgefmt: disable-start
  28. // comment1
  29. // comment2
  30. /* comment 3 */ /*
  31. comment4
  32. */ // comment 5
  33. /// Doccomment 1
  34. /// Doccomment 2
  35. /**
  36. * docccoment 3
  37. */
  38. // forgefmt: disable-end
  39. // forgefmt: disable-start
  40. function test1() {}
  41. function test2() {}
  42. // forgefmt: disable-end
  43. contract Constructors is Ownable, Changeable {
  44. //forgefmt: disable-next-item
  45. function Constructors(variable1) public Changeable(variable1) Ownable() onlyOwner {
  46. }
  47. //forgefmt: disable-next-item
  48. constructor(variable1, variable2, variable3, variable4, variable5, variable6, variable7) public Changeable(variable1, variable2, variable3, variable4, variable5, variable6, variable7) Ownable() onlyOwner {}
  49. }
  50. function test() {
  51. uint256 pi_approx = 666 / 212;
  52. uint256 pi_approx = /* forgefmt: disable-start */ 666 / 212; /* forgefmt: disable-end */
  53. // forgefmt: disable-next-item
  54. uint256 pi_approx = 666 /
  55. 212;
  56. uint256 test_postfix = 1; // forgefmt: disable-start
  57. // comment1
  58. // comment2
  59. // comment3
  60. // forgefmt: disable-end
  61. }
  62. // forgefmt: disable-next-item
  63. function testFunc(uint256 num, bytes32 data , address receiver)
  64. public payable attr1 Cool( "hello" ) {}
  65. function testAttrs(uint256 num, bytes32 data, address receiver)
  66. // forgefmt: disable-next-line
  67. public payable attr1 Cool( "hello" )
  68. {}
  69. // forgefmt: disable-next-line
  70. function testParams(uint256 num, bytes32 data , address receiver)
  71. public
  72. payable
  73. attr1
  74. Cool("hello")
  75. {}
  76. function testDoWhile() external {
  77. //forgefmt: disable-start
  78. uint256 i;
  79. do { "test"; } while (i != 0);
  80. do
  81. {}
  82. while
  83. (
  84. i != 0);
  85. bool someVeryVeryLongCondition;
  86. do { "test"; } while(
  87. someVeryVeryLongCondition && !someVeryVeryLongCondition &&
  88. !someVeryVeryLongCondition &&
  89. someVeryVeryLongCondition);
  90. do i++; while(i < 10);
  91. do do i++; while (i < 30); while(i < 20);
  92. //forgefmt: disable-end
  93. }
  94. function forStatement() {
  95. //forgefmt: disable-start
  96. for
  97. (uint256 i1
  98. ; i1 < 10; i1++)
  99. {
  100. i1++;
  101. }
  102. uint256 i2;
  103. for(++i2;i2<10;i2++)
  104. {}
  105. uint256 veryLongVariableName = 1000;
  106. for ( uint256 i3; i3 < 10
  107. && veryLongVariableName>999 && veryLongVariableName< 1001
  108. ; i3++)
  109. { i3 ++ ; }
  110. for (type(uint256).min;;) {}
  111. for (;;) { "test" ; }
  112. for (uint256 i4; i4< 10; i4++) i4++;
  113. for (uint256 i5; ;)
  114. for (uint256 i6 = 10; i6 > i5; i6--)
  115. i5++;
  116. //forgefmt: disable-end
  117. }
  118. function callArgTest() {
  119. //forgefmt: disable-start
  120. target.run{ gas: gasleft(), value: 1 wei };
  121. target.run{gas:1,value:0x00}();
  122. target.run{
  123. gas : 1000,
  124. value: 1 ether
  125. } ();
  126. target.run{ gas: estimate(),
  127. value: value(1) }();
  128. target.run { value:
  129. value(1 ether), gas: veryAndVeryLongNameOfSomeGasEstimateFunction() } ();
  130. target.run /* comment 1 */ { value: /* comment2 */ 1 };
  131. target.run { /* comment3 */ value: 1, // comment4
  132. gas: gasleft()};
  133. target.run {
  134. // comment5
  135. value: 1,
  136. // comment6
  137. gas: gasleft()};
  138. //forgefmt: disable-end
  139. }
  140. function ifTest() {
  141. // forgefmt: disable-start
  142. if (condition)
  143. execute();
  144. else
  145. executeElse();
  146. // forgefmt: disable-end
  147. /* forgefmt: disable-next-line */
  148. if (condition && anotherLongCondition ) {
  149. execute();
  150. }
  151. }
  152. function yulTest() {
  153. // forgefmt: disable-start
  154. assembly {
  155. let payloadSize := sub(calldatasize(), 4)
  156. calldatacopy(0, 4, payloadSize)
  157. mstore(payloadSize, shl(96, caller()))
  158. let result :=
  159. delegatecall(gas(), moduleImpl, 0, add(payloadSize, 20), 0, 0)
  160. returndatacopy(0, 0, returndatasize())
  161. switch result
  162. case 0 { revert(0, returndatasize()) }
  163. default { return(0, returndatasize()) }
  164. }
  165. // forgefmt: disable-end
  166. }
  167. function literalTest() {
  168. // forgefmt: disable-start
  169. true;
  170. 0x123_456;
  171. .1;
  172. "foobar";
  173. hex"001122FF";
  174. 0xc02aaa39b223Fe8D0A0e5C4F27ead9083c756Cc2;
  175. // forgefmt: disable-end
  176. // forgefmt: disable-next-line
  177. bytes memory bytecode = hex"ff";
  178. }
  179. function returnTest() {
  180. // forgefmt: disable-start
  181. if (val == 0) {
  182. return // return single 1
  183. 0x00;
  184. }
  185. if (val == 1) { return
  186. 1; }
  187. if (val == 2) {
  188. return 3
  189. -
  190. 1;
  191. }
  192. if (val == 4) {
  193. /* return single 2 */ return 2** // return single 3
  194. 3 // return single 4
  195. ;
  196. }
  197. return value(); // return single 5
  198. return ;
  199. return /* return mul 4 */
  200. (
  201. 987654321, 1234567890,/* return mul 5 */ false);
  202. // forgefmt: disable-end
  203. }
  204. function namedFuncCall() {
  205. // forgefmt: disable-start
  206. SimpleStruct memory simple = SimpleStruct({ val: 0 });
  207. ComplexStruct memory complex = ComplexStruct({ val: 1, anotherVal: 2, flag: true, timestamp: block.timestamp });
  208. StructWithAVeryLongNameThatExceedsMaximumLengthThatIsAllowedForFormatting memory long = StructWithAVeryLongNameThatExceedsMaximumLengthThatIsAllowedForFormatting({ whyNameSoLong: "dunno" });
  209. SimpleStruct memory simple2 = SimpleStruct(
  210. { // comment1
  211. /* comment2 */ val : /* comment3 */ 0
  212. }
  213. );
  214. // forgefmt: disable-end
  215. }
  216. function revertTest() {
  217. // forgefmt: disable-start
  218. revert ({ });
  219. revert EmptyError({});
  220. revert SimpleError({ val: 0 });
  221. revert ComplexError(
  222. {
  223. val: 0,
  224. ts: block.timestamp,
  225. message: "some reason"
  226. });
  227. revert SomeVeryVeryVeryLongErrorNameWithNamedArgumentsThatExceedsMaximumLength({ val: 0, ts: 0x00, message: "something unpredictable happened that caused execution to revert"});
  228. revert // comment1
  229. ({});
  230. // forgefmt: disable-end
  231. }
  232. function testTernary() {
  233. // forgefmt: disable-start
  234. bool condition;
  235. bool someVeryVeryLongConditionUsedInTheTernaryExpression;
  236. condition ? 0 : 1;
  237. someVeryVeryLongConditionUsedInTheTernaryExpression ? 1234567890 : 987654321;
  238. condition /* comment1 */ ? /* comment2 */ 1001 /* comment3 */ : /* comment4 */ 2002;
  239. // comment5
  240. someVeryVeryLongConditionUsedInTheTernaryExpression ? 1
  241. // comment6
  242. :
  243. // comment7
  244. 0; // comment8
  245. // forgefmt: disable-end
  246. }
  247. function thisTest() {
  248. // forgefmt: disable-start
  249. this.someFunc();
  250. this.someVeryVeryVeryLongVariableNameThatWillBeAccessedByThisKeyword();
  251. this // comment1
  252. .someVeryVeryVeryLongVariableNameThatWillBeAccessedByThisKeyword();
  253. address(this).balance;
  254. address thisAddress = address(
  255. // comment2
  256. /* comment3 */ this // comment 4
  257. );
  258. // forgefmt: disable-end
  259. }
  260. function tryTest() {
  261. // forgefmt: disable-start
  262. try unknown.empty() {} catch {}
  263. try unknown.lookup() returns (uint256) {} catch Error(string memory) {}
  264. try unknown.lookup() returns (uint256) {} catch Error(string memory) {} catch (bytes memory) {}
  265. try unknown
  266. .lookup() returns (uint256
  267. ) {
  268. } catch ( bytes memory ){}
  269. try unknown.empty() {
  270. unknown.doSomething();
  271. } catch {
  272. unknown.handleError();
  273. }
  274. try unknown.empty() {
  275. unknown.doSomething();
  276. } catch Error(string memory) {}
  277. catch Panic(uint) {}
  278. catch {
  279. unknown.handleError();
  280. }
  281. try unknown.lookupMultipleValues() returns (uint256, uint256, uint256, uint256, uint256) {} catch Error(string memory) {} catch {}
  282. try unknown.lookupMultipleValues() returns (uint256, uint256, uint256, uint256, uint256) {
  283. unknown.doSomething();
  284. }
  285. catch Error(string memory) {
  286. unknown.handleError();
  287. }
  288. catch {}
  289. // forgefmt: disable-end
  290. }
  291. function testArray() {
  292. // forgefmt: disable-start
  293. msg.data[
  294. // comment1
  295. 4:];
  296. msg.data[
  297. : /* comment2 */ msg.data.length // comment3
  298. ];
  299. msg.data[
  300. // comment4
  301. 4 // comment5
  302. :msg.data.length /* comment6 */];
  303. // forgefmt: disable-end
  304. }
  305. function testUnit() {
  306. // forgefmt: disable-start
  307. uint256 timestamp;
  308. timestamp = 1 seconds;
  309. timestamp = 1 minutes;
  310. timestamp = 1 hours;
  311. timestamp = 1 days;
  312. timestamp = 1 weeks;
  313. uint256 value;
  314. value = 1 wei;
  315. value = 1 gwei;
  316. value = 1 ether;
  317. uint256 someVeryVeryVeryLongVariableNameForTheMultiplierForEtherValue;
  318. value = someVeryVeryVeryLongVariableNameForTheMultiplierForEtherValue * 1 /* comment1 */ ether; // comment2
  319. value = 1 // comment3
  320. // comment4
  321. ether; // comment5
  322. // forgefmt: disable-end
  323. }
  324. contract UsingExampleContract {
  325. // forgefmt: disable-start
  326. using UsingExampleLibrary for * ;
  327. using UsingExampleLibrary for uint;
  328. using Example.UsingExampleLibrary for uint;
  329. using { M.g, M.f} for uint;
  330. using UsingExampleLibrary for uint global;
  331. using { These, Are, MultipleLibraries, ThatNeedToBePut, OnSeparateLines } for uint;
  332. using { This.isareally.longmember.access.expression.that.needs.to.besplit.into.lines } for uint;
  333. // forgefmt: disable-end
  334. }
  335. function testAssignment() {
  336. // forgefmt: disable-start
  337. (, uint256 second) = (1, 2);
  338. (uint256 listItem001) = 1;
  339. (uint256 listItem002, uint256 listItem003) = (10, 20);
  340. (uint256 listItem004, uint256 listItem005, uint256 listItem006) =
  341. (10, 20, 30);
  342. // forgefmt: disable-end
  343. }
  344. function testWhile() {
  345. // forgefmt: disable-start
  346. uint256 i1;
  347. while ( i1 < 10 ) {
  348. i1++;
  349. }
  350. while (i1<10) i1++;
  351. while (i1<10)
  352. while (i1<10)
  353. i1++;
  354. uint256 i2;
  355. while ( i2 < 10) { i2++; }
  356. uint256 i3; while (
  357. i3 < 10
  358. ) { i3++; }
  359. uint256 i4; while (i4 < 10)
  360. { i4 ++ ;}
  361. uint256 someLongVariableName;
  362. while (
  363. someLongVariableName < 10 && someLongVariableName < 11 && someLongVariableName < 12
  364. ) { someLongVariableName ++; } someLongVariableName++;
  365. // forgefmt: disable-end
  366. }
  367. function testLine() {}
  368. function /* forgefmt: disable-line */ testLine( ) { }
  369. function testLine() {}
  370. function testLine( ) { } // forgefmt: disable-line
  371. // forgefmt: disable-start
  372. type Hello is uint256;
  373. error
  374. TopLevelCustomError();
  375. error TopLevelCustomErrorWithArg(uint x) ;
  376. error TopLevelCustomErrorArgWithoutName (string);
  377. event Event1(uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a, uint256 indexed a);
  378. // forgefmt: disable-stop