1
+ const assert = require ( 'assert' ) ;
1
2
const tape = require ( 'tape' ) ;
2
3
const semver = require ( 'semver' ) ;
3
4
const solc = require ( '../index.js' ) ;
@@ -9,6 +10,16 @@ var noRemoteVersions = (process.argv.indexOf('--no-remote-versions') >= 0);
9
10
function runTests ( solc , versionText ) {
10
11
console . log ( `Running tests with ${ versionText } ${ solc . version ( ) } ` ) ;
11
12
13
+ function resplitFileNameOnFirstColon ( fileName , contractName ) {
14
+ assert ( ! contractName . includes ( ':' ) ) ;
15
+
16
+ let contractNameComponents = fileName . split ( ':' ) ;
17
+ const truncatedFileName = contractNameComponents . shift ( ) ;
18
+ contractNameComponents . push ( contractName ) ;
19
+
20
+ return [ truncatedFileName , contractNameComponents . join ( ':' ) ] ;
21
+ }
22
+
12
23
function getBytecode ( output , fileName , contractName ) {
13
24
try {
14
25
var outputContract ;
@@ -29,6 +40,9 @@ function runTests (solc, versionText) {
29
40
if ( semver . lt ( solc . semver ( ) , '0.4.9' ) ) {
30
41
outputFile = output . contracts [ '' ] ;
31
42
} else {
43
+ if ( semver . gt ( solc . semver ( ) , '0.4.10' ) && semver . lt ( solc . semver ( ) , '0.4.20' ) ) {
44
+ [ fileName , contractName ] = resplitFileNameOnFirstColon ( fileName , contractName ) ;
45
+ }
32
46
outputFile = output . contracts [ fileName ] ;
33
47
}
34
48
return outputFile [ contractName ] [ 'evm' ] [ 'bytecode' ] [ 'object' ] ;
@@ -43,6 +57,9 @@ function runTests (solc, versionText) {
43
57
if ( semver . lt ( solc . semver ( ) , '0.4.9' ) ) {
44
58
outputFile = output . contracts [ '' ] ;
45
59
} else {
60
+ if ( semver . gt ( solc . semver ( ) , '0.4.10' ) && semver . gt ( solc . semver ( ) , '0.4.20' ) ) {
61
+ [ fileName , contractName ] = resplitFileNameOnFirstColon ( fileName , contractName ) ;
62
+ }
46
63
outputFile = output . contracts [ fileName ] ;
47
64
}
48
65
return outputFile [ contractName ] [ 'evm' ] [ 'gasEstimates' ] ;
@@ -757,6 +774,56 @@ function runTests (solc, versionText) {
757
774
}
758
775
st . end ( ) ;
759
776
} ) ;
777
+
778
+ t . test ( 'compiling standard JSON (file names containing symbols)' , function ( st ) {
779
+ var input = {
780
+ 'language' : 'Solidity' ,
781
+ 'settings' : {
782
+ 'outputSelection' : {
783
+ '*' : {
784
+ '*' : [ 'evm.bytecode' ]
785
+ }
786
+ }
787
+ } ,
788
+ 'sources' : {
789
+ '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/' : {
790
+ 'content' : 'contract C {}'
791
+ }
792
+ }
793
+ } ;
794
+
795
+ var output = JSON . parse ( solc . compile ( JSON . stringify ( input ) ) ) ;
796
+ st . ok ( expectNoError ( output ) ) ;
797
+ var C = getBytecodeStandard ( output , '!@#$%^&*()_+-=[]{}\\|"\';:~`<>,.?/' , 'C' ) ;
798
+ st . ok ( typeof C === 'string' ) ;
799
+ st . ok ( C . length > 0 ) ;
800
+ st . end ( ) ;
801
+ } ) ;
802
+
803
+ t . test ( 'compiling standard JSON (file names containing multiple semicolons)' , function ( st ) {
804
+ var input = {
805
+ 'language' : 'Solidity' ,
806
+ 'settings' : {
807
+ 'outputSelection' : {
808
+ '*' : {
809
+ '*' : [ 'evm.bytecode' ]
810
+ }
811
+ }
812
+ } ,
813
+ 'sources' : {
814
+ 'a:b:c:d:e:f:G.sol' : {
815
+ 'content' : 'contract G {}'
816
+ }
817
+ }
818
+ } ;
819
+
820
+ var output = JSON . parse ( solc . compile ( JSON . stringify ( input ) ) ) ;
821
+ st . ok ( expectNoError ( output ) ) ;
822
+ var G = getBytecodeStandard ( output , 'a:b:c:d:e:f:G.sol' , 'G' ) ;
823
+ st . ok ( typeof G === 'string' ) ;
824
+ st . ok ( G . length > 0 ) ;
825
+ st . end ( ) ;
826
+ } ) ;
760
827
} ) ;
761
828
} ) ;
762
829
@@ -810,8 +877,12 @@ if (!noRemoteVersions) {
810
877
'v0.2.1+commit.91a6b35' ,
811
878
'v0.3.6+commit.3fc68da' ,
812
879
'v0.4.0+commit.acd334c9' ,
880
+ 'v0.4.9+commit.364da425' ,
881
+ 'v0.4.10+commit.f0d539ae' ,
813
882
'v0.4.11+commit.68ef5810' ,
814
883
'v0.4.12+commit.194ff033' ,
884
+ 'v0.4.19+commit.c4cbbb05' ,
885
+ 'v0.4.20+commit.3155dd80' ,
815
886
'v0.4.26+commit.4563c3fc'
816
887
] ;
817
888
for ( var version in versions ) {
0 commit comments