Skip to content

Commit b302a52

Browse files
authored
Merge pull request #12 from tintinweb/fix/unitConstants
fixes "2 ether" not returning a value, const_int type guessing, update solc@0.8.11, minor issues
2 parents 0ca7eaf + 9011513 commit b302a52

File tree

6 files changed

+38
-37
lines changed

6 files changed

+38
-37
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log
22
All notable changes will be documented in this file.
33

4+
## v0.0.10
5+
- new: update to solc@0.8.11
6+
- new: basic autocomplete for built-ins (configurable via `.config`) - #11
7+
- fix: return value of unit constants (e.g. `2 ether`) - #12
8+
- fix: distinguish between/ autoguess const signed and unsigned int return values - #12
9+
- update: minor refactoring - #11
10+
411
## v0.0.9
512
- new: support the `import` directive - #8
613
- new: experimental support for `https` imports, i.e. `import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/IERC721.sol"`. This can be disabled by setting ` » .config set resolveHttpImports false`.

bin/main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,12 @@ vorpal
229229
.command("$_")
230230

231231
/** autocomplate built-ins (not context sensitive) */
232-
for (let builtin of builtIns) {
233-
vorpal //register built-in as command (1st level autocomplete, with 2nd level autocomplete for params)
234-
.command(`${builtin}`)
235-
.autocomplete(builtIns);
232+
if(config.enableAutoComplete){
233+
for (let builtin of builtIns) {
234+
vorpal //register built-in as command (1st level autocomplete, with 2nd level autocomplete for params)
235+
.command(`${builtin}`)
236+
.autocomplete(builtIns);
237+
}
236238
}
237239

238240
/** start in repl mode */

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "solidity-shell",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "",
55
"main": "src/index.js",
66
"bin": {
@@ -29,7 +29,7 @@
2929
"minimist": "^1.2.5",
3030
"readline-sync": "^1.4.10",
3131
"request": "^2.88.2",
32-
"solc": "^0.8.10",
32+
"solc": "^0.8.11",
3333
"sync-request": "^6.1.0",
3434
"vorpal": "^1.12.0",
3535
"web3": "^1.5.2"

src/compiler/autogenerated/builtIns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @license MIT
55
* */
66

7-
//autogenerated with # npm run updateCompilerList
7+
//autogenerated with # npm run updateBuiltIns
88
module.exports.builtIns = [
99
"pragma",
1010
"import",

src/handler.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const path = require('path');
1313
/** CONST */
1414
const rexTypeError = /Return argument type (.*) is not implicitly convertible to expected type \(type of first return variable\)/;
1515
const rexAssign = /[^=]=[^=];?/;
16-
const rexTypeDecl = /^([\w\[\]]+\s(memory|storage)?\s*\w+);?$/
16+
const rexTypeDecl = /^([\w\[\]]+\s(memory|storage)?\s*\w+);?$/;
17+
const rexUnits = /^(\d+\s*(wei|gwei|szabo|finney|ether|seconds|minutes|hours|days|weeks|years))\s*;?$/;
1718
const IGNORE_WARNINGS = [
1819
"Statement has no effect.",
1920
"Function state mutability can be restricted to ",
@@ -50,32 +51,26 @@ class SolidityStatement {
5051
constructor(rawCommand, scope) {
5152
this.rawCommand = rawCommand ? rawCommand.trim() : "";
5253
this.hasNoReturnValue = (rexAssign.test(this.rawCommand))
53-
|| (this.rawCommand.startsWith('delete'))
54+
|| (this.rawCommand.startsWith('delete '))
5455
|| (this.rawCommand.startsWith('assembly'))
5556
|| (this.rawCommand.startsWith('revert'))
56-
|| (rexTypeDecl.test(this.rawCommand))
57+
|| (rexTypeDecl.test(this.rawCommand) && !rexUnits.test(this.rawCommand)) /* looks like type decl but is not special builtin like "2 ether" */
5758

5859
if (scope) {
59-
this.scope = scope
60+
this.scope = scope;
6061
} else {
61-
if (this.rawCommand.startsWith('function ') || this.rawCommand.startsWith('modifier ')) {
62-
this.scope = SCOPE.CONTRACT;
63-
this.hasNoReturnValue = true;
64-
} else if (this.rawCommand.startsWith('mapping ') || this.rawCommand.startsWith('event ') || this.rawCommand.startsWith('error ')) {
62+
if (['function ', 'modifier ', 'mapping ', 'event ', 'error '].some(e => this.rawCommand.startsWith(e))) {
6563
this.scope = SCOPE.CONTRACT;
6664
this.hasNoReturnValue = true;
6765
} else if (this.rawCommand.startsWith('pragma solidity ')) {
6866
this.scope = SCOPE.VERSION_PRAGMA;
6967
this.hasNoReturnValue = true;
7068
this.rawCommand = this.fixStatement(this.rawCommand);
71-
} else if (this.rawCommand.startsWith('pragma ') || this.rawCommand.startsWith('import ')) {
69+
} else if (['pragma ', 'import '].some(e => this.rawCommand.startsWith(e))) {
7270
this.scope = SCOPE.SOURCE_UNIT;
7371
this.hasNoReturnValue = true;
7472
this.rawCommand = this.fixStatement(this.rawCommand);
75-
} else if (this.rawCommand.startsWith('struct ')) {
76-
this.scope = SCOPE.SOURCE_UNIT;
77-
this.hasNoReturnValue = true;
78-
} else if (this.rawCommand.startsWith('contract ') || this.rawCommand.startsWith('interface ')) {
73+
} else if (['contract ', 'interface ', 'struct '].some(e => this.rawCommand.startsWith(e))) {
7974
this.scope = SCOPE.SOURCE_UNIT;
8075
this.hasNoReturnValue = true;
8176
} else {
@@ -87,6 +82,7 @@ class SolidityStatement {
8782
}
8883
}
8984

85+
9086
if (this.hasNoReturnValue) {
9187
// expression
9288
this.returnExpression = ';';
@@ -127,6 +123,7 @@ class InteractiveSolidityShell {
127123
ganacheArgs: [],
128124
debugShowContract: false,
129125
resolveHttpImports: true,
126+
enableAutoComplete: true,
130127
}
131128

132129
this.settings = {
@@ -306,14 +303,7 @@ contract ${this.settings.templateContractName} {
306303
.catch(err => {
307304
return reject(err);
308305
});
309-
310-
311306
});
312-
313-
314-
315-
316-
317307
}
318308

319309
run(statement) {
@@ -359,7 +349,9 @@ contract ${this.settings.templateContractName} {
359349

360350
//console.log("2nd pass - detect return type")
361351
let retType = matches[1];
362-
if (retType.startsWith('int_const ')) {
352+
if (retType.startsWith('int_const -')) {
353+
retType = 'int';
354+
} else if (retType.startsWith('int_const ')) {
363355
retType = 'uint';
364356
} else if (retType.startsWith('contract ')) {
365357
retType = retType.split("contract ", 2)[1]

0 commit comments

Comments
 (0)