changed emptyElement to constant

This commit is contained in:
poma 2019-11-02 15:35:22 +03:00
parent 27a00bfd5f
commit 1fdabcc97c
13 changed files with 27 additions and 46 deletions

View file

@ -12,7 +12,7 @@ const hasherContract = artifacts.require('./Hasher.sol')
const MerkleTree = require('../lib/MerkleTree')
const hasherImpl = require('../lib/MiMC')
const { ETH_AMOUNT, MERKLE_TREE_HEIGHT, EMPTY_ELEMENT } = process.env
const { ETH_AMOUNT, MERKLE_TREE_HEIGHT } = process.env
// eslint-disable-next-line no-unused-vars
function BNArrayToStringArray(array) {
@ -27,7 +27,6 @@ contract('MerkleTreeWithHistory', accounts => {
let merkleTreeWithHistory
let hasherInstance
let levels = MERKLE_TREE_HEIGHT || 16
let zeroValue = EMPTY_ELEMENT || 1337
const sender = accounts[0]
// eslint-disable-next-line no-unused-vars
const value = ETH_AMOUNT || '1000000000000000000'
@ -39,19 +38,19 @@ contract('MerkleTreeWithHistory', accounts => {
before(async () => {
tree = new MerkleTree(
levels,
zeroValue,
null,
prefix,
)
hasherInstance = await hasherContract.deployed()
await MerkleTreeWithHistory.link(hasherContract, hasherInstance.address)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels)
snapshotId = await takeSnapshot()
})
describe('#constructor', () => {
it('should initialize', async () => {
const filled_subtrees = await merkleTreeWithHistory.filled_subtrees()
const zeroValue = await merkleTreeWithHistory.ZERO_VALUE()
filled_subtrees[0].should.be.eq.BN(zeroValue)
const zeros = await merkleTreeWithHistory.zeros()
zeros[0].should.be.eq.BN(zeroValue)
@ -70,7 +69,6 @@ contract('MerkleTreeWithHistory', accounts => {
hasher = new hasherImpl()
tree = new MerkleTree(
2,
zeroValue,
null,
prefix,
)
@ -91,7 +89,6 @@ contract('MerkleTreeWithHistory', accounts => {
const batchTree = new MerkleTree(
levels,
zeroValue,
elements,
prefix,
)
@ -131,7 +128,6 @@ contract('MerkleTreeWithHistory', accounts => {
const batchTree = new MerkleTree(
levels,
zeroValue,
elements,
prefix,
)
@ -150,7 +146,6 @@ contract('MerkleTreeWithHistory', accounts => {
console.time('MerkleTree')
tree = new MerkleTree(
levels,
zeroValue,
elements,
prefix,
)
@ -177,8 +172,7 @@ contract('MerkleTreeWithHistory', accounts => {
it('should reject if tree is full', async () => {
levels = 6
zeroValue = 1337
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels)
for (let i = 0; i < 2**levels; i++) {
await merkleTreeWithHistory.insert(i+42).should.be.fulfilled
@ -193,8 +187,8 @@ contract('MerkleTreeWithHistory', accounts => {
it.skip('hasher gas', async () => {
levels = 6
zeroValue = 1337
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels, zeroValue)
merkleTreeWithHistory = await MerkleTreeWithHistory.new(levels)
const zeroValue = await merkleTreeWithHistory.zeroValue()
const gas = await merkleTreeWithHistory.hashLeftRight.estimateGas(zeroValue, zeroValue)
console.log('gas', gas - 21000)
@ -208,7 +202,6 @@ contract('MerkleTreeWithHistory', accounts => {
hasher = new hasherImpl()
tree = new MerkleTree(
levels,
zeroValue,
null,
prefix,
null,