Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate test dataset (don't merge) #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/chai": "^4.2.15",
"@types/mocha": "^8.2.1",
"@types/node": "^14.14.25",
"bignumber.js": "^9.0.1",
"chai": "^4.3.0",
"endent": "^2.0.1",
"mocha": "^8.3.0",
Expand Down
33 changes: 28 additions & 5 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { randomHex, soliditySha3 } from 'web3-utils'
import { MerkleTree } from './merkleTree'
import { buf2hex, hex2buf } from './helpers'
import { helperRawAccounts } from './helperRawAccounts'
import { realData } from './realData'
import fs from 'fs'
import endent from 'endent'
import Web3 from 'web3'
import Bignumber from 'bignumber.js'

const web3 = new Web3()
const rawLeaves = [...Array(3000)].map((v) => ({ address: randomHex(20), amount: Math.floor(Math.random() * 100000) }))
const leaves = rawLeaves.map((v, i) => {
const ourAccounts = [
// '0x0bd793ea8334a77b2bfd604dbaedca11ea094306',
'0xb574F5F1396FDb17c03F441f673e5cCD15BE8251',
// '0x66b57885E8E9D84742faBda0cE6E3496055b012d',
'0xa75e8c75F193ee0079F6C75CA7fcBE79C40C517f',
'0x902Df9e56Def1641ce33A83d2FD2ACD41fd4Bc33',
// '0xae77f70FB7Ecb4009eeE0FBcf94D659Eff2F7DC9',
]
// const helperAccounts = helperRawAccounts.map((v) => v.address)
// // insert random accounts
// ourAccounts.forEach((v) => {
// const i = Math.floor((helperAccounts.length - 1) * Math.random())
// console.log(i)
// helperAccounts.splice(i, 0, v)
// })

// const rawLeaves = helperRawAccounts.map((v) => ({ address: v.address, amount: Math.floor(Math.random() * 100000) }))
const leaves = realData.map((v, i) => {
return {
buf: Buffer.concat([
hex2buf(web3.eth.abi.encodeParameter('uint256', i)),
Expand All @@ -23,12 +42,13 @@ export const tree = new MerkleTree(
(soliditySha3 as unknown) as (...str: string[]) => string,
)

const offset = leaves.length - 146;
export const leavesWithProof = leaves.slice(offset, offset + 10).map((l) => {
const offset = 0
export const leavesWithProof = leaves.map((l, i) => {
return {
address: l.address,
proof: tree.generateProof(buf2hex(l.buf)),
amount: l.amount,
amount: new Bignumber(l.amount).toFixed(),
index: String(i),
}
})

Expand All @@ -45,4 +65,7 @@ const template =
`
`

const templateJson = JSON.stringify({ merkleRoot: tree.root, leaves: leavesWithProof }, null, 2)

fs.writeFile('test/constants.js', template, () => {})
fs.writeFile('test/constants.json', templateJson, () => {})
septs marked this conversation as resolved.
Show resolved Hide resolved
Loading