File tree Expand file tree Collapse file tree 2 files changed +74
-3
lines changed Expand file tree Collapse file tree 2 files changed +74
-3
lines changed Original file line number Diff line number Diff line change @@ -115,24 +115,26 @@ impl ContractsByArtifact {
115115
116116 /// Finds a contract which has a similar bytecode as `code`.
117117 pub fn find_by_creation_code ( & self , code : & [ u8 ] ) -> Option < ArtifactWithContractRef < ' _ > > {
118- self . find_by_code ( code, ContractData :: bytecode)
118+ self . find_by_code ( code, 0.1 , ContractData :: bytecode)
119119 }
120120
121121 /// Finds a contract which has a similar deployed bytecode as `code`.
122122 pub fn find_by_deployed_code ( & self , code : & [ u8 ] ) -> Option < ArtifactWithContractRef < ' _ > > {
123- self . find_by_code ( code, ContractData :: deployed_bytecode)
123+ self . find_by_code ( code, 0.15 , ContractData :: deployed_bytecode)
124124 }
125125
126+ /// Finds a contract based on provided bytecode and accepted match score.
126127 fn find_by_code (
127128 & self ,
128129 code : & [ u8 ] ,
130+ accepted_score : f64 ,
129131 get : impl Fn ( & ContractData ) -> Option < & Bytes > ,
130132 ) -> Option < ArtifactWithContractRef < ' _ > > {
131133 self . iter ( )
132134 . filter_map ( |( id, contract) | {
133135 if let Some ( deployed_bytecode) = get ( contract) {
134136 let score = bytecode_diff_score ( deployed_bytecode. as_ref ( ) , code) ;
135- ( score <= 0.1 ) . then_some ( ( score, ( id, contract) ) )
137+ ( score <= accepted_score ) . then_some ( ( score, ( id, contract) ) )
136138 } else {
137139 None
138140 }
Original file line number Diff line number Diff line change @@ -1202,3 +1202,72 @@ contract AContractTest is DSTest {
12021202"# ] ] ,
12031203 ) ;
12041204} ) ;
1205+
1206+ forgetest ! ( test_identical_bytecodes, |prj, cmd| {
1207+ prj. insert_ds_test( ) ;
1208+ prj. add_source(
1209+ "AContract.sol" ,
1210+ r#"
1211+ contract AContract {
1212+ uint256 public number;
1213+ address public immutable usdc1;
1214+ address public immutable usdc2;
1215+ address public immutable usdc3;
1216+ address public immutable usdc4;
1217+ address public immutable usdc5;
1218+ address public immutable usdc6;
1219+
1220+ constructor() {
1221+ address a = 0x176211869cA2b568f2A7D4EE941E073a821EE1ff;
1222+ usdc1 = a;
1223+ usdc2 = a;
1224+ usdc3 = a;
1225+ usdc4 = a;
1226+ usdc5 = a;
1227+ usdc6 = a;
1228+ }
1229+
1230+ function setNumber(uint256 newNumber) public {
1231+ number = newNumber;
1232+ }
1233+
1234+ function increment() public {
1235+ number++;
1236+ }
1237+ }
1238+ "# ,
1239+ )
1240+ . unwrap( ) ;
1241+
1242+ prj. add_source(
1243+ "AContractTest.sol" ,
1244+ r#"
1245+ import "./test.sol";
1246+ import {AContract} from "./AContract.sol";
1247+
1248+ contract AContractTest is DSTest {
1249+ AContract public counter;
1250+
1251+ function setUp() public {
1252+ counter = new AContract();
1253+ counter.setNumber(0);
1254+ }
1255+
1256+ function test_Increment() public {
1257+ counter.increment();
1258+ assertEq(counter.number(), 1);
1259+ }
1260+ }
1261+ "# ,
1262+ )
1263+ . unwrap( ) ;
1264+
1265+ cmd. arg( "coverage" ) . args( [ "--summary" . to_string( ) ] ) . assert_success( ) . stdout_eq( str ![ [ r#"
1266+ ...
1267+ | File | % Lines | % Statements | % Branches | % Funcs |
1268+ |-------------------|---------------|---------------|---------------|---------------|
1269+ | src/AContract.sol | 100.00% (9/9) | 100.00% (9/9) | 100.00% (0/0) | 100.00% (3/3) |
1270+ | Total | 100.00% (9/9) | 100.00% (9/9) | 100.00% (0/0) | 100.00% (3/3) |
1271+
1272+ "# ] ] ) ;
1273+ } ) ;
You can’t perform that action at this time.
0 commit comments