From 1974628be8595b9b199051c0586d188094fcec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=8B=E5=85=9A=20Lidang?= Date: Wed, 7 Jun 2023 04:24:47 -0500 Subject: [PATCH] update --- darc-protocol/scripts/deployDARC.ts | 8 +- .../batch_add_and_enable_plugin_test.ts | 132 +++++++++++------- 2 files changed, 88 insertions(+), 52 deletions(-) diff --git a/darc-protocol/scripts/deployDARC.ts b/darc-protocol/scripts/deployDARC.ts index 1ffd145..ea80ec2 100644 --- a/darc-protocol/scripts/deployDARC.ts +++ b/darc-protocol/scripts/deployDARC.ts @@ -15,11 +15,11 @@ export async function deployDARC(): Promise { const signers = await ethers.getSigners(); - for(let i = 0; i < signers.length; i++){ - console.log("signer: " + signers[i].address); - } + // for(let i = 0; i < signers.length; i++){ + // console.log("signer: " + signers[i].address); + // } - console.log("DARC address: ", darc.address); + // console.log("DARC address: ", darc.address); await darc.deployed(); await darc.initialize(); return darc.address; diff --git a/darc-protocol/test/operationUnitTest/batch_add_and_enable_plugin_test.ts b/darc-protocol/test/operationUnitTest/batch_add_and_enable_plugin_test.ts index 547bd8a..d51ca03 100644 --- a/darc-protocol/test/operationUnitTest/batch_add_and_enable_plugin_test.ts +++ b/darc-protocol/test/operationUnitTest/batch_add_and_enable_plugin_test.ts @@ -15,7 +15,7 @@ const target2 = '0x90F79bf6EB2c4f870365E785982E1f101E93b906'; const target3 = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65'; -describe.only("test for batch add and enable plugins", function () { +describe("test for batch add and enable plugins", function () { it ("batch batch add and enable plugins", async function () { @@ -71,7 +71,7 @@ describe.only("test for batch add and enable plugins", function () { ADDRESS_ARRAY: [], STRING_ARRAY: [], UINT256_2DARRAY: [], - ADDRESS_2DARRAY: [ [target1] ], + ADDRESS_2DARRAY: [ ["0x70997970C51812dc3A010C7d01b50e0d17dc79C8"] ], STRING_2DARRAY: [], } }; @@ -96,7 +96,7 @@ describe.only("test for batch add and enable plugins", function () { node_deny_target1 ], votingRuleIndex: 0, - note: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC should not operate", + note: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8 should not operate", bIsEnabled: true, bIsInitialized: true, bIsBeforeOperation: true, @@ -105,10 +105,34 @@ describe.only("test for batch add and enable plugins", function () { UINT256_2DARRAY: [], ADDRESS_2DARRAY: [] } - }], + }, + // { + // operatorAddress: programOperatorAddress, + // opcode: 1, // mint token + // param: { + // UINT256_ARRAY: [], + // ADDRESS_ARRAY: [], + // STRING_ARRAY: [], + // BOOL_ARRAY: [], + // VOTING_RULE_ARRAY: [], + // PARAMETER_ARRAY: [], + // PLUGIN_ARRAY: [], + // UINT256_2DARRAY: [ + // [BigNumber.from(0), BigNumber.from(1)], + // [BigNumber.from(100)], // amount = 100 + // ], + // ADDRESS_2DARRAY: [ + // [target1], + // ] + // } + // } + ], } ); + + + // get darc address const darcAddress = darc.address; @@ -119,9 +143,9 @@ describe.only("test for batch add and enable plugins", function () { * Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH) Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d */ - + let bIsException = false; const signer_address1 = ethers.provider.getSigner(1); - + const target_addr = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; // get darc factory const DarcFactory = await ethers.getContractFactory("DARC", signer_address1); // attach darc contract @@ -129,10 +153,10 @@ describe.only("test for batch add and enable plugins", function () { // try to run a batch mint token instruction with target1 as the operator try { - const result = darc2.entrance({ - programOperatorAddress: target1, + const result = await darc2.entrance({ + programOperatorAddress: target_addr, operations: [{ - operatorAddress: target1, + operatorAddress: target_addr, opcode: 1, // mint token param: { UINT256_ARRAY: [], @@ -147,57 +171,69 @@ describe.only("test for batch add and enable plugins", function () { [BigNumber.from(100)], // amount = 100 ], ADDRESS_2DARRAY: [ - [target1], + [target_addr], ] } }], }); + bIsException = false; - console.log(JSON.stringify(result)); } catch (err) { - console.log(err); + bIsException = true; } + // make sure that an exception is thrown + expect(bIsException).to.equal(true); // make sure that no token is minted const totalSupplyOfTokenClass0 = await darc2.getTokenOwners(BigNumber.from(0)); - console.log(totalSupplyOfTokenClass0); - - // try to run a batch mint token instruction with target1 as the operator - try { - const result = darc.entrance({ - programOperatorAddress: programOperatorAddress, - operations: [{ - operatorAddress: programOperatorAddress, - opcode: 1, // mint token - param: { - UINT256_ARRAY: [], - ADDRESS_ARRAY: [], - STRING_ARRAY: [], - BOOL_ARRAY: [], - VOTING_RULE_ARRAY: [], - PARAMETER_ARRAY: [], - PLUGIN_ARRAY: [], - UINT256_2DARRAY: [ - [BigNumber.from(0)], - [BigNumber.from(100)], // amount = 100 - ], - ADDRESS_2DARRAY: [ - [target1], - ] - } - }], - }); - - console.log(JSON.stringify(result)); - // make sure that no token is minted - const totalSupplyOfTokenClass0 = await darc2.getTokenOwners(BigNumber.from(0)); - console.log(totalSupplyOfTokenClass0); - } - catch (err) { - console.log(err); - } + //console.log(totalSupplyOfTokenClass0); + expect(totalSupplyOfTokenClass0.length).to.equal(0); + + // try to run a batch mint token instruction with target1 as the operator + try { + const result3 = await darc.entrance({ + programOperatorAddress: programOperatorAddress, + operations: [{ + operatorAddress: programOperatorAddress, + opcode: 1, // mint token + param: { + UINT256_ARRAY: [], + ADDRESS_ARRAY: [], + STRING_ARRAY: [], + BOOL_ARRAY: [], + VOTING_RULE_ARRAY: [], + PARAMETER_ARRAY: [], + PLUGIN_ARRAY: [], + UINT256_2DARRAY: [ + [BigNumber.from(0)], + [BigNumber.from(100)], // amount = 100 + ], + ADDRESS_2DARRAY: [ + [target1], + ] + } + }], + }); + + bIsException = false; + } + catch (err) { + //console.log(err); + bIsException = true; + } + + expect(bIsException).to.equal(false); + + // then check the token owners from darc2 + const totalSupplyOfTokenClass0_darc2 = await darc2.getTokenOwners(BigNumber.from(0)); + //console.log(totalSupplyOfTokenClass0_darc2); + + // // list all plugins + // const plugins = await darc.getPluginInfo(); + // console.log(plugins); + expect (totalSupplyOfTokenClass0_darc2[0].toLowerCase()).equal(target1.toLowerCase()); });