test task
This commit is contained in:
parent
efe2fee40e
commit
6a5f6835e8
|
@ -3,6 +3,7 @@ import { resolve } from "path";
|
||||||
import type { HardhatUserConfig } from "hardhat/config";
|
import type { HardhatUserConfig } from "hardhat/config";
|
||||||
import "@nomicfoundation/hardhat-toolbox-viem";
|
import "@nomicfoundation/hardhat-toolbox-viem";
|
||||||
import { env } from "./lib/common";
|
import { env } from "./lib/common";
|
||||||
|
import "./tasks/test";
|
||||||
|
|
||||||
[
|
[
|
||||||
`.env.${process.env.APP_ENV}.contracts`,
|
`.env.${process.env.APP_ENV}.contracts`,
|
||||||
|
@ -22,6 +23,7 @@ const config: HardhatUserConfig = {
|
||||||
networks: {
|
networks: {
|
||||||
localhost: {
|
localhost: {
|
||||||
url: LOCAL_NODE_URL,
|
url: LOCAL_NODE_URL,
|
||||||
|
chainId: 31337,
|
||||||
accounts: {
|
accounts: {
|
||||||
mnemonic: process.env.MNEMONIC || TEST_MNEMONIC
|
mnemonic: process.env.MNEMONIC || TEST_MNEMONIC
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { task } from "hardhat/config";
|
||||||
|
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import config from "../hardhat.config";
|
||||||
|
|
||||||
|
export const getDeployedContractAddress = async (hre: HardhatRuntimeEnvironment, contractName: string, network: string) => {
|
||||||
|
const chainId = config.networks?.[network]?.chainId;
|
||||||
|
if (!chainId) {
|
||||||
|
throw new Error(`Chain ID for network ${network} not found in hardhat.config.ts`);
|
||||||
|
}
|
||||||
|
const artifactsPath = path.join(__dirname, `../ignition/deployments/chain-${chainId}/deployed_addresses.json`);
|
||||||
|
const deploymentData = JSON.parse(fs.readFileSync(artifactsPath, 'utf8'));
|
||||||
|
const deployedAddress = deploymentData[`${contractName}#${contractName}`];
|
||||||
|
|
||||||
|
if (!deployedAddress) {
|
||||||
|
throw new Error(`Contract ${contractName} not found in deployment data for network ${network}`);
|
||||||
|
}
|
||||||
|
return deployedAddress as `0x${string}` | null;
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
|
||||||
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
|
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
|
||||||
"@openzeppelin/contracts": "^5.2.0",
|
"@openzeppelin/contracts": "^5.2.0",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
|
@ -1356,7 +1357,6 @@
|
||||||
"integrity": "sha512-xTNQNI/9xkHvjmCJnJOTyqDSl8uq1rKb2WOVmixQxFtRd7Oa3ecO8zM0cyC2YmOK+jHB9WPZ+F/ijkHg1CoORA==",
|
"integrity": "sha512-xTNQNI/9xkHvjmCJnJOTyqDSl8uq1rKb2WOVmixQxFtRd7Oa3ecO8zM0cyC2YmOK+jHB9WPZ+F/ijkHg1CoORA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ethereumjs-util": "^7.1.4"
|
"ethereumjs-util": "^7.1.4"
|
||||||
},
|
},
|
||||||
|
@ -1370,7 +1370,6 @@
|
||||||
"integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==",
|
"integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/pbkdf2": "^3.0.0",
|
"@types/pbkdf2": "^3.0.0",
|
||||||
"@types/secp256k1": "^4.0.1",
|
"@types/secp256k1": "^4.0.1",
|
||||||
|
@ -1395,7 +1394,6 @@
|
||||||
"integrity": "sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg==",
|
"integrity": "sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/bn.js": "^5.1.0",
|
"@types/bn.js": "^5.1.0",
|
||||||
"bn.js": "^5.1.2",
|
"bn.js": "^5.1.2",
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"author": "moon.eth",
|
"author": "moon.eth",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
|
||||||
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
|
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
|
||||||
"@openzeppelin/contracts": "^5.2.0",
|
"@openzeppelin/contracts": "^5.2.0",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { task } from "hardhat/config";
|
||||||
|
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||||
|
import config from "../hardhat.config";
|
||||||
|
import { getDeployedContractAddress } from "../lib/task-helper";
|
||||||
|
|
||||||
|
task("test-task", "Test task")
|
||||||
|
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
|
||||||
|
console.log("Transition mint task started");
|
||||||
|
|
||||||
|
const network = hre.network.name;
|
||||||
|
if (!config.networks?.[network]) {
|
||||||
|
throw new Error(`Network ${network} not configured in hardhat.config.ts`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chainId = config.networks[network].chainId;
|
||||||
|
if (!chainId) {
|
||||||
|
throw new Error(`Chain ID for network ${network} not found in hardhat.config.ts`);
|
||||||
|
}
|
||||||
|
const deployedAddress = await getDeployedContractAddress(hre, "TenGransToken", network);
|
||||||
|
if (!deployedAddress) {
|
||||||
|
throw new Error("TenGransToken address not found in deployment artifacts");
|
||||||
|
}
|
||||||
|
|
||||||
|
const tenGransToken = await hre.viem.getContractAt(
|
||||||
|
"TenGransToken",
|
||||||
|
deployedAddress
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("Connected to TenGransToken at:", deployedAddress);
|
||||||
|
console.log("Contract:", tenGransToken);
|
||||||
|
});
|
Loading…
Reference in New Issue