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

WIP: Tests, ESM, TS, Docs, Release Lib #2

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules/
build/
contracts.js
cache/
cache/
typechain/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Tribute Contract CLI

In order to make the local npm package (the tribute contracts CLI app) to be globally available in our workstation, run a command: `npm link`. This step allows us to run the `tc` command at any location from the command line.
12 changes: 12 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current",
},
},
],
],
};
23 changes: 18 additions & 5 deletions cli-config.js → cli.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("dotenv").config({ path: ".env" });
const { contracts } = require("./contracts");
import dotenv from "dotenv";
dotenv.config({ path: ".env" });

if (!process.env.ETHEREUM_NETWORK)
throw Error("Missing ETHEREUM_NETWORK env var");
Expand All @@ -10,7 +10,22 @@ if (!process.env.SNAPSHOT_HUB_API_URL)
if (!process.env.TRUFFLE_MNEMONIC)
throw Error("Missing env var: <TRUFFLE_MNEMONIC>");

const configs = {
const contracts = {
// DAO Core Contracts
DaoRegistry: "0xf68f5498DD766A8d65c4785219d61FCC5E0E920A",

// Extensions
BankExtension: "0x141f5fCa84Cc82EF0A6751241019471731289456",

// Adapters
ManagingContract: "0xb09bCc172050fBd4562da8b229Cf3E45Dc3045A6",
OffchainVotingContract: "0x4339316e04CFfB5961D1c41fEF8E44bfA2A7fBd1",

// Helpers
Multicall: "0x47a2Db5D68751EeAdFBC44851E84AcDB4F7299Cc",
}

export const configs = {
network: process.env.ETHEREUM_NETWORK,
space: process.env.SNAPSHOT_HUB_SPACE,
snapshotHubApi: process.env.SNAPSHOT_HUB_API_URL,
Expand All @@ -23,5 +38,3 @@ const configs = {
? process.env.GANACHE_URL
: "http://localhost:7545",
};

module.exports = { configs };
50 changes: 50 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import dotenv from "dotenv";
dotenv.config({ path: ".env" });

// import "@nomiclabs/hardhat-waffle";
import "hardhat-typechain";
import "@nomiclabs/hardhat-ganache";

if (!process.env.TRUFFLE_MNEMONIC) {
throw new Error("Please set your TRUFFLE_MNEMONIC in a .env file");
}
const mnemonic = process.env.TRUFFLE_MNEMONIC;

if (!process.env.INFURA_KEY || !process.env.ALCHEMY_KEY) {
throw new Error("Please set your INFURA_KEY or ALCHEMY_KEY in a .env file");
}

const config = {
// https://hardhat.org/config/#path-configuration
paths: {
tests: "./test",
sources: "./build",
artifacts: "./build/compiled",
cache: "./build/cache",
},
defaultNetwork: "ganache",
networks: {
ganache: {
network_id: "1337",
accounts: {
count: 10,
initialIndex: 0,
mnemonic,
path: "m/44'/60'/0'/0",
},
url: "http://localhost:7545",
},
},
solidity: {
version: "0.8.0",
settings: {
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
optimizer: {
enabled: true,
runs: 200,
},
},
},
};

export default config;
37 changes: 37 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node

import { configs } from "./cli.config";
import { error, notice } from "./src/utils/logging";
import { managingCommands } from "./src/interfaces/cli/commands/managing-cmd.js";
import { offchainCommands } from "./src/interfaces/cli/commands/offchain-cmd.js";
import { Command } from "commander";
const program = new Command();
import { readFile } from "fs/promises";

const main = async () => {
// const pkg = JSON.parse(await readFile("./package.json"));
// program.version(pkg.version);

program
.command("list")
.description("List all contracts available to interact with.")
.action(() => {
notice("Available contracts to interact...");
Object.keys(configs.contracts).map((c) =>
console.log(`${c} @ ${configs.contracts[c]}`)
);
});

managingCommands(program);
offchainCommands(program);

program
.parseAsync(process.argv)
.then(() => process.exit(0))
.catch((e) => {
error("Error:", e);
process.exit(1);
});
};

main();
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const configs = {
transform: {
"^.+\\.(js)$": "babel-jest",
},
verbose: true,
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "node",
roots: ["./test"],
coverageProvider: "v8",
};

module.exports = configs;
11 changes: 11 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { server } from "./test/msw-mocks";

// Establish API mocking before all tests.
beforeAll(() => server.listen());

// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers());

// Clean up after the tests are finished.
afterAll(() => server.close());
Loading