|
From: Pelle B. <pe...@us...> - 2004-03-22 20:20:17
|
Update of /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9416/src/test/org/neuclear/ledger Modified Files: LedgerTest.java Log Message: Added a verified transfer to neuclear-ledger. Added InsufficientFundsException to be thrown if transfer isnt verified. HeldTransfers also are now verified. Index: LedgerTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/LedgerTest.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** LedgerTest.java 21 Mar 2004 00:48:36 -0000 1.11 --- LedgerTest.java 22 Mar 2004 17:33:02 -0000 1.12 *************** *** 16,22 **** * $Id$ * $Log$ * Revision 1.11 2004/03/21 00:48:36 pelle * The problem with Enveloped signatures has now been fixed. It was a problem in the way transforms work. I have bandaided it, but in the future if better support for transforms need to be made, we need to rethink it a bit. Perhaps using the new crypto channel's in neuclear-commons. ! * * Revision 1.10 2004/01/02 23:18:35 pelle * Added StatementFactory pattern and refactored the ledger to use it. --- 16,27 ---- * $Id$ * $Log$ + * Revision 1.12 2004/03/22 17:33:02 pelle + * Added a verified transfer to neuclear-ledger. + * Added InsufficientFundsException to be thrown if transfer isnt verified. + * HeldTransfers also are now verified. + * * Revision 1.11 2004/03/21 00:48:36 pelle * The problem with Enveloped signatures has now been fixed. It was a problem in the way transforms work. I have bandaided it, but in the future if better support for transforms need to be made, we need to rethink it a bit. Perhaps using the new crypto channel's in neuclear-commons. ! * <p/> * Revision 1.10 2004/01/02 23:18:35 pelle * Added StatementFactory pattern and refactored the ledger to use it. *************** *** 170,173 **** --- 175,205 ---- } + public final void testVerifiedTransfer() throws LedgerException { + // Need a positive amount in alice's account + if (ledger.getAvailableBalance(ALICE) < 100) + ledger.transfer("MONEY PRESS", ALICE, -ledger.getAvailableBalance(ALICE) + 100, "FUND"); + final double aliceBalance = ledger.getBalance(ALICE); + final double bobBalance = ledger.getBalance(BOB); + final double amount = 100; + + assertTrue("ALICE has a balance of 100 or more", aliceBalance >= 100); + + ledger.verifiedTransfer(ALICE, BOB, amount, "LOAN"); + assertEquals("ALICE BALANCE", aliceBalance - amount, ledger.getBalance(ALICE), 0); + assertEquals("BOB BALANCE", bobBalance + amount, ledger.getBalance(BOB), 0); + + // Now check that it throws InsufficientFundsException + try { + ledger.verifiedTransfer(ALICE, BOB, ledger.getAvailableBalance(ALICE) + 10, "To much"); + assertTrue("InssuficientFundsException should have been thrown", false); + } catch (InsufficientFundsException e) { + ; + } + + + System.out.println("Alice's Balance: " + ledger.getBalance(ALICE)); + System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); + } + public final void testMultiTransfer() throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException { final double bobBalance = ledger.getBalance(BOB); *************** *** 177,180 **** --- 209,213 ---- cumulative += i; assertEquals("BOB BALANCE", bobBalance + cumulative, ledger.getBalance(BOB), 0); + assertEquals("BOB AVAILABLE BALANCE", ledger.getBalance(BOB), ledger.getAvailableBalance(BOB), 0); } System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); *************** *** 187,190 **** --- 220,225 ---- public final void testHoldAndExpireTransfer() throws LowlevelLedgerException, UnBalancedTransactionException, InvalidTransactionException { + if (ledger.getAvailableBalance(ALICE) < 100) + ledger.transfer("MONEY PRESS", ALICE, -ledger.getAvailableBalance(ALICE) + 100, "FUND"); final double aliceBalance = ledger.getBalance(ALICE); final double bobBalance = ledger.getBalance(BOB); *************** *** 216,222 **** --- 251,261 ---- public final void testHoldAndCancelTransfer() throws LowlevelLedgerException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException { + if (ledger.getAvailableBalance(ALICE) < 100) + ledger.transfer("MONEY PRESS", ALICE, -ledger.getAvailableBalance(ALICE) + 100, "FUND"); final double aliceBalance = ledger.getBalance(ALICE); final double bobBalance = ledger.getBalance(BOB); final double amount = 100; + System.out.println("Alice's Balance: " + ledger.getBalance(ALICE)); + System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); PostedHeldTransaction tran = ledger.hold(ALICE, BOB, new Date(System.currentTimeMillis() + 5000), amount, "LOAN"); *************** *** 240,246 **** --- 279,289 ---- public final void testHoldAndCompleteTransfer() throws LowlevelLedgerException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException, TransactionExpiredException { + if (ledger.getAvailableBalance(ALICE) < 100) + ledger.transfer("MONEY PRESS", ALICE, -ledger.getAvailableBalance(ALICE) + 100, "FUND"); final double aliceBalance = ledger.getBalance(ALICE); final double bobBalance = ledger.getBalance(BOB); final double amount = 100; + System.out.println("Alice's Balance: " + ledger.getBalance(ALICE)); + System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); PostedHeldTransaction tran = ledger.hold(ALICE, BOB, new Date(System.currentTimeMillis() + 5000), amount, "LOAN"); *************** *** 263,266 **** --- 306,330 ---- } + public final void testHoldAndInsufficientFunds() throws LowlevelLedgerException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException { + final double aliceBalance = ledger.getBalance(ALICE); + final double bobBalance = ledger.getBalance(BOB); + final double amount = 100; + System.out.println("Alice's Balance: " + ledger.getBalance(ALICE)); + System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); + + // Now check that it throws InsufficientFundsException + try { + ledger.hold(ALICE, BOB, new Date(System.currentTimeMillis() + 5000), ledger.getAvailableBalance(ALICE) + 10, "To much"); + assertTrue("InssuficientFundsException should have been thrown", false); + } catch (InsufficientFundsException e) { + ; + } + + + System.out.println("Alice's Balance: " + ledger.getBalance(ALICE)); + System.out.println("Bob's Balance: " + ledger.getBalance(BOB)); + } + + protected Ledger ledger; } |