From 81d783d48f4b159190c0caef311ec277cc06a2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=8B=E5=85=9A=20Lidang?= Date: Sat, 29 Apr 2023 05:22:38 -0500 Subject: [PATCH] add --- darc-js/src/runtime/runtime.ts | 14 ++++++++++++++ darc-js/tests/rpcCall-test.ts | 20 ++++++++------------ darc-protocol/scripts/deployDARC.ts | 5 +++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/darc-js/src/runtime/runtime.ts b/darc-js/src/runtime/runtime.ts index 9061dbc..d27343f 100644 --- a/darc-js/src/runtime/runtime.ts +++ b/darc-js/src/runtime/runtime.ts @@ -48,4 +48,18 @@ export async function deployDARC(version: DARC_VERSION, param: DeployParam): Pro const contract = await contractFactory.deploy(); contract.initialize(); return contract.address; +} + +export async function attachDARCwithProvider (address: string, version: DARC_VERSION, provider: ethers.providers.Provider): Promise { + const darcBinaryStruct = darcBinary(version); + const abi = darcBinaryStruct.abi; + const contract = new ethers.Contract(address, abi, provider); + return contract; +} + +export async function attachDARCwithWallet (address: string, version: DARC_VERSION, wallet: ethers.Wallet): Promise { + const darcBinaryStruct = darcBinary(version); + const abi = darcBinaryStruct.abi; + const contract = new ethers.Contract(address, abi, wallet); + return contract; } \ No newline at end of file diff --git a/darc-js/tests/rpcCall-test.ts b/darc-js/tests/rpcCall-test.ts index 445874d..775a447 100644 --- a/darc-js/tests/rpcCall-test.ts +++ b/darc-js/tests/rpcCall-test.ts @@ -1,6 +1,6 @@ import {ethers} from 'ethers'; import { expect } from 'chai'; -import { deployDARC } from '../src/runtime/runtime'; +import { deployDARC, attachDARCwithWallet } from '../src/runtime/runtime'; import 'mocha'; //import { setTimeout } from "timers/promises"; @@ -167,17 +167,13 @@ describe.only('RPC call test', }; - const attached_local_darc2 = new ethers.Contract(darc_contract_address, darcBinary(DARC_VERSION.Test).abi, signer); - // const local_darc2 = new ethers.ContractFactory( - // darcBinary(DARC_VERSION.Test).abi, - // darcBinary(DARC_VERSION.Test).bytecode, - // signer - // ); + const attached_local_darc2 = await attachDARCwithWallet( + darc_contract_address, + DARC_VERSION.Test, + signer, + ); - //const attached_local_darc2 = local_darc.attach(darc_contract_address); - - //console.log("here is the local darc address: " + local_darc.address); - console.log("The deployed contract of local_darc 2 is " + attached_local_darc2.address); + console.log("The attached contract of local_darc 2 is " + attached_local_darc2.address); await new Promise(resolve1 => setTimeout(resolve1, 100)); // check the number of token classes. If it is 0, then create a token class first @@ -201,6 +197,6 @@ describe.only('RPC call test', const balance = await attached_local_darc2.getTokenOwnerBalance(BigInt(0), target1); console.log("balance: " + balance.toString()); - expect(balance.toString()).to.equal("20"); + expect(balance.toBigInt()).to.equal(BigInt(20)); }); }); \ No newline at end of file diff --git a/darc-protocol/scripts/deployDARC.ts b/darc-protocol/scripts/deployDARC.ts index 0336f84..1ffd145 100644 --- a/darc-protocol/scripts/deployDARC.ts +++ b/darc-protocol/scripts/deployDARC.ts @@ -3,6 +3,11 @@ import { ethers } from "hardhat"; import { typeProgram, typePluginArray, typeVotingRuleArray } from "./ProgramTypes"; import { BigNumber } from "ethers"; + +/** + * The function to deploy DARC contract, initialize it, and return the address. + * @returns The address of the deployed DARC contract. + */ export async function deployDARC(): Promise { const DARC = await ethers.getContractFactory("DARC");