@lfdecentralizedtrust/zeto-contracts 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +70 -162
  2. package/contracts/factory.sol +30 -34
  3. package/contracts/factory_upgradeable.sol +160 -0
  4. package/contracts/lib/common/util.sol +40 -0
  5. package/contracts/lib/interfaces/ILockableCapability.sol +318 -0
  6. package/contracts/lib/interfaces/{izeto.sol → IZeto.sol} +13 -1
  7. package/contracts/lib/interfaces/{izeto_initializable.sol → IZetoInitializable.sol} +14 -12
  8. package/contracts/lib/interfaces/{izeto_kyc.sol → IZetoKyc.sol} +3 -3
  9. package/contracts/lib/interfaces/IZetoLockableCapability.sol +237 -0
  10. package/contracts/lib/interfaces/IZetoStorage.sol +106 -0
  11. package/contracts/lib/interfaces/{izeto_lockable.sol → IZetoVerifier.sol} +8 -21
  12. package/contracts/lib/registry.sol +77 -27
  13. package/contracts/lib/storage/base.sol +210 -0
  14. package/contracts/lib/storage/nullifier.sol +166 -0
  15. package/contracts/lib/zeto_common.sol +277 -28
  16. package/contracts/lib/zeto_fungible.sol +451 -33
  17. package/contracts/lib/zeto_fungible_base.sol +69 -0
  18. package/contracts/lib/zeto_fungible_burn.sol +83 -53
  19. package/contracts/lib/zeto_fungible_burn_nullifier.sol +115 -72
  20. package/contracts/lib/zeto_fungible_nullifier.sol +167 -0
  21. package/contracts/lib/zeto_lockable.sol +613 -0
  22. package/contracts/lib/zeto_non_fungible.sol +236 -0
  23. package/contracts/lib/zeto_non_fungible_base.sol +61 -0
  24. package/contracts/lib/zeto_non_fungible_nullifier.sol +61 -0
  25. package/contracts/test/escrow1.sol +90 -34
  26. package/contracts/test/escrow2.sol +64 -29
  27. package/contracts/test/qurrency.sol +10 -2
  28. package/contracts/test/smt.sol +8 -3
  29. package/contracts/test/tendecimals.sol +14 -12
  30. package/contracts/verifiers/impl/anon.sol +189 -0
  31. package/contracts/verifiers/impl/anon_batch.sol +301 -0
  32. package/contracts/verifiers/impl/anon_enc.sol +266 -0
  33. package/contracts/verifiers/impl/anon_enc_batch.sol +602 -0
  34. package/contracts/verifiers/impl/anon_enc_nullifier.sol +287 -0
  35. package/contracts/verifiers/impl/anon_enc_nullifier_batch.sol +679 -0
  36. package/contracts/verifiers/impl/anon_enc_nullifier_kyc.sol +294 -0
  37. package/contracts/verifiers/impl/anon_enc_nullifier_kyc_batch.sol +686 -0
  38. package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation.sol +413 -0
  39. package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation_batch.sol +1141 -0
  40. package/contracts/verifiers/impl/anon_nullifier_kyc_transfer.sol +217 -0
  41. package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked.sol +196 -0
  42. package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked_batch.sol +308 -0
  43. package/contracts/verifiers/impl/anon_nullifier_kyc_transfer_batch.sol +385 -0
  44. package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer.sol +497 -0
  45. package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer_batch.sol +1001 -0
  46. package/contracts/verifiers/{verifier_anon_nullifier_transferLocked.sol → impl/anon_nullifier_transfer.sol} +12 -19
  47. package/contracts/verifiers/{verifier_anon_nullifier_transferLocked_batch.sol → impl/anon_nullifier_transfer_batch.sol} +44 -51
  48. package/contracts/verifiers/impl/burn.sol +182 -0
  49. package/contracts/verifiers/impl/burn_batch.sol +238 -0
  50. package/contracts/verifiers/impl/burn_nullifier.sol +203 -0
  51. package/contracts/verifiers/impl/burn_nullifier_batch.sol +315 -0
  52. package/contracts/verifiers/impl/deposit.sol +182 -0
  53. package/contracts/verifiers/impl/deposit_kyc.sol +189 -0
  54. package/contracts/verifiers/impl/nf_anon.sol +175 -0
  55. package/contracts/verifiers/{verifier_nf_anon_nullifier_transferLocked.sol → impl/nf_anon_nullifier_transfer.sol} +6 -13
  56. package/contracts/verifiers/impl/withdraw.sol +189 -0
  57. package/contracts/verifiers/impl/withdraw_batch.sol +245 -0
  58. package/contracts/verifiers/impl/withdraw_nullifier.sol +210 -0
  59. package/contracts/verifiers/impl/withdraw_nullifier_batch.sol +322 -0
  60. package/contracts/verifiers/verifier_anon.sol +31 -186
  61. package/contracts/verifiers/verifier_anon_batch.sol +31 -298
  62. package/contracts/verifiers/verifier_anon_enc.sol +31 -263
  63. package/contracts/verifiers/verifier_anon_enc_batch.sol +31 -599
  64. package/contracts/verifiers/verifier_anon_enc_nullifier.sol +31 -284
  65. package/contracts/verifiers/verifier_anon_enc_nullifier_batch.sol +33 -676
  66. package/contracts/verifiers/verifier_anon_enc_nullifier_kyc.sol +31 -291
  67. package/contracts/verifiers/verifier_anon_enc_nullifier_kyc_batch.sol +33 -683
  68. package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation.sol +33 -410
  69. package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation_batch.sol +33 -1138
  70. package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer.sol +33 -214
  71. package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked.sol +33 -221
  72. package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked_batch.sol +33 -389
  73. package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer_batch.sol +33 -382
  74. package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer.sol +33 -221
  75. package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer_batch.sol +33 -389
  76. package/contracts/verifiers/verifier_anon_nullifier_transfer.sol +33 -207
  77. package/contracts/verifiers/verifier_anon_nullifier_transfer_batch.sol +33 -375
  78. package/contracts/verifiers/verifier_burn.sol +31 -179
  79. package/contracts/verifiers/verifier_burn_batch.sol +31 -235
  80. package/contracts/verifiers/verifier_burn_nullifier.sol +31 -200
  81. package/contracts/verifiers/verifier_burn_nullifier_batch.sol +31 -312
  82. package/contracts/verifiers/verifier_deposit.sol +31 -179
  83. package/contracts/verifiers/verifier_deposit_kyc.sol +34 -0
  84. package/contracts/verifiers/verifier_nf_anon.sol +31 -172
  85. package/contracts/verifiers/verifier_nf_anon_nullifier_transfer.sol +33 -179
  86. package/contracts/verifiers/verifier_withdraw.sol +31 -186
  87. package/contracts/verifiers/verifier_withdraw_batch.sol +31 -242
  88. package/contracts/verifiers/verifier_withdraw_nullifier.sol +31 -207
  89. package/contracts/verifiers/verifier_withdraw_nullifier_batch.sol +33 -319
  90. package/contracts/zeto_anon.sol +77 -231
  91. package/contracts/zeto_anon_burnable.sol +56 -12
  92. package/contracts/zeto_anon_enc.sol +93 -190
  93. package/contracts/zeto_anon_enc_nullifier.sol +249 -195
  94. package/contracts/zeto_anon_enc_nullifier_kyc.sol +51 -232
  95. package/contracts/zeto_anon_enc_nullifier_non_repudiation.sol +231 -238
  96. package/contracts/zeto_anon_nullifier.sol +164 -298
  97. package/contracts/zeto_anon_nullifier_burnable.sol +68 -18
  98. package/contracts/zeto_anon_nullifier_kyc.sol +40 -345
  99. package/contracts/zeto_anon_nullifier_qurrency.sol +218 -360
  100. package/contracts/zeto_nf_anon.sol +55 -130
  101. package/contracts/zeto_nf_anon_nullifier.sol +90 -152
  102. package/hardhat.config.ts +9 -3
  103. package/ignition/modules/lib/deps.ts +9 -6
  104. package/ignition/modules/zeto_anon_burnable.ts +8 -7
  105. package/ignition/modules/zeto_anon_enc_nullifier.ts +33 -1
  106. package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +2 -2
  107. package/ignition/modules/zeto_anon_enc_nullifier_non_repudiation.ts +2 -1
  108. package/ignition/modules/zeto_anon_nullifier.ts +30 -5
  109. package/ignition/modules/zeto_anon_nullifier_burnable.ts +52 -17
  110. package/ignition/modules/zeto_anon_nullifier_kyc.ts +27 -12
  111. package/ignition/modules/zeto_anon_nullifier_qurrency.ts +2 -1
  112. package/ignition/modules/zeto_nf_anon_nullifier.ts +16 -12
  113. package/package.json +4 -2
  114. package/scripts/deploy_cloneable.ts +19 -10
  115. package/scripts/deploy_upgradeable.ts +9 -5
  116. package/scripts/tokens/Zeto_Anon.ts +3 -3
  117. package/scripts/tokens/Zeto_AnonBurnable.ts +1 -1
  118. package/scripts/tokens/Zeto_AnonEnc.ts +12 -3
  119. package/scripts/tokens/Zeto_AnonEncNullifier.ts +7 -3
  120. package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +1 -1
  121. package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +3 -1
  122. package/scripts/tokens/Zeto_AnonNullifier.ts +3 -1
  123. package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +3 -1
  124. package/scripts/tokens/Zeto_AnonNullifierKyc.ts +1 -1
  125. package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +3 -1
  126. package/scripts/tokens/Zeto_NfAnon.ts +2 -2
  127. package/scripts/tokens/Zeto_NfAnonNullifier.ts +3 -2
  128. package/test/factory.ts +46 -73
  129. package/test/factory_upgradeable.ts +311 -0
  130. package/test/lib/anon_nullifier_helpers.ts +89 -0
  131. package/test/lib/anon_zeto_helpers.ts +76 -0
  132. package/test/lib/deploy.ts +3 -2
  133. package/test/lib/utils.ts +74 -35
  134. package/test/test/escrow1.ts +185 -58
  135. package/test/test/escrow2.ts +200 -107
  136. package/test/test/qurrency.ts +13 -33
  137. package/test/usdc-shielding.ts +39 -26
  138. package/test/utils.ts +144 -21
  139. package/test/zeto_anon.ts +956 -465
  140. package/test/zeto_anon_enc.ts +881 -142
  141. package/test/zeto_anon_enc_nullifier.ts +847 -38
  142. package/test/zeto_anon_enc_nullifier_kyc.ts +120 -181
  143. package/test/zeto_anon_enc_nullifier_non_repudiation.ts +77 -46
  144. package/test/zeto_anon_nullifier.ts +1212 -953
  145. package/test/zeto_anon_nullifier_kyc.ts +674 -655
  146. package/test/zeto_anon_nullifier_qurrency.ts +452 -306
  147. package/test/zeto_nf_anon.ts +737 -137
  148. package/test/zeto_nf_anon_nullifier.ts +876 -246
  149. package/contracts/lib/zeto_base.sol +0 -293
  150. package/contracts/lib/zeto_fungible_withdraw.sol +0 -132
  151. package/contracts/lib/zeto_fungible_withdraw_nullifier.sol +0 -144
  152. package/contracts/lib/zeto_nullifier.sol +0 -334
  153. package/contracts/zkDvP.sol_ +0 -273
  154. package/test/zkDvP.ts_ +0 -455
  155. /package/contracts/lib/{common.sol → common/common.sol} +0 -0
package/test/zkDvP.ts_ DELETED
@@ -1,455 +0,0 @@
1
- // Copyright © 2024 Kaleido, Inc.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- //
5
- // Licensed under the Apache License, Version 2.0 (the "License");
6
- // you may not use this file except in compliance with the License.
7
- // You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing, software
12
- // distributed under the License is distributed on an "AS IS" BASIS,
13
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- // See the License for the specific language governing permissions and
15
- // limitations under the License.
16
-
17
- import { ethers, ignition, network } from "hardhat";
18
- import { Signer, encodeBytes32String, ZeroHash, lock } from "ethers";
19
- import { expect } from "chai";
20
- import { loadCircuit, getProofHash } from "zeto-js";
21
- import zkDvPModule from "../ignition/modules/zkDvP";
22
- import zetoAnonTests from "./zeto_anon";
23
- import zetoNFAnonTests from "./zeto_nf_anon";
24
- import {
25
- UTXO,
26
- User,
27
- newUser,
28
- newUTXO,
29
- doMint,
30
- newAssetUTXO,
31
- ZERO_UTXO,
32
- parseUTXOEvents,
33
- } from "./lib/utils";
34
- import {
35
- loadProvingKeys,
36
- prepareLockProof,
37
- prepareAssetLockProof,
38
- } from "./utils";
39
- import { deployZeto } from "./lib/deploy";
40
-
41
- describe("DvP flows between fungible and non-fungible tokens based on Zeto with anonymity without encryption or nullifiers", function () {
42
- // users interacting with each other in the DvP transactions
43
- let Alice: User;
44
- let Bob: User;
45
- let Charlie: User;
46
-
47
- // instances of the contracts
48
- let zkAsset: any;
49
- let zkPayment: any;
50
- let zkDvP: any;
51
-
52
- // asset UTXOs to be minted and transferred
53
- let asset1: UTXO;
54
- let asset2: UTXO;
55
- // payment UTXOs to be minted and transferred
56
- let payment1: UTXO;
57
- let payment2: UTXO;
58
-
59
- // other variables
60
- let deployer: Signer;
61
-
62
- before(async function () {
63
- if (network.name !== "hardhat") {
64
- // accommodate for longer block times on public networks
65
- this.timeout(120000);
66
- }
67
- let [d, a, b, c] = await ethers.getSigners();
68
- deployer = d;
69
- Alice = await newUser(a);
70
- Bob = await newUser(b);
71
- Charlie = await newUser(c);
72
-
73
- ({ deployer, zeto: zkAsset } = await deployZeto("Zeto_NfAnon"));
74
- console.log(`ZK Asset contract deployed at ${zkAsset.target}`);
75
- ({ deployer, zeto: zkPayment } = await deployZeto("Zeto_Anon"));
76
- console.log(`ZK Payment contract deployed at ${zkPayment.target}`);
77
- ({ zkDvP } = await ignition.deploy(zkDvPModule, {
78
- parameters: {
79
- zkDvP: {
80
- assetToken: zkAsset.target,
81
- paymentToken: zkPayment.target,
82
- },
83
- },
84
- }));
85
- });
86
-
87
- it("mint to Alice some payment tokens", async function () {
88
- payment1 = newUTXO(10, Alice);
89
- payment2 = newUTXO(20, Alice);
90
- const result = await doMint(zkPayment, deployer, [payment1, payment2]);
91
-
92
- // simulate Alice and Bob listening to minting events and updating his local merkle tree
93
- for (const log of result.logs) {
94
- const event = zkPayment.interface.parseLog(log as any);
95
- expect(event.args.outputs.length).to.equal(2);
96
- }
97
- });
98
-
99
- it("mint to Bob some asset tokens", async function () {
100
- asset1 = newUTXO(10, Alice);
101
- asset2 = newUTXO(20, Alice);
102
- const result = await doMint(zkAsset, deployer, [asset1, asset2]);
103
-
104
- // simulate Bob listening to minting events and updating his local merkle tree
105
- const event = zkAsset.interface.parseLog(result.logs[0] as any);
106
- expect(event.args.outputs[0].toString()).to.equal(asset1.hash.toString());
107
- expect(event.args.outputs[1].toString()).to.equal(asset2.hash.toString());
108
- });
109
-
110
- it("Initiating a successful DvP transaction with payment inputs", async function () {
111
- const utxo1 = newUTXO(10, Alice);
112
- const utxo2 = newUTXO(20, Alice);
113
- const utxo3 = newUTXO(25, Bob);
114
- const utxo4 = newUTXO(5, Alice);
115
- await expect(
116
- zkDvP
117
- .connect(Alice.signer)
118
- .initiateTrade(
119
- [utxo1.hash, utxo2.hash],
120
- [utxo3.hash, utxo4.hash],
121
- ZeroHash,
122
- 0,
123
- 0,
124
- ZeroHash,
125
- ),
126
- ).fulfilled;
127
- });
128
-
129
- it("Initiating a successful DvP transaction with asset inputs", async function () {
130
- const utxo1 = newUTXO(10, Alice);
131
- const utxo2 = newUTXO(20, Alice);
132
- await expect(
133
- zkDvP
134
- .connect(Alice.signer)
135
- .initiateTrade(
136
- [0, 0],
137
- [0, 0],
138
- ZeroHash,
139
- utxo1.hash,
140
- utxo2.hash,
141
- ZeroHash,
142
- ),
143
- ).fulfilled;
144
- });
145
-
146
- it("Initiating a successful DvP transaction with payment inputs and accepting by specifying asset inputs", async function () {
147
- // the authority mints some payment tokens to Alice
148
- const _utxo1 = newUTXO(100, Alice);
149
- await doMint(zkPayment, deployer, [_utxo1]);
150
- // the authority mints some asset tokens to Bob
151
- const utxo3 = newAssetUTXO(202, "http://ipfs.io/file-hash-1", Bob);
152
- await doMint(zkAsset, deployer, [utxo3]);
153
-
154
- // 1. Alice initiates a trade with Bob using the payment tokens
155
- // 1.1 Alice generates the proposed output payment UTXO for Bob
156
- const utxo2 = newUTXO(100, Bob);
157
-
158
- // 1.2 Alice generates the proof for the trade proposal
159
- const circuit1 = await loadCircuit("anon");
160
- const { provingKeyFile: provingKey1 } = loadProvingKeys("anon");
161
- const proof1 = await zetoAnonTests.prepareProof(
162
- circuit1,
163
- provingKey1,
164
- Alice,
165
- [_utxo1, ZERO_UTXO],
166
- [utxo2, ZERO_UTXO],
167
- [Bob, {}],
168
- );
169
- const hash1 = getProofHash(proof1.encodedProof);
170
- const lockProof1 = await prepareLockProof(Alice, [_utxo1, ZERO_UTXO]);
171
-
172
- // 1.3 Alice initiates the trade with Bob
173
- const tx1 = await zkDvP
174
- .connect(Alice.signer)
175
- .initiateTrade([_utxo1.hash, 0], [utxo2.hash, 0], hash1, 0, 0, ZeroHash);
176
- const result1 = await tx1.wait();
177
- const event = zkDvP.interface.parseLog(result1.logs[0]);
178
- const tradeId = event.args.tradeId;
179
-
180
- // 2. Bob accepts the trade by using the asset tokens
181
- // 2.1 Bob generates the proposed output asset UTXO for Alice
182
- const utxo4 = newAssetUTXO(202, "http://ipfs.io/file-hash-1", Alice);
183
-
184
- // 2.2 Bob generates the proof for accepting the trade
185
- const circuit2 = await loadCircuit("nf_anon");
186
- const { provingKeyFile: provingKey2 } = loadProvingKeys("nf_anon");
187
- const proof2 = await zetoNFAnonTests.prepareProof(
188
- circuit2,
189
- provingKey2,
190
- Bob,
191
- utxo3,
192
- utxo4,
193
- Alice,
194
- );
195
- const hash2 = getProofHash(proof2.encodedProof);
196
- const lockProof2 = await prepareAssetLockProof(Bob, [utxo3, ZERO_UTXO]);
197
-
198
- await expect(
199
- zkDvP
200
- .connect(Bob.signer)
201
- .acceptTrade(
202
- tradeId,
203
- [0, 0],
204
- [0, 0],
205
- ZeroHash,
206
- utxo3.hash,
207
- utxo4.hash,
208
- hash2,
209
- ),
210
- ).fulfilled;
211
-
212
- // 3. Alice sends her proof to complete the trade (the trade will still be pending completion)
213
- const tx2 = await zkDvP
214
- .connect(Alice.signer)
215
- .completeTrade(tradeId, proof1.encodedProof, lockProof1.encodedProof);
216
- const tx2Result = await tx2.wait();
217
-
218
- // 4. Bob sends his proof to complete the trade (the trade will be completed)
219
- const tx3 = await zkDvP
220
- .connect(Bob.signer)
221
- .completeTrade(tradeId, proof2.encodedProof, lockProof2.encodedProof);
222
- const tx3Result = await tx3.wait();
223
-
224
- // check that the trade is completed
225
- const events = parseUTXOEvents(zkDvP, tx3Result);
226
- expect(events[0].tradeId).to.equal(tradeId);
227
- expect(events[0].trade.status).to.equal(2n); // enum for TradeStatus.Completed
228
- });
229
- describe("failure cases", function () {
230
- // the following failure cases rely on the hardhat network
231
- // to return the details of the errors. This is not possible
232
- // on non-hardhat networks
233
- if (network.name !== "hardhat") {
234
- return;
235
- }
236
-
237
- it("Initiating a DvP transaction without payment input or asset input should fail", async function () {
238
- await expect(
239
- zkDvP
240
- .connect(Alice.signer)
241
- .initiateTrade([0, 0], [0, 0], ZeroHash, 0, 0, ZeroHash),
242
- ).rejectedWith(
243
- "Payment inputs and asset input cannot be zero at the same time",
244
- );
245
- });
246
-
247
- it("Initiating a DvP transaction with payment input but no payment output should fail", async function () {
248
- const utxo1 = newUTXO(10, Alice);
249
- const utxo2 = newUTXO(20, Alice);
250
- await expect(
251
- zkDvP
252
- .connect(Alice.signer)
253
- .initiateTrade(
254
- [utxo1.hash, utxo2.hash],
255
- [0, 0],
256
- ZeroHash,
257
- 0,
258
- 0,
259
- ZeroHash,
260
- ),
261
- ).rejectedWith(
262
- "Payment outputs cannot be zero when payment inputs are non-zero",
263
- );
264
- });
265
-
266
- it("Initiating a DvP transaction with payment inputs and asset inputs should fail", async function () {
267
- const utxo1 = newUTXO(10, Alice);
268
- const utxo2 = newUTXO(20, Alice);
269
- const utxo3 = newUTXO(25, Bob);
270
- const utxo4 = newUTXO(5, Alice);
271
- await expect(
272
- zkDvP
273
- .connect(Alice.signer)
274
- .initiateTrade(
275
- [utxo1.hash, utxo2.hash],
276
- [utxo3.hash, utxo4.hash],
277
- ZeroHash,
278
- utxo3.hash,
279
- 0,
280
- ZeroHash,
281
- ),
282
- ).rejectedWith(
283
- "Payment inputs and asset input cannot be provided at the same time",
284
- );
285
- });
286
-
287
- it("Initiating a DvP transaction with asset input but no asset output should fail", async function () {
288
- const utxo1 = newUTXO(10, Alice);
289
- await expect(
290
- zkDvP
291
- .connect(Alice.signer)
292
- .initiateTrade([0, 0], [0, 0], ZeroHash, utxo1.hash, 0, ZeroHash),
293
- ).rejectedWith(
294
- "Asset output cannot be zero when asset input is non-zero",
295
- );
296
- });
297
-
298
- it("Accepting a trade using an invalid trade ID should fail", async function () {
299
- await expect(
300
- zkDvP
301
- .connect(Bob.signer)
302
- .acceptTrade(1000, [0, 0], [0, 0], ZeroHash, 0, 0, ZeroHash),
303
- ).rejectedWith("Trade does not exist");
304
- });
305
-
306
- it("Failing cases for accepting a trade with payment terms", async function () {
307
- const mockProofHash = encodeBytes32String("moch proof hash");
308
- const utxo1 = newUTXO(20, Alice);
309
- const utxo2 = newUTXO(20, Bob);
310
- const tx1 = await zkDvP
311
- .connect(Alice.signer)
312
- .initiateTrade(
313
- [utxo1.hash, 0],
314
- [utxo2.hash, 0],
315
- mockProofHash,
316
- 0,
317
- 0,
318
- mockProofHash,
319
- );
320
- const result = await tx1.wait();
321
- const event = zkDvP.interface.parseLog(result.logs[0]);
322
- const tradeId = event.args.tradeId;
323
-
324
- const utxo3 = newAssetUTXO(25, "http://ipfs.io/file-hash-1", Bob);
325
- await expect(
326
- zkDvP
327
- .connect(Bob.signer)
328
- .acceptTrade(
329
- tradeId,
330
- [utxo1.hash, 0],
331
- [0, 0],
332
- mockProofHash,
333
- 0,
334
- 0,
335
- mockProofHash,
336
- ),
337
- ).rejectedWith("Payment inputs already provided by the trade initiator");
338
- await expect(
339
- zkDvP
340
- .connect(Bob.signer)
341
- .acceptTrade(
342
- tradeId,
343
- [0, 0],
344
- [utxo2.hash, 0],
345
- mockProofHash,
346
- 0,
347
- 0,
348
- mockProofHash,
349
- ),
350
- ).rejectedWith("Payment outputs already provided by the trade initiator");
351
- await expect(
352
- zkDvP
353
- .connect(Bob.signer)
354
- .acceptTrade(
355
- tradeId,
356
- [0, 0],
357
- [0, 0],
358
- mockProofHash,
359
- 0,
360
- 0,
361
- mockProofHash,
362
- ),
363
- ).rejectedWith("Asset input must be provided to accept the trade");
364
- await expect(
365
- zkDvP
366
- .connect(Bob.signer)
367
- .acceptTrade(
368
- tradeId,
369
- [0, 0],
370
- [0, 0],
371
- mockProofHash,
372
- utxo3.hash,
373
- 0,
374
- mockProofHash,
375
- ),
376
- ).rejectedWith("Asset output must be provided to accept the trade");
377
- });
378
-
379
- it("Failing cases for accepting a trade with asset terms", async function () {
380
- const mockProofHash = encodeBytes32String("mock proof hash");
381
- const utxo1 = newAssetUTXO(100, "http://ipfs.io/file-hash-1", Alice);
382
- const utxo2 = newAssetUTXO(202, "http://ipfs.io/file-hash-2", Bob);
383
- const tx1 = await zkDvP
384
- .connect(Alice.signer)
385
- .initiateTrade(
386
- [0, 0],
387
- [0, 0],
388
- ZeroHash,
389
- utxo1.hash,
390
- utxo2.hash,
391
- mockProofHash,
392
- );
393
- const result = await tx1.wait();
394
- const event = zkDvP.interface.parseLog(result.logs[0]);
395
- const tradeId = event.args.tradeId;
396
-
397
- const utxo3 = newUTXO(10, Bob);
398
- const utxo4 = newUTXO(20, Bob);
399
- const utxo5 = newUTXO(25, Alice);
400
- const utxo6 = newUTXO(5, Bob);
401
- await expect(
402
- zkDvP
403
- .connect(Bob.signer)
404
- .acceptTrade(
405
- tradeId,
406
- [utxo3.hash, utxo4.hash],
407
- [utxo5.hash, utxo6.hash],
408
- mockProofHash,
409
- utxo1.hash,
410
- utxo2.hash,
411
- mockProofHash,
412
- ),
413
- ).rejectedWith("Asset inputs already provided by the trade initiator");
414
- await expect(
415
- zkDvP
416
- .connect(Bob.signer)
417
- .acceptTrade(
418
- tradeId,
419
- [utxo3.hash, utxo4.hash],
420
- [utxo5.hash, utxo6.hash],
421
- mockProofHash,
422
- 0,
423
- utxo2.hash,
424
- mockProofHash,
425
- ),
426
- ).rejectedWith("Asset outputs already provided by the trade initiator");
427
- await expect(
428
- zkDvP
429
- .connect(Bob.signer)
430
- .acceptTrade(
431
- tradeId,
432
- [0, 0],
433
- [0, 0],
434
- mockProofHash,
435
- 0,
436
- 0,
437
- mockProofHash,
438
- ),
439
- ).rejectedWith("Payment inputs must be provided to accept the trade");
440
- await expect(
441
- zkDvP
442
- .connect(Bob.signer)
443
- .acceptTrade(
444
- tradeId,
445
- [utxo3.hash, utxo4.hash],
446
- [0, 0],
447
- mockProofHash,
448
- 0,
449
- 0,
450
- mockProofHash,
451
- ),
452
- ).rejectedWith("Payment outputs must be provided to accept the trade");
453
- });
454
- });
455
- }).timeout(600000);
File without changes