UNPKG

2.06 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 "metadata",
38 "evm.bytecode.object",
39 "evm.bytecode.sourceMap",
40 "evm.deployedBytecode.object",
41 "evm.deployedBytecode.sourceMap",
42 "devdoc",
43 "userdoc"
44 ]
45 }
46 }
47 }
48 });
49 var solcOut = JSON.parse(solc.compile(solcIn));
50
51 // contracts now grouped by solidity source file
52 var rawA = solcOut.contracts["A.sol"].A;
53
54 var A = Schema.normalize(rawA);
55
56 var expected = {
57 abi: rawA.abi,
58 metadata: rawA.metadata,
59 bytecode: "0x" + rawA.evm.bytecode.object,
60 deployedBytecode: "0x" + rawA.evm.deployedBytecode.object,
61 sourceMap: rawA.evm.bytecode.sourceMap,
62 deployedSourceMap: rawA.evm.deployedBytecode.sourceMap,
63 devdoc: rawA.devdoc,
64 userdoc: rawA.userdoc
65 };
66
67 Object.keys(expected).forEach(function(key) {
68 var expectedValue = expected[key];
69 var actualValue = A[key];
70
71 assert.deepEqual(
72 actualValue,
73 expectedValue,
74 "Mismatched schema output for key `" +
75 key +
76 "` (" +
77 JSON.stringify(actualValue) +
78 " != " +
79 JSON.stringify(expectedValue) +
80 ")"
81 );
82 });
83
84 // throws error if invalid
85 Schema.validate(A);
86 done();
87 });
88});