From 5b0564dc2127975ad91fa9cc47cdb2e1dd5ab4c5 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 27 Jan 2025 14:35:21 +0000 Subject: [PATCH] fix: false positive recent votes tests (#1166) --- .../Concerns/Transaction/CanBeSorted.php | 2 +- database/factories/WalletFactory.php | 1 - .../Livewire/Validators/MissedBlocksTest.php | 2 - .../Livewire/Validators/RecentVotesTest.php | 187 ++++++++++-------- .../Livewire/Validators/ValidatorsTest.php | 2 - ...2020_10_19_042141_create_wallets_table.php | 1 - 6 files changed, 109 insertions(+), 86 deletions(-) diff --git a/app/Models/Concerns/Transaction/CanBeSorted.php b/app/Models/Concerns/Transaction/CanBeSorted.php index e934321ec..a2d09ea40 100644 --- a/app/Models/Concerns/Transaction/CanBeSorted.php +++ b/app/Models/Concerns/Transaction/CanBeSorted.php @@ -19,7 +19,7 @@ public function scopeSortByAge(mixed $query, SortDirection $sortDirection): Buil public function scopeSortByAddress(mixed $query, SortDirection $sortDirection): Builder { - return $query->join('wallets', 'wallets.public_key', '=', 'transactions.sender_public_key') + return $query->join('wallets', 'wallets.address', '=', 'transactions.sender_address') ->orderBy('wallets.address', $sortDirection->value); } diff --git a/database/factories/WalletFactory.php b/database/factories/WalletFactory.php index 3fe3584b4..deeb604ac 100644 --- a/database/factories/WalletFactory.php +++ b/database/factories/WalletFactory.php @@ -17,7 +17,6 @@ public function definition() $wallet = $this->faker->wallet; return [ - 'id' => $this->faker->uuid, 'address' => $wallet['address'], 'public_key' => $wallet['publicKey'], 'balance' => $this->faker->numberBetween(1, 1000) * 1e18, diff --git a/tests/Feature/Http/Livewire/Validators/MissedBlocksTest.php b/tests/Feature/Http/Livewire/Validators/MissedBlocksTest.php index d307bd6f3..c72f22ba7 100644 --- a/tests/Feature/Http/Livewire/Validators/MissedBlocksTest.php +++ b/tests/Feature/Http/Livewire/Validators/MissedBlocksTest.php @@ -586,7 +586,6 @@ $sortByVotesData[$wallet['address']] = random_int(10, 100); $validatorData[] = [ - 'id' => faker()->uuid, 'balance' => faker()->numberBetween(1, 1000) * 1e18, 'nonce' => faker()->numberBetween(1, 1000), 'updated_at' => faker()->numberBetween(1, 1000), @@ -677,7 +676,6 @@ $sortByVotesData[$wallet['address']] = random_int(10, 100); $validatorData[] = [ - 'id' => faker()->uuid, 'balance' => faker()->numberBetween(1, 1000) * 1e18, 'nonce' => faker()->numberBetween(1, 1000), 'updated_at' => faker()->numberBetween(1, 1000), diff --git a/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php b/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php index 856418951..4e7a385db 100644 --- a/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php +++ b/tests/Feature/Http/Livewire/Validators/RecentVotesTest.php @@ -26,32 +26,42 @@ function generateReceipts(): void function generateTransactions(): array { $validator1 = Wallet::factory()->activeValidator()->create([ + 'address' => '0x522CbD1C22529a27ba4BFDBf4b6f037F71b2AC77', 'attributes' => [ 'username' => 'validator-1', ], ]); $validator2 = Wallet::factory()->activeValidator()->create([ + 'address' => '0x09C94A51cb63b4b70A9Dbf190543c371741D13Fd', 'attributes' => [ 'username' => 'validator-2', ], ]); $validator3 = Wallet::factory()->activeValidator()->create([ + 'address' => '0x2a74550fC2e741118182B7ab020DC0B7Ed01e1db', 'attributes' => [ 'username' => 'validator-3', ], ]); - $voteTransaction = Transaction::factory()->vote($validator1->address)->create([ - 'timestamp' => Carbon::parse('2023-09-18 03:41:04')->getTimestampMs(), - 'sender_address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B', - ]); + $sender1 = Wallet::factory()->create(['address' => '0xC5a19e23E99bdFb7aae4301A009763AdC01c1b5B']); + $sender2 = Wallet::factory()->create(['address' => '0x38b4a84773bC55e88D07cBFC76444C2A37600084']); - $unvoteTransaction = Transaction::factory()->unvote()->create([ - 'timestamp' => Carbon::parse('2023-09-18 04:41:04')->getTimestampMs(), - 'sender_address' => '0x38b4a84773bC55e88D07cBFC76444C2A37600084', - ]); + $voteTransaction = Transaction::factory() + ->vote($validator1->address) + ->create([ + 'timestamp' => Carbon::parse('2023-09-18 03:41:04')->getTimestampMs(), + 'sender_address' => $sender1->address, + ]); + + $unvoteTransaction = Transaction::factory() + ->unvote() + ->create([ + 'timestamp' => Carbon::parse('2023-09-18 04:41:04')->getTimestampMs(), + 'sender_address' => $sender2->address, + ]); generateReceipts(); @@ -240,10 +250,15 @@ function generateTransactions(): array ->assertSet('sortKey', 'age') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, ]); }); @@ -255,41 +270,15 @@ function generateTransactions(): array ->call('sortBy', 'age') ->assertSet('sortDirection', SortDirection::ASC) ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - ]); -}); - -it('should sort name in ascending order', function () { - $data = generateTransactions(); - - Livewire::test(RecentVotes::class) - ->call('setIsReady') - ->call('sortBy', 'name') - ->assertSet('sortDirection', SortDirection::ASC) - ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - ]); -}); - -it('should sort name in descending order', function () { - $data = generateTransactions(); - - Livewire::test(RecentVotes::class) - ->call('setIsReady') - ->call('sortBy', 'name') - ->call('sortBy', 'name') - ->assertSet('sortDirection', SortDirection::DESC) - ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, ]); }); @@ -301,10 +290,15 @@ function generateTransactions(): array ->call('sortBy', 'address') ->assertSet('sortDirection', SortDirection::ASC) ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, ]); }); @@ -317,10 +311,15 @@ function generateTransactions(): array ->call('sortBy', 'address') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, ]); }); @@ -332,10 +331,15 @@ function generateTransactions(): array ->call('sortBy', 'type') ->assertSet('sortDirection', SortDirection::ASC) ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, ]); }); @@ -348,10 +352,15 @@ function generateTransactions(): array ->call('sortBy', 'type') ->assertSet('sortDirection', SortDirection::DESC) ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, ]); }); @@ -401,18 +410,28 @@ function generateTransactions(): array $this->get('/test-validators?sort=type&sort-direction=asc') ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, ]); $this->get('/test-validators?sort=type&sort-direction=desc') ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, ]); }); @@ -425,18 +444,28 @@ function generateTransactions(): array $this->get('/test-validators?sort=type&sort-direction=desc') ->assertSeeInOrder([ - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, ]); $this->get('/test-validators?sort=type&sort-direction=testing') ->assertSeeInOrder([ - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, - $data['unvoteTransaction']->address, - $data['voteTransaction']->address, + 'vote-item*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-item*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, + + 'vote-mobile*'.$data['voteTransaction']->id, + $data['voteTransaction']->id, + 'vote-mobile*'.$data['unvoteTransaction']->id, + $data['unvoteTransaction']->id, ]); }); diff --git a/tests/Feature/Http/Livewire/Validators/ValidatorsTest.php b/tests/Feature/Http/Livewire/Validators/ValidatorsTest.php index e52d86e70..8ea4f5836 100644 --- a/tests/Feature/Http/Livewire/Validators/ValidatorsTest.php +++ b/tests/Feature/Http/Livewire/Validators/ValidatorsTest.php @@ -830,7 +830,6 @@ foreach (range(1, 145) as $rank) { $wallet = faker()->wallet; $validatorData[] = [ - 'id' => faker()->uuid, 'balance' => faker()->numberBetween(1, 1000) * 1e18, 'nonce' => faker()->numberBetween(1, 1000), 'attributes' => [ @@ -895,7 +894,6 @@ foreach (range(1, 145) as $rank) { $wallet = faker()->wallet; $validatorData[] = [ - 'id' => faker()->uuid, 'balance' => faker()->numberBetween(1, 1000) * 1e18, 'nonce' => faker()->numberBetween(1, 1000), 'updated_at' => faker()->numberBetween(1, 1000), diff --git a/tests/migrations/2020_10_19_042141_create_wallets_table.php b/tests/migrations/2020_10_19_042141_create_wallets_table.php index 76456149b..a1fc642bd 100644 --- a/tests/migrations/2020_10_19_042141_create_wallets_table.php +++ b/tests/migrations/2020_10_19_042141_create_wallets_table.php @@ -11,7 +11,6 @@ final class CreateWalletsTable extends Migration public function up() { Schema::create('wallets', function (Blueprint $table) { - $table->string('id'); $table->string('address'); $table->string('public_key')->nullable(); $table->addColumn('numeric', 'balance');