@truffle/contract-schema
Advanced tools
Comparing version 3.3.2 to 3.3.3
35
index.js
@@ -71,3 +71,3 @@ var pkgVersion = require("./package.json").version; | ||
value = JSON.parse(value); | ||
} catch (e) { | ||
} catch (_) { | ||
value = undefined; | ||
@@ -111,5 +111,27 @@ } | ||
sourceMap: { | ||
transform: function (value) { | ||
if (typeof value === "string") { | ||
try { | ||
return JSON.parse(value); | ||
} catch (_) { | ||
return value; | ||
} | ||
} else { | ||
return value; | ||
} | ||
}, | ||
sources: ["sourceMap", "srcmap", "evm.bytecode.sourceMap"] | ||
}, | ||
deployedSourceMap: { | ||
transform: function (value) { | ||
if (typeof value === "string") { | ||
try { | ||
return JSON.parse(value); | ||
} catch (_) { | ||
return value; | ||
} | ||
} else { | ||
return value; | ||
} | ||
}, | ||
sources: [ | ||
@@ -126,9 +148,6 @@ "deployedSourceMap", | ||
transform: function (value, obj) { | ||
var schemaVersion = obj.schemaVersion || "0.0.0"; | ||
// legacyAST introduced in v2.0.0 | ||
if (schemaVersion[0] < 2) { | ||
if (value) { | ||
return value; | ||
} else { | ||
return obj.ast; | ||
} else { | ||
return value; | ||
} | ||
@@ -202,3 +221,3 @@ } | ||
return transform(obj[key]); | ||
} catch (e) { | ||
} catch (_) { | ||
return undefined; | ||
@@ -205,0 +224,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
}, | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"main": "index.js", | ||
@@ -43,3 +43,3 @@ "directories": { | ||
}, | ||
"gitHead": "198cde0e2ce60647bf80c420c053df32da7d898c" | ||
"gitHead": "06bf8933851fe6e38dc4c832d0a68fc05817b8a4" | ||
} |
@@ -1,8 +0,8 @@ | ||
var assert = require("assert"); | ||
var solc = require("solc"); | ||
var Schema = require("../"); | ||
var debug = require("debug")("test:solc"); // eslint-disable-line no-unused-vars | ||
const assert = require("assert"); | ||
const solc = require("solc"); | ||
const Schema = require("../"); | ||
const debug = require("debug")("test:solc"); | ||
describe("solc", function() { | ||
var exampleSolidity = `pragma solidity ^0.5.0; | ||
const exampleSolidity = `pragma solidity ^0.5.0; | ||
@@ -22,6 +22,6 @@ contract A { | ||
it("processes solc standard JSON output correctly", function(done) { | ||
it("processes solc standard JSON output correctly", function() { | ||
this.timeout(5000); | ||
var solcIn = JSON.stringify({ | ||
const solcIn = JSON.stringify({ | ||
language: "Solidity", | ||
@@ -45,2 +45,6 @@ sources: { | ||
"userdoc" | ||
], | ||
"": [ | ||
"ast", | ||
"legacyAST" | ||
] | ||
@@ -51,10 +55,15 @@ } | ||
}); | ||
var solcOut = JSON.parse(solc.compile(solcIn)); | ||
const solcOut = JSON.parse(solc.compile(solcIn)); | ||
// contracts now grouped by solidity source file | ||
var rawA = solcOut.contracts["A.sol"].A; | ||
debug("solcOut: %O", solcOut); | ||
var A = Schema.normalize(rawA); | ||
const rawA = Object.assign( | ||
{}, | ||
solcOut.contracts["A.sol"].A, // contracts now grouped by solidity source file | ||
solcOut.sources["A.sol"] | ||
); | ||
var expected = { | ||
const A = Schema.normalize(rawA); | ||
const expected = { | ||
abi: rawA.abi, | ||
@@ -71,4 +80,4 @@ metadata: rawA.metadata, | ||
Object.keys(expected).forEach(function(key) { | ||
var expectedValue = expected[key]; | ||
var actualValue = A[key]; | ||
const expectedValue = expected[key]; | ||
const actualValue = A[key]; | ||
@@ -88,6 +97,9 @@ assert.deepEqual( | ||
//check that ast and legacyAST have the correct form | ||
assert.equal(A.ast.nodeType, "SourceUnit"); | ||
assert.equal(A.legacyAST.name, "SourceUnit"); | ||
// throws error if invalid | ||
Schema.validate(A); | ||
done(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274515
6727