11<?php
22
3- use Illuminate \Support \Facades \Event ;
4- use Farbcode \LaravelEvm \Jobs \SendTransaction ;
3+ use Farbcode \LaravelEvm \Contracts \FeePolicy ;
4+ use Farbcode \LaravelEvm \Contracts \NonceManager ;
5+ use Farbcode \LaravelEvm \Contracts \RpcClient ;
6+ use Farbcode \LaravelEvm \Contracts \Signer ;
57use Farbcode \LaravelEvm \Events \TxFailed ;
6- use Farbcode \LaravelEvm \Contracts \{RpcClient , Signer , NonceManager , FeePolicy };
8+ use Farbcode \LaravelEvm \Jobs \SendTransaction ;
9+ use Illuminate \Support \Facades \Event ;
710
8- class FFailSigner implements Signer {
11+ class FFailSigner implements Signer
12+ {
913 public function __construct (private string $ pk ) {}
10- public function getAddress (): string { return '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef ' ; }
11- public function privateKey (): string { return $ this ->pk ; }
14+
15+ public function getAddress (): string
16+ {
17+ return '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef ' ;
18+ }
19+
20+ public function privateKey (): string
21+ {
22+ return $ this ->pk ;
23+ }
1224}
13- class FFailNonce implements NonceManager {
14- public function getPendingNonce (string $ address , callable $ fetcher ): int { return 1 ; }
25+ class FFailNonce implements NonceManager
26+ {
27+ public function getPendingNonce (string $ address , callable $ fetcher ): int
28+ {
29+ return 1 ;
30+ }
31+
1532 public function markUsed (string $ address , int $ nonce ): void {}
1633}
17- class FFailFees implements FeePolicy {
18- public function suggest (callable $ gasPriceFetcher ): array { return [1_000_000_000 , 50_000_000_000 ]; }
19- public function replace (int $ oldPriority , int $ oldMax ): array { return [$ oldPriority + 1_000_000_000 , $ oldMax + 10_000_000_000 ]; }
34+ class FFailFees implements FeePolicy
35+ {
36+ public function suggest (callable $ gasPriceFetcher ): array
37+ {
38+ return [1_000_000_000 , 50_000_000_000 ];
39+ }
40+
41+ public function replace (int $ oldPriority , int $ oldMax ): array
42+ {
43+ return [$ oldPriority + 1_000_000_000 , $ oldMax + 10_000_000_000 ];
44+ }
2045}
21- class FFailRpc implements RpcClient {
22- public function call (string $ method , array $ params = []): mixed {
23- if ($ method === 'eth_estimateGas ' ) { return '0x5208 ' ; }
24- if ($ method === 'eth_getTransactionCount ' ) { return '0x1 ' ; }
25- if ($ method === 'eth_gasPrice ' ) { return '0x3b9aca00 ' ; }
26- if ($ method === 'eth_getTransactionReceipt ' ) { return []; }
27- if ($ method === 'eth_sendRawTransaction ' ) { throw new RuntimeException ('simulated failure ' ); }
46+ class FFailRpc implements RpcClient
47+ {
48+ public function call (string $ method , array $ params = []): mixed
49+ {
50+ if ($ method === 'eth_estimateGas ' ) {
51+ return '0x5208 ' ;
52+ }
53+ if ($ method === 'eth_getTransactionCount ' ) {
54+ return '0x1 ' ;
55+ }
56+ if ($ method === 'eth_gasPrice ' ) {
57+ return '0x3b9aca00 ' ;
58+ }
59+ if ($ method === 'eth_getTransactionReceipt ' ) {
60+ return [];
61+ }
62+ if ($ method === 'eth_sendRawTransaction ' ) {
63+ throw new RuntimeException ('simulated failure ' );
64+ }
65+
2866 return [];
2967 }
30- public function callRaw (string $ method , array $ params = []): array { return []; }
31- public function health (): array { return ['chainId ' => 137 , 'block ' => 123 ]; }
68+
69+ public function callRaw (string $ method , array $ params = []): array
70+ {
71+ return [];
72+ }
73+
74+ public function health (): array
75+ {
76+ return ['chainId ' => 137 , 'block ' => 123 ];
77+ }
3278}
3379
3480it ('emits TxFailed on initial broadcast error ' , function () {
@@ -43,10 +89,10 @@ public function health(): array { return ['chainId' => 137, 'block' => 123]; }
4389 'confirm_timeout ' => 0 ,
4490 'max_replacements ' => 0 ,
4591 'poll_interval_ms ' => 50 ,
46- 'queue ' => 'evm-send '
92+ 'queue ' => 'evm-send ' ,
4793 ]
4894 );
49- $ job ->handle (new FFailRpc () , new FFailSigner ('0x ' .str_repeat ('aa ' ,32 )), new FFailNonce () , new FFailFees () );
95+ $ job ->handle (new FFailRpc , new FFailSigner ('0x ' .str_repeat ('aa ' , 32 )), new FFailNonce , new FFailFees );
5096 Event::assertDispatched (TxFailed::class, function ($ e ) {
5197 return str_contains ($ e ->reason , 'rpc_send_error ' );
5298 });
0 commit comments