1
1
const fs = require ( "fs" ) ;
2
2
const _ = require ( "underscore" ) ;
3
3
const solc = require ( "solc" ) ;
4
- const prompt = require ( "prompt" ) ;
5
4
const path = require ( "path" ) ;
6
5
const util = require ( "util" ) ;
7
6
const exec = util . promisify ( require ( "child_process" ) . exec ) ;
8
7
9
- console . log ( `Mandatory: Solc cli tool should be installed globally. Please put the contract name only` ) ;
10
- prompt . start ( ) ;
8
+ console . log ( `Mandatory: Solc cli tool should be installed globally. Please put the contract name only in any order` ) ;
11
9
12
- prompt . get ( [ "LogicContract" , "ProxyContract" ] , async ( err , result ) => {
13
- let temp ;
14
- let logicFilePath ;
15
- let proxyFilePath ;
10
+ let contractA = process . argv . slice ( 2 ) [ 0 ] ;
11
+ let contractB = process . argv . slice ( 2 ) [ 1 ] ;
16
12
17
- const fileList = walkSync ( "./contracts" , [ ] ) ;
13
+ compareStorage ( contractA , contractB ) ;
14
+
15
+ async function compareStorage ( ) {
18
16
19
- let paths = findPath ( result . LogicContract , result . ProxyContract , fileList ) ;
17
+ const fileList = walkSync ( "./contracts" , [ ] ) ;
18
+ let paths = findPath ( contractA , contractB , fileList ) ;
20
19
21
20
if ( paths . length == 2 ) {
22
21
console . log ( "Contracts exists \n" ) ;
23
22
24
23
await flatContracts ( paths ) ;
25
24
let temp ;
26
- let logicFilePath = `./flat/${ path . basename ( paths [ 0 ] ) } ` ;
27
- let proxyFilePath = `./flat/${ path . basename ( paths [ 1 ] ) } ` ;
25
+ let contractAPath = `./flat/${ path . basename ( paths [ 0 ] ) } ` ;
26
+ let contractBPath = `./flat/${ path . basename ( paths [ 1 ] ) } ` ;
28
27
29
- if ( path . basename ( paths [ 0 ] ) === result . LogicContract ) {
30
- temp = logicFilePath ;
31
- logicFilePath = proxyFilePath ;
32
- proxyFilePath = temp ;
28
+ if ( path . basename ( paths [ 0 ] ) === contractA ) {
29
+ temp = contractAPath ;
30
+ contractAPath = contractBPath ;
31
+ contractBPath = temp ;
33
32
}
34
33
35
- let logicAST = await getAST ( logicFilePath ) ;
36
- let proxyAST = await getAST ( proxyFilePath ) ;
34
+ let contractAAST = await getAST ( contractAPath ) ;
35
+ let contractBAST = await getAST ( contractBPath ) ;
37
36
// Deleting the temp folder (no longer required)
38
37
await flushTemp ( ) ;
39
38
40
- console . log ( compareStorageLayouts ( parseContract ( logicAST ) , parseContract ( proxyAST ) ) ) ;
39
+ var result = compareStorageLayouts ( parseContract ( contractAAST ) , parseContract ( contractBAST ) ) ;
40
+ if ( ! result )
41
+ process . exit ( 1 ) ;
41
42
} else {
42
43
console . log ( "Contracts doesn't exists" ) ;
43
44
}
44
- } ) ;
45
+ }
45
46
46
47
function traverseAST ( _input , _elements ) {
47
48
if ( _input . children ) {
@@ -101,7 +102,7 @@ function parseContract(input) {
101
102
return orderedStateVariables ;
102
103
}
103
104
104
- var walkSync = function ( dir , filelist ) {
105
+ function walkSync ( dir , filelist ) {
105
106
files = fs . readdirSync ( dir ) ;
106
107
filelist = filelist || [ ] ;
107
108
files . forEach ( function ( file ) {
@@ -114,7 +115,7 @@ var walkSync = function(dir, filelist) {
114
115
return filelist ;
115
116
} ;
116
117
117
- var findPath = function ( logicContractName , proxyContractName , fileList ) {
118
+ function findPath ( logicContractName , proxyContractName , fileList ) {
118
119
let paths = new Array ( ) ;
119
120
for ( let i = 0 ; i < fileList . length ; i ++ ) {
120
121
if (
0 commit comments