Merge pull request #174 from gradido/community_14_04_21

Community 14.04.21
This commit is contained in:
einhornimmond 2021-04-14 18:08:07 +02:00 committed by GitHub
commit 8fe2cdf4fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 245 additions and 236 deletions

View File

@ -197,7 +197,7 @@ Type::build('timestamp')
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS'); header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: *'); header('Access-Control-Allow-Headers: *');
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
exit(0); exit(0);
} }

View File

@ -65,7 +65,7 @@ Router::scope('/', function (RouteBuilder $routes) {
if($entry == 'ElopageWebhook' || $entry == 'AppRequests') { if($entry == 'ElopageWebhook' || $entry == 'AppRequests') {
return true; return true;
} }
if($request->clientIp() == '127.0.0.1' || $request->clientIp() == 'localhost') { if($request->clientIp() == '127.0.0.1' || $request->clientIp() == 'localhost' || $request->clientIp() == '') {
return true; return true;
} }
$allowedCaller = Configure::read('API.allowedCaller'); $allowedCaller = Configure::read('API.allowedCaller');

View File

@ -4,7 +4,7 @@ CREATE TABLE `transactions` (
`transaction_type_id` int(10) unsigned NOT NULL, `transaction_type_id` int(10) unsigned NOT NULL,
`tx_hash` binary(48) DEFAULT NULL, `tx_hash` binary(48) DEFAULT NULL,
`memo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `memo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`blockchain_type_id` bigint(20) unsigned NOT NULL DEFAULT 1, `blockchain_type_id` bigint(20) unsigned NOT NULL DEFAULT 1,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View File

@ -42,20 +42,20 @@ class StateBalancesController extends AppController
$this->set(compact('stateBalances')); $this->set(compact('stateBalances'));
} }
private function updateBalance($stateUserId) private function updateBalances($stateUserId)
{ {
$stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions');
$transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); $transactionsTable = TableRegistry::getTableLocator()->get('Transactions');
// info: cakephp use lazy loading, query will be executed later only if needed // info: cakephp use lazy loading, query will be executed later only if needed
$state_balances = $this->StateBalances->find('all')->where(['state_user_id' => $stateUserId]); $state_balances = $this->StateBalances->find('all')->where(['state_user_id' => $stateUserId]);
$state_user_transactions = $stateUserTransactionsTable $state_user_transactions = $stateUserTransactionsTable
->find('all') ->find()
->where(['state_user_id' => $stateUserId]) ->where(['state_user_id' => $stateUserId])
->order(['transaction_id ASC']) ->order(['transaction_id ASC'])
->contain(false); //->contain(false);
;
if(!$state_user_transactions || !$state_user_transactions->count()) { if(!$state_user_transactions || !$state_user_transactions->count()) {
//debug($state_user_transactions);
return true; return true;
} }
@ -66,10 +66,12 @@ class StateBalancesController extends AppController
$update_state_balance = false; $update_state_balance = false;
if($state_balances->count() == 0) { if($state_balances->count() == 0) {
$create_state_balance = true; $create_state_balance = true;
$recalculate_state_user_transactions_balance = true;
} }
if($state_balances->count() > 1) { if($state_balances->count() > 1) {
$clear_state_balance = true; $clear_state_balance = true;
$create_state_balance = true; $create_state_balance = true;
$recalculate_state_user_transactions_balance = true;
} }
if($state_balances->count() == 1) { if($state_balances->count() == 1) {
if($state_user_transactions->count() == 0){ if($state_user_transactions->count() == 0){
@ -125,6 +127,7 @@ class StateBalancesController extends AppController
$transaction_ids = []; $transaction_ids = [];
if($recalculate_state_user_transactions_balance) { if($recalculate_state_user_transactions_balance) {
$state_user_transactions_array = $state_user_transactions->toArray(); $state_user_transactions_array = $state_user_transactions->toArray();
foreach($state_user_transactions_array as $i => $state_user_transaction) { foreach($state_user_transactions_array as $i => $state_user_transaction) {
$transaction_ids[$state_user_transaction->transaction_id] = $i; $transaction_ids[$state_user_transaction->transaction_id] = $i;
@ -144,7 +147,7 @@ class StateBalancesController extends AppController
$amount_date = null; $amount_date = null;
$amount = 0; $amount = 0;
if($transaction->transaction_type_id == 1) { if($transaction->transaction_type_id == 1) { // creation
$temp = $transaction->transaction_creations[0]; $temp = $transaction->transaction_creations[0];
$balance_temp = $this->StateBalances->newEntity(); $balance_temp = $this->StateBalances->newEntity();
@ -153,8 +156,10 @@ class StateBalancesController extends AppController
$amount = $balance_temp->partDecay($transaction->received); $amount = $balance_temp->partDecay($transaction->received);
$amount_date = $transaction->received; $amount_date = $transaction->received;
//$amount_date = //$amount_date =
} else if($transaction->transaction_type_id == 2) { } else if($transaction->transaction_type_id == 2) { // transfer
$temp = $transaction->transaction_send_coins[0]; $temp = $transaction->transaction_send_coins[0];
$amount = intval($temp->amount); $amount = intval($temp->amount);
// reverse if sender // reverse if sender
@ -162,18 +167,22 @@ class StateBalancesController extends AppController
$amount *= -1.0; $amount *= -1.0;
} }
$amount_date = $transaction->received; $amount_date = $transaction->received;
} }
if($i == 0) { if($i == 0) {
$balance_cursor->amount = $amount; $balance_cursor->amount = $amount;
} else { } else {
$balance_cursor->amount = $balance_cursor->partDecay($amount_date) + $amount; $balance_cursor->amount = $balance_cursor->partDecay($amount_date) + $amount;
} }
$balance_cursor->record_date = $amount_date; $balance_cursor->record_date = $amount_date;
$state_user_transaction_index = $transaction_ids[$transaction->id]; $state_user_transaction_index = $transaction_ids[$transaction->id];
$state_user_transactions_array[$state_user_transaction_index]->balance = $balance_cursor->amount; $state_user_transactions_array[$state_user_transaction_index]->balance = $balance_cursor->amount;
$state_user_transactions_array[$state_user_transaction_index]->balance_date = $balance_cursor->record_date; $state_user_transactions_array[$state_user_transaction_index]->balance_date = $balance_cursor->record_date;
$i++; $i++;
} }
$results = $stateUserTransactionsTable->saveMany($state_user_transactions_array); $results = $stateUserTransactionsTable->saveMany($state_user_transactions_array);
$errors = []; $errors = [];
foreach($results as $i => $result) { foreach($results as $i => $result) {
@ -221,7 +230,7 @@ class StateBalancesController extends AppController
} }
$user = $session->read('StateUser'); $user = $session->read('StateUser');
$update_balance_result = $this->updateBalance($user['id']); $update_balance_result = $this->updateBalances($user['id']);
if($update_balance_result !== true) { if($update_balance_result !== true) {
$this->addAdminError('StateBalances', 'overview', $update_balance_result, $user['id']); $this->addAdminError('StateBalances', 'overview', $update_balance_result, $user['id']);
} }
@ -446,36 +455,21 @@ class StateBalancesController extends AppController
} }
$session = $this->getRequest()->getSession(); $session = $this->getRequest()->getSession();
$user = $session->read('StateUser'); $user = $session->read('StateUser');
$this->updateBalances($user['id']); $this->updateBalances($user['id']);
$public_key_bin = hex2bin($user['public_hex']); $state_balance = $this->StateBalances->find()->where(['state_user_id' => $user['id']])->first();
$stateUserQuery = $this->StateBalances->StateUsers
->find('all')
->where(['public_key' => $public_key_bin])
->contain(['StateBalances']);
$result_user_count = $stateUserQuery->count(); if(!$state_balance) {
if($result_user_count < 1) {
return $this->returnJson(['state' => 'success', 'balance' => 0]); return $this->returnJson(['state' => 'success', 'balance' => 0]);
} }
else if($result_user_count > 1) {
return $this->returnJson([ return $this->returnJson([
'state' => 'error', 'state' => 'success',
'msg' => 'multiple entrys found', 'balance' => $state_balance->amount,
'details' => ['public_key' => $user['public_hex'], 'entry_count' => $result_count] 'decay' => $state_balance->decay
]); ]);
} }
$state_balances = $stateUserQuery->first()->state_balances;
$state_balances_count = count($state_balances);
if($state_balances_count > 1) {
return $this->returnJson(['state' => 'error', 'msg' => 'state balances count isn\'t as expected, expect 1 or 0', 'details' => $state_balances_count]);
}
if(!$state_balances_count) {
return $this->returnJson(['state' => 'success', 'balance' => 0]);
}
return $this->returnJson(['state' => 'success', 'balance' => $state_balances[0]->amount]);
}
public function ajaxListTransactions($session_id, $page, $count) public function ajaxListTransactions($session_id, $page, $count)

View File

@ -44,7 +44,7 @@ class StateBalance extends Entity
return $dateOrTime->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); return $dateOrTime->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT);
} else { } else {
var_dump($dateOrTime); var_dump($dateOrTime);
debug_print_backtrace(0, 4); debug_print_backtrace(0, 6);
die("date or time unexpected object"); die("date or time unexpected object");
} }
} }

View File

@ -148,6 +148,13 @@ class Transaction extends TransactionBase {
if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) { if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) {
$this->addErrors($this->mTransactionBody->getErrors()); $this->addErrors($this->mTransactionBody->getErrors());
$connection->rollback(); $connection->rollback();
// correct auto-increment value to prevent gaps
$transactionsTable = $this->getTable('transactions');
$transactions = $transactionsTable->find()->select(['id'])->contain(false);
$count = $transactions->count();
$connection = ConnectionManager::get('default');
$connection->execute("ALTER TABLE `transactions` auto_increment = $count;");
return false; return false;
} }

View File

@ -76,9 +76,10 @@ class TransactionBody extends TransactionBase {
$transactionEntity->transaction_type_id = $this->transactionTypeId; $transactionEntity->transaction_type_id = $this->transactionTypeId;
$transactionEntity->memo = $this->getMemo(); $transactionEntity->memo = $this->getMemo();
$transactionEntity->received = new Date();
if ($transactionsTable->save($transactionEntity)) { if ($transactionsTable->save($transactionEntity)) {
// reload entity to get received date filled from mysql
$transactionEntity = $transactionsTable->get($transactionEntity->id);
// success // success
$this->mTransactionID = $transactionEntity->id; $this->mTransactionID = $transactionEntity->id;
if(!$this->mSpecificTransaction->save($transactionEntity->id, $firstPublic, $transactionEntity->received)) { if(!$this->mSpecificTransaction->save($transactionEntity->id, $firstPublic, $transactionEntity->received)) {

View File

@ -0,0 +1,36 @@
<?php
namespace App\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class BaseTestFixture extends TestFixture
{
// after copy from sql export, replace all hex values to hex strings with regExp (z.B. within Netbeans)
// 0x([0-9a-f]*) => '$1'
protected function sqlEntrysToRecords($sql_entries, $fields) {
$field_array_keys = array_keys($fields);
$records = [];
foreach($sql_entries as $sql_entry) {
$record = [];
foreach($sql_entry as $i => $value) {
$field = $field_array_keys[$i];
if($fields[$field]['type'] == 'binary') {
if(is_string($value)) {
$record[$field] = hex2bin($value);
}
} else {
$record[$field] = $value;
}
}
$records[] = $record;
}
return $records;
}
}

View File

@ -15,16 +15,17 @@ class StateBalancesFixture extends TestFixture
*/ */
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
public $fields = [ public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => true], 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'state_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'state_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'modified' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'modified' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'record_date' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
], ],
'_options' => [ '_options' => [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'collation' => 'utf8_bin' 'collation' => 'utf8mb4_unicode_ci'
], ],
]; ];
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
@ -36,18 +37,6 @@ class StateBalancesFixture extends TestFixture
public function init() public function init()
{ {
$this->records = [ $this->records = [
[
'id' => 1,
'state_user_id' => 1,
'modified' => '2019-11-05 18:02:28',
'amount' => 1200
],
[
'id' => 10,
'state_user_id' => 4,
'modified' => '2019-11-11 14:58:54',
'amount' => 1200000
]
]; ];
parent::init(); parent::init();
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* StateUserTransactionsFixture * StateUserTransactionsFixture
*/ */
class StateUserTransactionsFixture extends TestFixture class StateUserTransactionsFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -19,6 +19,8 @@ class StateUserTransactionsFixture extends TestFixture
'state_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'state_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'transaction_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'transaction_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'transaction_type_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'transaction_type_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'balance' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'balance_date' => ['type' => 'timestamp', 'length' => null, 'null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '', 'precision' => null],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
], ],
@ -35,14 +37,23 @@ class StateUserTransactionsFixture extends TestFixture
*/ */
public function init() public function init()
{ {
$this->records = [ $sql = [
[ [1, 4, 1, 1, 0, '2021-04-09 00:00:00'],
'id' => 1, [2, 1, 2, 1, 0, '2021-04-12 00:00:00'],
'state_user_id' => 1, [5, 1, 3, 2, 0, '2021-04-12 00:00:00'],
'transaction_id' => 1, [6, 4, 3, 2, 0, '2021-04-12 00:00:00'],
'transaction_type_id' => 1, [7, 1, 4, 2, 0, '2021-04-14 00:00:00'],
], [8, 4, 4, 2, 0, '2021-04-14 00:00:00'],
[23, 1, 5, 2, 0, '2021-04-14 09:01:07'],
[24, 4, 5, 2, 0, '2021-04-14 09:01:07'],
[25, 4, 6, 2, 0, '2021-04-14 09:02:28'],
[26, 1, 6, 2, 0, '2021-04-14 09:02:28'],
[27, 4, 7, 2, 0, '2021-04-14 09:28:46'],
[28, 1, 7, 2, 0, '2021-04-14 09:28:46'],
[29, 4, 8, 2, 0, '2021-04-14 09:31:28'],
[30, 1, 8, 2, 0, '2021-04-14 09:31:28']
]; ];
$this->records = $this->sqlEntrysToRecords($sql, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* StateUsersFixture * StateUsersFixture
*/ */
class StateUsersFixture extends TestFixture class StateUsersFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -15,22 +15,26 @@ class StateUsersFixture extends TestFixture
*/ */
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
public $fields = [ public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null],
'group_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'group_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], 'email' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], 'first_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], 'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'disabled' => ['type' => 'tinyinteger', 'length' => 4, 'unsigned' => false, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []], 'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []],
], ],
'_options' => [ '_options' => [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'collation' => 'utf8_bin' 'collation' => 'utf8mb4_unicode_ci'
], ],
]; ];
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
/** /**
* Init method * Init method
@ -39,35 +43,12 @@ class StateUsersFixture extends TestFixture
*/ */
public function init() public function init()
{ {
$this->records = [ $sql_entrys = [
[ [1, 0, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0],
'id' => 1, [3, 0, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0],
'index_id' => 0, [4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0]
'group_id' => 0,
'public_key' => hex2bin('94ae135b93cd9f33752b4e55c41903a3faa13a75bb90bfd411ea1d4a1a5e711f'),
'email' => '***REMOVED***',
'first_name' => 'Dario',
'last_name' => 'Rekowski'
],
[
'id' => 4,
'index_id' => 0,
'group_id' => 0,
'public_key' => hex2bin('8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d'),
'email' => 'dariofrodo@gmx.de',
'first_name' => 'Dario',
'last_name' => 'Frodo'
],
[
'id' => 11,
'index_id' => 0,
'group_id' => 0,
'public_key' => hex2bin('61b923c218cb63a64a8c62f3860121283b9577f374d0a31590ba02cdc2912999'),
'email' => 'em741@gmx.de',
'first_name' => 'Dario',
'last_name' => 'Rekowski'
],
]; ];
$this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* TransactionCreationsFixture * TransactionCreationsFixture
*/ */
class TransactionCreationsFixture extends TestFixture class TransactionCreationsFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -15,17 +15,18 @@ class TransactionCreationsFixture extends TestFixture
*/ */
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
public $fields = [ public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'transaction_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'transaction_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'state_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'state_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'ident_hash' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'ident_hash' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'target_date' => ['type' => 'timestamp', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
], ],
'_options' => [ '_options' => [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'collation' => 'utf8_bin' 'collation' => 'utf8mb4_unicode_ci'
], ],
]; ];
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
@ -36,34 +37,11 @@ class TransactionCreationsFixture extends TestFixture
*/ */
public function init() public function init()
{ {
$sql = [
// (1, 1, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2020-12-01 00:00:00'), [2, 1, 4, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '2021-01-01 00:00:00'],
// (2, 2, 2, 10000000, 0x3235303332373635330000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'), [3, 2, 1, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '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' => 1,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 2,
'transaction_id' => 2,
'state_user_id' => 1,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
[
'id' => 3,
'transaction_id' => 3,
'state_user_id' => 1,
'amount' => 10000000,
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
],
]; ];
$this->records = $this->sqlEntrysToRecords($sql, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* TransactionSendCoinsFixture * TransactionSendCoinsFixture
*/ */
class TransactionSendCoinsFixture extends TestFixture class TransactionSendCoinsFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -15,11 +15,12 @@ class TransactionSendCoinsFixture extends TestFixture
*/ */
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
public $fields = [ public $fields = [
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'transaction_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'transaction_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'state_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'sender_public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'state_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'receiver_public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'receiver_public_key' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
'receiver_user_id' => ['type' => 'binary', 'length' => 64, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'receiver_user_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => true, 'default' => '0', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'amount' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'sender_final_balance' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'sender_final_balance' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'_constraints' => [ '_constraints' => [
@ -27,7 +28,7 @@ class TransactionSendCoinsFixture extends TestFixture
], ],
'_options' => [ '_options' => [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'collation' => 'utf8_bin' 'collation' => 'utf8mb4_unicode_ci'
], ],
]; ];
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
@ -38,18 +39,16 @@ class TransactionSendCoinsFixture extends TestFixture
*/ */
public function init() public function init()
{ {
// (1, 4, 2, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355, 1, 15000000, 15000000); $sql = [
$this->records = [ [2, 3, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 1000000, 6254699],
[ [3, 4, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 7027197],
'id' => 1, [11, 5, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 6922113],
'transaction_id' => 4, [12, 6, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9212951],
'state_user_id' => 1, [13, 7, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9112627],
'receiver_public_key' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d', [14, 8, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 8912594]
'receiver_user_id' => 4,
'amount' => 15000000,
'sender_final_balance' => 15000000
],
]; ];
$this->records = $this->sqlEntrysToRecords($sql, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* TransactionSignaturesFixture * TransactionSignaturesFixture
*/ */
class TransactionSignaturesFixture extends TestFixture class TransactionSignaturesFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -35,36 +35,17 @@ class TransactionSignaturesFixture extends TestFixture
*/ */
public function init() public function init()
{ {
// (1, 1, 0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355), $sql = [
// (2, 2, 0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355), [1, 1, '1c5357f9438f700a5378abadd0dbd74d90e335c6b9691bb9e126520813f3218573b19226382efb89aa8444a9ca98c2e8933463335baac37baf2f4eecd990600a', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'],
// (3, 3, 0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355), [2, 2, '5215376ae7fb989993e3466961636519d4ade77b3bde066149ade028ad54a1a88ca8a206fcf09f52839ae0ed37b99df08ec9af12f3f37197979a206489e3ff0f', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'],
// (4, 4, 0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102, 0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088); [3, 3, 'c70f124feaaea02194d22a5f597963ed3e430343122a0952877854766fe37a709f92b39510de2aae494ef11abe743cd59f08f971b1e0e36f4c333990453d8b0d', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'],
$this->records = [ [4, 4, 'a65b39e51ab6191c51d5629bbcefd30f85f801efbb14e1c635c519e97abe217a248820fa1fc6aef56227c9d888c1919bc92471d5d7ae3522c9c50fba9f0d8402', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'],
[ [5, 5, 'a65b39e51ab6191c51d5629bbcefd30f85f801efbb14e1c635c519e97abe217a248820fa1fc6aef56227c9d888c1919bc92471d5d7ae3522c9c50fba9f0d8402', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'],
'id' => 1, [6, 6, 'c233726674bff9bfb8ccb98bf358c6bc701825d971ece915d3c3a3de98886d1d13ee2f773cd9fc4ccbe543ac17be0d780ebead23a0dbf4ec814f7bae2efb9c0e', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'],
'transaction_id' => 1, [7, 7, '83ab780535883ec53ee76d0f68db0e1596418c9e100c806a4d4655d4dedf589d54a6319a2795dabab301e212b52f0dafb2725b7583447f19e47cb417d188a107', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'],
'signature' => '0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705', [8, 8, '83ab780535883ec53ee76d0f68db0e1596418c9e100c806a4d4655d4dedf589d54a6319a2795dabab301e212b52f0dafb2725b7583447f19e47cb417d188a107', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2']
'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'
],
]; ];
$this->records = $this->sqlEntrysToRecords($sql, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture;
/** /**
* TransactionsFixture * TransactionsFixture
*/ */
class TransactionsFixture extends TestFixture class TransactionsFixture extends BaseTestFixture
{ {
/** /**
* Fields * Fields
@ -15,17 +15,19 @@ class TransactionsFixture extends TestFixture
*/ */
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
public $fields = [ public $fields = [
'id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null],
'state_group_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'state_group_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'transaction_type_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], 'transaction_type_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'tx_hash' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], 'tx_hash' => ['type' => 'binary', 'length' => 48, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
'memo' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_unicode_ci', 'comment' => '', 'precision' => null, 'fixed' => null],
'received' => ['type' => 'timestamp', 'length' => null, 'null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '', 'precision' => null], 'received' => ['type' => 'timestamp', 'length' => null, 'null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '', 'precision' => null],
'blockchain_type_id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => true, 'null' => false, 'default' => '1', 'comment' => '', 'precision' => null, 'autoIncrement' => null],
'_constraints' => [ '_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
], ],
'_options' => [ '_options' => [
'engine' => 'InnoDB', 'engine' => 'InnoDB',
'collation' => 'utf8_bin' 'collation' => 'utf8mb4_unicode_ci'
], ],
]; ];
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
@ -36,44 +38,17 @@ class TransactionsFixture extends TestFixture
*/ */
public function init() public function init()
{ {
// (1, NULL, 1, 0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987, 'AGE Dezember 2020', '2021-02-19 13:18:52'), $sql = [
// (2, NULL, 1, 0xdea38d4dd72af1e0d90621ae8139efbbdb3b44b60be04b0d40cfc157afd2c19c, 'AGE Januar 2021', '2021-02-19 13:25:36'), [1, NULL, 1, '15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000', 'AGE Januar 2021', '2021-04-09 00:00:00', 1],
// (3, NULL, 1, 0x4e7734ed84dcd8ddc5286b87ff85eb12704092d51f485e7c4dbcb4a68ba296ce, 'AGE Februar 2021', '2021-02-19 13:25:37'), [2, NULL, 1, 'f932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000', 'AGE Januar 2021', '2021-04-12 00:00:00', 1],
// (4, NULL, 2, 0x065b5b75b7f4b156fe2b07b54b1a3df0c4eadc40c0f6940c666fed4d75751f8f, 'Ich teile mit dir\r\n \r\nmiau _=', '2021-02-19 13:27:14'); [3, NULL, 2, '4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000', 'test', '2021-04-12 00:00:00', 1],
$this->records = [ [4, NULL, 2, 'fc6e69696beb7c56ad7c511fc3999f954411427bec810184b70c092911deae1900000000000000000000000000000000', 'test time', '2021-04-14 00:00:00', 1],
[ [5, NULL, 2, 'a7149ebc0d6cd8c061906dafe05e13689b51642a41100d0ec7bb6cd2dcafdc1800000000000000000000000000000000', 'test time', '2021-04-14 09:01:07', 1],
'id' => 1, [6, NULL, 2, '2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000', 'test time 3', '2021-04-14 09:02:28', 1],
'group_id' => NULL, [7, NULL, 2, 'c2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000', 'test login crash', '2021-04-14 09:28:46', 1],
'transaction_type_id' => 1, [8, NULL, 2, '5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000', 'test login crash', '2021-04-14 09:31:28', 1]
'tx_hash' => '0x7dc55cf3a1a39b441d87d5452c40cad8e7fd8aab573ed1da0bf118129fc77987',
'memo' => 'AGE Dezember 2020',
'received' => '2021-02-19 13:18:52'
],
[
'id' => 2,
'group_id' => NULL,
'transaction_type_id' => 1,
'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'
],
]; ];
$this->records = $this->sqlEntrysToRecords($sql, $this->fields);
parent::init(); parent::init();
} }
} }

View File

@ -3,6 +3,9 @@ namespace App\Test\TestCase\Controller;
use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
use Cake\ORM\TableRegistry;
use Cake\I18n\Time;
/** /**
* App\Controller\StateBalancesController Test Case * App\Controller\StateBalancesController Test Case
@ -22,6 +25,7 @@ class StateBalancesControllerTest extends TestCase
'app.TransactionCreations', 'app.TransactionCreations',
'app.Transactions', 'app.Transactions',
'app.StateUsers', 'app.StateUsers',
'app.StateUserTransactions',
'app.StateErrors', 'app.StateErrors',
'app.TransactionSignatures', 'app.TransactionSignatures',
'app.TransactionSendCoins', 'app.TransactionSendCoins',
@ -29,6 +33,12 @@ class StateBalancesControllerTest extends TestCase
'app.TransactionTypes' 'app.TransactionTypes'
]; ];
public function setUp()
{
parent::setUp();
$this->StateBalances = TableRegistry::getTableLocator()->get('StateBalances');
}
/** /**
* Test initialize method * Test initialize method
* *
@ -64,7 +74,7 @@ class StateBalancesControllerTest extends TestCase
* *
* @return void * @return void
*/ */
public function testAjaxGetBalance() public function testAjaxGetBalance1()
{ {
$session_id = rand(); $session_id = rand();
$this->session([ $this->session([
@ -73,13 +83,52 @@ class StateBalancesControllerTest extends TestCase
'StateUser' => [ 'StateUser' => [
'id' => 1, 'id' => 1,
'email_checked' => 1, 'email_checked' => 1,
'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' 'public_hex' => 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'
] ]
]); ]);
//echo "balance: $balance";
$this->getAndParse('/state-balances/ajaxGetBalance/' . $session_id, $response = $this->getAndParseWithoutCompare('/state-balances/ajaxGetBalance/' . $session_id);
['state' => 'success', 'balance' => 1200000]
); $this->assertEquals('success', $response->state);
$this->assertEquals(7321828, $response->balance);
$this->assertLessThan(7321828, $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(9112595, $response->balance);
$this->assertLessThan(9112595, $response->decay);
} }
public function testAjaxGetBalanceInvalidSession() public function testAjaxGetBalanceInvalidSession()
@ -242,7 +291,24 @@ class StateBalancesControllerTest extends TestCase
$expected = json_encode($expected); $expected = json_encode($expected);
} }
$this->assertEquals($expected, $responseBodyString); $this->assertEquals($expected, $responseBodyString);
} }
private function getAndParseWithoutCompare($path)
{
$this->configRequest([
'headers' => ['Accept' => 'application/json']
]);
$this->disableErrorHandlerMiddleware();
$this->get($path);
// Check that the response was a 200
$this->assertResponseOk();
$responseBodyString = (string)$this->_response->getBody();
$json = json_decode($responseBodyString);
$this->assertNotFalse($json);
return $json;
}
} }

View File

@ -120,14 +120,5 @@ class StateBalancesTableTest extends TestCase
{ {
$this->markTestIncomplete('Not implemented yet.'); $this->markTestIncomplete('Not implemented yet.');
} }
/*
* calculate balance at end of month
* work only if state balance at begin of month exist
* use transaction_send_coins and transaction_creations
*/
//public function updateLastStateBalanceOfMonth($month, $year, $state_user_id)
public function testUpdateLastStateBalanceOfMonth()
{
}
} }