|
10 | 10 | import java.io.File; |
11 | 11 | import java.util.Arrays; |
12 | 12 | import java.util.List; |
| 13 | +import org.apache.commons.lang3.ArrayUtils; |
13 | 14 | import org.junit.Assert; |
14 | 15 | import org.junit.Test; |
15 | 16 | import org.testng.collections.Lists; |
@@ -215,38 +216,53 @@ private IncrementalMerkleVoucherContainer createMerkleVoucherContainer() { |
215 | 216 | return voucher; |
216 | 217 | } |
217 | 218 |
|
218 | | - private String getParamsFile(String fileName){ |
| 219 | + private String getParamsFile(String fileName) { |
219 | 220 | return SendCoinShieldTest.class.getClassLoader() |
220 | 221 | .getResource("params" + File.separator + fileName).getFile(); |
221 | 222 | } |
222 | | - private void librustzcashInitZksnarkParams() { |
| 223 | + |
| 224 | + public static byte[] stringToAscii(String value) { |
| 225 | + List<Byte> sbu = Lists.newArrayList(); |
| 226 | + char[] chars = value.toCharArray(); |
| 227 | + for (int i = 0; i < chars.length; i++) { |
| 228 | + sbu.add((byte) chars[i]); |
| 229 | + } |
| 230 | + |
| 231 | + Byte[] bytes = sbu.toArray(new Byte[sbu.size()]); |
| 232 | + return ArrayUtils.toPrimitive(bytes); |
| 233 | + |
| 234 | + } |
| 235 | + |
| 236 | + private void librustzcashInitZksnarkParams() throws Exception { |
223 | 237 |
|
224 | 238 | String file1 = getParamsFile("sapling-spend.params"); |
225 | 239 |
|
226 | 240 | byte[] spend_path = file1.getBytes(); |
227 | 241 | int spend_path_len = spend_path.length; |
228 | | - byte[] spend_hash = ByteArray.fromHexString( |
229 | | - "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c"); |
| 242 | + byte[] spend_hash = stringToAscii( |
| 243 | + "8270785a1a0d0bc77196f000ee6d221c9c9894f55307bd9357c3f0105d31ca63991ab91324160d8f53e2bbd3c2633a6eb8bdf5205d822e7f3f73edac51b2b70c\0"); |
230 | 244 |
|
231 | 245 | String file2 = getParamsFile("sapling-output.params"); |
232 | 246 | byte[] output_path = file2.getBytes(); |
233 | 247 | int output_path_len = output_path.length; |
234 | | - byte[] output_hash = ByteArray.fromHexString( |
235 | | - "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028"); |
| 248 | + byte[] output_hash = |
| 249 | + stringToAscii( |
| 250 | + "657e3d38dbb5cb5e7dd2970e8b03d69b4787dd907285b5a7f0790dcc8072f60bf593b32cc2d1c030e00ff5ae64bf84c5c3beb84ddc841d48264b4a171744d028\0"); |
236 | 251 |
|
237 | 252 | String file3 = getParamsFile("sprout-groth16.params"); |
238 | 253 | byte[] sprout_path = file3.getBytes(); |
239 | 254 | int sprout_path_len = sprout_path.length; |
240 | | - byte[] sprout_hash = ByteArray.fromHexString( |
241 | | - "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a"); |
| 255 | + byte[] sprout_hash = |
| 256 | + stringToAscii( |
| 257 | + "e9b238411bd6c0ec4791e9d04245ec350c9c5744f5610dfcce4365d5ca49dfefd5054e371842b3f88fa1b9d7e8e075249b3ebabd167fa8b0f3161292d36c180a\0"); |
242 | 258 |
|
243 | 259 | Librustzcash.librustzcashInitZksnarkParams(spend_path, spend_path_len, spend_hash, |
244 | 260 | output_path, output_path_len, output_hash, sprout_path, sprout_path_len, |
245 | 261 | sprout_hash); |
246 | 262 | } |
247 | 263 |
|
248 | 264 | @Test |
249 | | - public void testGenerateSpendProof() { |
| 265 | + public void testGenerateSpendProof() throws Exception { |
250 | 266 | librustzcashInitZksnarkParams(); |
251 | 267 |
|
252 | 268 | TransactionBuilder builder = new TransactionBuilder(); |
|
0 commit comments