Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Feb 6, 2025
1 parent 1a68832 commit 6c677ad
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions database/factories/TransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function multiPayment(array $recipients, array $amounts): Factory

return $this->withPayload($payload)
->state(fn () => [
'amount' => 0,
'recipient_address' => Network::knownContract('multipayment'),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use App\Contracts\Network as NetworkContract;
use App\Models\Transaction;
use App\Models\Wallet;
use App\Services\BigNumber;
use App\Services\Transactions\Aggregates\Historical\AveragesAggregate;
use Carbon\Carbon;
use Tests\Feature\Http\Livewire\__stubs\NetworkStub;

it('should return count', function () {
it('should return count for non-multipayment', function () {
$daysSinceEpoch = 2;
$networkStub = new NetworkStub(true, Carbon::now()->subDay($daysSinceEpoch));

Expand All @@ -22,16 +24,74 @@

$transactionCount = 12;

Transaction::factory($transactionCount)
Transaction::factory(6)
->withReceipt()
->create([
'amount' => 10 * 1e18,
'amount' => 20 * 1e18,
'gas_price' => 25,
]);

Transaction::factory(6)
->withReceipt()
->unvote()
->create([
'amount' => 0 * 1e18,
'gas_price' => 25,
]);

expect(Transaction::count())->toBe($transactionCount);

expect((new AveragesAggregate())->aggregate())->toBe([
'count' => $transactionCount / $daysSinceEpoch,
'amount' => 60,
'amount' => 120 / $daysSinceEpoch,
'fee' => (((25 * 21000) * $transactionCount) / $daysSinceEpoch) / 1e9,
]);
});

it('should return count for multipayment', function () {
$daysSinceEpoch = 2;
$networkStub = new NetworkStub(true, Carbon::now()->subDay($daysSinceEpoch));

app()->singleton(NetworkContract::class, fn () => $networkStub);

expect((new AveragesAggregate())->aggregate())->toBe([
'count' => 0,
'amount' => 0,
'fee' => 0,
]);

$transactionCount = 4;

Transaction::factory(2)
->withReceipt()
->create([
'amount' => 10 * 1e18,
'gas_price' => 25,
]);

$recipient = Wallet::factory()->create();

Transaction::factory()
->withReceipt()
->multiPayment([$recipient->address], [BigNumber::new(14 * 1e18)])
->create([
'amount' => 0,
'gas_price' => 25,
]);

Transaction::factory()
->withReceipt()
->multiPayment([$recipient->address, $recipient->address], [BigNumber::new(14 * 1e18), BigNumber::new(14 * 1e18)])
->create([
'amount' => 0,
'gas_price' => 25,
]);

expect(Transaction::count())->toBe($transactionCount);

expect((new AveragesAggregate())->aggregate())->toBe([
'count' => (int) round($transactionCount / $daysSinceEpoch),
'amount' => 62 / $daysSinceEpoch,
'fee' => (((25 * 21000) * $transactionCount) / $daysSinceEpoch) / 1e9,
]);
});

0 comments on commit 6c677ad

Please sign in to comment.