Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make directory naming consistent with package name of go bindings #18

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
```

Expand All @@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/abigen/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
6 changes: 6 additions & 0 deletions src/abigen/wasm/wasm_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

(() => {
Expand Down
10 changes: 5 additions & 5 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
Loading