-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #743 from schemar/generate_proof_data
Generate proof data
- Loading branch information
Showing
6 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import FuzzyProofGenerator from './src/FuzzyProofGenerator'; | ||
import ProofData from './src/ProofData'; | ||
import patterns from './patterns'; | ||
|
||
interface HexProof { | ||
value: string; | ||
encodedPath: string; | ||
rlpParentNodes: string; | ||
root: string; | ||
} | ||
|
||
/** Converts a buffer to a hex string with a leading 0x. */ | ||
function bufferToHex(buffer: Buffer): string { | ||
return `0x${buffer.toString('hex')}`; | ||
} | ||
|
||
/** Converts a proof to a hex proof. */ | ||
function proofToHexProof(proof: ProofData): HexProof { | ||
return { | ||
value: bufferToHex(proof.value), | ||
encodedPath: bufferToHex(proof.encodedPath), | ||
rlpParentNodes: bufferToHex(proof.rlpParentNodes), | ||
root: bufferToHex(proof.root), | ||
}; | ||
} | ||
|
||
const proofs: ProofData[] = []; | ||
|
||
// Run 4 times to generate more data. | ||
for (let i = 0; i < 4; i += 1) { | ||
patterns.forEach( | ||
(pattern: string): number => proofs.push(FuzzyProofGenerator.generateByPattern(pattern)), | ||
); | ||
} | ||
|
||
// Convert to hex to be in line with the rest of the code base. | ||
const hexProofs: HexProof[] = proofs.map( | ||
(proof: ProofData): HexProof => proofToHexProof(proof), | ||
); | ||
|
||
const filePath: string = path.join( | ||
__dirname, | ||
'..', | ||
'..', | ||
'test', | ||
'data', | ||
'generatedProofData.json', | ||
); | ||
|
||
fs.writeFileSync(filePath, JSON.stringify(hexProofs)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const patterns: string[] = [ | ||
'l', | ||
'bl', | ||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbl', | ||
'ebl', | ||
'bebl', | ||
'bbebbl', | ||
'bebbbbl', | ||
'bbbebbbbbl', | ||
'ebebl', | ||
'ebebebebebl', | ||
'bbebbebebebebbbebebl', | ||
'bebb', | ||
'bebebb', | ||
'ebb', | ||
'ebebebebbb', | ||
]; | ||
|
||
export { patterns as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default interface ProofData { | ||
value: Buffer; | ||
encodedPath: Buffer; | ||
rlpParentNodes: Buffer; | ||
root: Buffer; | ||
} |