remove redundant event

This commit is contained in:
Alexey 2019-07-19 20:08:47 +03:00
parent 66754181f2
commit 13b9a948dc
4 changed files with 18 additions and 18 deletions

5
cli.js
View File

@ -47,8 +47,9 @@ async function withdraw(note, receiver) {
let deposit = createDeposit(bigInt.leBuff2int(buf.slice(0, 32)), bigInt.leBuff2int(buf.slice(32, 64)))
console.log('Getting current state from mixer contract')
const events = await mixer.getPastEvents('LeafAdded', { fromBlock: mixer.deployedBlock, toBlock: 'latest' })
const leaves = events.sort(e => e.returnValues.leaf_index).map(e => e.returnValues.leaf)
const events = await mixer.getPastEvents('Deposit', { fromBlock: mixer.deployedBlock, toBlock: 'latest' })
console.log('events', events)
const leaves = events.sort(e => e.returnValues.leafIndex).map(e => e.returnValues.commitment)
const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves)
const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call()
// todo make sure that function input is 32 bytes long

View File

@ -16,8 +16,6 @@ contract MerkleTreeWithHistory {
uint32 public next_index = 0;
event LeafAdded(uint256 indexed leaf, uint32 leaf_index);
constructor(uint256 tree_levels, uint256 zero_value) public {
levels = tree_levels;
@ -48,7 +46,6 @@ contract MerkleTreeWithHistory {
}
function _insert(uint256 leaf) internal {
uint32 leaf_index = next_index;
uint32 current_index = next_index;
require(current_index != 2**(levels - 1), "Merkle tree is full");
next_index += 1;
@ -74,8 +71,6 @@ contract MerkleTreeWithHistory {
current_root = (current_root + 1) % ROOT_HISTORY_SIZE;
_roots[current_root] = current_level_hash;
emit LeafAdded(leaf, leaf_index);
}
function isKnownRoot(uint256 root) public view returns(bool) {

View File

@ -13,7 +13,7 @@ contract Mixer is MerkleTreeWithHistory {
mapping(uint256 => bool) public commitments;
IVerifier verifier;
event Deposit(address from, uint256 indexed commitment);
event Deposit(uint256 indexed commitment, uint256 leafIndex);
event Withdraw(address to, uint256 nullifier, uint256 fee);
/**
@ -40,7 +40,7 @@ contract Mixer is MerkleTreeWithHistory {
require(!commitments[commitment], "The commitment has been submitted");
_insert(commitment);
commitments[commitment] = true;
emit Deposit(msg.sender, commitment);
emit Deposit(commitment, next_index - 1);
}
/**

View File

@ -96,15 +96,19 @@ contract('Mixer', accounts => {
describe('#deposit', () => {
it('should emit event', async () => {
const commitment = 42
const { logs } = await mixer.deposit(commitment, { value, from: sender })
logs[0].event.should.be.equal('LeafAdded')
logs[0].args.leaf.should.be.eq.BN(toBN(commitment))
logs[0].args.leaf_index.should.be.eq.BN(toBN(0))
let commitment = 42
let { logs } = await mixer.deposit(commitment, { value, from: sender })
logs[1].event.should.be.equal('Deposit')
logs[1].args.from.should.be.equal(sender)
logs[1].args.commitment.should.be.eq.BN(toBN(commitment))
logs[0].event.should.be.equal('Deposit')
logs[0].args.commitment.should.be.eq.BN(toBN(commitment))
logs[0].args.leafIndex.should.be.eq.BN(toBN(0))
commitment = 12;
({ logs } = await mixer.deposit(commitment, { value, from: accounts[2] }))
logs[0].event.should.be.equal('Deposit')
logs[0].args.commitment.should.be.eq.BN(toBN(commitment))
logs[0].args.leafIndex.should.be.eq.BN(toBN(1))
})
it('should throw if there is a such commitment', async () => {