tornado-core/test/deposit.ts

69 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

2024-10-26 21:54:31 +03:00
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers';
import { anyValue } from '@nomicfoundation/hardhat-chai-matchers/withArgs';
import { ethers } from 'hardhat';
import { expect } from 'chai';
import { formatEther } from 'ethers';
import { ETHTornado__factory, Verifier__factory } from '@tornado/contracts';
import { Deposit, deployHasher } from '../src';
const { getSigners } = ethers;
const NOTES_COUNT = 100;
describe('./src/deposit.ts', function () {
const instanceFixture = async () => {
const [owner] = await getSigners();
2024-10-26 21:54:31 +03:00
const Hasher = (await (await deployHasher(owner)).wait())?.contractAddress as string;
2024-10-26 21:54:31 +03:00
const Verifier = await new Verifier__factory(owner).deploy();
2024-10-26 21:54:31 +03:00
const Instance = await new ETHTornado__factory(owner).deploy(Verifier.target, Hasher, 1n, 20);
2024-10-26 21:54:31 +03:00
return { Instance };
};
2024-10-26 21:54:31 +03:00
it('Deposit New Note', async function () {
const { Instance } = await loadFixture(instanceFixture);
2024-10-26 21:54:31 +03:00
const [owner] = await getSigners();
2024-10-26 21:54:31 +03:00
const netId = Number((await owner.provider.getNetwork()).chainId);
2024-10-26 21:54:31 +03:00
const deposit = await Deposit.createNote({
currency: 'eth',
amount: formatEther(1),
netId,
});
2024-10-26 21:54:31 +03:00
const resp = await Instance.deposit(deposit.commitmentHex, {
value: 1n,
});
2024-10-26 21:54:31 +03:00
await expect(resp).to.emit(Instance, 'Deposit').withArgs(deposit.commitmentHex, 0, anyValue);
2024-10-26 21:54:31 +03:00
expect(await Instance.commitments(deposit.commitmentHex)).to.be.true;
});
2024-10-26 21:54:31 +03:00
xit(`Creating ${NOTES_COUNT} random notes`, async function () {
const notes = (await Promise.all(
// eslint-disable-next-line prefer-spread
Array.apply(null, Array(NOTES_COUNT)).map(() =>
Deposit.createNote({
currency: 'eth',
amount: '0.1',
netId: 31337,
}),
),
)) as Deposit[];
notes.forEach(({ noteHex, commitmentHex, nullifierHex }) => {
// ((secret.length: 31) + (nullifier.length: 31)) * 2 + (prefix: 2) = 126
expect(noteHex.length === 126).to.be.true;
expect(commitmentHex.length === 66).to.be.true;
expect(nullifierHex.length === 66).to.be.true;
});
2024-10-26 21:54:31 +03:00
});
});