From 108bce351925634795f037409e3e087a1d315914 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 09:04:07 +0000 Subject: [PATCH 01/16] correct auto-increment basis for id in transactions --- community_server/src/Model/Transactions/TransactionBody.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/community_server/src/Model/Transactions/TransactionBody.php b/community_server/src/Model/Transactions/TransactionBody.php index e0d688dbb..87a029b80 100644 --- a/community_server/src/Model/Transactions/TransactionBody.php +++ b/community_server/src/Model/Transactions/TransactionBody.php @@ -76,9 +76,10 @@ class TransactionBody extends TransactionBase { $transactionEntity->transaction_type_id = $this->transactionTypeId; $transactionEntity->memo = $this->getMemo(); - $transactionEntity->received = new Date(); if ($transactionsTable->save($transactionEntity)) { + // reload entity to get received date filled from mysql + $transactionEntity = $transactionsTable->get($transactionEntity->id); // success $this->mTransactionID = $transactionEntity->id; if(!$this->mSpecificTransaction->save($transactionEntity->id, $firstPublic, $transactionEntity->received)) { From 892f7e98bfc95ac6a0d03bb7956eeeef8a1c2482 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 09:12:08 +0000 Subject: [PATCH 02/16] fix wrong commited file --- community_server/src/Model/Transactions/Transaction.php | 7 +++++++ .../src/Model/Transactions/TransactionBody.php | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/community_server/src/Model/Transactions/Transaction.php b/community_server/src/Model/Transactions/Transaction.php index da21495b9..21beb1d31 100644 --- a/community_server/src/Model/Transactions/Transaction.php +++ b/community_server/src/Model/Transactions/Transaction.php @@ -148,6 +148,13 @@ class Transaction extends TransactionBase { if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) { $this->addErrors($this->mTransactionBody->getErrors()); $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; } diff --git a/community_server/src/Model/Transactions/TransactionBody.php b/community_server/src/Model/Transactions/TransactionBody.php index 87a029b80..e0d688dbb 100644 --- a/community_server/src/Model/Transactions/TransactionBody.php +++ b/community_server/src/Model/Transactions/TransactionBody.php @@ -76,10 +76,9 @@ class TransactionBody extends TransactionBase { $transactionEntity->transaction_type_id = $this->transactionTypeId; $transactionEntity->memo = $this->getMemo(); + $transactionEntity->received = new Date(); if ($transactionsTable->save($transactionEntity)) { - // reload entity to get received date filled from mysql - $transactionEntity = $transactionsTable->get($transactionEntity->id); // success $this->mTransactionID = $transactionEntity->id; if(!$this->mSpecificTransaction->save($transactionEntity->id, $firstPublic, $transactionEntity->received)) { From 7e60084c89f97a4f115dd387bebee1a53ab77393 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 09:13:53 +0000 Subject: [PATCH 03/16] fix received time to filled in by db --- community_server/src/Model/Transactions/TransactionBody.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/community_server/src/Model/Transactions/TransactionBody.php b/community_server/src/Model/Transactions/TransactionBody.php index e0d688dbb..87a029b80 100644 --- a/community_server/src/Model/Transactions/TransactionBody.php +++ b/community_server/src/Model/Transactions/TransactionBody.php @@ -76,9 +76,10 @@ class TransactionBody extends TransactionBase { $transactionEntity->transaction_type_id = $this->transactionTypeId; $transactionEntity->memo = $this->getMemo(); - $transactionEntity->received = new Date(); if ($transactionsTable->save($transactionEntity)) { + // reload entity to get received date filled from mysql + $transactionEntity = $transactionsTable->get($transactionEntity->id); // success $this->mTransactionID = $transactionEntity->id; if(!$this->mSpecificTransaction->save($transactionEntity->id, $firstPublic, $transactionEntity->received)) { From a444e44e72d003a109cc5460f436da89258fcacf Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 09:18:06 +0000 Subject: [PATCH 04/16] fix wrongly commited filed --- community_server/src/Model/Transactions/Transaction.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/community_server/src/Model/Transactions/Transaction.php b/community_server/src/Model/Transactions/Transaction.php index 21beb1d31..53ddaa480 100644 --- a/community_server/src/Model/Transactions/Transaction.php +++ b/community_server/src/Model/Transactions/Transaction.php @@ -148,12 +148,6 @@ class Transaction extends TransactionBase { if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) { $this->addErrors($this->mTransactionBody->getErrors()); $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; } From afc01fd9f425e9f4d59fd22b61423ade247ed75d Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 09:21:41 +0000 Subject: [PATCH 05/16] put back change for other file --- community_server/src/Model/Transactions/Transaction.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/community_server/src/Model/Transactions/Transaction.php b/community_server/src/Model/Transactions/Transaction.php index 53ddaa480..21beb1d31 100644 --- a/community_server/src/Model/Transactions/Transaction.php +++ b/community_server/src/Model/Transactions/Transaction.php @@ -148,6 +148,12 @@ class Transaction extends TransactionBase { if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) { $this->addErrors($this->mTransactionBody->getErrors()); $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; } From 57144956b5436d4bf2fafd1bd394d0ce2a4ae7e7 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 10:00:44 +0000 Subject: [PATCH 06/16] add function for easy filling test fixtures with datas from db (export) --- .../tests/Fixture/BaseTestFixture.php | 28 ++++++++++ .../tests/Fixture/StateUsersFixture.php | 53 ++++++------------- 2 files changed, 45 insertions(+), 36 deletions(-) create mode 100644 community_server/tests/Fixture/BaseTestFixture.php diff --git a/community_server/tests/Fixture/BaseTestFixture.php b/community_server/tests/Fixture/BaseTestFixture.php new file mode 100644 index 000000000..33375aab0 --- /dev/null +++ b/community_server/tests/Fixture/BaseTestFixture.php @@ -0,0 +1,28 @@ + $value) { + $field = $field_array_keys[$i]; + $record[$field] = $value; + } + $records[] = $record; + } + } +} \ No newline at end of file diff --git a/community_server/tests/Fixture/StateUsersFixture.php b/community_server/tests/Fixture/StateUsersFixture.php index 04654dea9..80da262db 100644 --- a/community_server/tests/Fixture/StateUsersFixture.php +++ b/community_server/tests/Fixture/StateUsersFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * StateUsersFixture */ -class StateUsersFixture extends TestFixture +class StateUsersFixture extends BaseTestFixture { /** * Fields @@ -15,22 +15,26 @@ class StateUsersFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], - 'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], - 'group_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], + 'index_id' => ['type' => 'smallinteger', 'length' => 6, 'unsigned' => false, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => 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], - 'email' => ['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' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], - 'last_name' => ['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' => 'utf8mb4_unicode_ci', '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' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], 'public_key' => ['type' => 'unique', 'columns' => ['public_key'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; + + // @codingStandardsIgnoreEnd /** * Init method @@ -39,35 +43,12 @@ class StateUsersFixture extends TestFixture */ public function init() { - $this->records = [ - [ - 'id' => 1, - 'index_id' => 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' - ], + $sql_entrys = [ + [1, 0, 0, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], + [3, 0, 0, 0x131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6, 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], + [4, 0, 0, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] ]; + $this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields); parent::init(); } } From 4690192a71f8b720d463fc7c29b6dd84d8145add Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 10:04:17 +0000 Subject: [PATCH 07/16] update config for working with tests --- community_server/config/bootstrap.php | 2 +- community_server/config/routes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/community_server/config/bootstrap.php b/community_server/config/bootstrap.php index 55918ba20..77264ee0a 100644 --- a/community_server/config/bootstrap.php +++ b/community_server/config/bootstrap.php @@ -197,7 +197,7 @@ Type::build('timestamp') header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS'); header('Access-Control-Allow-Headers: *'); -if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { +if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') { exit(0); } diff --git a/community_server/config/routes.php b/community_server/config/routes.php index 5a537b9c2..322825c87 100644 --- a/community_server/config/routes.php +++ b/community_server/config/routes.php @@ -65,7 +65,7 @@ Router::scope('/', function (RouteBuilder $routes) { if($entry == 'ElopageWebhook' || $entry == 'AppRequests') { 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; } $allowedCaller = Configure::read('API.allowedCaller'); From 70f6fe8ca559afc5c7a48bb12081d2b8181e365e Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 10:59:53 +0000 Subject: [PATCH 08/16] update test fixtures with actual data set --- .../Fixture/StateUserTransactionsFixture.php | 27 +++++--- .../Fixture/TransactionCreationsFixture.php | 42 +++---------- .../Fixture/TransactionSendCoinsFixture.php | 33 +++++----- .../tests/Fixture/TransactionsFixture.php | 61 ++++++------------- 4 files changed, 63 insertions(+), 100 deletions(-) diff --git a/community_server/tests/Fixture/StateUserTransactionsFixture.php b/community_server/tests/Fixture/StateUserTransactionsFixture.php index c1aadb046..37a132eb5 100644 --- a/community_server/tests/Fixture/StateUserTransactionsFixture.php +++ b/community_server/tests/Fixture/StateUserTransactionsFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * StateUserTransactionsFixture */ -class StateUserTransactionsFixture extends TestFixture +class StateUserTransactionsFixture extends BaseTestFixture { /** * 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], '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], + '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' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], ], @@ -35,14 +37,23 @@ class StateUserTransactionsFixture extends TestFixture */ public function init() { - $this->records = [ - [ - 'id' => 1, - 'state_user_id' => 1, - 'transaction_id' => 1, - 'transaction_type_id' => 1, - ], + $sql = [ + [1, 4, 1, 1, 0, '2021-04-09 00:00:00'], + [2, 1, 2, 1, 0, '2021-04-12 00:00:00'], + [5, 1, 3, 2, 0, '2021-04-12 00:00:00'], + [6, 4, 3, 2, 0, '2021-04-12 00:00:00'], + [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(); } } diff --git a/community_server/tests/Fixture/TransactionCreationsFixture.php b/community_server/tests/Fixture/TransactionCreationsFixture.php index 593c9efe4..f0627d89e 100644 --- a/community_server/tests/Fixture/TransactionCreationsFixture.php +++ b/community_server/tests/Fixture/TransactionCreationsFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * TransactionCreationsFixture */ -class TransactionCreationsFixture extends TestFixture +class TransactionCreationsFixture extends BaseTestFixture { /** * Fields @@ -15,17 +15,18 @@ class TransactionCreationsFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], - 'transaction_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, '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], + 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'transaction_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], '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], + 'target_date' => ['type' => 'timestamp', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], '_constraints' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; // @codingStandardsIgnoreEnd @@ -36,34 +37,11 @@ class TransactionCreationsFixture extends TestFixture */ public function init() { - - // (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' => 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') - ], + $sql = [ + [2, 1, 4, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'], + [3, 2, 1, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'] ]; + $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); } } diff --git a/community_server/tests/Fixture/TransactionSendCoinsFixture.php b/community_server/tests/Fixture/TransactionSendCoinsFixture.php index d3686a3b2..fb9b30db3 100644 --- a/community_server/tests/Fixture/TransactionSendCoinsFixture.php +++ b/community_server/tests/Fixture/TransactionSendCoinsFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * TransactionSendCoinsFixture */ -class TransactionSendCoinsFixture extends TestFixture +class TransactionSendCoinsFixture extends BaseTestFixture { /** * Fields @@ -15,11 +15,12 @@ class TransactionSendCoinsFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], - 'transaction_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, '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], + 'id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'transaction_id' => ['type' => 'integer', 'length' => 10, 'unsigned' => true, '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_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], 'sender_final_balance' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], '_constraints' => [ @@ -27,7 +28,7 @@ class TransactionSendCoinsFixture extends TestFixture ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; // @codingStandardsIgnoreEnd @@ -38,18 +39,16 @@ class TransactionSendCoinsFixture extends TestFixture */ public function init() { - // (1, 4, 2, 0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355, 1, 15000000, 15000000); - $this->records = [ - [ - 'id' => 1, - 'transaction_id' => 4, - 'state_user_id' => 1, - 'receiver_public_key' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d', - 'receiver_user_id' => 4, - 'amount' => 15000000, - 'sender_final_balance' => 15000000 - ], + $sql = [ + [2, 3, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 1000000, 6254699], + [3, 4, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 7027197], + [11, 5, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 6922113], + [12, 6, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9212951], + [13, 7, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9112627], + [14, 8, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 8912594] ]; + + $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); } } diff --git a/community_server/tests/Fixture/TransactionsFixture.php b/community_server/tests/Fixture/TransactionsFixture.php index 0a1be1341..041aa834b 100644 --- a/community_server/tests/Fixture/TransactionsFixture.php +++ b/community_server/tests/Fixture/TransactionsFixture.php @@ -6,7 +6,7 @@ use Cake\TestSuite\Fixture\TestFixture; /** * TransactionsFixture */ -class TransactionsFixture extends TestFixture +class TransactionsFixture extends BaseTestFixture { /** * Fields @@ -15,17 +15,19 @@ class TransactionsFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], - 'state_group_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, '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], - 'tx_hash' => ['type' => 'binary', 'length' => 32, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => 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' => 10, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => 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], + 'blockchain_type_id' => ['type' => 'biginteger', 'length' => 20, 'unsigned' => true, 'null' => false, 'default' => '1', 'comment' => '', 'precision' => null, 'autoIncrement' => null], '_constraints' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; // @codingStandardsIgnoreEnd @@ -36,44 +38,17 @@ class TransactionsFixture extends TestFixture */ public function init() { - // (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' => NULL, - 'transaction_type_id' => 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' - ], + $sql = [ + [1, NULL, 1, 0x15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000, 'AGE Januar 2021', '2021-04-09 00:00:00', 1], + [2, NULL, 1, 0xf932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000, 'AGE Januar 2021', '2021-04-12 00:00:00', 1], + [3, NULL, 2, 0x4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000, 'test', '2021-04-12 00:00:00', 1], + [4, NULL, 2, 0xfc6e69696beb7c56ad7c511fc3999f954411427bec810184b70c092911deae1900000000000000000000000000000000, 'test time', '2021-04-14 00:00:00', 1], + [5, NULL, 2, 0xa7149ebc0d6cd8c061906dafe05e13689b51642a41100d0ec7bb6cd2dcafdc1800000000000000000000000000000000, 'test time', '2021-04-14 09:01:07', 1], + [6, NULL, 2, 0x2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000, 'test time 3', '2021-04-14 09:02:28', 1], + [7, NULL, 2, 0xc2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000, 'test login crash', '2021-04-14 09:28:46', 1], + [8, NULL, 2, 0x5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000, 'test login crash', '2021-04-14 09:31:28', 1] ]; + $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); } } From c10f19f2aefcafb63963f24571fe07a850ae058d Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 13:24:20 +0000 Subject: [PATCH 09/16] add return call (._.); --- community_server/tests/Fixture/BaseTestFixture.php | 1 + 1 file changed, 1 insertion(+) diff --git a/community_server/tests/Fixture/BaseTestFixture.php b/community_server/tests/Fixture/BaseTestFixture.php index 33375aab0..3590a2503 100644 --- a/community_server/tests/Fixture/BaseTestFixture.php +++ b/community_server/tests/Fixture/BaseTestFixture.php @@ -24,5 +24,6 @@ class BaseTestFixture extends TestFixture } $records[] = $record; } + return $records; } } \ No newline at end of file From 33d751edaa339bca5a33ee873d2f00453dd0545a Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 14:10:16 +0000 Subject: [PATCH 10/16] replace hex values with hex strings to work correct with php --- .../tests/Fixture/BaseTestFixture.php | 11 +++++++-- .../tests/Fixture/StateBalancesFixture.php | 19 ++++----------- .../tests/Fixture/StateUsersFixture.php | 7 +++--- .../Fixture/TransactionCreationsFixture.php | 4 ++-- .../Fixture/TransactionSendCoinsFixture.php | 12 +++++----- .../Fixture/TransactionSignaturesFixture.php | 24 +++++++++---------- .../tests/Fixture/TransactionsFixture.php | 16 ++++++------- 7 files changed, 45 insertions(+), 48 deletions(-) diff --git a/community_server/tests/Fixture/BaseTestFixture.php b/community_server/tests/Fixture/BaseTestFixture.php index 3590a2503..1f63aa55e 100644 --- a/community_server/tests/Fixture/BaseTestFixture.php +++ b/community_server/tests/Fixture/BaseTestFixture.php @@ -12,7 +12,8 @@ use Cake\TestSuite\Fixture\TestFixture; 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 = []; @@ -20,7 +21,13 @@ class BaseTestFixture extends TestFixture $record = []; foreach($sql_entry as $i => $value) { $field = $field_array_keys[$i]; - $record[$field] = $value; + if($fields[$field]['type'] == 'binary') { + if(is_string($value)) { + $record[$field] = hex2bin($value); + } + } else { + $record[$field] = $value; + } } $records[] = $record; } diff --git a/community_server/tests/Fixture/StateBalancesFixture.php b/community_server/tests/Fixture/StateBalancesFixture.php index 64118f3ed..f4a6fd7fc 100644 --- a/community_server/tests/Fixture/StateBalancesFixture.php +++ b/community_server/tests/Fixture/StateBalancesFixture.php @@ -15,16 +15,17 @@ class StateBalancesFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => true], - 'state_user_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], + '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], + '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], '_constraints' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; // @codingStandardsIgnoreEnd @@ -36,18 +37,6 @@ class StateBalancesFixture extends TestFixture public function init() { $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(); } diff --git a/community_server/tests/Fixture/StateUsersFixture.php b/community_server/tests/Fixture/StateUsersFixture.php index 80da262db..344296da4 100644 --- a/community_server/tests/Fixture/StateUsersFixture.php +++ b/community_server/tests/Fixture/StateUsersFixture.php @@ -44,11 +44,12 @@ class StateUsersFixture extends BaseTestFixture public function init() { $sql_entrys = [ - [1, 0, 0, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], - [3, 0, 0, 0x131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6, 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], - [4, 0, 0, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] + [1, 0, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], + [3, 0, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], + [4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] ]; $this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields); + echo bin2hex($this->records[0]['public_key']) . "\n"; parent::init(); } } diff --git a/community_server/tests/Fixture/TransactionCreationsFixture.php b/community_server/tests/Fixture/TransactionCreationsFixture.php index f0627d89e..1833385b4 100644 --- a/community_server/tests/Fixture/TransactionCreationsFixture.php +++ b/community_server/tests/Fixture/TransactionCreationsFixture.php @@ -38,8 +38,8 @@ class TransactionCreationsFixture extends BaseTestFixture public function init() { $sql = [ - [2, 1, 4, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'], - [3, 2, 1, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'] + [2, 1, 4, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '2021-01-01 00:00:00'], + [3, 2, 1, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '2021-01-01 00:00:00'] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); diff --git a/community_server/tests/Fixture/TransactionSendCoinsFixture.php b/community_server/tests/Fixture/TransactionSendCoinsFixture.php index fb9b30db3..a109dfd7f 100644 --- a/community_server/tests/Fixture/TransactionSendCoinsFixture.php +++ b/community_server/tests/Fixture/TransactionSendCoinsFixture.php @@ -40,12 +40,12 @@ class TransactionSendCoinsFixture extends BaseTestFixture public function init() { $sql = [ - [2, 3, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 1000000, 6254699], - [3, 4, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 7027197], - [11, 5, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 6922113], - [12, 6, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9212951], - [13, 7, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9112627], - [14, 8, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 8912594] + [2, 3, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 1000000, 6254699], + [3, 4, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 7027197], + [11, 5, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 6922113], + [12, 6, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9212951], + [13, 7, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9112627], + [14, 8, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 8912594] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); diff --git a/community_server/tests/Fixture/TransactionSignaturesFixture.php b/community_server/tests/Fixture/TransactionSignaturesFixture.php index c848461e1..9f7476fea 100644 --- a/community_server/tests/Fixture/TransactionSignaturesFixture.php +++ b/community_server/tests/Fixture/TransactionSignaturesFixture.php @@ -35,34 +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); + // (1, 1, '911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705', '80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'), + // (2, 2, '01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f', '80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'), + // (3, 3, '2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602', '80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'), + // (4, 4, 'cb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102', 'cccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088'); $this->records = [ [ 'id' => 1, 'transaction_id' => 1, - 'signature' => '0x911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705', - 'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355' + 'signature' => ''911b173577261c8b971b4e6ca56b5125ebd5155de8176ce35f9c95ae6929edf3f1e3095d29b37c8bc7cc2478981a41d8cdd3e5398a2c7aa7c691bd486836b705'', + 'pubkey' => ''80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'' ], [ 'id' => 2, 'transaction_id' => 2, - 'signature' => '0x01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f', - 'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355' + 'signature' => ''01e76b14190fa14cb5839d1129b04c4043e691895541b16ae1b54c6b3206d7933def3c58ebf195bc67a7cd5773554636c55fe5e7ddb0c81fb247c24761f8120f'', + 'pubkey' => ''80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'' ], [ 'id' => 3, 'transaction_id' => 3, - 'signature' => '0x2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602', - 'pubkey' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355' + 'signature' => ''2b8c56cac8993f445a8b41ab6e86a486faa18c1e945df1c0acce2bcb342b96d36c5fcb7e687c97cc89790a386241d4b911e8f7949a2da64eef290c5380fc8602'', + 'pubkey' => ''80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355'' ], [ 'id' => 4, 'transaction_id' => 4, - 'signature' => '0xcb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102', - 'pubkey' => '0xcccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088' + 'signature' => ''cb0e9f83b847f630cc6831d62aca8fbfa971af458a12389d7e43abb5bb0936b8e35dbc5b1d641eb2f793e253eb0b149a809860a69897bfe86ba4bfd178da8102'', + 'pubkey' => ''cccb338e003d2abb92178fc4302d1ab83f66b27d9c7e5b6b3ac91e0c23922088'' ], ]; parent::init(); diff --git a/community_server/tests/Fixture/TransactionsFixture.php b/community_server/tests/Fixture/TransactionsFixture.php index 041aa834b..befafc16b 100644 --- a/community_server/tests/Fixture/TransactionsFixture.php +++ b/community_server/tests/Fixture/TransactionsFixture.php @@ -39,14 +39,14 @@ class TransactionsFixture extends BaseTestFixture public function init() { $sql = [ - [1, NULL, 1, 0x15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000, 'AGE Januar 2021', '2021-04-09 00:00:00', 1], - [2, NULL, 1, 0xf932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000, 'AGE Januar 2021', '2021-04-12 00:00:00', 1], - [3, NULL, 2, 0x4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000, 'test', '2021-04-12 00:00:00', 1], - [4, NULL, 2, 0xfc6e69696beb7c56ad7c511fc3999f954411427bec810184b70c092911deae1900000000000000000000000000000000, 'test time', '2021-04-14 00:00:00', 1], - [5, NULL, 2, 0xa7149ebc0d6cd8c061906dafe05e13689b51642a41100d0ec7bb6cd2dcafdc1800000000000000000000000000000000, 'test time', '2021-04-14 09:01:07', 1], - [6, NULL, 2, 0x2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000, 'test time 3', '2021-04-14 09:02:28', 1], - [7, NULL, 2, 0xc2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000, 'test login crash', '2021-04-14 09:28:46', 1], - [8, NULL, 2, 0x5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000, 'test login crash', '2021-04-14 09:31:28', 1] + [1, NULL, 1, '15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000', 'AGE Januar 2021', '2021-04-09 00:00:00', 1], + [2, NULL, 1, 'f932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000', 'AGE Januar 2021', '2021-04-12 00:00:00', 1], + [3, NULL, 2, '4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000', 'test', '2021-04-12 00:00:00', 1], + [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], + [6, NULL, 2, '2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000', 'test time 3', '2021-04-14 09:02:28', 1], + [7, NULL, 2, 'c2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000', 'test login crash', '2021-04-14 09:28:46', 1], + [8, NULL, 2, '5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000', 'test login crash', '2021-04-14 09:31:28', 1] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); From fb19aae34af989520f33b46a4e0e32b9b61e1f66 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 14:10:16 +0000 Subject: [PATCH 11/16] replace hex values with hex strings to work correct with php --- .../tests/Fixture/BaseTestFixture.php | 11 +++++- .../tests/Fixture/StateBalancesFixture.php | 19 ++-------- .../tests/Fixture/StateUsersFixture.php | 6 +-- .../Fixture/TransactionCreationsFixture.php | 4 +- .../Fixture/TransactionSendCoinsFixture.php | 12 +++--- .../Fixture/TransactionSignaturesFixture.php | 38 +++++-------------- .../tests/Fixture/TransactionsFixture.php | 16 ++++---- 7 files changed, 41 insertions(+), 65 deletions(-) diff --git a/community_server/tests/Fixture/BaseTestFixture.php b/community_server/tests/Fixture/BaseTestFixture.php index 3590a2503..b22738883 100644 --- a/community_server/tests/Fixture/BaseTestFixture.php +++ b/community_server/tests/Fixture/BaseTestFixture.php @@ -12,7 +12,8 @@ use Cake\TestSuite\Fixture\TestFixture; class BaseTestFixture extends TestFixture { - + // after copy from sql export, replace all hex values to hex strings with regExp (z.B. within Netbeans) + // ''([0-9a-f]*) => '$1' protected function sqlEntrysToRecords($sql_entries, $fields) { $field_array_keys = array_keys($fields); $records = []; @@ -20,7 +21,13 @@ class BaseTestFixture extends TestFixture $record = []; foreach($sql_entry as $i => $value) { $field = $field_array_keys[$i]; - $record[$field] = $value; + if($fields[$field]['type'] == 'binary') { + if(is_string($value)) { + $record[$field] = hex2bin($value); + } + } else { + $record[$field] = $value; + } } $records[] = $record; } diff --git a/community_server/tests/Fixture/StateBalancesFixture.php b/community_server/tests/Fixture/StateBalancesFixture.php index 64118f3ed..f4a6fd7fc 100644 --- a/community_server/tests/Fixture/StateBalancesFixture.php +++ b/community_server/tests/Fixture/StateBalancesFixture.php @@ -15,16 +15,17 @@ class StateBalancesFixture extends TestFixture */ // @codingStandardsIgnoreStart public $fields = [ - 'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => true], - 'state_user_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], + '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], + '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], '_constraints' => [ 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], ], '_options' => [ 'engine' => 'InnoDB', - 'collation' => 'utf8_bin' + 'collation' => 'utf8mb4_unicode_ci' ], ]; // @codingStandardsIgnoreEnd @@ -36,18 +37,6 @@ class StateBalancesFixture extends TestFixture public function init() { $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(); } diff --git a/community_server/tests/Fixture/StateUsersFixture.php b/community_server/tests/Fixture/StateUsersFixture.php index 80da262db..a9b033bf7 100644 --- a/community_server/tests/Fixture/StateUsersFixture.php +++ b/community_server/tests/Fixture/StateUsersFixture.php @@ -44,9 +44,9 @@ class StateUsersFixture extends BaseTestFixture public function init() { $sql_entrys = [ - [1, 0, 0, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], - [3, 0, 0, 0x131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6, 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], - [4, 0, 0, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] + [1, 0, 0, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 'test1.gmail.de', 'Max', 'Mustermann', NULL, 0], + [3, 0, 0, '131c7f68dd94b2be4c913400ff7ff4cdc03ac2bda99c2d29edcacb3b065c67e6', 'test2.gmail.com', 'Ines', 'Mustermann', NULL, 0], + [4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] ]; $this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields); parent::init(); diff --git a/community_server/tests/Fixture/TransactionCreationsFixture.php b/community_server/tests/Fixture/TransactionCreationsFixture.php index f0627d89e..1833385b4 100644 --- a/community_server/tests/Fixture/TransactionCreationsFixture.php +++ b/community_server/tests/Fixture/TransactionCreationsFixture.php @@ -38,8 +38,8 @@ class TransactionCreationsFixture extends BaseTestFixture public function init() { $sql = [ - [2, 1, 4, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'], - [3, 2, 1, 10000000, 0x0000000000000000000000000000000000000000000000000000000000000000, '2021-01-01 00:00:00'] + [2, 1, 4, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '2021-01-01 00:00:00'], + [3, 2, 1, 10000000, '0000000000000000000000000000000000000000000000000000000000000000', '2021-01-01 00:00:00'] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); diff --git a/community_server/tests/Fixture/TransactionSendCoinsFixture.php b/community_server/tests/Fixture/TransactionSendCoinsFixture.php index fb9b30db3..a109dfd7f 100644 --- a/community_server/tests/Fixture/TransactionSendCoinsFixture.php +++ b/community_server/tests/Fixture/TransactionSendCoinsFixture.php @@ -40,12 +40,12 @@ class TransactionSendCoinsFixture extends BaseTestFixture public function init() { $sql = [ - [2, 3, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 1000000, 6254699], - [3, 4, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 7027197], - [11, 5, 0x0000000000000000000000000000000000000000000000000000000000000000, 1, 0xe3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2, 4, 100000, 6922113], - [12, 6, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9212951], - [13, 7, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 9112627], - [14, 8, 0x0000000000000000000000000000000000000000000000000000000000000000, 4, 0xf7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f, 1, 100000, 8912594] + [2, 3, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 1000000, 6254699], + [3, 4, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 7027197], + [11, 5, '0000000000000000000000000000000000000000000000000000000000000000', 1, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 4, 100000, 6922113], + [12, 6, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9212951], + [13, 7, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 9112627], + [14, 8, '0000000000000000000000000000000000000000000000000000000000000000', 4, 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f', 1, 100000, 8912594] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); diff --git a/community_server/tests/Fixture/TransactionSignaturesFixture.php b/community_server/tests/Fixture/TransactionSignaturesFixture.php index c848461e1..24c19b3b8 100644 --- a/community_server/tests/Fixture/TransactionSignaturesFixture.php +++ b/community_server/tests/Fixture/TransactionSignaturesFixture.php @@ -35,35 +35,15 @@ 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' => '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' - ], + $sql = [ + [1, 1, '1c5357f9438f700a5378abadd0dbd74d90e335c6b9691bb9e126520813f3218573b19226382efb89aa8444a9ca98c2e8933463335baac37baf2f4eecd990600a', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'], + [2, 2, '5215376ae7fb989993e3466961636519d4ade77b3bde066149ade028ad54a1a88ca8a206fcf09f52839ae0ed37b99df08ec9af12f3f37197979a206489e3ff0f', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'], + [3, 3, 'c70f124feaaea02194d22a5f597963ed3e430343122a0952877854766fe37a709f92b39510de2aae494ef11abe743cd59f08f971b1e0e36f4c333990453d8b0d', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'], + [4, 4, 'a65b39e51ab6191c51d5629bbcefd30f85f801efbb14e1c635c519e97abe217a248820fa1fc6aef56227c9d888c1919bc92471d5d7ae3522c9c50fba9f0d8402', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'], + [5, 5, 'a65b39e51ab6191c51d5629bbcefd30f85f801efbb14e1c635c519e97abe217a248820fa1fc6aef56227c9d888c1919bc92471d5d7ae3522c9c50fba9f0d8402', 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f'], + [6, 6, 'c233726674bff9bfb8ccb98bf358c6bc701825d971ece915d3c3a3de98886d1d13ee2f773cd9fc4ccbe543ac17be0d780ebead23a0dbf4ec814f7bae2efb9c0e', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'], + [7, 7, '83ab780535883ec53ee76d0f68db0e1596418c9e100c806a4d4655d4dedf589d54a6319a2795dabab301e212b52f0dafb2725b7583447f19e47cb417d188a107', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'], + [8, 8, '83ab780535883ec53ee76d0f68db0e1596418c9e100c806a4d4655d4dedf589d54a6319a2795dabab301e212b52f0dafb2725b7583447f19e47cb417d188a107', 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2'] ]; parent::init(); } diff --git a/community_server/tests/Fixture/TransactionsFixture.php b/community_server/tests/Fixture/TransactionsFixture.php index 041aa834b..befafc16b 100644 --- a/community_server/tests/Fixture/TransactionsFixture.php +++ b/community_server/tests/Fixture/TransactionsFixture.php @@ -39,14 +39,14 @@ class TransactionsFixture extends BaseTestFixture public function init() { $sql = [ - [1, NULL, 1, 0x15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000, 'AGE Januar 2021', '2021-04-09 00:00:00', 1], - [2, NULL, 1, 0xf932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000, 'AGE Januar 2021', '2021-04-12 00:00:00', 1], - [3, NULL, 2, 0x4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000, 'test', '2021-04-12 00:00:00', 1], - [4, NULL, 2, 0xfc6e69696beb7c56ad7c511fc3999f954411427bec810184b70c092911deae1900000000000000000000000000000000, 'test time', '2021-04-14 00:00:00', 1], - [5, NULL, 2, 0xa7149ebc0d6cd8c061906dafe05e13689b51642a41100d0ec7bb6cd2dcafdc1800000000000000000000000000000000, 'test time', '2021-04-14 09:01:07', 1], - [6, NULL, 2, 0x2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000, 'test time 3', '2021-04-14 09:02:28', 1], - [7, NULL, 2, 0xc2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000, 'test login crash', '2021-04-14 09:28:46', 1], - [8, NULL, 2, 0x5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000, 'test login crash', '2021-04-14 09:31:28', 1] + [1, NULL, 1, '15f242a7bb92a7db82678e0baf5ec1734c038ac0dc7b19e6d1ebbcf92a6cf3ad00000000000000000000000000000000', 'AGE Januar 2021', '2021-04-09 00:00:00', 1], + [2, NULL, 1, 'f932eca7686802d1697773fea713a3c6a3e3dace8b5aa552dd8503d50ce349f500000000000000000000000000000000', 'AGE Januar 2021', '2021-04-12 00:00:00', 1], + [3, NULL, 2, '4e2235f208edaf5cbb285955732022a625cf1e100eb629c56896d2fbfb8b34e800000000000000000000000000000000', 'test', '2021-04-12 00:00:00', 1], + [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], + [6, NULL, 2, '2e3c3ab3e42c06f2ecb12f61c970712467d8ad9ddfa16fa58dd76492e5924b7d00000000000000000000000000000000', 'test time 3', '2021-04-14 09:02:28', 1], + [7, NULL, 2, 'c2c6354d77ff371daeee25fce9c947748b53d3d6b8398a92bd681923cfd2057100000000000000000000000000000000', 'test login crash', '2021-04-14 09:28:46', 1], + [8, NULL, 2, '5a8cbf1aaac06b00b2951ff39983cb2ca9a1e6710d72c8e5067278dc679a823100000000000000000000000000000000', 'test login crash', '2021-04-14 09:31:28', 1] ]; $this->records = $this->sqlEntrysToRecords($sql, $this->fields); parent::init(); From a99f727eab6cf48ab8f47b69a7d63c76d246ee1c Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 14:19:01 +0000 Subject: [PATCH 12/16] remove timestamp on_update because it didn't make sense. I don't know why I have make it so in the first place --- .../skeema/gradido_community/transactions.sql | 2 +- .../Controller/StateBalancesController.php | 62 ++++++++++++++----- .../src/Model/Entity/StateBalance.php | 2 +- .../StateBalancesControllerTest.php | 3 +- .../Model/Table/StateBalancesTableTest.php | 11 +--- 5 files changed, 50 insertions(+), 30 deletions(-) diff --git a/community_server/skeema/gradido_community/transactions.sql b/community_server/skeema/gradido_community/transactions.sql index 8641f0057..e6009608e 100644 --- a/community_server/skeema/gradido_community/transactions.sql +++ b/community_server/skeema/gradido_community/transactions.sql @@ -4,7 +4,7 @@ CREATE TABLE `transactions` ( `transaction_type_id` int(10) unsigned NOT NULL, `tx_hash` binary(48) DEFAULT 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, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index c89dce8db..cfd341135 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -42,20 +42,21 @@ class StateBalancesController extends AppController $this->set(compact('stateBalances')); } - private function updateBalance($stateUserId) + private function updateBalances($stateUserId) { + echo "stateUserId: $stateUserId\n"; $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); // 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_user_transactions = $stateUserTransactionsTable - ->find('all') + ->find() ->where(['state_user_id' => $stateUserId]) ->order(['transaction_id ASC']) - ->contain(false); - + //->contain(false); + ; + if(!$state_user_transactions || !$state_user_transactions->count()) { - //debug($state_user_transactions); return true; } @@ -66,10 +67,12 @@ class StateBalancesController extends AppController $update_state_balance = false; if($state_balances->count() == 0) { $create_state_balance = true; + $recalculate_state_user_transactions_balance = true; } if($state_balances->count() > 1) { $clear_state_balance = true; $create_state_balance = true; + $recalculate_state_user_transactions_balance = true; } if($state_balances->count() == 1) { if($state_user_transactions->count() == 0){ @@ -125,6 +128,7 @@ class StateBalancesController extends AppController $transaction_ids = []; if($recalculate_state_user_transactions_balance) { + echo "recalculate state user transaction balances \n"; $state_user_transactions_array = $state_user_transactions->toArray(); foreach($state_user_transactions_array as $i => $state_user_transaction) { $transaction_ids[$state_user_transaction->transaction_id] = $i; @@ -144,17 +148,23 @@ class StateBalancesController extends AppController $amount_date = null; $amount = 0; - if($transaction->transaction_type_id == 1) { + if($transaction->transaction_type_id == 1) { // creation + echo "creation\n"; $temp = $transaction->transaction_creations[0]; - + echo "creation amount: " . $temp->amount . "\n"; + echo "target date: " . $temp->target_date . "\n"; $balance_temp = $this->StateBalances->newEntity(); $balance_temp->amount = $temp->amount; $balance_temp->record_date = $temp->target_date; $amount = $balance_temp->partDecay($transaction->received); $amount_date = $transaction->received; + echo "amount in state_user_transactions: $amount\n"; + echo "date in state_user_transactions: $amount_date\n"; + echo "diff: " . ($temp->amount - $amount) . "\n"; //$amount_date = - } else if($transaction->transaction_type_id == 2) { + } else if($transaction->transaction_type_id == 2) { // transfer + echo "send coins\n"; $temp = $transaction->transaction_send_coins[0]; $amount = intval($temp->amount); // reverse if sender @@ -162,18 +172,23 @@ class StateBalancesController extends AppController $amount *= -1.0; } $amount_date = $transaction->received; + echo "amount: " . $amount . "\n"; + echo "date: " . $amount_date . "\n"; } if($i == 0) { $balance_cursor->amount = $amount; } else { $balance_cursor->amount = $balance_cursor->partDecay($amount_date) + $amount; } + echo "balance cursor amount: " . $balance_cursor->amount . "\n"; $balance_cursor->record_date = $amount_date; $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_date = $balance_cursor->record_date; $i++; + echo "##########################\n"; } + $results = $stateUserTransactionsTable->saveMany($state_user_transactions_array); $errors = []; foreach($results as $i => $result) { @@ -446,13 +461,29 @@ class StateBalancesController extends AppController } $session = $this->getRequest()->getSession(); $user = $session->read('StateUser'); + $this->updateBalances($user['id']); + + echo "try to unhex: ". $user['public_hex'] . "\n"; $public_key_bin = hex2bin($user['public_hex']); + //var_dump($public_key_bin); $stateUserQuery = $this->StateBalances->StateUsers ->find('all') - ->where(['public_key' => $public_key_bin]) - ->contain(['StateBalances']); + //->where(['public_key' => $public_key_bin]) + ->where(['id' => $user['id']]) + //->contain(['StateBalances']) + ; + $hex_from_db = bin2hex(stream_get_contents($stateUserQuery->first()->public_key)); + echo "hex from db: $hex_from_db\n"; + echo "state user query array: \n"; + var_dump($stateUserQuery->toArray()); + echo "\n"; + + $state_balance = $this->StateBalances->find()->where(['state_user_id' => $user['id']]); + echo "state balance:\n"; + var_dump($state_balance->toArray()); + echo "\n"; $result_user_count = $stateUserQuery->count(); if($result_user_count < 1) { @@ -465,16 +496,13 @@ class StateBalancesController extends AppController 'details' => ['public_key' => $user['public_hex'], 'entry_count' => $result_count] ]); } - $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) { + //$state_balance = $stateUserQuery->first()->state_balances; + + if(!$state_balance) { return $this->returnJson(['state' => 'success', 'balance' => 0]); } - return $this->returnJson(['state' => 'success', 'balance' => $state_balances[0]->amount]); + return $this->returnJson(['state' => 'success', 'balance' => $state_balance->amount]); } diff --git a/community_server/src/Model/Entity/StateBalance.php b/community_server/src/Model/Entity/StateBalance.php index a93a0a4b1..8e0d42942 100644 --- a/community_server/src/Model/Entity/StateBalance.php +++ b/community_server/src/Model/Entity/StateBalance.php @@ -44,7 +44,7 @@ class StateBalance extends Entity return $dateOrTime->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); } else { var_dump($dateOrTime); - debug_print_backtrace(0, 4); + debug_print_backtrace(0, 6); die("date or time unexpected object"); } } diff --git a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php index 2901015cf..256688d17 100644 --- a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php +++ b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php @@ -22,6 +22,7 @@ class StateBalancesControllerTest extends TestCase 'app.TransactionCreations', 'app.Transactions', 'app.StateUsers', + 'app.StateUserTransactions', 'app.StateErrors', 'app.TransactionSignatures', 'app.TransactionSendCoins', @@ -73,7 +74,7 @@ class StateBalancesControllerTest extends TestCase 'StateUser' => [ 'id' => 1, 'email_checked' => 1, - 'public_hex' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d' + 'public_hex' => 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f' ] ]); //echo "balance: $balance"; diff --git a/community_server/tests/TestCase/Model/Table/StateBalancesTableTest.php b/community_server/tests/TestCase/Model/Table/StateBalancesTableTest.php index 9ab6d30f0..68049de34 100644 --- a/community_server/tests/TestCase/Model/Table/StateBalancesTableTest.php +++ b/community_server/tests/TestCase/Model/Table/StateBalancesTableTest.php @@ -120,14 +120,5 @@ class StateBalancesTableTest extends TestCase { $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() - { - - } + } From f6ddce27570d4cf5cbc31ee0a12f1bf2c34fb549 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 14:28:08 +0000 Subject: [PATCH 13/16] add merge bug --- community_server/tests/Fixture/BaseTestFixture.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/community_server/tests/Fixture/BaseTestFixture.php b/community_server/tests/Fixture/BaseTestFixture.php index 27eb36989..1f63aa55e 100644 --- a/community_server/tests/Fixture/BaseTestFixture.php +++ b/community_server/tests/Fixture/BaseTestFixture.php @@ -13,11 +13,7 @@ use Cake\TestSuite\Fixture\TestFixture; class BaseTestFixture extends TestFixture { // after copy from sql export, replace all hex values to hex strings with regExp (z.B. within Netbeans) -<<<<<<< HEAD - // ''([0-9a-f]*) => '$1' -======= // 0x([0-9a-f]*) => '$1' ->>>>>>> 33d751edaa339bca5a33ee873d2f00453dd0545a protected function sqlEntrysToRecords($sql_entries, $fields) { $field_array_keys = array_keys($fields); $records = []; From 1a22c3dd8271ce3885a358f4603ba0bac5da5895 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 14:31:16 +0000 Subject: [PATCH 14/16] =?UTF-8?q?lost=20update=20(=E2=8A=99=5F=E2=97=8E)?= =?UTF-8?q?=20(=C3=A2=C2=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- community_server/tests/Fixture/StateUsersFixture.php | 1 - 1 file changed, 1 deletion(-) diff --git a/community_server/tests/Fixture/StateUsersFixture.php b/community_server/tests/Fixture/StateUsersFixture.php index 344296da4..a9b033bf7 100644 --- a/community_server/tests/Fixture/StateUsersFixture.php +++ b/community_server/tests/Fixture/StateUsersFixture.php @@ -49,7 +49,6 @@ class StateUsersFixture extends BaseTestFixture [4, 0, 0, 'e3369de3623ce8446d0424c4013e7a1d71a2671ae3d7bf1e798ebf0665d145f2', 'test3.yahoo.com', 'Samuel', 'Schmied', NULL, 0] ]; $this->records = $this->sqlEntrysToRecords($sql_entrys, $this->fields); - echo bin2hex($this->records[0]['public_key']) . "\n"; parent::init(); } } From b5ad8ced687f07ef2444e7e2b8ba99e19a9f95c9 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 15:02:17 +0000 Subject: [PATCH 15/16] success in testing updateBalances with: 'sudo -u www-data ./vendor/bin/phpunit --filter testAjaxGetBalance' --- .../Controller/StateBalancesController.php | 62 ++++----------- .../StateBalancesControllerTest.php | 77 +++++++++++++++++-- 2 files changed, 85 insertions(+), 54 deletions(-) diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index cfd341135..3b5e0481e 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -44,7 +44,6 @@ class StateBalancesController extends AppController private function updateBalances($stateUserId) { - echo "stateUserId: $stateUserId\n"; $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); // info: cakephp use lazy loading, query will be executed later only if needed @@ -128,7 +127,7 @@ class StateBalancesController extends AppController $transaction_ids = []; if($recalculate_state_user_transactions_balance) { - echo "recalculate state user transaction balances \n"; + $state_user_transactions_array = $state_user_transactions->toArray(); foreach($state_user_transactions_array as $i => $state_user_transaction) { $transaction_ids[$state_user_transaction->transaction_id] = $i; @@ -148,23 +147,19 @@ class StateBalancesController extends AppController $amount_date = null; $amount = 0; - if($transaction->transaction_type_id == 1) { // creation - echo "creation\n"; + if($transaction->transaction_type_id == 1) { // creation $temp = $transaction->transaction_creations[0]; - echo "creation amount: " . $temp->amount . "\n"; - echo "target date: " . $temp->target_date . "\n"; + $balance_temp = $this->StateBalances->newEntity(); $balance_temp->amount = $temp->amount; $balance_temp->record_date = $temp->target_date; $amount = $balance_temp->partDecay($transaction->received); $amount_date = $transaction->received; - echo "amount in state_user_transactions: $amount\n"; - echo "date in state_user_transactions: $amount_date\n"; - echo "diff: " . ($temp->amount - $amount) . "\n"; + //$amount_date = } else if($transaction->transaction_type_id == 2) { // transfer - echo "send coins\n"; + $temp = $transaction->transaction_send_coins[0]; $amount = intval($temp->amount); // reverse if sender @@ -172,21 +167,20 @@ class StateBalancesController extends AppController $amount *= -1.0; } $amount_date = $transaction->received; - echo "amount: " . $amount . "\n"; - echo "date: " . $amount_date . "\n"; + } if($i == 0) { $balance_cursor->amount = $amount; } else { $balance_cursor->amount = $balance_cursor->partDecay($amount_date) + $amount; } - echo "balance cursor amount: " . $balance_cursor->amount . "\n"; + $balance_cursor->record_date = $amount_date; $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_date = $balance_cursor->record_date; $i++; - echo "##########################\n"; + } $results = $stateUserTransactionsTable->saveMany($state_user_transactions_array); @@ -464,45 +458,17 @@ class StateBalancesController extends AppController $this->updateBalances($user['id']); - - echo "try to unhex: ". $user['public_hex'] . "\n"; - $public_key_bin = hex2bin($user['public_hex']); - //var_dump($public_key_bin); - $stateUserQuery = $this->StateBalances->StateUsers - ->find('all') - //->where(['public_key' => $public_key_bin]) - ->where(['id' => $user['id']]) - //->contain(['StateBalances']) - ; - $hex_from_db = bin2hex(stream_get_contents($stateUserQuery->first()->public_key)); - echo "hex from db: $hex_from_db\n"; - echo "state user query array: \n"; - var_dump($stateUserQuery->toArray()); - echo "\n"; - - $state_balance = $this->StateBalances->find()->where(['state_user_id' => $user['id']]); - echo "state balance:\n"; - var_dump($state_balance->toArray()); - echo "\n"; - - $result_user_count = $stateUserQuery->count(); - if($result_user_count < 1) { - return $this->returnJson(['state' => 'success', 'balance' => 0]); - } - else if($result_user_count > 1) { - return $this->returnJson([ - 'state' => 'error', - 'msg' => 'multiple entrys found', - 'details' => ['public_key' => $user['public_hex'], 'entry_count' => $result_count] - ]); - } - //$state_balance = $stateUserQuery->first()->state_balances; + $state_balance = $this->StateBalances->find()->where(['state_user_id' => $user['id']])->first(); if(!$state_balance) { return $this->returnJson(['state' => 'success', 'balance' => 0]); } - return $this->returnJson(['state' => 'success', 'balance' => $state_balance->amount]); + return $this->returnJson([ + 'state' => 'success', + 'balance' => $state_balance->amount, + 'decay' => $state_balance->decay + ]); } diff --git a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php index 256688d17..df3ff8512 100644 --- a/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php +++ b/community_server/tests/TestCase/Controller/StateBalancesControllerTest.php @@ -3,6 +3,9 @@ namespace App\Test\TestCase\Controller; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; +use Cake\ORM\TableRegistry; +use Cake\I18n\Time; + /** * App\Controller\StateBalancesController Test Case @@ -29,6 +32,12 @@ class StateBalancesControllerTest extends TestCase 'app.StateBalances', 'app.TransactionTypes' ]; + + public function setUp() + { + parent::setUp(); + $this->StateBalances = TableRegistry::getTableLocator()->get('StateBalances'); + } /** * Test initialize method @@ -65,7 +74,7 @@ class StateBalancesControllerTest extends TestCase * * @return void */ - public function testAjaxGetBalance() + public function testAjaxGetBalance1() { $session_id = rand(); $this->session([ @@ -77,10 +86,49 @@ class StateBalancesControllerTest extends TestCase 'public_hex' => 'f7f4a49a4ac10379f8b9ddcb731c4d9ec495e6edd16075f52672cd25e3179f0f' ] ]); - //echo "balance: $balance"; - $this->getAndParse('/state-balances/ajaxGetBalance/' . $session_id, - ['state' => 'success', 'balance' => 1200000] - ); + + $response = $this->getAndParseWithoutCompare('/state-balances/ajaxGetBalance/' . $session_id); + + $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() @@ -243,7 +291,24 @@ class StateBalancesControllerTest extends TestCase $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 a 200 + $this->assertResponseOk(); + + $responseBodyString = (string)$this->_response->getBody(); + $json = json_decode($responseBodyString); + $this->assertNotFalse($json); + + return $json; + } } From c5d433233942e31b54053be331d95a94e834bc59 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 14 Apr 2021 15:36:15 +0000 Subject: [PATCH 16/16] fix function call --- community_server/src/Controller/StateBalancesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index 3b5e0481e..6b5539ce1 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -230,7 +230,7 @@ class StateBalancesController extends AppController } $user = $session->read('StateUser'); - $update_balance_result = $this->updateBalance($user['id']); + $update_balance_result = $this->updateBalances($user['id']); if($update_balance_result !== true) { $this->addAdminError('StateBalances', 'overview', $update_balance_result, $user['id']); }