Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Apr 29, 2023
1 parent ab9bf04 commit 81d783d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
14 changes: 14 additions & 0 deletions darc-js/src/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Contract> {
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<Contract> {
const darcBinaryStruct = darcBinary(version);
const abi = darcBinaryStruct.abi;
const contract = new ethers.Contract(address, abi, wallet);
return contract;
}
20 changes: 8 additions & 12 deletions darc-js/tests/rpcCall-test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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));
});
});
5 changes: 5 additions & 0 deletions darc-protocol/scripts/deployDARC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {

const DARC = await ethers.getContractFactory("DARC");
Expand Down

0 comments on commit 81d783d

Please sign in to comment.