@@ -471,7 +471,7 @@ func TestFetchSACMetadata(t *testing.T) {
471471 assert .Equal (t , uint32 (7 ), contract .Decimals )
472472 })
473473
474- t .Run ("skips contract with malformed name gracefully " , func (t * testing.T ) {
474+ t .Run ("returns error for contract with malformed name" , func (t * testing.T ) {
475475 mockRPCService := NewRPCServiceMock (t )
476476 mockContractModel := data .NewContractModelMock (t )
477477 pool := pond .NewPool (5 )
@@ -493,12 +493,14 @@ func TestFetchSACMetadata(t *testing.T) {
493493
494494 result , err := service .FetchSACMetadata (ctx , []string {contractID })
495495
496- // Should not error, but skip the malformed contract
497- require .NoError (t , err )
498- assert .Empty (t , result )
496+ // Should return error for malformed contract name
497+ require .Error (t , err )
498+ assert .Nil (t , result )
499+ assert .Contains (t , err .Error (), "failed to fetch metadata" )
500+ assert .Contains (t , err .Error (), "malformed SAC name" )
499501 })
500502
501- t .Run ("skips contract when RPC fails gracefully " , func (t * testing.T ) {
503+ t .Run ("returns error when RPC fails" , func (t * testing.T ) {
502504 mockRPCService := NewRPCServiceMock (t )
503505 mockContractModel := data .NewContractModelMock (t )
504506 pool := pond .NewPool (5 )
@@ -515,9 +517,11 @@ func TestFetchSACMetadata(t *testing.T) {
515517
516518 result , err := service .FetchSACMetadata (ctx , []string {contractID })
517519
518- // Should not error, but skip the failed contract
519- require .NoError (t , err )
520- assert .Empty (t , result )
520+ // Should return error when RPC fails
521+ require .Error (t , err )
522+ assert .Nil (t , result )
523+ assert .Contains (t , err .Error (), "failed to fetch metadata" )
524+ assert .Contains (t , err .Error (), "RPC timeout" )
521525 })
522526
523527 t .Run ("processes multiple contracts successfully" , func (t * testing.T ) {
@@ -553,6 +557,38 @@ func TestFetchSACMetadata(t *testing.T) {
553557 require .NoError (t , err )
554558 assert .Len (t , result , 2 )
555559 })
560+
561+ t .Run ("returns error and no partial results when one contract fails" , func (t * testing.T ) {
562+ mockRPCService := NewRPCServiceMock (t )
563+ mockContractModel := data .NewContractModelMock (t )
564+ pool := pond .NewPool (5 )
565+ defer pool .Stop ()
566+
567+ contractID1 := "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC"
568+ contractID2 := "CA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJUWDA"
569+
570+ // First contract succeeds, second fails
571+ nameScVal1 := xdr.ScVal {Type : xdr .ScValTypeScvString , Str : ptrToScString ("USDC:GCNY5OXYSY4FKHOPT2SPOQZAOEIGXB5LBYW3HVU3OWSTQITS65M5RCNY" )}
572+
573+ mockRPCService .On ("SimulateTransaction" , mock .Anything , mock .Anything ).Return (
574+ entities.RPCSimulateTransactionResult {
575+ Results : []entities.RPCSimulateHostFunctionResult {{XDR : nameScVal1 }},
576+ }, nil ,
577+ ).Once ()
578+ mockRPCService .On ("SimulateTransaction" , mock .Anything , mock .Anything ).Return (
579+ entities.RPCSimulateTransactionResult {}, errors .New ("RPC timeout" ),
580+ ).Once ()
581+
582+ service , err := NewContractMetadataService (mockRPCService , mockContractModel , pool )
583+ require .NoError (t , err )
584+
585+ result , err := service .FetchSACMetadata (ctx , []string {contractID1 , contractID2 })
586+
587+ // Should return error and no partial results
588+ require .Error (t , err )
589+ assert .Nil (t , result )
590+ assert .Contains (t , err .Error (), "failed to fetch metadata for 1 SAC contracts" )
591+ })
556592}
557593
558594func TestFetchBatch (t * testing.T ) {
0 commit comments