Skip to content

Commit

Permalink
refactor: hide failed transactions in recent votes table (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Jan 22, 2025
1 parent 9f18033 commit f819816
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/Http/Livewire/Validators/RecentVotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ private function getRecentVotesQuery(): Builder
$sortDirection = SortDirection::DESC;
}

// TODO: fetch only vote transaction types - https://app.clickup.com/t/86dv8nz3e
return Transaction::query()
->join('receipts', 'transactions.id', '=', 'receipts.id')
->where('receipts.success', true)
->where('timestamp', '>=', Timestamp::now()->subDays(30)->unix() * 1000)
->where(function ($query) {
$query->where(fn ($query) => $query->when($this->filter['vote'], function ($query) {
Expand Down
52 changes: 52 additions & 0 deletions tests/Feature/Http/Livewire/Validators/RecentVotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Enums\SortDirection;
use App\Http\Livewire\Validators\RecentVotes;
use App\Models\Receipt;
use App\Models\Transaction;
use App\Models\Wallet;
use App\ViewModels\WalletViewModel;
Expand All @@ -12,6 +13,16 @@
use Illuminate\View\Compilers\BladeCompiler;
use Livewire\Livewire;

function generateReceipts(): void
{
foreach (Transaction::all() as $transaction) {
Receipt::factory()->create([
'id' => $transaction->id,
'success' => true,
]);
}
}

function generateTransactions(): array
{
$validator1 = Wallet::factory()->activeValidator()->create([
Expand Down Expand Up @@ -42,6 +53,8 @@ function generateTransactions(): array
'sender_address' => '0x38b4a84773bC55e88D07cBFC76444C2A37600084',
]);

generateReceipts();

return [
'validator1' => $validator1,
'validator2' => $validator2,
Expand Down Expand Up @@ -70,6 +83,8 @@ function generateTransactions(): array
'sender_public_key' => $wallet->public_key,
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->assertSee('Showing 0 results')
->call('setIsReady')
Expand All @@ -92,6 +107,8 @@ function generateTransactions(): array
'sender_public_key' => $wallet->public_key,
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->assertSee('Showing 0 results')
->call('setIsReady')
Expand Down Expand Up @@ -160,6 +177,8 @@ function generateTransactions(): array
'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(),
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->call('setIsReady')
->set('filter', [
Expand All @@ -185,6 +204,8 @@ function generateTransactions(): array
'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(),
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->call('setIsReady')
->set('filter', [
Expand Down Expand Up @@ -419,6 +440,33 @@ function generateTransactions(): array
]);
});

it('should not show failed transactions', function () {
$validator = Wallet::factory()->activeValidator()->create();

$failedTransaction = Transaction::factory()->vote($validator->address)->create([
'timestamp' => Carbon::now()->subMinute(2)->getTimestampMs(),
]);

$successfulTransaction = Transaction::factory()->vote($validator->address)->create([
'timestamp' => Carbon::now()->subMinute(1)->getTimestampMs(),
]);

Receipt::factory()->create([
'id' => $failedTransaction->id,
'success' => false,
]);

Receipt::factory()->create([
'id' => $successfulTransaction->id,
'success' => true,
]);

Livewire::test(RecentVotes::class)
->call('setIsReady')
->assertDontSee($failedTransaction->id)
->assertSee($successfulTransaction->id);
});

it('should sort name then address in ascending order when missing names', function () {
$validator1 = new WalletViewModel(Wallet::factory()->activeValidator()->create([
'attributes' => [
Expand Down Expand Up @@ -449,6 +497,8 @@ function generateTransactions(): array
'timestamp' => Carbon::parse('2023-09-18 06:41:07')->getTimestampMs(),
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->call('setIsReady')
->call('sortBy', 'name')
Expand Down Expand Up @@ -514,6 +564,8 @@ function generateTransactions(): array
'timestamp' => Carbon::parse('2023-09-18 06:41:07')->getTimestampMs(),
]);

generateReceipts();

Livewire::test(RecentVotes::class)
->call('setIsReady')
->call('sortBy', 'name')
Expand Down

0 comments on commit f819816

Please sign in to comment.