From efd351a60c702123e95bcc6899f112b517f48527 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 14 Apr 2022 21:37:06 +0300 Subject: [PATCH 1/5] #469 add test --- tests/Units/Domain/WalletFloatTest.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Units/Domain/WalletFloatTest.php b/tests/Units/Domain/WalletFloatTest.php index 4999b3afb..1bd6a4f68 100644 --- a/tests/Units/Domain/WalletFloatTest.php +++ b/tests/Units/Domain/WalletFloatTest.php @@ -304,6 +304,29 @@ public function testBitcoin(): void self::assertSame('256.00000256000000000000000000000001', $user->balanceFloat); } + /** + * Case from @EdX9. + * + * @see https://github.com/bavix/laravel-wallet/issues/469 + * + * @throws ExceptionInterface + */ + public function testBigFloat(): void + { + /** @var User[] $users */ + $users = UserFloatFactory::times(2)->create(); + + [$first, $second] = $users; + + self::assertSame(0, $first->balanceInt); + self::assertSame(0, $second->balanceInt); + + $first->forceTransferFloat($second, 6629944401); + + self::assertSame(-662994440100, $first->balanceInt); + self::assertSame(662994440100, $second->balanceInt); + } + /** * Case from @ucanbehack. * From 001113f3492fef1711c79fd173455f26009e2480 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 14 Apr 2022 21:37:06 +0300 Subject: [PATCH 2/5] add support mysql57 --- .github/workflows/phpunits.yaml | 16 +++++++++++++++- tests/Infra/TestCase.php | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/phpunits.yaml b/.github/workflows/phpunits.yaml index 8159f51e5..f7f4a4376 100644 --- a/.github/workflows/phpunits.yaml +++ b/.github/workflows/phpunits.yaml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-versions: [8.0, 8.1] - databases: [testing, pgsql, mysql, mariadb] + databases: [testing, pgsql, mysql, mysql57, mariadb] caches: [array, redis, memcached] services: @@ -84,6 +84,20 @@ jobs: ports: - 3307:3306 + mysql57: + image: bitnami/mysql:5.7 + env: + MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password + MYSQL_ROOT_PASSWORD: wallet + MYSQL_DATABASE: wallet + options: >- + --health-cmd="mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + ports: + - 3308:3306 + steps: - name: Checkout id: git-checkout diff --git a/tests/Infra/TestCase.php b/tests/Infra/TestCase.php index f24add7a8..bd89988f0 100644 --- a/tests/Infra/TestCase.php +++ b/tests/Infra/TestCase.php @@ -65,6 +65,9 @@ protected function getEnvironmentSetUp($app): void $config->set('database.connections.mariadb', array_merge($mysql, [ 'port' => 3307, ])); + $config->set('database.connections.mysql57', array_merge($mysql, [ + 'port' => 3308, + ])); // new table name's $config->set('wallet.transaction.table', 'transaction'); From 9600f4ccfd761ad5326f6b88cc1aef5f79fbf822 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 14 Apr 2022 22:23:54 +0300 Subject: [PATCH 3/5] decimal_places deposit amount --- src/Services/PrepareService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Services/PrepareService.php b/src/Services/PrepareService.php index dccaa836d..357019cf6 100644 --- a/src/Services/PrepareService.php +++ b/src/Services/PrepareService.php @@ -83,10 +83,11 @@ public function transferLazy( ?array $meta = null ): TransferLazyDtoInterface { $discount = $this->personalDiscountService->getDiscount($from, $to); + $toWallet = $this->castService->getWallet($to); $from = $this->castService->getWallet($from); $fee = $this->taxService->getFee($to, $amount); - $amountWithoutDiscount = $this->mathService->sub($amount, $discount); + $amountWithoutDiscount = $this->mathService->sub($amount, $discount, $toWallet->decimal_places); $depositAmount = $this->mathService->compare($amountWithoutDiscount, 0) === -1 ? '0' : $amountWithoutDiscount; $withdrawAmount = $this->mathService->add($depositAmount, $fee, $from->decimal_places); From 9fe71f15a4f3667bab301b2322fc1bc6f271f3f9 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 14 Apr 2022 22:26:55 +0300 Subject: [PATCH 4/5] Revert "add support mysql57" This reverts commit 1e7bbd3a744c9c84bcf7bd8659a901ece7f604e9. --- .github/workflows/phpunits.yaml | 16 +--------------- tests/Infra/TestCase.php | 3 --- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/phpunits.yaml b/.github/workflows/phpunits.yaml index f7f4a4376..8159f51e5 100644 --- a/.github/workflows/phpunits.yaml +++ b/.github/workflows/phpunits.yaml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-versions: [8.0, 8.1] - databases: [testing, pgsql, mysql, mysql57, mariadb] + databases: [testing, pgsql, mysql, mariadb] caches: [array, redis, memcached] services: @@ -84,20 +84,6 @@ jobs: ports: - 3307:3306 - mysql57: - image: bitnami/mysql:5.7 - env: - MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password - MYSQL_ROOT_PASSWORD: wallet - MYSQL_DATABASE: wallet - options: >- - --health-cmd="mysqladmin ping" - --health-interval 10s - --health-timeout 5s - --health-retries 10 - ports: - - 3308:3306 - steps: - name: Checkout id: git-checkout diff --git a/tests/Infra/TestCase.php b/tests/Infra/TestCase.php index bd89988f0..f24add7a8 100644 --- a/tests/Infra/TestCase.php +++ b/tests/Infra/TestCase.php @@ -65,9 +65,6 @@ protected function getEnvironmentSetUp($app): void $config->set('database.connections.mariadb', array_merge($mysql, [ 'port' => 3307, ])); - $config->set('database.connections.mysql57', array_merge($mysql, [ - 'port' => 3308, - ])); // new table name's $config->set('wallet.transaction.table', 'transaction'); From 6c3bc1fa95d65eac4cfd9a9c522aa1bf3880da0d Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Thu, 14 Apr 2022 22:29:42 +0300 Subject: [PATCH 5/5] update changelog.md --- changelog.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index d6475d3b4..f697e157b 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [8.2.1] - 2022-04-14 +### Fixed +- Error in force transaction float #469 @EdX9 + ## [8.2.0] - 2022-04-03 ### Added - Add exception `TransactionStartException` @@ -819,7 +823,8 @@ The operation is now executed in the transaction and updates the new `refund` fi - Exceptions: AmountInvalid, BalanceIsEmpty. - Models: Transfer, Transaction. -[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.2.0...develop +[Unreleased]: https://github.com/bavix/laravel-wallet/compare/8.2.1...develop +[8.2.1]: https://github.com/bavix/laravel-wallet/compare/8.2.0...8.2.1 [8.2.0]: https://github.com/bavix/laravel-wallet/compare/8.1.1...8.2.0 [8.1.1]: https://github.com/bavix/laravel-wallet/compare/8.1.0...8.1.1 [8.1.0]: https://github.com/bavix/laravel-wallet/compare/8.0.6...8.1.0