UNPKG

1.95 kBJavaScriptView Raw
1var assert = require("assert");
2var solc = require("solc");
3var Schema = require("../");
4var debug = require("debug")("test:solc"); // eslint-disable-line no-unused-vars
5
6describe("solc", function() {
7 var exampleSolidity = `pragma solidity ^0.5.0;
8
9contract A {
10 uint x;
11
12 function doStuff() public {
13 x = 5;
14 }
15}
16
17contract B {
18 function somethingElse() public pure {}
19}
20`;
21
22 it("processes solc standard JSON output correctly", function(done) {
23 this.timeout(5000);
24
25 var solcIn = JSON.stringify({
26 language: "Solidity",
27 sources: {
28 "A.sol": {
29 content: exampleSolidity
30 }
31 },
32 settings: {
33 outputSelection: {
34 "*": {
35 "*": [
36 "abi",
37 "evm.bytecode.object",
38 "evm.bytecode.sourceMap",
39 "evm.deployedBytecode.object",
40 "evm.deployedBytecode.sourceMap",
41 "devdoc",
42 "userdoc"
43 ]
44 }
45 }
46 }
47 });
48 var solcOut = JSON.parse(solc.compile(solcIn));
49
50 // contracts now grouped by solidity source file
51 var rawA = solcOut.contracts["A.sol"].A;
52
53 var A = Schema.normalize(rawA);
54
55 var expected = {
56 abi: rawA.abi,
57 bytecode: "0x" + rawA.evm.bytecode.object,
58 deployedBytecode: "0x" + rawA.evm.deployedBytecode.object,
59 sourceMap: rawA.evm.bytecode.sourceMap,
60 deployedSourceMap: rawA.evm.deployedBytecode.sourceMap
61 };
62
63 Object.keys(expected).forEach(function(key) {
64 var expectedValue = expected[key];
65 var actualValue = A[key];
66
67 assert.deepEqual(
68 actualValue,
69 expectedValue,
70 "Mismatched schema output for key `" +
71 key +
72 "` (" +
73 JSON.stringify(actualValue) +
74 " != " +
75 JSON.stringify(expectedValue) +
76 ")"
77 );
78 });
79
80 // throws error if invalid
81 Schema.validate(A);
82 done();
83 });
84});