diff --git a/community_server/src/Controller/AppRequestsController.php b/community_server/src/Controller/AppRequestsController.php index 12ea77d0b..4cefdbd47 100644 --- a/community_server/src/Controller/AppRequestsController.php +++ b/community_server/src/Controller/AppRequestsController.php @@ -273,7 +273,8 @@ class AppRequestsController extends AppController $this->viewBuilder()->setLayout('ajax'); $login_result = $this->requestLogin($session_id, false); if($login_result !== true) { - return $this->returnJson($login_result); + $this->set('body', $login_result); + return; } $session = $this->getRequest()->getSession(); $user = $session->read('StateUser'); @@ -282,16 +283,24 @@ class AppRequestsController extends AppController $state_balance = $state_balances_table->find()->where(['state_user_id' => $user['id']])->first(); - if(!$state_balance) { - return $this->returnJson(['state' => 'success', 'balance' => 0]); - } + $now = new FrozenTime(); - $body = [ - 'state' => 'success', - 'balance' => $state_balance->amount, - 'decay' => $state_balance->partDecay($now), - 'decay_date' => $now - ]; + if(!$state_balance) { + $body = [ + 'state' => 'success', + 'balance' => 0, + 'decay' => 0 + ]; + } else { + + $body = [ + 'state' => 'success', + 'balance' => $state_balance->amount, + 'decay' => $state_balance->partDecay($now), + ]; + } + + $body['decay_date'] = $now; $this->set('body', $body); } @@ -299,35 +308,31 @@ class AppRequestsController extends AppController { $this->viewBuilder()->setLayout('ajax'); $startTime = microtime(true); + $login_result = $this->requestLogin($session_id, false); + if($login_result !== true) { return $this->returnJson($login_result); } $session = $this->getRequest()->getSession(); $user = $session->read('StateUser'); - - + $stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances'); $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); - $stateBalancesTable->updateBalances($user['id']); - + $gdtSum = 0; + $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); - + if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { $gdtSum = intval($gdtEntries['data']['sum']); } else { $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id'] ? $user['id'] : 0); } - $stateUserTransactions_total = $stateUserTransactionsTable - ->find() - ->select(['id']) - ->where(['state_user_id' => $user['id']]) - ->contain([]); $stateUserTransactionsQuery = $stateUserTransactionsTable ->find() @@ -340,17 +345,18 @@ class AppRequestsController extends AppController $decay = true; $transactions = []; $transactions_from_db = $stateUserTransactionsQuery->toArray(); - if($stateUserTransactionsQuery->count() > 0) { + + if(count($transactions_from_db)) { if($orderDirection == 'DESC') { $transactions_from_db = array_reverse($transactions_from_db); } + $transactions = $transactionsTable->listTransactionsHumanReadable($transactions_from_db, $user, $decay); if($orderDirection == 'DESC') { $transactions = array_reverse($transactions); } - - } + } $state_balance = $stateBalancesTable->find()->where(['state_user_id' => $user['id']])->first(); @@ -358,7 +364,7 @@ class AppRequestsController extends AppController 'state' => 'success', 'transactions' => $transactions, 'transactionExecutingCount' => $session->read('Transactions.executing'), - 'count' => $stateUserTransactions_total->count(), + 'count' => $stateUserTransactionsQuery->count(), 'gdtSum' => $gdtSum, 'timeUsed' => microtime(true) - $startTime ]; @@ -372,8 +378,8 @@ class AppRequestsController extends AppController $body['balance'] = $state_balance->amount; $body['decay'] = $stateBalancesTable->calculateDecay($state_balance->amount, $state_balance->record_date, $now); } - - $this->set('body', $body); + + $this->set('body', $body); } private function acquireAccessToken($session_id) diff --git a/community_server/src/Controller/JsonRequestHandlerController.php b/community_server/src/Controller/JsonRequestHandlerController.php index 4013ace9f..65bf48440 100644 --- a/community_server/src/Controller/JsonRequestHandlerController.php +++ b/community_server/src/Controller/JsonRequestHandlerController.php @@ -374,27 +374,21 @@ class JsonRequestHandlerController extends AppController { private function putTransaction($transactionBase64) { $transaction = new Transaction($transactionBase64); - //echo "new transaction\n$transactionBase64\n"; - /*try { - $transactionBin = sodium_base642bin($transactionBase64, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); - $transaction = new Transaction($transactionBin); - } catch(\SodiumException $e) { - //echo 'exception: '. $e->getMessage(); - return $this->returnJson(['state' => 'error', 'msg' => 'error decoding base 64', 'details' => $e->getMessage(), 'base64' => $transactionBase64]); - }*/ - //echo "after new transaction
"; if($transaction->hasErrors()) { $this->sendEMailTransactionFailed($transaction, 'parse'); return $this->returnJson(['state' => 'error', 'msg' => 'error parsing transaction', 'details' => $transaction->getErrors()]); } - //echo "after check on errors
"; + if(!$transaction->validate()) { //$transaction_details $this->sendEMailTransactionFailed($transaction, 'validate'); - return $this->returnJsonSaveError($transaction, ['state' => 'error', 'msg' => 'error validate transaction', 'details' => $transaction->getErrors()]); + return $this->returnJsonSaveError($transaction, [ + 'state' => 'error', + 'msg' => 'error validate transaction', + 'details' => $transaction->getErrors() + ]); } - //echo "after validate
"; if ($transaction->save()) { // success diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index 0dc9b672d..f16ed407b 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -151,35 +151,6 @@ class StateBalancesController extends AppController $this->set('gdtSum', $gdtSum); } - public function ajaxGetBalance($session_id = 0) - { - if(!$session_id) { - return $this->returnJson(['state' => 'error', 'msg' => 'invalid session id']); - } - $login_result = $this->requestLogin($session_id, false); - if($login_result !== true) { - return $this->returnJson($login_result); - } - $session = $this->getRequest()->getSession(); - $user = $session->read('StateUser'); - - $this->StateBalances->updateBalances($user['id']); - - $state_balance = $this->StateBalances->find()->where(['state_user_id' => $user['id']])->first(); - - if(!$state_balance) { - return $this->returnJson(['state' => 'success', 'balance' => 0]); - } - $now = new FrozenTime(); - - return $this->returnJson([ - 'state' => 'success', - 'balance' => $state_balance->amount, - 'decay' => $this->StateBalances->calculateDecay($state_balance->amount, $state_balance->record_date, $now), - 'decay_date' => $now - ]); - } - public function ajaxGdtOverview() { diff --git a/community_server/tests/TestCase/Controller/AppRequestControllerTest.php b/community_server/tests/TestCase/Controller/AppRequestControllerTest.php new file mode 100644 index 000000000..fcf5ad5aa --- /dev/null +++ b/community_server/tests/TestCase/Controller/AppRequestControllerTest.php @@ -0,0 +1,303 @@ +session([ + 'session_id' => $session_id, + 'Transaction' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'id' => 1, + 'email_checked' => 1, + 'public_hex' => 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f' + ] + ]); + + $response = $this->getAndParseWithoutCompare('/api/get-balance/' . $session_id); + $this->assertEquals('success', $response->state); + $this->assertEquals(9100000, $response->balance); + $this->assertLessThan(9100000, $response->decay); + + } + + public function testGetBalance2() + { + $session_id = rand(); + $this->session([ + 'session_id' => $session_id, + 'Transaction' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'id' => 3, + 'email_checked' => 1, + 'public_hex' => '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6' + ] + ]); + + $response = $this->getAndParseWithoutCompare('/api/get-balance/' . $session_id); + $this->assertEquals('success', $response->state); + $this->assertEquals(0, $response->balance); + } + public function testGetBalance3() + { + $session_id = rand(); + $this->session([ + 'session_id' => $session_id, + 'Transaction' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'id' => 4, + 'email_checked' => 1, + 'public_hex' => 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2' + ] + ]); + + $response = $this->getAndParseWithoutCompare('/api/get-balance/' . $session_id); + $this->assertEquals('success', $response->state); + $this->assertEquals(10900000, $response->balance); + $this->assertLessThan(10900000, $response->decay); + } + + public function testGetBalanceInvalidSession() + { + $session_id = rand(); + $this->session([ + 'session_id' => $session_id, + 'Transaction' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'email_checked' => 1, + 'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' + ] + ]); + + $this->getAndParse('/api/get-balance/' . 1211, + ['state' => 'not found', 'msg' => 'invalid session'] + ); + } + + public function testGetBalanceInvalidSessionId() + { + $session_id = rand(); + $this->session([ + 'session_id' => $session_id, + 'Transaction' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'email_checked' => 1, + 'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' + ] + ]); + + $this->getAndParse('/api/get-balance/' , + ['state' => 'not found', 'msg' => 'invalid session'] + ); + } + + /** + * Test ajaxListTransactions method + * + * @return void + */ + public function testListTransactions() + { + //ajaxListTransactions + $session_id = rand(); + $this->session([ + 'session_id' => $session_id, + 'Transactions' => ['pending' => 0, 'executing' => 0], + 'StateUser' => [ + 'id' => 1, + 'first_name' => 'Dario', + 'last_name' => 'Frodo', + 'email_checked' => 1, + 'email' => 'fördertest@gradido.org', + 'public_hex' => '94ae135b93cd9f33752b4e55c41903a3faa13a75bb90bfd411ea1d4a1a5e711f' + ] + ]); + //echo "balance: $balance"; + $expectedResult = '{ + "state": "success", + "transactions": [ + { + "name": "Gradido Akademie", + "type": "creation", + "transaction_id": 2, + "date": "2021-04-12T00:00:00+00:00", + "target_date": "2021-01-01T00:00:00+00:00", + "creation_amount": 10000000, + "balance": 10000000, + "memo": "AGE Januar 2021" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "send", + "transaction_id": 3, + "date": "2021-04-12T00:00:00+00:00", + "balance": 1000000, + "memo": "test", + "pubkey": "e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "send", + "transaction_id": 4, + "date": "2021-04-14T00:00:00+00:00", + "balance": 100000, + "memo": "test time", + "pubkey": "e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "send", + "transaction_id": 5, + "date": "2021-04-14T09:01:07+00:00", + "balance": 100000, + "memo": "test time", + "pubkey": "e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "receive", + "transaction_id": 6, + "date": "2021-04-14T09:02:28+00:00", + "balance": 100000, + "memo": "test time 3", + "pubkey": "0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "receive", + "transaction_id": 7, + "date": "2021-04-14T09:28:46+00:00", + "balance": 100000, + "memo": "test login crash", + "pubkey": "0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "name": "Samuel Schmied", + "email": "test3.yahoo.com", + "type": "receive", + "transaction_id": 8, + "date": "2021-04-14T09:31:28+00:00", + "balance": 100000, + "memo": "test login crash", + "pubkey": "0000000000000000000000000000000000000000000000000000000000000000" + } + ], + "transactionExecutingCount": 0, + "count": 7, + "gdtSum": 180000, + "timeUsed": 0.5575470924377441, + "decay_date": "2021-05-28T09:35:02+00:00", + "balance": 9100000, + "decay": 9100000 +}'; + $this->getAndParse('/api/list-transactions/', json_decode($expectedResult, true)); + } + + + private function getAndParse($path, $expected) + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + + $this->disableErrorHandlerMiddleware(); + $this->get($path); + + // Check that the response was in 2xx - 3xx + $this->assertResponseSuccess(); + $json = (object)$this->viewVariable('body'); + + if(!$json) { + // Check that the response was a 200 + $this->assertResponseOk(); + + $responseBodyString = (string)$this->_response->getBody(); + $json = json_decode($responseBodyString); + $this->assertNotFalse($json); + } else { + $responseBodyString = json_encode($json); + } + + if(is_array($expected)) { + $dynamic_fields = ['timeUsed', 'decay_date', 'decay']; + // copy timeUsed because this value will be variy always + foreach($dynamic_fields as $field) { + if(isset($expected[$field]) && isset($json->$field)) { + $expected[$field] = $json->$field; + } + } + $expected = json_encode($expected); + } + + $this->assertEquals($expected, $responseBodyString); + } + private function getAndParseWithoutCompare($path) + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + + $this->disableErrorHandlerMiddleware(); + $this->get($path); + + // Check that the response was in 2xx - 3xx + $this->assertResponseSuccess(); + $view_body = $this->viewVariable('body'); + if($view_body) { + return (object)$view_body; + } + // Check that the response was a 200 + $this->assertResponseOk(); + $responseBodyString = (string)$this->_response->getBody(); + $json = json_decode($responseBodyString, true); + $this->assertNotFalse($json); + + return $json; + } +} diff --git a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php index e6766129d..b0e2d7253 100644 --- a/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php +++ b/community_server/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php @@ -31,13 +31,12 @@ class JsonRequestHandlerControllerTest extends TestCase ]; public $transactions = [ - 'validCreation' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQJ8wF12eZo3hcMAlAKKJ9WLT-zuSkNmGh7D98UEqH4KoIysnCkXqEya9EBZl9o11_nJ8xmm_nOevuVjR-GfLMQ8qSQoOSGFsbG8gV2VsdCAxMjMSBgiZm4ruBUovCicKIJSuE1uTzZ8zdStOVcQZA6P6oTp1u5C_1BHqHUoaXnEfEKDakwEQtYntlgo', + 'validCreation' => 'CmYKZAog4zad42I86ERtBCTEAT56HXGiZxrj178eeY6_BmXRRfISQDnatUMvitiiP0-sY93JStYPhPKKPU4Vosv_EGrh77BVs48xhPgPj2QHWC3oyuuMh6nN8YNjBQZx20rKvdQ4uwMSRwoMQUdFIE1haSAyMDIxEgYI_c3ChQY6LwolCiD39KSaSsEDefi53ctzHE2exJXm7dFgdfUmcs0l4xefDxDQDxoGCPqbtIQG', 'validCreation900' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQCaZHmvmvJOt336E3qst3rn1pptdAR5ZPzePaUT10x0_Yky8FnEiQtMGNy1yT94QErzwQudJZjJwDY2uyK4cTgkSOxIGCKb1vYUGOjEKJwog4zad42I86ERtBCTEAT56HXGiZxrj178eeY6_BmXRRfIQgNHKCBoGCIDMuf8F', 'validCreation1200' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQF8jptIrosEyVmCf3WEIGVOK0NR8YCcO0j-s8v2yUyR5BKus0ciT6B7IA5LDtn7eQX6zHjg1v5WlsTiZuOpuNgwSRAoHVG8gbXVjaBIGCL3Jv4UGOjEKJwog4zad42I86ERtBCTEAT56HXGiZxrj178eeY6_BmXRRfIQgOy4CxoGCOG5toQG', 'notBase64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3', 'validTransfer' => 'CmYKZAog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8SQA0ZVQ9T1qBabzmgDO1NAWNy2J6mlv0YjMP99CiV7bSR0zemt5XoM-kTviR1aTqKggzpSYSyTN5T6gIx2xa-hgkSYwoLTXkgQmlydGhkYXkSBgie0L-FBjJMCkoKJgog9_SkmkrBA3n4ud3LcxxNnsSV5u3RYHX1JnLNJeMXnw8QgIl6EiDjNp3jYjzoRG0EJMQBPnodcaJnGuPXvx55jr8GZdFF8g', - 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==', - 'creationValid' => 'GmYKZAogLtKKHPXhFtg2FUBrxXcVIiHC93SlZW9moOdUD3V21xsSQHpXYAGiVmSfhjB3o7OPx0ZJuPXrDk5eu1_AOhQBODU3KpUqBRA9yMX54S_mvGijGubCNRcMLcm7wiYbyAG-3AkqSwoQZWluIE1vbmF0c2dlaGFsdBIGCKqs5vEFSi8KJwoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0QgNrECRDKyd3uAQ' + 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==' ]; /*public function setUp() { @@ -132,30 +131,17 @@ class JsonRequestHandlerControllerTest extends TestCase } public function testValidTransfer() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validTransfer']], - ['state' => 'success'] - ); - } - - /*public function testMissingPreviousTransaction() - { - - }*/ - - public function testValidTransaction() - { - $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation']], - ['state' => 'success'] + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validTransfer']], + ['state' => 'success'] ); } - + public function testValidCreation() { $this->postAndParse( - ['method' => 'putTransaction', 'transaction' => $this->transactions['creationValid']], + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation']], ['state' => 'success'] ); } diff --git a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php index cfa6bebc4..9ef8d28e9 100644 --- a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php +++ b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php @@ -69,142 +69,7 @@ class StateBalancesControllerTest extends TestCase $this->markTestIncomplete('Not implemented yet.'); } - /** - * Test ajaxGetBalance method - * - * @return void - */ - public function testAjaxGetBalance1() - { - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'id' => 1, - 'email_checked' => 1, - 'public_hex' => 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f' - ] - ]); - - $response = $this->getAndParseWithoutCompare('/state-balances/ajaxGetBalance/' . $session_id); - - $this->assertEquals('success', $response->state); - $this->assertEquals(7321825, $response->balance); - $this->assertLessThan(7321825, $response->decay); - - } - public function testAjaxGetBalance2() - { - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'id' => 3, - 'email_checked' => 1, - 'public_hex' => '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6' - ] - ]); - - $response = $this->getAndParseWithoutCompare('/state-balances/ajaxGetBalance/' . $session_id); - $this->assertEquals('success', $response->state); - $this->assertEquals(0, $response->balance); - } - public function testAjaxGetBalance3() - { - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'id' => 4, - 'email_checked' => 1, - 'public_hex' => 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2' - ] - ]); - - $response = $this->getAndParseWithoutCompare('/state-balances/ajaxGetBalance/' . $session_id); - $this->assertEquals('success', $response->state); - $this->assertEquals(9112592, $response->balance); - $this->assertLessThan(9112592, $response->decay); - } - - public function testAjaxGetBalanceInvalidSession() - { - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'email_checked' => 1, - 'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' - ] - ]); - //echo "balance: $balance"; - $this->getAndParse('/state-balances/ajaxGetBalance/' . 1211, - ['state' => 'not found', 'msg' => 'invalid session'] - ); - } - - public function testAjaxGetBalanceInvalidSessionId() - { - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'email_checked' => 1, - 'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' - ] - ]); - //echo "balance: $balance"; - $this->getAndParse('/state-balances/ajaxGetBalance' , - ['state' => 'error', 'msg' => 'invalid session id'] - ); - } - - /** - * Test ajaxListTransactions method - * - * @return void - */ - public function testAjaxListTransactions() - { - //ajaxListTransactions - $session_id = rand(); - $this->session([ - 'session_id' => $session_id, - 'Transaction' => ['pending' => 0, 'executing' => 0], - 'StateUser' => [ - 'id' => 1, - 'first_name' => 'Dario', - 'last_name' => 'Frodo', - 'email_checked' => 1, - 'email' => 'fördertest@gradido.org', - 'public_hex' => '94ae135b93cd9f33752b4e55c41903a3faa13a75bb90bfd411ea1d4a1a5e711f' - ] - ]); - //echo "balance: $balance"; - $this->getAndParse('/state-balances/ajaxListTransactions/' . $session_id, - [ - 'state' => 'success', 'transactions' => [[ - 'name' => 'Dario Frodo', - 'email'=> 'dariofrodo@gmx.de', - 'type'=> '', - 'transaction_id' => 4, - 'date' => '2021-02-19T13:27:14+00:00', - 'balance' => 150000001, - 'memo' => '' - ]], - 'transactionExecutingCount' => 0, - 'count' => 1, - 'gdtSum' => 0, - 'timeUsed' => 0.03168010711669922 - ] - ); - } /** * Test overviewGdt method diff --git a/community_server/tests/TestCase/Model/Entity/TableTest.php b/community_server/tests/TestCase/Model/Entity/TableTest.php deleted file mode 100644 index 5a189942a..000000000 --- a/community_server/tests/TestCase/Model/Entity/TableTest.php +++ /dev/null @@ -1,51 +0,0 @@ -Table = new Table(); - } - - /** - * tearDown method - * - * @return void - */ - public function tearDown() - { - unset($this->Table); - - parent::tearDown(); - } - - /** - * Test initial setup - * - * @return void - */ - public function testInitialization() - { - $this->markTestIncomplete('Not implemented yet.'); - } -} diff --git a/community_server/tests/TestCase/Model/Transactions/TransactionCreationTest.php b/community_server/tests/TestCase/Model/Transactions/TransactionCreationTest.php index 60a6307ed..2e62dca0c 100644 --- a/community_server/tests/TestCase/Model/Transactions/TransactionCreationTest.php +++ b/community_server/tests/TestCase/Model/Transactions/TransactionCreationTest.php @@ -31,83 +31,7 @@ class TransactionCreationTest extends TestCase } - public function testHashingFunction() - { - $pairs = [ - "a" => 97, - "b" => 98, - "c" => 99, - "d" => 100, - "aa" => 12513, - "ab" => 12514, - "@" => 64, - ".d" => 5988, - "gmx" => 1701624, - "@gmx" => 135919352, - "@gmx.de" => 3742152099, - "***REMOVED***" => 2928827813, - "***REMOVED***" => 1899591683, - "***REMOVED***" => 2089074830, - "maximilian.muster@gradido.net" => 793144931, - "coin-info5@gradido.net" => 1829129963, - "coin-info6@gradido.net" => 1830178539, - "coin-info8@gradido.net" => 1832275691, - "coin-info9@gradido.net" => 1833324267, - "coin-info10@gradido.net" => 3877298078, - "coin-info11@gradido.net" => 3878346654, - "coin-info12@gradido.net" => 3879395230, - "***REMOVED***" => 2089074830, - "***REMOVED***" => 3996757473, - "***REMOVED***" => 3788634614, - "***REMOVED***" => 807797884, - "***REMOVED***" => 1640973721, - "***REMOVED***" => 2025729173, - "***REMOVED***" => 1961122507, - "***REMOVED***" => 362466358, - "***REMOVED***" => 3796728871, - "***REMOVED***" => 807797884, - "***REMOVED***" => 3794905967, - "***REMOVED***" => 3077694284, - "***REMOVED***" => 3246159770, - "***REMOVED***" => 3123402690, - "testneu-11-12-3@gradido.net" => 4092403827, - "***REMOVED***" => 3151414199, - "***REMOVED***" => 3526188273, - "***REMOVED***" => 966804823, - "***REMOVED***" => 1309273258, - "***REMOVED***" => 995978784, - "***REMOVED***" => 310113324, - "***REMOVED***" => 1309273258, - "***REMOVED***" => 530108573, - "***REMOVED***" => 1734855679, - "***REMOVED***" => 767779182, - "***REMOVED***" => 2247491519, - "***REMOVED***" => 3248626267, - "***REMOVED***" => 3516649930, - "***REMOVED***" => 231214190, - "***REMOVED***" => 4247461928, - "***REMOVED***" => 324829839, - "***REMOVED***" => 3046147747, - "***REMOVED***" => 3207307415, - "***REMOVED***" => 728893500, - "***REMOVED***" => 3905254663, - "***REMOVED***" => 3207307415, - "***REMOVED***" => 1155733239, - "***REMOVED***" => 2013046423, - "***REMOVED***" => 4033835283, - "***REMOVED***" => 1945541625, - "***REMOVED***" => 2310715309, - "***REMOVED***" => 1221362064, - "***REMOVED***" => 4161339877 - ]; - foreach($pairs as $email => $cpp_hash) { - $php_hash = TransactionCreation::DRMakeStringHash($email); - // assertEquals(mixed $expected, mixed $actual[, string $message = '']) - if($php_hash != $cpp_hash) { - $this->assertEquals($cpp_hash, $php_hash, "hashes for $email don't match"); - } - } - } + }