This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Replace project directory in metadata with "project://" #4137
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const debug = require("debug")("compile:test:test_metadata"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { Compile } = require("@truffle/compile-solidity"); | ||
const CompilerSupplier = require("../compilerSupplier"); | ||
const assert = require("assert"); | ||
const { findOne } = require("./helpers"); | ||
const workingDirectory = "/home/fakename/truffleproject"; | ||
const compileOptions = { | ||
working_directory: workingDirectory, | ||
compilers: { | ||
solc: { | ||
version: "0.4.25", | ||
settings: { | ||
optimizer: { | ||
enabled: false, | ||
runs: 200 | ||
} | ||
} | ||
} | ||
}, | ||
quiet: true | ||
}; | ||
const supplierOptions = { | ||
solcConfig: compileOptions.compilers.solc, | ||
events: { | ||
emit: () => {} | ||
} | ||
}; | ||
|
||
describe("Compile - solidity ^0.4.0", function () { | ||
this.timeout(5000); // solc | ||
let source = null; | ||
let solc = null; // gets loaded via supplier | ||
|
||
before("get solc", async function () { | ||
this.timeout(40000); | ||
|
||
const supplier = new CompilerSupplier(supplierOptions); | ||
({ solc } = await supplier.load()); | ||
}); | ||
|
||
describe("Metadata", function () { | ||
before("get code", function () { | ||
source = fs.readFileSync( | ||
path.join(__dirname, "./sources/v0.4.x/SimpleOrdered.sol"), | ||
"utf-8" | ||
); | ||
}); | ||
|
||
it("does not include absolute paths in metadata", async function () { | ||
const sourcePath = `${workingDirectory}/contracts/SimpleOrdered.sol`; | ||
const sources = { [sourcePath]: source }; | ||
|
||
const { compilations } = await Compile.sources({ | ||
sources, | ||
options: compileOptions | ||
}); | ||
|
||
const SimpleOrdered = findOne("SimpleOrdered", compilations[0].contracts); | ||
const metadata = JSON.parse(SimpleOrdered.metadata); | ||
const metadataSources = Object.keys(metadata.sources); | ||
const metadataTargets = Object.keys(metadata.settings.compilationTarget); | ||
const metadataPaths = metadataSources.concat(metadataTargets); | ||
debug("metadataPaths: %O", metadataPaths); | ||
assert(metadataPaths.every( | ||
sourcePath => sourcePath.startsWith("project://") && | ||
!sourcePath.includes(workingDirectory) | ||
)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a little pedantic but is it technically more proper to have this argument be the complete replacement string? Then we should strip off the relative path portion and replace it with "exactly" what we will be using? Like what if (and yeah, I think this is pretty pedantic) one day we decide to use "project::" instead of "project:/"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree about replacement style - better to replace the whole thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on that as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've changed this.