File tree 2 files changed +61
-1
lines changed
src/compiler/compilers/starknet_contract
2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -332,9 +332,18 @@ pub fn find_project_contracts(
332
332
Vec :: new ( )
333
333
} ;
334
334
335
- Ok ( internal_contracts
335
+ // Deduplicate found contracts by contract path.
336
+ let mut contracts_found = internal_contracts
336
337
. into_iter ( )
337
338
. chain ( external_contracts)
339
+ . map ( |decl| ( decl. module_id ( ) . full_path ( db. upcast ( ) ) , decl) )
340
+ . sorted_by_key ( |( path, _) | path. clone ( ) )
341
+ . collect_vec ( ) ;
342
+ contracts_found. dedup_by_key ( |( path, _) | path. clone ( ) ) ;
343
+
344
+ Ok ( contracts_found
345
+ . into_iter ( )
346
+ . map ( |( _path, decl) | decl)
338
347
. collect ( ) )
339
348
}
340
349
Original file line number Diff line number Diff line change @@ -558,3 +558,54 @@ fn can_build_external_reexported_contracts() {
558
558
]
559
559
) ;
560
560
}
561
+ #[ test]
562
+ fn can_dedup_contract_reexports ( ) {
563
+ let t = TempDir :: new ( ) . unwrap ( ) ;
564
+ let hello = t. child ( "hello" ) ;
565
+ let world = t. child ( "world" ) ;
566
+
567
+ ProjectBuilder :: start ( )
568
+ . name ( "hello" )
569
+ . version ( "0.1.0" )
570
+ . manifest_extra ( indoc ! { r#"
571
+ [lib]
572
+ [[target.starknet-contract]]
573
+ "# } )
574
+ . dep_starknet ( )
575
+ . lib_cairo ( indoc ! { r#"
576
+ // Note that Balance contract can be accessed both through mod tree and the reexport.
577
+ pub mod a;
578
+ pub use a::Balance;
579
+ "# } )
580
+ . src ( "src/a.cairo" , BALANCE_CONTRACT )
581
+ . build ( & hello) ;
582
+
583
+ ProjectBuilder :: start ( )
584
+ . name ( "world" )
585
+ . version ( "0.1.0" )
586
+ . dep ( "hello" , hello)
587
+ . manifest_extra ( formatdoc ! { r#"
588
+ [[target.starknet-contract]]
589
+ build-external-contracts = ["hello::*"]
590
+ "# } )
591
+ . dep_starknet ( )
592
+ . build ( & world) ;
593
+
594
+ Scarb :: quick_snapbox ( )
595
+ . arg ( "build" )
596
+ . current_dir ( & world)
597
+ . assert ( )
598
+ . success ( )
599
+ . stdout_matches ( indoc ! { r#"
600
+ [..] Compiling world v0.1.0 ([..]/Scarb.toml)
601
+ [..] Finished `dev` profile target(s) in [..]
602
+ "# } ) ;
603
+
604
+ assert_eq ! (
605
+ world. child( "target/dev" ) . files( ) ,
606
+ vec![
607
+ "world.starknet_artifacts.json" ,
608
+ "world_Balance.contract_class.json" ,
609
+ ]
610
+ ) ;
611
+ }
You can’t perform that action at this time.
0 commit comments