Skip to content

Commit

Permalink
feat: diff between two verified Solidity contracts (naddison36#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 authored Dec 14, 2022
1 parent 8d7972b commit 26cac8e
Show file tree
Hide file tree
Showing 14 changed files with 1,489 additions and 71 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The three subcommands:
* class: Generates a UML class diagram from Solidity source code. default
* storage: Generates a diagram of a contract's storage slots.
* flatten: Merges verified source files from a Blockchain explorer into one local file.
* diff: Compares the flattened Solidity code from a Blockchain explorer for two contracts.
The Solidity code can be pulled from verified source code on Blockchain explorers like Etherscan or from local Solidity files.
Expand All @@ -73,7 +74,7 @@ Commands:
### Class usage

```
Usage: sol2uml class <fileFolderAddress> [options]
Usage: sol2uml class [options] <fileFolderAddress>
Generates UML diagrams from Solidity source code.
Expand Down Expand Up @@ -114,7 +115,7 @@ Options:
### Storage usage

```
Usage: sol2uml storage <fileFolderAddress> [options]
Usage: sol2uml storage [options] <fileFolderAddress>
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.
Expand All @@ -136,7 +137,7 @@ Options:
### Flatten usage

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

### Diff usage

```
Usage: sol2uml diff [options] <addressA> <addressB>
The results show the comparision of contract A to B.
The green sections are additions to contract B that are not in contract A.
The red sections are removals from contract A that are not in contract B.
The line numbers are from contract B. There are no line numbers for the red sections as they are not in contract B.
Compare verified Solidity code differences between two contracts.
Arguments:
addressA Contract address in hexadecimal format with a 0x prefix.
addressB Contract address in hexadecimal format with a 0x prefix.
Options:
-l, --lineBuffer <value> Minimum number a lines before and after changes (default: "4")
-s, --saveFiles Save the flattened contract code to the filesystem. The file names will be the contract address with a .sol extension. (default: false)
-h, --help display help for command
```

## UML Class diagram examples

To generate a diagram of all contracts under the contracts folder and its sub folders
Expand Down
35 changes: 8 additions & 27 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
// jest.config.js
module.exports = {
verbose: true,
transform: {
"^.+\\.tsx?$": 'ts-jest'
},
testPathIgnorePatterns: [
"/build/",
"/node_modules/",
],
testRegex: '/__tests__/.*\\.test\\.ts$',
moduleFileExtensions: [
'ts',
'tsx',
'js',
'jsx',
'json',
'node'
],
globals: {
'ts-jest': {
diagnostics: {
// Do not fail on TS compilation errors
// https://kulshekhar.github.io/ts-jest/user/config/diagnostics#do-not-fail-on-first-error
warnOnly: true
}
}
},
testEnvironment: 'node'
verbose: true,
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testPathIgnorePatterns: ['/build/', '/node_modules/'],
testRegex: '/__tests__/.*\\.test\\.ts$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'node',
}
7 changes: 7 additions & 0 deletions lib/diff.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Compares code using Google's diff_match_patch and displays the results in the console.
* @param codeA
* @param codeB
* @param lineBuff the number of lines to display before and after each change.
*/
export declare const diffCode: (codeA: string, codeB: string, lineBuff: number) => void;
188 changes: 188 additions & 0 deletions lib/diff.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/filterClasses.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/parserEtherscan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26cac8e

Please sign in to comment.