Skip to content

Commit

Permalink
feat: multi file diff
Browse files Browse the repository at this point in the history
feat: cross chain diff
chore: validation of address arguments and options
  • Loading branch information
naddison36 committed Aug 13, 2023
1 parent 93b028e commit c7e959e
Show file tree
Hide file tree
Showing 19 changed files with 886 additions and 104 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,21 @@ 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.
Arguments:
addressA Contract address in hexadecimal format with a 0x prefix of the first contract.
addressB Contract address in hexadecimal format with a 0x prefix of the second contract.
addressA Contract address in hexadecimal format with a 0x prefix of the first contract
addressB Contract address in hexadecimal format with a 0x prefix of the second contract
Options:
-l, --lineBuffer <value> Minimum number of lines before and after changes (default: "4")
--aFile <value> Contract A source code filename without the .sol extension. (default: compares all source files)
--bFile <value> Contract B source code filename without the .sol extension. (default: aFile if specified)
-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
-l, --lineBuffer <value> Minimum number of lines before and after changes (default: 4)
-af --aFile <value> Contract A source code filename without the .sol extension (default: compares all source files)
-bf --bFile <value> Contract B source code filename without the .sol extension (default: aFile if specified)
-bn, --bNetwork <network> Ethereum network which maps to a blockchain explorer for contract B if on a different blockchain to contract A. Contract A uses the `network` option (default: value of `network` option) (choices: "mainnet", "goerli", "sepolia", "polygon",
"arbitrum", "avalanche", "bsc", "crono", "fantom", "moonbeam", "optimism", "gnosis", "celo")
-be, --bExplorerUrl <url> Override the `bNetwork` option with custom blockchain explorer API URL for contract B if on a different blockchain to contract A. Contract A uses the `explorerUrl` (default: value of `explorerUrl` option)
-bk, --bApiKey <key> Blockchain explorer API key for contract B if on a different blockchain to contract A. Contract A uses the `apiKey` option (default: value of `apiKey` option)
-s, --summary Only show a summary of the file differences. (default: false)
--flatten Flatten into a single file before comparing (default: false)
--saveFiles Save the flattened contract code to the filesystem when using the `flatten` option. The file names will be the contract address with a .sol extension (default: false)
-h, --help display help for command
```

## UML Class diagram examples
Expand Down
35 changes: 35 additions & 0 deletions lib/diffContracts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { EtherscanParser } from './parserEtherscan';
interface DiffOptions {
network: string;
lineBuffer: number;
}
interface FlattenAndDiffOptions extends DiffOptions {
aFile?: string;
bFile?: string;
saveFiles?: boolean;
}
interface DiffFiles {
filename?: string;
aCode?: string;
bCode?: string;
result: 'added' | 'removed' | 'match' | 'changed';
}
interface CompareContracts {
files: DiffFiles[];
contractNameA: string;
contractNameB: string;
}
export declare const compareContracts: (addressA: string, addressB: string, etherscanParserA: EtherscanParser, etherscanParserB: EtherscanParser, options: DiffOptions) => Promise<CompareContracts>;
export declare const displayContractNames: (addressA: string, addressB: string, contractNameA: string, contractNameB: string, options: {
network: string;
bNetwork?: string;
}) => void;
export declare const displayFileDiffSummary: (fileDiffs: DiffFiles[]) => void;
export declare const displayFileDiffs: (fileDiffs: DiffFiles[], options?: {
lineBuffer?: number;
}) => void;
export declare const flattenAndDiff: (addressA: string, addressB: string, aEtherscanParser: EtherscanParser, bEtherscanParser: EtherscanParser, options: FlattenAndDiffOptions) => Promise<{
contractNameA: string;
contractNameB: string;
}>;
export {};
135 changes: 135 additions & 0 deletions lib/diffContracts.js

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

2 changes: 1 addition & 1 deletion lib/parserEtherscan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export declare class EtherscanParser {
* @oaram filename optional, case-sensitive name of the source file without the .sol
*/
getSourceCode(contractAddress: string, filename?: string): Promise<{
files: readonly {
files: {
code: string;
filename: string;
}[];
Expand Down
Loading

0 comments on commit c7e959e

Please sign in to comment.