aboutsummaryrefslogtreecommitdiff
path: root/src/auditordb/test_auditordb.c
blob: f8faa0694f601e011afc22a570441bdb31a1be97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
  This file is part of TALER
  Copyright (C) 2016 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file auditordb/test_auditordb.c
 * @brief test cases for DB interaction functions
 * @author Gabor X Toth
 */
#include "platform.h"
#include <gnunet/gnunet_db_lib.h>
#include "taler_auditordb_lib.h"
#include "taler_auditordb_plugin.h"


/**
 * Global result from the testcase.
 */
static int result = -1;

/**
 * Report line of error if @a cond is true, and jump to label "drop".
 */
#define FAILIF(cond)                              \
  do {                                          \
    if (! (cond)) { break;}                     \
    GNUNET_break (0);                         \
    goto drop;                                \
  } while (0)


/**
 * Initializes @a ptr with random data.
 */
#define RND_BLK(ptr)                                                    \
  GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))

/**
 * Initializes @a ptr with zeros.
 */
#define ZR_BLK(ptr) \
  memset (ptr, 0, sizeof (*ptr))


/**
 * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
 */
#define CURRENCY "EUR"

/**
 * Database plugin under test.
 */
static struct TALER_AUDITORDB_Plugin *plugin;


/**
 * Main function that will be run by the scheduler.
 *
 * @param cls closure with config
 */
static void
run (void *cls)
{
  struct GNUNET_CONFIGURATION_Handle *cfg = cls;
  uint64_t rowid;

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "loading database plugin\n");

  if (NULL ==
      (plugin = TALER_AUDITORDB_plugin_load (cfg)))
  {
    result = 77;
    return;
  }

  (void) plugin->drop_tables (plugin->cls,
                              GNUNET_YES);
  if (GNUNET_OK !=
      plugin->create_tables (plugin->cls))
  {
    result = 77;
    goto unload;
  }
  if (GNUNET_SYSERR ==
      plugin->preflight (plugin->cls))
  {
    result = 77;
    goto drop;
  }

  FAILIF (GNUNET_OK !=
          plugin->start (plugin->cls));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "initializing\n");

  struct TALER_Amount value;
  struct TALER_Amount fee_withdraw;
  struct TALER_Amount fee_deposit;
  struct TALER_Amount fee_refresh;
  struct TALER_Amount fee_refund;

  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":1.000010",
                                         &value));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":0.000011",
                                         &fee_withdraw));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":0.000012",
                                         &fee_deposit));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":0.000013",
                                         &fee_refresh));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":0.000014",
                                         &fee_refund));

  struct TALER_MasterPublicKeyP master_pub;
  struct TALER_ReservePublicKeyP reserve_pub;
  struct TALER_DenominationHash rnd_hash;
  struct TALER_DenominationPrivateKey denom_priv;
  struct TALER_DenominationPublicKey denom_pub;
  struct TALER_DenominationHash denom_pub_hash;
  struct GNUNET_TIME_Timestamp now;
  struct GNUNET_TIME_Timestamp past;
  struct GNUNET_TIME_Timestamp future;
  struct GNUNET_TIME_Timestamp date;

  RND_BLK (&master_pub);
  RND_BLK (&reserve_pub);
  RND_BLK (&rnd_hash);
  GNUNET_assert (GNUNET_OK ==
                 TALER_denom_priv_create (&denom_priv,
                                          &denom_pub,
                                          TALER_DENOMINATION_RSA,
                                          1024));
  TALER_denom_pub_hash (&denom_pub,
                        &denom_pub_hash);
  TALER_denom_priv_free (&denom_priv);
  TALER_denom_pub_free (&denom_pub);

  now = GNUNET_TIME_timestamp_get ();
  past = GNUNET_TIME_absolute_to_timestamp (
    GNUNET_TIME_absolute_subtract (now.abs_time,
                                   GNUNET_TIME_relative_multiply (
                                     GNUNET_TIME_UNIT_HOURS,
                                     4)));
  future = GNUNET_TIME_absolute_to_timestamp (
    GNUNET_TIME_absolute_add (now.abs_time,
                              GNUNET_TIME_relative_multiply (
                                GNUNET_TIME_UNIT_HOURS,
                                4)));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: auditor_insert_exchange\n");
  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_exchange (plugin->cls,
                                   &master_pub,
                                   "https://exchange/"));


  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_auditor_progress\n");

  struct TALER_AUDITORDB_ProgressPointCoin ppc = {
    .last_deposit_serial_id = 123,
    .last_melt_serial_id = 456,
    .last_refund_serial_id = 789,
    .last_withdraw_serial_id = 555
  };
  struct TALER_AUDITORDB_ProgressPointCoin ppc2 = {
    .last_deposit_serial_id = 0,
    .last_melt_serial_id = 0,
    .last_refund_serial_id = 0,
    .last_withdraw_serial_id = 0
  };

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_auditor_progress_coin (plugin->cls,
                                                &master_pub,
                                                &ppc));
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_auditor_progress\n");

  ppc.last_deposit_serial_id++;
  ppc.last_melt_serial_id++;
  ppc.last_refund_serial_id++;
  ppc.last_withdraw_serial_id++;

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_auditor_progress_coin (plugin->cls,
                                                &master_pub,
                                                &ppc));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_auditor_progress\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_auditor_progress_coin (plugin->cls,
                                             &master_pub,
                                             &ppc2));
  FAILIF ( (ppc.last_deposit_serial_id != ppc2.last_deposit_serial_id) ||
           (ppc.last_melt_serial_id != ppc2.last_melt_serial_id) ||
           (ppc.last_refund_serial_id != ppc2.last_refund_serial_id) ||
           (ppc.last_withdraw_serial_id != ppc2.last_withdraw_serial_id) );

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_reserve_info\n");

  struct TALER_Amount reserve_balance, withdraw_fee_balance;
  struct TALER_Amount reserve_balance2 = {}, withdraw_fee_balance2 = {};

  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":12.345678",
                                         &reserve_balance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":23.456789",
                                         &withdraw_fee_balance));


  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_reserve_info (plugin->cls,
                                       &reserve_pub,
                                       &master_pub,
                                       &reserve_balance,
                                       &withdraw_fee_balance,
                                       past,
                                       "payto://bla/blub"));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_reserve_info\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_reserve_info (plugin->cls,
                                       &reserve_pub,
                                       &master_pub,
                                       &reserve_balance,
                                       &withdraw_fee_balance,
                                       future));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_reserve_info\n");

  char *payto;

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_reserve_info (plugin->cls,
                                    &reserve_pub,
                                    &master_pub,
                                    &rowid,
                                    &reserve_balance2,
                                    &withdraw_fee_balance2,
                                    &date,
                                    &payto));
  FAILIF (0 != strcmp (payto,
                       "payto://bla/blub"));
  GNUNET_free (payto);
  FAILIF (0 != GNUNET_memcmp (&date, &future)
          || 0 != GNUNET_memcmp (&reserve_balance2, &reserve_balance)
          || 0 != GNUNET_memcmp (&withdraw_fee_balance2,
                                 &withdraw_fee_balance));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_reserve_summary\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_reserve_summary (plugin->cls,
                                          &master_pub,
                                          &withdraw_fee_balance,
                                          &reserve_balance));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_reserve_summary\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_reserve_summary (plugin->cls,
                                          &master_pub,
                                          &reserve_balance,
                                          &withdraw_fee_balance));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_reserve_summary\n");

  ZR_BLK (&reserve_balance2);
  ZR_BLK (&withdraw_fee_balance2);

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_reserve_summary (plugin->cls,
                                       &master_pub,
                                       &reserve_balance2,
                                       &withdraw_fee_balance2));

  FAILIF ( (0 != GNUNET_memcmp (&reserve_balance2,
                                &reserve_balance) ||
            (0 != GNUNET_memcmp (&withdraw_fee_balance2,
                                 &withdraw_fee_balance)) ) );

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_denomination_balance\n");

  struct TALER_Amount denom_balance;
  struct TALER_Amount denom_loss;
  struct TALER_Amount denom_loss2;
  struct TALER_Amount deposit_fee_balance;
  struct TALER_Amount melt_fee_balance;
  struct TALER_Amount refund_fee_balance;
  struct TALER_Amount denom_balance2;
  struct TALER_Amount deposit_fee_balance2;
  struct TALER_Amount melt_fee_balance2;
  struct TALER_Amount refund_fee_balance2;
  struct TALER_Amount rbalance;
  struct TALER_Amount rbalance2;
  struct TALER_Amount loss;
  struct TALER_Amount loss2;
  struct TALER_Amount iirp;
  struct TALER_Amount iirp2;
  uint64_t nissued;

  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":12.345678",
                                         &denom_balance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":0.1",
                                         &denom_loss));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":23.456789",
                                         &deposit_fee_balance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":34.567890",
                                         &melt_fee_balance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":45.678901",
                                         &refund_fee_balance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":13.57986",
                                         &rbalance));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":1.6",
                                         &loss));
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":1.1",
                                         &iirp));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_denomination_balance (plugin->cls,
                                               &denom_pub_hash,
                                               &denom_balance,
                                               &denom_loss,
                                               &rbalance,
                                               &loss,
                                               42));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_denomination_balance\n");

  ppc.last_withdraw_serial_id++;
  ppc.last_deposit_serial_id++;
  ppc.last_melt_serial_id++;
  ppc.last_refund_serial_id++;

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_denomination_balance (plugin->cls,
                                               &denom_pub_hash,
                                               &denom_balance,
                                               &denom_loss,
                                               &rbalance,
                                               &loss,
                                               62));
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_denomination_balance\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_denomination_balance (plugin->cls,
                                            &denom_pub_hash,
                                            &denom_balance2,
                                            &denom_loss2,
                                            &rbalance2,
                                            &loss2,
                                            &nissued));

  FAILIF (0 != GNUNET_memcmp (&denom_balance2, &denom_balance));
  FAILIF (0 != GNUNET_memcmp (&denom_loss2, &denom_loss));
  FAILIF (0 != GNUNET_memcmp (&rbalance2, &rbalance));
  FAILIF (62 != nissued);


  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_balance_summary\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_balance_summary (plugin->cls,
                                          &master_pub,
                                          &refund_fee_balance,
                                          &melt_fee_balance,
                                          &deposit_fee_balance,
                                          &denom_balance,
                                          &rbalance,
                                          &loss,
                                          &iirp));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_balance_summary\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_balance_summary (plugin->cls,
                                          &master_pub,
                                          &denom_balance,
                                          &deposit_fee_balance,
                                          &melt_fee_balance,
                                          &refund_fee_balance,
                                          &rbalance,
                                          &loss,
                                          &iirp));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_balance_summary\n");

  ZR_BLK (&denom_balance2);
  ZR_BLK (&deposit_fee_balance2);
  ZR_BLK (&melt_fee_balance2);
  ZR_BLK (&refund_fee_balance2);
  ZR_BLK (&rbalance2);
  ZR_BLK (&loss2);
  ZR_BLK (&iirp2);

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_balance_summary (plugin->cls,
                                       &master_pub,
                                       &denom_balance2,
                                       &deposit_fee_balance2,
                                       &melt_fee_balance2,
                                       &refund_fee_balance2,
                                       &rbalance2,
                                       &loss2,
                                       &iirp2));

  FAILIF ( (0 != GNUNET_memcmp (&denom_balance2,
                                &denom_balance) ) ||
           (0 != GNUNET_memcmp (&deposit_fee_balance2,
                                &deposit_fee_balance) ) ||
           (0 != GNUNET_memcmp (&melt_fee_balance2,
                                &melt_fee_balance) ) ||
           (0 != GNUNET_memcmp (&refund_fee_balance2,
                                &refund_fee_balance)) );
  FAILIF (0 != GNUNET_memcmp (&rbalance2,
                              &rbalance));
  FAILIF (0 != GNUNET_memcmp (&loss2,
                              &loss));
  FAILIF (0 != GNUNET_memcmp (&iirp2,
                              &iirp));


  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_historic_denom_revenue\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_historic_denom_revenue (plugin->cls,
                                                 &master_pub,
                                                 &denom_pub_hash,
                                                 past,
                                                 &rbalance,
                                                 &loss));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_historic_denom_revenue (plugin->cls,
                                                 &master_pub,
                                                 &rnd_hash,
                                                 now,
                                                 &rbalance,
                                                 &loss));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: select_historic_denom_revenue\n");

  int
  select_historic_denom_revenue_result (
    void *cls,
    const struct TALER_DenominationHash *denom_pub_hash2,
    struct GNUNET_TIME_Timestamp revenue_timestamp2,
    const struct TALER_Amount *revenue_balance2,
    const struct TALER_Amount *loss2)
  {
    static int n = 0;

    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "select_historic_denom_revenue_result: row %u\n", n);

    if ((2 <= n++)
        || (cls != NULL)
        || ((0 != GNUNET_memcmp (&revenue_timestamp2, &past))
            && (0 != GNUNET_memcmp (&revenue_timestamp2, &now)))
        || ((0 != GNUNET_memcmp (denom_pub_hash2, &denom_pub_hash))
            && (0 != GNUNET_memcmp (denom_pub_hash2, &rnd_hash)))
        || (0 != GNUNET_memcmp (revenue_balance2, &rbalance))
        || (0 != GNUNET_memcmp (loss2, &loss)))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  "select_historic_denom_revenue_result: result does not match\n");
      GNUNET_break (0);
      return GNUNET_SYSERR;
    }
    return GNUNET_OK;
  }


  FAILIF (0 >=
          plugin->select_historic_denom_revenue (plugin->cls,
                                                 &master_pub,
                                                 &
                                                 select_historic_denom_revenue_result,
                                                 NULL));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_historic_reserve_revenue\n");

  struct TALER_Amount reserve_profits;
  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":56.789012",
                                         &reserve_profits));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_historic_reserve_revenue (plugin->cls,
                                                   &master_pub,
                                                   past,
                                                   future,
                                                   &reserve_profits));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_historic_reserve_revenue (plugin->cls,
                                                   &master_pub,
                                                   now,
                                                   future,
                                                   &reserve_profits));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: select_historic_reserve_revenue\n");

  int
  select_historic_reserve_revenue_result (
    void *cls,
    struct GNUNET_TIME_Timestamp start_time2,
    struct GNUNET_TIME_Timestamp end_time2,
    const struct TALER_Amount *reserve_profits2)
  {
    static int n = 0;

    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "select_historic_reserve_revenue_result: row %u\n", n);

    if ((2 <= n++)
        || (cls != NULL)
        || ((0 != GNUNET_memcmp (&start_time2, &past))
            && (0 != GNUNET_memcmp (&start_time2, &now)))
        || (0 != GNUNET_memcmp (&end_time2, &future))
        || (0 != GNUNET_memcmp (reserve_profits2, &reserve_profits)))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                  "select_historic_reserve_revenue_result: result does not match\n");
      GNUNET_break (0);
      return GNUNET_SYSERR;
    }
    return GNUNET_OK;
  }


  FAILIF (0 >=
          plugin->select_historic_reserve_revenue (plugin->cls,
                                                   &master_pub,
                                                   select_historic_reserve_revenue_result,
                                                   NULL));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: insert_predicted_result\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_predicted_result (plugin->cls,
                                           &master_pub,
                                           &rbalance));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: update_predicted_result\n");

  GNUNET_assert (GNUNET_OK ==
                 TALER_string_to_amount (CURRENCY ":78.901234",
                                         &rbalance));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_predicted_result (plugin->cls,
                                           &master_pub,
                                           &rbalance));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->insert_wire_fee_summary (plugin->cls,
                                           &master_pub,
                                           &rbalance));
  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->update_wire_fee_summary (plugin->cls,
                                           &master_pub,
                                           &reserve_profits));
  {
    struct TALER_Amount rprof;

    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
            plugin->get_wire_fee_summary (plugin->cls,
                                          &master_pub,
                                          &rprof));
    FAILIF (0 !=
            TALER_amount_cmp (&rprof,
                              &reserve_profits));
  }
  FAILIF (0 >
          plugin->commit (plugin->cls));


  FAILIF (GNUNET_OK !=
          plugin->start (plugin->cls));

  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
              "Test: get_predicted_balance\n");

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->get_predicted_balance (plugin->cls,
                                         &master_pub,
                                         &rbalance2));

  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
          plugin->del_reserve_info (plugin->cls,
                                    &reserve_pub,
                                    &master_pub));

  FAILIF (0 != TALER_amount_cmp (&rbalance2,
                                 &rbalance));

  plugin->rollback (plugin->cls);

#if GC_IMPLEMENTED
  FAILIF (GNUNET_OK !=
          plugin->gc (plugin->cls));
#endif

  result = 0;

drop:
  {
    plugin->rollback (plugin->cls);
    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                "Test: auditor_delete_exchange\n");
    GNUNET_break (GNUNET_OK ==
                  plugin->start (plugin->cls));
    GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
                  plugin->delete_exchange (plugin->cls,
                                           &master_pub));
    GNUNET_break (0 <=
                  plugin->commit (plugin->cls));
  }
  GNUNET_break (GNUNET_OK ==
                plugin->drop_tables (plugin->cls,
                                     GNUNET_YES));
unload:
  TALER_AUDITORDB_plugin_unload (plugin);
  plugin = NULL;
}


int
main (int argc,
      char *const argv[])
{
  const char *plugin_name;
  char *config_filename;
  char *testname;
  struct GNUNET_CONFIGURATION_Handle *cfg;

  (void) argc;
  result = -1;
  if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
  {
    GNUNET_break (0);
    return -1;
  }
  GNUNET_log_setup (argv[0],
                    "WARNING",
                    NULL);
  plugin_name++;
  (void) GNUNET_asprintf (&testname,
                          "test-auditor-db-%s", plugin_name);
  (void) GNUNET_asprintf (&config_filename,
                          "%s.conf", testname);
  cfg = GNUNET_CONFIGURATION_create ();
  if (GNUNET_OK !=
      GNUNET_CONFIGURATION_parse (cfg,
                                  config_filename))
  {
    GNUNET_break (0);
    GNUNET_free (config_filename);
    GNUNET_free (testname);
    return 2;
  }
  GNUNET_SCHEDULER_run (&run, cfg);
  GNUNET_CONFIGURATION_destroy (cfg);
  GNUNET_free (config_filename);
  GNUNET_free (testname);
  return result;
}