Skip to content

Commit b46886d

Browse files
committed
In tests use inheritance and not libraries unless required for the test
1 parent 4c37589 commit b46886d

File tree

1 file changed

+84
-84
lines changed

1 file changed

+84
-84
lines changed

test/compiler.js

+84-84
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ function runTests (solc, versionText) {
102102
return;
103103
}
104104

105-
var output = JSON.parse(solc.lowlevel.compileSingle('contract x { function g() public {} }'));
105+
var output = JSON.parse(solc.lowlevel.compileSingle('contract A { function g() public {} }'));
106106
st.ok('contracts' in output);
107-
var bytecode = getBytecode(output, '', 'x');
107+
var bytecode = getBytecode(output, '', 'A');
108108
st.ok(typeof bytecode === 'string');
109109
st.ok(bytecode.length > 0);
110110
st.end();
@@ -152,16 +152,16 @@ function runTests (solc, versionText) {
152152
}
153153

154154
var input = {
155-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
156-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
155+
'a.sol': 'contract A { function f() public returns (uint) { return 7; } }',
156+
'b.sol': 'import "a.sol"; contract B is A { function g() public { f(); } }'
157157
};
158158
var output = JSON.parse(solc.lowlevel.compileMulti(JSON.stringify({sources: input})));
159-
var x = getBytecode(output, 'cont.sol', 'x');
160-
st.ok(typeof x === 'string');
161-
st.ok(x.length > 0);
162-
var L = getBytecode(output, 'lib.sol', 'L');
163-
st.ok(typeof L === 'string');
164-
st.ok(L.length > 0);
159+
var B = getBytecode(output, 'b.sol', 'B');
160+
st.ok(typeof B === 'string');
161+
st.ok(B.length > 0);
162+
var A = getBytecode(output, 'a.sol', 'A');
163+
st.ok(typeof A === 'string');
164+
st.ok(A.length > 0);
165165
st.end();
166166
});
167167

@@ -174,22 +174,22 @@ function runTests (solc, versionText) {
174174
}
175175

176176
var input = {
177-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
177+
'b.sol': 'import "a.sol"; contract B is A { function g() public { f(); } }'
178178
};
179179
function findImports (path) {
180-
if (path === 'lib.sol') {
181-
return { contents: 'library L { function f() public returns (uint) { return 7; } }' };
180+
if (path === 'a.sol') {
181+
return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
182182
} else {
183183
return { error: 'File not found' };
184184
}
185185
}
186186
var output = JSON.parse(solc.lowlevel.compileCallback(JSON.stringify({sources: input}), 0, findImports));
187-
var x = getBytecode(output, 'cont.sol', 'x');
188-
var L = getBytecode(output, 'lib.sol', 'L');
189-
st.ok(typeof x === 'string');
190-
st.ok(x.length > 0);
191-
st.ok(typeof L === 'string');
192-
st.ok(L.length > 0);
187+
var B = getBytecode(output, 'b.sol', 'B');
188+
st.ok(typeof B === 'string');
189+
st.ok(B.length > 0);
190+
var A = getBytecode(output, 'a.sol', 'A');
191+
st.ok(typeof A === 'string');
192+
st.ok(A.length > 0);
193193
st.end();
194194
});
195195

@@ -202,7 +202,7 @@ function runTests (solc, versionText) {
202202
}
203203

204204
var input = {
205-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
205+
'b.sol': 'import "a.sol"; contract B { function g() public { f(); } }'
206206
};
207207
function findImports (path) {
208208
return { error: 'File not found' };
@@ -232,7 +232,7 @@ function runTests (solc, versionText) {
232232
}
233233

234234
var input = {
235-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
235+
'b.sol': 'import "a.sol"; contract B { function g() public { f(); } }'
236236
};
237237
function findImports (path) {
238238
throw new Error('Could not implement this interface properly...');
@@ -269,7 +269,7 @@ function runTests (solc, versionText) {
269269
}
270270

271271
var input = {
272-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
272+
'b.sol': 'import "a.sol"; contract B is A { function g() public { f(); } }'
273273
};
274274
var output = JSON.parse(solc.lowlevel.compileCallback(JSON.stringify({sources: input})));
275275
st.plan(3);
@@ -304,11 +304,11 @@ function runTests (solc, versionText) {
304304
}
305305
},
306306
'sources': {
307-
'lib.sol': {
308-
'content': 'library L { function f() public returns (uint) { return 7; } }'
307+
'a.sol': {
308+
'content': 'contract A { function f() public returns (uint) { return 7; } }'
309309
},
310-
'cont.sol': {
311-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
310+
'b.sol': {
311+
'content': 'import "a.sol"; contract B is A { function g() public { f(); } }'
312312
}
313313
}
314314
};
@@ -322,8 +322,8 @@ function runTests (solc, versionText) {
322322
}
323323

324324
var output = JSON.parse(solc.lowlevel.compileStandard(JSON.stringify(input)));
325-
st.ok(bytecodeExists(output, 'cont.sol', 'x'));
326-
st.ok(bytecodeExists(output, 'lib.sol', 'L'));
325+
st.ok(bytecodeExists(output, 'a.sol', 'A'));
326+
st.ok(bytecodeExists(output, 'b.sol', 'B'));
327327
st.end();
328328
});
329329

@@ -379,15 +379,15 @@ function runTests (solc, versionText) {
379379
}
380380
},
381381
'sources': {
382-
'cont.sol': {
383-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
382+
'b.sol': {
383+
'content': 'import "a.sol"; contract B is A { function g() public { f(); } }'
384384
}
385385
}
386386
};
387387

388388
function findImports (path) {
389-
if (path === 'lib.sol') {
390-
return { contents: 'library L { function f() public returns (uint) { return 7; } }' };
389+
if (path === 'a.sol') {
390+
return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
391391
} else {
392392
return { error: 'File not found' };
393393
}
@@ -402,8 +402,8 @@ function runTests (solc, versionText) {
402402
}
403403

404404
var output = JSON.parse(solc.lowlevel.compileStandard(JSON.stringify(input), findImports));
405-
st.ok(bytecodeExists(output, 'cont.sol', 'x'));
406-
st.ok(bytecodeExists(output, 'lib.sol', 'L'));
405+
st.ok(bytecodeExists(output, 'a.sol', 'A'));
406+
st.ok(bytecodeExists(output, 'b.sol', 'B'));
407407
st.end();
408408
});
409409

@@ -425,31 +425,31 @@ function runTests (solc, versionText) {
425425
}
426426
},
427427
'sources': {
428-
'lib.sol': {
429-
'content': 'library L { function f() public returns (uint) { return 7; } }'
428+
'a.sol': {
429+
'content': 'contract A { function f() public returns (uint) { return 7; } }'
430430
},
431-
'cont.sol': {
432-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } function h() internal {} }'
431+
'b.sol': {
432+
'content': 'import "a.sol"; contract B is A { function g() public { f(); } function h() internal {} }'
433433
}
434434
}
435435
};
436436

437437
var output = JSON.parse(solc.compile(JSON.stringify(input)));
438438
st.ok(expectNoError(output));
439-
var x = getBytecodeStandard(output, 'cont.sol', 'x');
440-
st.ok(typeof x === 'string');
441-
st.ok(x.length > 0);
442-
var xGas = getGasEstimate(output, 'cont.sol', 'x');
443-
st.ok(typeof xGas === 'object');
444-
st.ok(typeof xGas['creation'] === 'object');
445-
st.ok(typeof xGas['creation']['codeDepositCost'] === 'string');
446-
st.ok(typeof xGas['external'] === 'object');
447-
st.ok(typeof xGas['external']['g()'] === 'string');
448-
st.ok(typeof xGas['internal'] === 'object');
449-
st.ok(typeof xGas['internal']['h()'] === 'string');
450-
var L = getBytecodeStandard(output, 'lib.sol', 'L');
451-
st.ok(typeof L === 'string');
452-
st.ok(L.length > 0);
439+
var B = getBytecodeStandard(output, 'b.sol', 'B');
440+
st.ok(typeof B === 'string');
441+
st.ok(B.length > 0);
442+
var BGas = getGasEstimate(output, 'b.sol', 'B');
443+
st.ok(typeof BGas === 'object');
444+
st.ok(typeof BGas['creation'] === 'object');
445+
st.ok(typeof BGas['creation']['codeDepositCost'] === 'string');
446+
st.ok(typeof BGas['external'] === 'object');
447+
st.ok(typeof BGas['external']['g()'] === 'string');
448+
st.ok(typeof BGas['internal'] === 'object');
449+
st.ok(typeof BGas['internal']['h()'] === 'string');
450+
var A = getBytecodeStandard(output, 'a.sol', 'A');
451+
st.ok(typeof A === 'string');
452+
st.ok(A.length > 0);
453453
st.end();
454454
});
455455

@@ -471,28 +471,28 @@ function runTests (solc, versionText) {
471471
}
472472
},
473473
'sources': {
474-
'cont.sol': {
475-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
474+
'b.sol': {
475+
'content': 'import "a.sol"; contract B is A { function g() public { f(); } }'
476476
}
477477
}
478478
};
479479

480480
function findImports (path) {
481-
if (path === 'lib.sol') {
482-
return { contents: 'library L { function f() public returns (uint) { return 7; } }' };
481+
if (path === 'a.sol') {
482+
return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
483483
} else {
484484
return { error: 'File not found' };
485485
}
486486
}
487487

488488
var output = JSON.parse(solc.compile(JSON.stringify(input), findImports));
489489
st.ok(expectNoError(output));
490-
var x = getBytecodeStandard(output, 'cont.sol', 'x');
491-
st.ok(typeof x === 'string');
492-
st.ok(x.length > 0);
493-
var L = getBytecodeStandard(output, 'lib.sol', 'L');
494-
st.ok(typeof L === 'string');
495-
st.ok(L.length > 0);
490+
var A = getBytecodeStandard(output, 'a.sol', 'A');
491+
st.ok(typeof A === 'string');
492+
st.ok(A.length > 0);
493+
var B = getBytecodeStandard(output, 'b.sol', 'B');
494+
st.ok(typeof B === 'string');
495+
st.ok(B.length > 0);
496496
st.end();
497497
});
498498

@@ -514,28 +514,28 @@ function runTests (solc, versionText) {
514514
}
515515
},
516516
'sources': {
517-
'cont.sol': {
518-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
517+
'b.sol': {
518+
'content': 'import "a.sol"; contract B is A { function g() public { f(); } }'
519519
}
520520
}
521521
};
522522

523523
function findImports (path) {
524-
if (path === 'lib.sol') {
525-
return { contents: 'library L { function f() public returns (uint) { return 7; } }' };
524+
if (path === 'a.sol') {
525+
return { contents: 'contract A { function f() public returns (uint) { return 7; } }' };
526526
} else {
527527
return { error: 'File not found' };
528528
}
529529
}
530530

531531
var output = JSON.parse(solc.compile(JSON.stringify(input), { import: findImports }));
532532
st.ok(expectNoError(output));
533-
var x = getBytecodeStandard(output, 'cont.sol', 'x');
534-
st.ok(typeof x === 'string');
535-
st.ok(x.length > 0);
536-
var L = getBytecodeStandard(output, 'lib.sol', 'L');
537-
st.ok(typeof L === 'string');
538-
st.ok(L.length > 0);
533+
var A = getBytecodeStandard(output, 'a.sol', 'A');
534+
st.ok(typeof A === 'string');
535+
st.ok(A.length > 0);
536+
var B = getBytecodeStandard(output, 'b.sol', 'B');
537+
st.ok(typeof B === 'string');
538+
st.ok(B.length > 0);
539539
st.end();
540540
});
541541

@@ -565,18 +565,18 @@ function runTests (solc, versionText) {
565565
'lib.sol': {
566566
'content': 'library L { function f() public returns (uint) { return 7; } }'
567567
},
568-
'cont.sol': {
569-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
568+
'a.sol': {
569+
'content': 'import "lib.sol"; contract A { function g() public { L.f(); } }'
570570
}
571571
}
572572
};
573573

574574
var output = JSON.parse(solc.compile(JSON.stringify(input)));
575575
st.ok(expectNoError(output));
576-
var x = getBytecodeStandard(output, 'cont.sol', 'x');
577-
st.ok(typeof x === 'string');
578-
st.ok(x.length > 0);
579-
st.ok(Object.keys(linker.findLinkReferences(x)).length === 0);
576+
var A = getBytecodeStandard(output, 'a.sol', 'A');
577+
st.ok(typeof A === 'string');
578+
st.ok(A.length > 0);
579+
st.ok(Object.keys(linker.findLinkReferences(A)).length === 0);
580580
var L = getBytecodeStandard(output, 'lib.sol', 'L');
581581
st.ok(typeof L === 'string');
582582
st.ok(L.length > 0);
@@ -608,18 +608,18 @@ function runTests (solc, versionText) {
608608
'lib.sol': {
609609
'content': 'library L { function f() public returns (uint) { return 7; } }'
610610
},
611-
'cont.sol': {
612-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
611+
'a.sol': {
612+
'content': 'import "lib.sol"; contract A { function g() public { L.f(); } }'
613613
}
614614
}
615615
};
616616

617617
var output = JSON.parse(solc.lowlevel.compileStandard(JSON.stringify(input)));
618618
st.ok(expectNoError(output));
619-
var x = getBytecodeStandard(output, 'cont.sol', 'x');
620-
st.ok(typeof x === 'string');
621-
st.ok(x.length > 0);
622-
st.ok(Object.keys(linker.findLinkReferences(x)).length === 0);
619+
var A = getBytecodeStandard(output, 'a.sol', 'A');
620+
st.ok(typeof A === 'string');
621+
st.ok(A.length > 0);
622+
st.ok(Object.keys(linker.findLinkReferences(A)).length === 0);
623623
var L = getBytecodeStandard(output, 'lib.sol', 'L');
624624
st.ok(typeof L === 'string');
625625
st.ok(L.length > 0);

0 commit comments

Comments
 (0)