From dff0270499128f2d4337e235749cb1912cc0357d Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Sun, 10 Mar 2024 13:51:58 +0200 Subject: [PATCH 1/3] Made directory naming consistent with package name of go bindings --- package-lock.json | 4 ++-- package.json | 2 +- src/abigen/generator.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index d293a81..7c03592 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@solarity/hardhat-gobind", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@solarity/hardhat-gobind", - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "dependencies": { "lodash": "4.17.21" diff --git a/package.json b/package.json index 15c567e..a463535 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-gobind", - "version": "1.2.0", + "version": "1.2.1", "description": "Generation of smart contract bindings for Golang", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/abigen/generator.js b/src/abigen/generator.js index 35a1849..3c8ab11 100644 --- a/src/abigen/generator.js +++ b/src/abigen/generator.js @@ -58,8 +58,10 @@ module.exports = class Generator { const source = artifact.sourceName; const abiPath = `${this.outDir}/${contract}.abi`; - const genDir = `${this.outDir}/${path.dirname(source)}/${contract}`; + const packageName = contract.replaceAll("-", "").replaceAll("_", "").toLowerCase(); + + const genDir = `${this.outDir}/${path.dirname(source)}/${packageName}`; const genPath = `${genDir}/${contract}.${this.lang}`; const argv = `abigen --abi ${abiPath} --pkg ${packageName} --type ${contract} --lang ${this.lang} --out ${genPath}`; From c473528cb9258d79a3efdef3b8b8a707c081b4cd Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Sun, 10 Mar 2024 14:16:00 +0200 Subject: [PATCH 2/3] Updated README and doc --- README.md | 38 +++++++++++++++++++++--------------- src/abigen/wasm/wasm_exec.js | 6 ++++++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 977fc70..8039b29 100644 --- a/README.md +++ b/README.md @@ -97,18 +97,18 @@ Consider we have Hardhat project with the following structure (excluding some fi ``` . ├── contracts -│   ├── Example.sol -│   ├── Sample.sol -│   └── interfaces -│   ├── IExample.sol -│   └── ISample.sol +│ ├── Example.sol +│ ├── Sample.sol +│ └── interfaces +│ ├── IExample.sol +│ └── ISample.sol ├── hardhat.config.ts └── node_modules └── @openzeppelin └── contracts └── access - └── Ownable - │  └── Ownable.sol + ├── Ownable + │ └── Ownable.sol └── Ownable2Step └── Ownable2Step.sol ``` @@ -119,17 +119,22 @@ Consider we have Hardhat project with the following structure (excluding some fi generated-types └── bindings ├── @openzeppelin - │   └── contracts - │   └── access - │   ├── Ownable.go - │   └── Ownable2Step.go + │ └── contracts + │ └── access + │ ├── ownable + │ │ └── Ownable.go + │ └── ownable2step + │ └── Ownable2Step.go + │ └── contracts - ├── Example.go - ├── Sample.go + ├── example + │ └── Example.go + ├── sample + │ └── Sample.go └── interfaces - └── IExample - │  └── IExample.go - └── ISample + ├── iexample + │ └── IExample.go + └── isample └── ISample.go ``` @@ -146,3 +151,4 @@ skipFiles: ["contracts/interfaces", "@openzeppelin", "@solarity"], - `--verbose` is not available in CLI because of names clash with Hardhat. [Learn more](https://hardhat.org/hardhat-runner/docs/errors#HH202). - `node_modules` must not be present in the path. +- All environment variables are omitted when the abigen.wasm is called diff --git a/src/abigen/wasm/wasm_exec.js b/src/abigen/wasm/wasm_exec.js index 459a90e..03b773c 100644 --- a/src/abigen/wasm/wasm_exec.js +++ b/src/abigen/wasm/wasm_exec.js @@ -2,6 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Source: https://github.com/golang/go/blob/48b10c9af7955bcab179b60a148a633a0a75cde7/misc/wasm/wasm_exec.js + +// This file is a modified version of the original wasm_exec.js file from the Go project. +// Changes: +// - Removed environment variables passing to the binary + "use strict"; (() => { From 7f02a018ee1ac2cc8d7b822435f6e8ae5cd82bd7 Mon Sep 17 00:00:00 2001 From: Kyryl Riabov Date: Sun, 10 Mar 2024 14:18:01 +0200 Subject: [PATCH 3/3] Fixed tests --- test/integration.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration.test.ts b/test/integration.test.ts index 011472a..22f6819 100644 --- a/test/integration.test.ts +++ b/test/integration.test.ts @@ -16,7 +16,7 @@ describe("GoBind x Hardhat integration", function () { const assertContractsGenerated = (outdir: string) => { assertExists(outdir); assertExists(`${outdir}/contracts`); - assertExists(`${outdir}/contracts/Lock/Lock.go`); + assertExists(`${outdir}/contracts/lock/Lock.go`); }; describe("Main logic with default config", function () { @@ -62,9 +62,9 @@ describe("GoBind x Hardhat integration", function () { assertNotExists(this.outdir); }); - const contractPaths = ["Mock1/Mock1.go", "Mock2/Mock2.go"].map((p) => "contracts/" + p); - const interfacePaths = ["IMock1/IMock1.go", "IMock2/IMock2.go"].map((p) => "contracts/interfaces/" + p); - const dependecyPaths = ["access/Ownable/Ownable.go", "utils/Context/Context.go"].map( + const contractPaths = ["mock1/Mock1.go", "mock2/Mock2.go"].map((p) => "contracts/" + p); + const interfacePaths = ["imock1/IMock1.go", "imock2/IMock2.go"].map((p) => "contracts/interfaces/" + p); + const dependecyPaths = ["access/ownable/Ownable.go", "utils/context/Context.go"].map( (p) => "@openzeppelin/contracts/" + p, ); const allPaths = [...contractPaths, ...interfacePaths, ...dependecyPaths]; @@ -112,7 +112,7 @@ describe("GoBind x Hardhat integration", function () { }); it(`for ${caseToString(0)} generates only Ownable.go`, async function () { - const ownablePath = "@openzeppelin/contracts/access/Ownable/Ownable.go"; + const ownablePath = "@openzeppelin/contracts/access/ownable/Ownable.go"; this.env.config.gobind.onlyFiles = testCases[0].only; await this.env.run(TASK_GOBIND, abigenPath);