Skip to content

Commit

Permalink
chore: diff's aFile option can be used to filter the code compare whe…
Browse files Browse the repository at this point in the history
…n there are multiple source files

chore: bumped version to v2.5.13
  • Loading branch information
naddison36 committed Aug 18, 2023
1 parent 49ad29d commit 65dc3bc
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 27 deletions.
5 changes: 2 additions & 3 deletions lib/diffContracts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ interface DiffOptions {
bNetwork?: string;
lineBuffer: number;
summary?: boolean;
}
interface FlattenAndDiffOptions extends DiffOptions {
aFile?: string;
bFile?: string;
saveFiles?: boolean;
Expand All @@ -24,7 +22,7 @@ interface CompareContracts {
}
export declare const compareVerifiedContracts: (addressA: string, aEtherscanParser: EtherscanParser, addressB: string, bEtherscanParser: EtherscanParser, options: DiffOptions) => Promise<void>;
export declare const compareVerified2Local: (addressA: string, aEtherscanParser: EtherscanParser, fileOrBaseFolders: string[], options: DiffOptions) => Promise<void>;
export declare const compareFlattenContracts: (addressA: string, addressB: string, aEtherscanParser: EtherscanParser, bEtherscanParser: EtherscanParser, options: FlattenAndDiffOptions) => Promise<{
export declare const compareFlattenContracts: (addressA: string, addressB: string, aEtherscanParser: EtherscanParser, bEtherscanParser: EtherscanParser, options: DiffOptions) => Promise<{
contractNameA: string;
contractNameB: string;
}>;
Expand All @@ -33,5 +31,6 @@ export declare const diffVerifiedContracts: (addressA: string, addressB: string,
export declare const displayFileDiffSummary: (fileDiffs: DiffFiles[]) => void;
export declare const displayFileDiffs: (fileDiffs: DiffFiles[], options?: {
lineBuffer?: number;
aFile?: string;
}) => void;
export {};
22 changes: 19 additions & 3 deletions lib/diffContracts.js

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

8 changes: 4 additions & 4 deletions lib/sol2uml.js

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

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sol2uml",
"version": "2.5.12",
"version": "2.5.13",
"description": "Solidity contract visualisation tool.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
29 changes: 21 additions & 8 deletions src/ts/diffContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ interface DiffOptions {
bNetwork?: string
lineBuffer: number
summary?: boolean
}

interface FlattenAndDiffOptions extends DiffOptions {
aFile?: string
bFile?: string
saveFiles?: boolean
Expand Down Expand Up @@ -58,11 +55,15 @@ export const compareVerifiedContracts = async (
displayFileDiffs(files, options)
}

const aFileDesc = options.aFile ? `"${options.aFile}" file for the ` : ''
const bFileDesc = options.aFile
? `"${options.bFile || options.aFile}" file for the `
: ''
console.log(
`Compared the "${contractNameA}" contract with address ${addressA} on ${options.network}`,
`Compared the ${aFileDesc}"${contractNameA}" contract with address ${addressA} on ${options.network}`,
)
console.log(
`to the "${contractNameB}" contract with address ${addressB} on ${
`to the ${bFileDesc}"${contractNameB}" contract with address ${addressB} on ${
options.bNetwork || options.network
}\n`,
)
Expand All @@ -87,8 +88,9 @@ export const compareVerified2Local = async (
displayFileDiffs(files, options)
}

const aFileDesc = `"${options.aFile}" file for the `
console.log(
`Compared the "${contractNameA}" contract with address ${addressA} on ${options.network}`,
`Compared the ${aFileDesc}"${contractNameA}" contract with address ${addressA} on ${options.network}`,
)
if (local) {
console.log(`to local file "${fileOrBaseFolders}"\n`)
Expand All @@ -103,7 +105,7 @@ export const compareFlattenContracts = async (
addressB: string,
aEtherscanParser: EtherscanParser,
bEtherscanParser: EtherscanParser,
options: FlattenAndDiffOptions,
options: DiffOptions,
): Promise<{ contractNameA: string; contractNameB: string }> => {
// Get verified Solidity code from Etherscan and flatten
const { solidityCode: codeA, contractName: contractNameA } =
Expand Down Expand Up @@ -356,9 +358,14 @@ export const displayFileDiffSummary = (fileDiffs: DiffFiles[]) => {

export const displayFileDiffs = (
fileDiffs: DiffFiles[],
options: { lineBuffer?: number } = {},
options: { lineBuffer?: number; aFile?: string } = {},
) => {
let aFileFound = false
for (const file of fileDiffs) {
if (options.aFile) {
if (file.filename !== options.aFile) continue
else aFileFound = true
}
switch (file.result) {
case 'added':
console.log(`Added ${file.filename}`)
Expand All @@ -374,4 +381,10 @@ export const displayFileDiffs = (
break
}
}
// If filtering on an aFile, but it was not found
if (options.aFile && !aFileFound) {
throw new Error(
`Could not display code diff for file "${options.aFile}".\nMake sure the full file path and extension is used as displayed in the file summary.`,
)
}
}
8 changes: 4 additions & 4 deletions src/ts/sol2uml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ The line numbers are from contract B. There are no line numbers for the red sect
)
.option(
'-af --aFile <value>',
'Contract A source code filename without the .sol extension (default: compares all source files)',
'Limit code compare to contract A source file with the full path and extension as displayed in the file summary (default: compares all source files)',
)
.option(
'-bf --bFile <value>',
'Contract B source code filename without the .sol extension (default: aFile if specified)',
'Contract B source file with the full path and extension as displayed in the file summary. Used if aFile is specified and the source file has been renamed (default: aFile if specified)',
)
.addOption(
new Option(
Expand Down Expand Up @@ -535,8 +535,8 @@ The line numbers are from contract B. There are no line numbers for the red sect
combinedOptions.bNetwork || combinedOptions.network,
combinedOptions.bExplorerUrl || combinedOptions.explorerUrl,
)
// If flattening or just comparing a single file
if (options.flatten || options.aFile) {
// If flattening
if (options.flatten) {
await compareFlattenContracts(
addressA,
addressB,
Expand Down
26 changes: 24 additions & 2 deletions tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sol2uml flatten 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c -v
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --summary
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --aFile Governable
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --aFile contracts/governance/Governable.sol
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --aFile VaultCore
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --aFile OETHVaultCore --bFile VaultCore -v
sol2uml diff 0x1091588Cc431275F99DC5Df311fd8E1Ab81c89F3 0xEA24e9Bac006DE9635Ac7fA4D767fFb64FB5645c --aFile VaultStorage
Expand Down Expand Up @@ -45,13 +46,34 @@ sol2uml diff 0x48Cf14DeA2f5dD31c57218877195913412D3278A 0x997c35A0bf8E21404aE437
sol2uml diff 0x48Cf14DeA2f5dD31c57218877195913412D3278A 0x997c35A0bf8E21404aE4379841E0603C957138c3 --flatten
sol2uml diff 0x997c35A0bf8E21404aE4379841E0603C957138c3 .,node_modules

### OUSD Harvestor upgrade
### Proxy
sol2uml diff 0x21Fb5812D70B3396880D30e90D9e5C1202266c89 .,node_modules
sol2uml diff 0x21Fb5812D70B3396880D30e90D9e5C1202266c89 .,node_modules --aFile contracts/governance/Governable.sol
### Implementation
sol2uml diff 0x5e72eb0ab74b5b4d2766a7956d210746ceab96e1 .,node_modules

### Harvesters
sol2uml diff 0x5E72EB0ab74B5B4d2766a7956D210746Ceab96E1 0x1d6e0d7a1244276acf22a4e1dfc3c58186b1f624 -v

## Curve
### stETH and frxETH Metapool
### Vyper contracts
### Vyper contracts - stETH and frxETH Metapool
sol2uml diff 0xdc24316b9ae028f1497c275eb9192a3ea0f67022 0xa1f8a6807c402e4a15ef4eba36528a3fed24e577 -v
### Vyper contracts - frxETH and OETH Metapool
sol2uml diff 0xa1f8a6807c402e4a15ef4eba36528a3fed24e577 0x94b17476a93b3262d87b9a326965d1e91f9c13e7
### Vyper contracts - rETH and OETH Metapool
sol2uml diff 0x0f3159811670c117c372428d4e69ac32325e4d0f 0x94b17476a93b3262d87b9a326965d1e91f9c13e7
### Vyper contracts Metapools deployed from Curve Facgtory 0xb9fc157394af804a3578134a6585c0dc9cc990d4
sol2uml diff 0xd0a5ca7b57780240db17bb89773fda8f0efce274 0x94b17476a93b3262d87b9a326965d1e91f9c13e7
sol2uml diff 0xd0a5ca7b57780240db17bb89773fda8f0efce274 0x4029f7dcbdf6059ed80da6856526e7510d64fa21
sol2uml diff 0x4029f7dcbdf6059ed80da6856526e7510d64fa21 0xd4cedef74fb8885b8e1de21fba5a2e2f33f21f58
sol2uml diff 0xAb3435bd2959fD713F7e50389Ff374Bfee2E3B4b 0x9a64dec8da8ce892ff711d715d9a8fc82e966a44

sol2uml diff 0x0c58c509305a8a7fe9a6a60ceaac6185b96ecbb7 0xd82c2eb10f4895cabed6eda6eeee234bd1a9838b
# 22 to 32 days ago
sol2uml diff 0x9d1784097ffeadae206faf65188561abaa9093a8 0x16f780aed4e5caa1b0c9a3ae6f67460d4d0cfeb5
# 16 to 32 days ago
sol2uml diff 0x901ac4816b427cea4a26099ead7051c8e54dace9 0x16f780aed4e5caa1b0c9a3ae6f67460d4d0cfeb5
### FRAX/USDC (crvFRAX) mainnet v arbitrum
sol2uml diff 0xdcef968d416a41cdac0ed8702fac8128a64241a2 0xc9b8a3fdecb9d5b218d02555a8baf332e5b740d5 --bNetwork arbitrum
sol2uml diff 0xdcef968d416a41cdac0ed8702fac8128a64241a2 0xc9b8a3fdecb9d5b218d02555a8baf332e5b740d5 --bn arbitrum
Expand Down

0 comments on commit 65dc3bc

Please sign in to comment.