mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-06-21 12:44:17 -04:00
Update unit test on contracts for encryptedNote
This commit is contained in:
parent
2abf02f818
commit
abdca319ed
6 changed files with 336 additions and 130 deletions
28
test/encrypt.test.js
Normal file
28
test/encrypt.test.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const { getEncryptionPublicKey } = require('eth-sig-util')
|
||||
const { toBN } = require('web3-utils')
|
||||
|
||||
const Account = require('../src/account')
|
||||
const {
|
||||
packEncryptedMessage,
|
||||
unpackEncryptedMessage,
|
||||
} = require('../src/utils')
|
||||
|
||||
describe('#encrypt', () => {
|
||||
// EncryptedNote
|
||||
const privateKey = web3.eth.accounts.create().privateKey.slice(2)
|
||||
const publicKey = getEncryptionPublicKey(privateKey)
|
||||
|
||||
it('should work', () => {
|
||||
const account = new Account()
|
||||
const encryptedAccount = account.encrypt(publicKey)
|
||||
const encryptedMessage = packEncryptedMessage(encryptedAccount)
|
||||
const unpackedMessage = unpackEncryptedMessage(encryptedMessage)
|
||||
const account2 = Account.decrypt(privateKey, unpackedMessage)
|
||||
|
||||
assert(account.amount.toString() === toBN(account2.amount).toString())
|
||||
assert(account.secret.toString() === toBN(account2.secret).toString())
|
||||
assert(account.nullifier.toString() === toBN(account2.nullifier).toString())
|
||||
assert(account.commitment.toString() === toBN(account2.commitment).toString())
|
||||
})
|
||||
})
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue