mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-05-03 23:04:53 -04:00
fix address formatting in tests
This commit is contained in:
parent
f5486f0943
commit
2962f30ed5
2 changed files with 22 additions and 48 deletions
|
@ -23,6 +23,8 @@ const MerkleTree = require('../lib/MerkleTree')
|
|||
|
||||
const rbigint = (nbytes) => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes))
|
||||
const pedersenHash = (data) => circomlib.babyJub.unpackPoint(circomlib.pedersenHash.hash(data))[0]
|
||||
const toFixedHex = (number, length = 32) => '0x' + bigInt(number).toString(16).padStart(length * 2, '0')
|
||||
const getRandomRecipient = () => rbigint(20)
|
||||
|
||||
function generateDeposit() {
|
||||
let deposit = {
|
||||
|
@ -43,27 +45,12 @@ function BNArrayToStringArray(array) {
|
|||
return arrayToPrint
|
||||
}
|
||||
|
||||
function getRandomRecipient() {
|
||||
let recipient = rbigint(20)
|
||||
while (toHex(recipient.toString()).length !== 42) {
|
||||
recipient = rbigint(20)
|
||||
}
|
||||
return recipient
|
||||
}
|
||||
|
||||
function snarkVerify(proof) {
|
||||
proof = unstringifyBigInts2(proof)
|
||||
const verification_key = unstringifyBigInts2(require('../build/circuits/withdraw_verification_key.json'))
|
||||
return snarkjs['groth'].isValid(verification_key, proof, proof.publicSignals)
|
||||
}
|
||||
|
||||
function toFixedHex(number, length = 32) {
|
||||
let str = bigInt(number).toString(16)
|
||||
while (str.length < length * 2) str = '0' + str
|
||||
str = '0x' + str
|
||||
return str
|
||||
}
|
||||
|
||||
contract('ETHMixer', accounts => {
|
||||
let mixer
|
||||
const sender = accounts[0]
|
||||
|
@ -212,7 +199,7 @@ contract('ETHMixer', accounts => {
|
|||
const balanceMixerBefore = await web3.eth.getBalance(mixer.address)
|
||||
const balanceRelayerBefore = await web3.eth.getBalance(relayer)
|
||||
const balanceOperatorBefore = await web3.eth.getBalance(operator)
|
||||
const balanceRecieverBefore = await web3.eth.getBalance(toHex(recipient.toString()))
|
||||
const balanceRecieverBefore = await web3.eth.getBalance(toFixedHex(recipient, 20))
|
||||
let isSpent = await mixer.isSpent(toFixedHex(input.nullifierHash))
|
||||
isSpent.should.be.equal(false)
|
||||
|
||||
|
@ -232,7 +219,7 @@ contract('ETHMixer', accounts => {
|
|||
const balanceMixerAfter = await web3.eth.getBalance(mixer.address)
|
||||
const balanceRelayerAfter = await web3.eth.getBalance(relayer)
|
||||
const balanceOperatorAfter = await web3.eth.getBalance(operator)
|
||||
const balanceRecieverAfter = await web3.eth.getBalance(toHex(recipient.toString()))
|
||||
const balanceRecieverAfter = await web3.eth.getBalance(toFixedHex(recipient, 20))
|
||||
const feeBN = toBN(fee.toString())
|
||||
balanceMixerAfter.should.be.eq.BN(toBN(balanceMixerBefore).sub(toBN(value)))
|
||||
balanceRelayerAfter.should.be.eq.BN(toBN(balanceRelayerBefore))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue