chore: add test case for ERC20 sum check inside snark circuit

This commit is contained in:
Wanseob Lim
2021-02-02 02:29:07 +09:00
parent 71c41b285a
commit 67aa8da7ff
3 changed files with 29 additions and 0 deletions

View File

@@ -96,4 +96,17 @@ describe('zk_transaction_1_2.test.circom', () => {
const result: SNARKResult = await genSNARK(inputs, wasm, finalZkey, vk)
expect(result).toBeDefined()
}, 20000)
it('should fail to create a SNARK proof', async () => {
const tx = txs.tx_1_false
const signer = accounts.alice
const merkleProof = {
0: await utxoTree.merkleProof({
hash: utxos.utxo1_in_1.hash(),
index: Field.from(0),
}),
}
const inputs = ZkWizard.snarkInput({ tx, signer, merkleProof })
// eslint-disable-next-line jest/require-tothrow-message
await expect(genSNARK(inputs, wasm, finalZkey, vk)).rejects.toThrow()
}, 20000)
})

View File

@@ -9,6 +9,13 @@ const tx_1: RawTx = {
fee: Field.from(1),
}
/** @dev prints DAI */
const tx_1_false: RawTx = {
inflow: [utxos.utxo1_in_1],
outflow: [utxos.utxo1_out_1, utxos.utxo1_out_2_false],
fee: Field.from(1),
}
const tx_2_1: RawTx = {
inflow: [utxos.utxo2_1_in_1],
outflow: [utxos.utxo2_1_out_1, utxos.utxo2_1_out_2],
@@ -36,6 +43,7 @@ const tx_4: RawTx = {
}
export const txs = {
tx_1,
tx_1_false,
tx_2_1,
tx_2_2,
tx_3,

View File

@@ -18,6 +18,13 @@ const utxo1_out_2: Utxo = Utxo.newEtherNote({
salt: 13,
eth: 1111,
})
const utxo1_out_2_false: Utxo = Utxo.newERC20Note({
owner: accounts.alice.zkAddress,
salt: 13,
eth: 1111,
tokenAddr: TokenUtils.DAI,
erc20Amount: 8888,
})
const utxo2_1_in_1: Utxo = Utxo.newERC20Note({
owner: accounts.alice.zkAddress,
salt: 14,
@@ -133,6 +140,7 @@ export const utxos = {
utxo1_in_1,
utxo1_out_1,
utxo1_out_2,
utxo1_out_2_false,
utxo2_1_in_1,
utxo2_1_out_1,
utxo2_1_out_2,