From 1f4b159929977e95695bcf9ee43f9f7af82eb79f Mon Sep 17 00:00:00 2001 From: Rosco Kalis Date: Mon, 21 Dec 2020 17:24:03 +0100 Subject: [PATCH] Fix bug with library linking for Solidity >=0.7.5 --- test/metacoin/truffle-config.js | 2 +- verify.js | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/test/metacoin/truffle-config.js b/test/metacoin/truffle-config.js index dedcb59..a7c52bf 100644 --- a/test/metacoin/truffle-config.js +++ b/test/metacoin/truffle-config.js @@ -4,7 +4,7 @@ require('dotenv').config() module.exports = { compilers: { solc: { - version: '0.7.0', + version: '0.8.0', settings: { optimizer: { enabled: true, diff --git a/verify.js b/verify.js index 3d52a69..878ebff 100644 --- a/verify.js +++ b/verify.js @@ -120,7 +120,7 @@ const verifyContract = async (artifact, options) => { const sendVerifyRequest = async (artifact, options) => { const compilerVersion = extractCompilerVersion(artifact) const encodedConstructorArgs = await fetchConstructorValues(artifact, options) - const inputJSON = await fetchInputJSON(artifact, options) + const inputJSON = getInputJSON(artifact, options) const postQueries = { apikey: options.apiKey, @@ -187,9 +187,11 @@ const fetchConstructorValues = async (artifact, options) => { } } -const fetchInputJSON = async (artifact, options) => { +const getInputJSON = (artifact, options) => { const metadata = JSON.parse(artifact.metadata) + const libraries = getLibraries(artifact, options) + const inputJSON = { language: metadata.language, sources: metadata.sources, @@ -197,7 +199,7 @@ const fetchInputJSON = async (artifact, options) => { remappings: metadata.settings.remappings, optimizer: metadata.settings.optimizer, evmVersion: metadata.settings.evmVersion, - libraries: { '': artifact.networks[`${options.networkId}`].links || {} } + libraries } } @@ -212,6 +214,31 @@ const fetchInputJSON = async (artifact, options) => { return inputJSON } +const getLibraries = (artifact, options) => { + const libraries = { + // Example data structure of libraries object in Standard Input JSON + // 'ConvertLib.sol': { + // 'ConvertLib': '0x...', + // 'OtherLibInSameSourceFile': '0x...' + // } + } + + const links = artifact.networks[`${options.networkId}`].links || {} + + for (const libraryName in links) { + // Retrieve the source path for this library + const libraryArtifact = getArtifact(libraryName, options) + const librarySourceFile = libraryArtifact.ast.absolutePath + + // Add the library to the object of libraries for this source path + const librariesForSourceFile = libraries[librarySourceFile] || {} + librariesForSourceFile[libraryName] = links[libraryName] + libraries[librarySourceFile] = librariesForSourceFile + } + + return libraries +} + const verificationStatus = async (guid, options) => { logger.debug(`Checking status of verification request ${guid}`) // Retry API call every second until status is no longer pending