Skip to content

Commit 1f9f8e0

Browse files
kiriyaga-txfusionkiriyagaalcuadrado
authored
fix: support for vyper version 0.4.0 with the new output identifiers (#5469)
* fix: support for vyper version 0.4.0 with the new output identifiers * Create wet-cars-sin.md --------- Co-authored-by: Marko Arambasic <[email protected]> Co-authored-by: Patricio Palladino <[email protected]>
1 parent 01dd5b6 commit 1f9f8e0

File tree

7 files changed

+69
-3
lines changed

7 files changed

+69
-3
lines changed

.changeset/wet-cars-sin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomiclabs/hardhat-vyper": patch
3+
---
4+
5+
Support Vyper 0.4.0's new output identifiers (Thanks, @kiriyaga-txfusion!)

packages/hardhat-vyper/src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export const ARTIFACT_FORMAT_VERSION = "hh-vyper-artifact-1";
33
export const DEBUG_NAMESPACE = "hardhat:plugin:vyper";
44
export const CACHE_FORMAT_VERSION = "hh-vy-cache-1";
55
export const VYPER_FILES_CACHE_FILENAME = "vyper-files-cache.json";
6+
export const OUTPUT_BREAKABLE_VYPER_VERSION = "0.4.0";

packages/hardhat-vyper/src/index.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import {
2323
TASK_COMPILE_VYPER_LOG_DOWNLOAD_COMPILER_END,
2424
TASK_COMPILE_VYPER_LOG_COMPILATION_RESULT,
2525
} from "./task-names";
26-
import { DEFAULT_VYPER_VERSION } from "./constants";
26+
import {
27+
DEFAULT_VYPER_VERSION,
28+
OUTPUT_BREAKABLE_VYPER_VERSION,
29+
} from "./constants";
2730
import { Compiler } from "./compiler";
2831
import { CompilerDownloader } from "./downloader";
2932
import {
@@ -344,10 +347,24 @@ ${list}`
344347
}
345348
);
346349

347-
for (const [sourceName, output] of Object.entries(contracts)) {
350+
const { localPathToSourceName } = await import(
351+
"hardhat/utils/source-names"
352+
);
353+
354+
for (const [contractSourceIdentifier, output] of Object.entries(
355+
contracts
356+
)) {
357+
const sourceName = semver.gte(
358+
vyperVersion,
359+
OUTPUT_BREAKABLE_VYPER_VERSION
360+
)
361+
? await localPathToSourceName(
362+
config.paths.root,
363+
contractSourceIdentifier
364+
)
365+
: contractSourceIdentifier;
348366
const artifact = getArtifactFromVyperOutput(sourceName, output);
349367
await artifacts.saveArtifactAndDebugFile(artifact);
350-
351368
const file = files.find((f) => f.sourceName === sourceName);
352369
assertPluginInvariant(
353370
file !== undefined,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pragma version ~=0.4.0
2+
3+
IMMUTABLE_1: public(immutable(String[4]))
4+
5+
@deploy
6+
@payable
7+
def __init__():
8+
IMMUTABLE_1 = "A"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# pragma version ~=0.4.0
2+
3+
IMMUTABLE_1: public(immutable(String[4]))
4+
5+
@deploy
6+
@payable
7+
def __init__():
8+
IMMUTABLE_1 = "B"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require("../../../src/index");
2+
3+
module.exports = {
4+
vyper: {
5+
compilers: [
6+
{
7+
version: "0.4.0",
8+
settings: {
9+
evmVersion: "paris",
10+
optimize: "gas",
11+
},
12+
},
13+
],
14+
},
15+
};

packages/hardhat-vyper/test/tests.ts

+12
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,16 @@ describe("Vyper plugin", function () {
305305
);
306306
});
307307
});
308+
309+
describe("compile project with different ouput identifiers returned from the vyper compiler", function () {
310+
useFixtureProject("compilation-with-vyper-output-breakable-version");
311+
useEnvironment();
312+
313+
it("Should successfully compile the contracts for versions >= 0.4.0", async function () {
314+
await this.env.run(TASK_COMPILE);
315+
316+
assert.equal(this.env.artifacts.readArtifactSync("A").contractName, "A");
317+
assert.equal(this.env.artifacts.readArtifactSync("B").contractName, "B");
318+
});
319+
});
308320
});

0 commit comments

Comments
 (0)