Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Jun 7, 2023
1 parent c7201f7 commit 73b2299
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ contract ConditionExpressionFactory is
else if (exp == EnumConditionExpression.OPERATOR_NAME_EQUALS) {
return false;//exp_OPERATOR_NAME_EQUALS(bIsBeforeOperation, operation, paramList);
}
else if (exp == EnumConditionExpression.OPERATOR_ADDRESS_EQUALS) {
return exp_OPERATOR_ADDRESS_EUQALS(bIsBeforeOperation, operation, param);
}

// default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ contract OperatorExpressionFunctions is MachineStateManager {
* @param param: the parameters of the condition node.
* This is function to check if the operator address is equal to the operator role of the condition node
*/
function exp_OPERATOR_ADDRESS_EUQALS(bool bIsBeforeOperation, Operation memory operation, Param memory param) internal view returns (bool) {

function exp_OPERATOR_ADDRESS_EUQALS(bool bIsBeforeOperation, Operation memory operation, NodeParam memory param) internal view returns (bool) {
// the address is the ADDRESS_2DARRAY[0][0]
require (param.ADDRESS_2DARRAY.length == 1, "Operator address is not provided");
require(param.ADDRESS_2DARRAY[0].length == 1, "Operator address is not provided");
address operatorAddress = param.ADDRESS_2DARRAY[0][0];
if (bIsBeforeOperation) {
return operation.operatorAddress == operatorAddress;
} else {
return operation.operatorAddress == operatorAddress;
}
}
}
125 changes: 110 additions & 15 deletions darc-protocol/test/operationUnitTest/batch_add_and_enable_plugin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
import { expect } from "chai";
import { ethers } from "hardhat";
import { BigNumber } from "ethers";
import { ConditionNodeStruct } from "../../typechain-types/contracts/DARC";

// test for batch create token class instruction on DARC

Expand All @@ -14,7 +15,7 @@ const target2 = '0x90F79bf6EB2c4f870365E785982E1f101E93b906';

const target3 = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65';

describe("test for batch add and enable plugins", function () {
describe.only("test for batch add and enable plugins", function () {


it ("batch batch add and enable plugins", async function () {
Expand Down Expand Up @@ -58,6 +59,22 @@ describe("test for batch add and enable plugins", function () {
});

// add and enable a before-operation plugin: user with address = target1 cannnot operate the darc

const node_deny_target1: ConditionNodeStruct = {
id: BigNumber.from(0),
nodeType: BigNumber.from(1), // expression
logicalOperator: 0, // undefined
conditionExpression: 3, // OPERATOR_ADDRESS_EQUALS
childList: [], // empty
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],
STRING_ARRAY: [],
UINT256_2DARRAY: [],
ADDRESS_2DARRAY: [ [target1] ],
STRING_2DARRAY: [],
}
};
await darc.entrance(
{
programOperatorAddress: initProgram.programOperatorAddress,
Expand All @@ -75,7 +92,9 @@ describe("test for batch add and enable plugins", function () {
{
returnType: BigNumber.from(2), // NO
level: 100,
conditionNodes: ConditionNodeStruct[];
conditionNodes: [
node_deny_target1
],
votingRuleIndex: 0,
note: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC should not operate",
bIsEnabled: true,
Expand All @@ -90,20 +109,96 @@ describe("test for batch add and enable plugins", function () {
}
);

const numberOfTokenClasses2 = await darc.getNumberOfTokenClasses();
// get darc address
const darcAddress = darc.address;



// create a ethers.js signer with information
/**
* Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
*/

expect(numberOfTokenClasses2 ).to.equal(2);
const signer_address1 = ethers.provider.getSigner(1);

// get darc factory
const DarcFactory = await ethers.getContractFactory("DARC", signer_address1);
// attach darc contract
const darc2 = DarcFactory.attach(darcAddress);

// try to run a batch mint token instruction with target1 as the operator
try {
const result = darc2.entrance({
programOperatorAddress: target1,
operations: [{
operatorAddress: target1,
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));
}
catch (err) {
console.log(err);
}


// 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],
]
}
}],
});

const tokenResult0 = await darc.getTokenInfo(0);
const tokenResult1 = await darc.getTokenInfo(1);

expect(tokenResult0[0].toNumber()).to.equal(10);
expect(tokenResult0[1].toNumber()).to.equal(10);
expect(tokenResult1[0].toNumber()).to.equal(1);
expect(tokenResult1[1].toNumber()).to.equal(1);
expect(tokenResult0[2]).to.equal("Class1");
expect(tokenResult1[2]).to.equal("Class2");
expect(tokenResult0[3].toNumber()).to.equal(0);
expect(tokenResult1[3].toNumber()).to.equal(0);
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);
}
});


});

0 comments on commit 73b2299

Please sign in to comment.