add test data (3x creations, 1 transfer) to test fixtures

This commit is contained in:
Dario Rekowski on RockPI 2021-02-19 13:36:44 +00:00
parent 84d60a111c
commit 0bc355dd99
9 changed files with 384 additions and 34 deletions

View File

@ -263,9 +263,9 @@ return [
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => env('DB_USER', 'root'),
'password' => env('DB_PASSWORD', ''),
'database' => env('DB_DATABASE', 'gradido_community'),
'username' => 'my_app',
'password' => 'secret',
'database' => 'my_app',
/*
* You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
*/
@ -294,7 +294,7 @@ return [
*/
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('MARIADB_URL', null),
'url' => env('DATABASE_URL', null),
],
/**
@ -394,9 +394,14 @@ return [
// Gradido specific configuration
// Login Server ip and port
'LoginServer' => [
'host' => 'login-server',
'host' => 'http://127.0.0.1',
'port' => 1201
],
'API' => [
'allowedCaller' => [''] // insert domains or ips from login-server and gdt if they not at localhost
],
'ServerAdminEmail' => 'info@gradido.net', // email 'from' field for transfer notification emails
'noReplyEmail' => 'no-replay@gradido.net', // email sender for creation notification emails to user
'GroupNode' => false
];

View File

@ -139,13 +139,15 @@ class AppController extends Controller
}
}
protected function requestLogin()
protected function requestLogin($session_id = 0)
{
$session = $this->getRequest()->getSession();
// check login
// disable encryption for cookies
//$this->Cookie->configKey('User', 'encryption', false);
$session_id = intval($this->request->getCookie('GRADIDO_LOGIN', ''));
if(!$session_id) {
$session_id = intval($this->request->getCookie('GRADIDO_LOGIN', ''));
}
$ip = $this->request->clientIp();
if (!$session->check('client_ip')) {
$session->write('client_ip', $ip);

View File

@ -15,7 +15,7 @@ class ServerUsersController extends AppController
public function initialize()
{
parent::initialize();
//$this->Auth->allow(['add', 'edit']);
$this->Auth->allow(['add', 'edit']);
$this->Auth->deny('index');
}

View File

@ -38,6 +38,8 @@ class StateBalancesController extends AppController
$this->set(compact('stateBalances'));
}
public function overview()
{
@ -174,6 +176,154 @@ class StateBalancesController extends AppController
$this->set('timeUsed', microtime(true) - $startTime);
$this->set('gdtSum', $gdtSum);
}
public function ajaxGetBalance($session_id)
{
if(!isset($session_id) || !$session_id) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']);
}
$startTime = microtime(true);
$session = $this->getRequest()->getSession();
$result = $this->requestLogin($session_id);
if ($result !== true) {
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
}
$user = $session->read('StateUser');
return $this->returnJson(['state' => 'success', 'balance' => $session->read('StateUser.balance')]);
}
public function ajaxListTransactions($session_id, $page, $count)
{
if(!isset($session_id) || !$session_id) {
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']);
}
$startTime = microtime(true);
$session = $this->getRequest()->getSession();
$result = $this->requestLogin($session_id);
if ($result !== true) {
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
}
$user = $session->read('StateUser');
$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 {
if($user) {
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']);
} else {
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0);
}
}
$creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations');
$creationTransactions = $creationsTable
->find('all')
->where(['state_user_id' => $user['id']])
->contain(['Transactions']);
$transferTable = TableRegistry::getTableLocator()->get('TransactionSendCoins');
$transferTransactions = $transferTable
->find('all')
->where(['OR' => ['state_user_id' => $user['id'], 'receiver_user_id' => $user['id']]])
->contain(['Transactions']);
$involvedUserIds = [];
foreach ($transferTransactions as $sendCoins) {
//var_dump($sendCoins);
if ($sendCoins->state_user_id != $user['id']) {
array_push($involvedUserIds, intval($sendCoins->state_user_id));
} elseif ($sendCoins->receiver_user_id != $user['id']) {
array_push($involvedUserIds, intval($sendCoins->receiver_user_id));
}
}
/*echo "state user from sendCoins: $sendCoins->state_user_id<br>";
echo "receiver user from sendCoins: $sendCoins->receiver_user_id<br>";
echo "user id from logged in user: ".$user['id']. '<br>';
*/
//var_dump($involvedUserIds);
// exchange key with values and drop duplicates
$involvedUser_temp = array_flip($involvedUserIds);
// exchange back
$involvedUserIds = array_flip($involvedUser_temp);
$userTable = TableRegistry::getTableLocator()->get('StateUsers');
$involvedUser = $userTable->find('all', [
'contain' => false,
'where' => ['id IN' => $involvedUserIds],
'fields' => ['id', 'first_name', 'last_name', 'email']
]);
//var_dump($involvedUser->toArray());
$involvedUserIndices = [];
foreach ($involvedUser as $involvedUser) {
$involvedUserIndices[$involvedUser->id] = $involvedUser;
}
// sender or receiver when user has sended money
// group name if creation
// type: gesendet / empfangen / geschöpft
// transaktion nr / id
// date
// balance
$transactions = [];
foreach ($creationTransactions as $creation) {
//var_dump($creation);
array_push($transactions, [
'name' => 'Gradido Akademie',
'type' => 'creation',
'transaction_id' => $creation->transaction_id,
'date' => $creation->transaction->received,
'balance' => $creation->amount,
'memo' => $creation->transaction->memo
]);
}
foreach ($transferTransactions as $sendCoins) {
$type = '';
$otherUser = null;
if ($sendCoins->state_user_id == $user['id']) {
$type = 'send';
if(isset($involvedUserIndices[$sendCoins->receiver_user_id])) {
$otherUser = $involvedUserIndices[$sendCoins->receiver_user_id];
}
} else if ($sendCoins->receiver_user_id == $user['id']) {
$type = 'receive';
if(isset($involvedUserIndices[$sendCoins->state_user_id])) {
$otherUser = $involvedUserIndices[$sendCoins->state_user_id];
}
}
if(null == $otherUser) {
$otherUser = $this->StateBalances->StateUsers->newEntity();
}
array_push($transactions, [
'name' => $otherUser->first_name . ' ' . $otherUser->last_name,
'email' => $otherUser->email,
'type' => $type,
'transaction_id' => $sendCoins->transaction_id,
'date' => $sendCoins->transaction->received,
'balance' => $sendCoins->amount,
'memo' => $sendCoins->transaction->memo
]);
}
uasort($transactions, array($this, 'sortTransactions'));
return $this->returnJson([
'state' => 'success',
'transactions' => $transactions,
'transactionExecutingCount' => $session->read('Transaction.executing'),
'count' => count($transactions),
'gdtSum' => $gdtSum,
'timeUsed' => microtime(true) - $startTime
]);
}
public function overviewGdt()
{

View File

@ -37,22 +37,31 @@ class TransactionCreationsFixture extends TestFixture
public function init()
{
//(8, 17, 11, 1210000, 0x2d31333636313339343833000000000000000000000000000000000000000000)
// (1, 1, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2020-12-01 00:00:00'),
// (2, 2, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'),
// (3, 3, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2021-02-01 00:00:00');
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'state_user_id' => 11,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('2d31333636313339343833000000000000000000000000000000000000000000')
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 8,
'transaction_id' => 17,
'state_user_id' => 11,
'amount' => 1210000,
'ident_hash' => hex2bin('2d31333636313339343833000000000000000000000000000000000000000000')
'id' => 2,
'transaction_id' => 2,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 3,
'transaction_id' => 3,
'state_user_id' => 2,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
];
parent::init();

View File

@ -38,15 +38,16 @@ class TransactionSendCoinsFixture extends TestFixture
*/
public function init()
{
// (1, 4, 2, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355, 1, 15000000, 15000000);
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'state_user_id' => 1,
'receiver_public_key' => 'Lorem ipsum dolor sit amet',
'receiver_user_id' => 'Lorem ipsum dolor sit amet',
'amount' => 1,
'sender_final_balance' => 1
'transaction_id' => 4,
'state_user_id' => 2,
'receiver_public_key' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355',
'receiver_user_id' => 1,
'amount' => 150000001,
'sender_final_balance' => 15000000
],
];
parent::init();

View File

@ -35,12 +35,34 @@ class TransactionSignaturesFixture extends TestFixture
*/
public function init()
{
// (1, 1, 0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (2, 2, 0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (3, 3, 0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355),
// (4, 4, 0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102, 0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088);
$this->records = [
[
'id' => 1,
'transaction_id' => 1,
'signature' => 'Lorem ipsum dolor sit amet',
'pubkey' => 'Lorem ipsum dolor sit amet'
'signature' => '0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 2,
'transaction_id' => 2,
'signature' => '0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 3,
'transaction_id' => 3,
'signature' => '0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602',
'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'
],
[
'id' => 4,
'transaction_id' => 4,
'signature' => '0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102',
'pubkey' => '0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088'
],
];
parent::init();

View File

@ -36,23 +36,42 @@ class TransactionsFixture extends TestFixture
*/
public function init()
{
//(17, 0, 1, 0x0000000000000000000000000000000000000000000000000000000000000000, '', '2019-11-05 15:13:27');
// (1, NULL, 1, 0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987, 'AGE Dezember 2020', '2021-02-19 13:18:52'),
// (2, NULL, 1, 0xdea38d4dd72af1e0d90621ae8139efbbdb3b44b60be04b0d40cfc157afd2c19c, 'AGE Januar 2021', '2021-02-19 13:25:36'),
// (3, NULL, 1, 0x4e7734ed84dcd8ddc5286b87ff85eb12704092d51f485e7c4dbcb4a68ba296ce, 'AGE Februar 2021', '2021-02-19 13:25:37'),
// (4, NULL, 2, 0x065b5b75b7f4b156fe2b07b54b1a3df0c4eadc40c0f6940c666fed4d75751f8f, 'Ich teile mit dir\r\n \r\nmiau _=', '2021-02-19 13:27:14');
$this->records = [
[
'id' => 1,
'group_id' => 0,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x0000000000000000000000000000000000000000000000000000000000000000',
'memo' => '',
'received' => 1571314633
'tx_hash' => '0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987',
'memo' => 'AGE Dezember 2020',
'received' => '2021-02-19 13:18:52'
],
[
'id' => 17,
'group_id' => 0,
'id' => 2,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x0000000000000000000000000000000000000000000000000000000000000000',
'memo' => '',
'received' => 1572966807
'tx_hash' => '0xdea38d4dd72af1e0d90621ae8139efbbdb3b44b60be04b0d40cfc157afd2c19c',
'memo' => 'AGE Januar 2021',
'received' => '2021-02-19 13:25:36'
],
[
'id' => 3,
'group_id' => NULL,
'transaction_type_id' => 1,
'tx_hash' => '0x4e7734ed84dcd8ddc5286b87ff85eb12704092d51f485e7c4dbcb4a68ba296ce',
'memo' => 'AGE Februar 2021',
'received' => '2021-02-19 13:25:37'
],
[
'id' => 4,
'group_id' => NULL,
'transaction_type_id' => 2,
'tx_hash' => '0x065b5b75b7f4b156fe2b07b54b1a3df0c4eadc40c0f6940c666fed4d75751f8f',
'memo' => 'Ich teile mit dir\r\n \r\nmiau _=',
'received' => '2021-02-19 13:27:14'
],
];
parent::init();

View File

@ -0,0 +1,142 @@
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\StateBalancesController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* App\Controller\StateBalancesController Test Case
*
* @uses \App\Controller\StateBalancesController
*/
class StateBalancesControllerTest extends TestCase
{
use IntegrationTestTrait;
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.TransactionCreations',
'app.Transactions',
'app.StateUsers',
'app.StateErrors',
'app.TransactionSignatures',
'app.TransactionSendCoins',
'app.StateBalances',
'app.TransactionTypes'
];
/**
* Test initialize method
*
* @return void
*/
public function testInitialize()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test index method
*
* @return void
*/
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test overview method
*
* @return void
*/
public function testOverview()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test ajaxGetBalance method
*
* @return void
*/
public function testAjaxGetBalance()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test ajaxListTransactions method
*
* @return void
*/
public function testAjaxListTransactions()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test overviewGdt method
*
* @return void
*/
public function testOverviewGdt()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test sortTransactions method
*
* @return void
*/
public function testSortTransactions()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test view method
*
* @return void
*/
public function testView()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test add method
*
* @return void
*/
public function testAdd()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test edit method
*
* @return void
*/
public function testEdit()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test delete method
*
* @return void
*/
public function testDelete()
{
$this->markTestIncomplete('Not implemented yet.');
}
}