Skip to content

Commit 26cac8e

Browse files
authored
feat: diff between two verified Solidity contracts (#125)
1 parent 8d7972b commit 26cac8e

14 files changed

+1489
-71
lines changed

README.md

+26-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The three subcommands:
4949
* class: Generates a UML class diagram from Solidity source code. default
5050
* storage: Generates a diagram of a contract's storage slots.
5151
* flatten: Merges verified source files from a Blockchain explorer into one local file.
52+
* diff: Compares the flattened Solidity code from a Blockchain explorer for two contracts.
5253
5354
The Solidity code can be pulled from verified source code on Blockchain explorers like Etherscan or from local Solidity files.
5455
@@ -73,7 +74,7 @@ Commands:
7374
### Class usage
7475

7576
```
76-
Usage: sol2uml class <fileFolderAddress> [options]
77+
Usage: sol2uml class [options] <fileFolderAddress>
7778
7879
Generates UML diagrams from Solidity source code.
7980
@@ -114,7 +115,7 @@ Options:
114115
### Storage usage
115116

116117
```
117-
Usage: sol2uml storage <fileFolderAddress> [options]
118+
Usage: sol2uml storage [options] <fileFolderAddress>
118119
119120
WARNING: sol2uml does not use the Solidity compiler so may differ with solc. A known example is fixed-sized arrays declared with an expression will fail to be sized.
120121
@@ -136,7 +137,7 @@ Options:
136137
### Flatten usage
137138

138139
```
139-
Usage: sol2uml flatten <contractAddress> [options]
140+
Usage: sol2uml flatten <contractAddress>
140141
141142
In order for the merged code to compile, the following is done:
142143
1. pragma solidity is set using the compiler of the verified contract.
@@ -154,6 +155,28 @@ Options:
154155
-h, --help display help for command
155156
```
156157

158+
### Diff usage
159+
160+
```
161+
Usage: sol2uml diff [options] <addressA> <addressB>
162+
163+
The results show the comparision of contract A to B.
164+
The green sections are additions to contract B that are not in contract A.
165+
The red sections are removals from contract A that are not in contract B.
166+
The line numbers are from contract B. There are no line numbers for the red sections as they are not in contract B.
167+
168+
Compare verified Solidity code differences between two contracts.
169+
170+
Arguments:
171+
addressA Contract address in hexadecimal format with a 0x prefix.
172+
addressB Contract address in hexadecimal format with a 0x prefix.
173+
174+
Options:
175+
-l, --lineBuffer <value> Minimum number a lines before and after changes (default: "4")
176+
-s, --saveFiles Save the flattened contract code to the filesystem. The file names will be the contract address with a .sol extension. (default: false)
177+
-h, --help display help for command
178+
```
179+
157180
## UML Class diagram examples
158181

159182
To generate a diagram of all contracts under the contracts folder and its sub folders

jest.config.js

+8-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
// jest.config.js
22
module.exports = {
3-
verbose: true,
4-
transform: {
5-
"^.+\\.tsx?$": 'ts-jest'
6-
},
7-
testPathIgnorePatterns: [
8-
"/build/",
9-
"/node_modules/",
10-
],
11-
testRegex: '/__tests__/.*\\.test\\.ts$',
12-
moduleFileExtensions: [
13-
'ts',
14-
'tsx',
15-
'js',
16-
'jsx',
17-
'json',
18-
'node'
19-
],
20-
globals: {
21-
'ts-jest': {
22-
diagnostics: {
23-
// Do not fail on TS compilation errors
24-
// https://kulshekhar.github.io/ts-jest/user/config/diagnostics#do-not-fail-on-first-error
25-
warnOnly: true
26-
}
27-
}
28-
},
29-
testEnvironment: 'node'
3+
verbose: true,
4+
transform: {
5+
'^.+\\.tsx?$': 'ts-jest',
6+
},
7+
testPathIgnorePatterns: ['/build/', '/node_modules/'],
8+
testRegex: '/__tests__/.*\\.test\\.ts$',
9+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
10+
testEnvironment: 'node',
3011
}

lib/diff.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Compares code using Google's diff_match_patch and displays the results in the console.
3+
* @param codeA
4+
* @param codeB
5+
* @param lineBuff the number of lines to display before and after each change.
6+
*/
7+
export declare const diffCode: (codeA: string, codeB: string, lineBuff: number) => void;

lib/diff.js

+188
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/filterClasses.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parserEtherscan.js

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)