Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Jun 7, 2023
1 parent ea4452f commit c7201f7
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.9;
/**
* @title ConditionExpressionFunctions
* @author DARC Team
* @notice Functions of criteria expression related to Machine State
*/


import "../../../../MachineState.sol";
import "../../../../MachineStateManager.sol";
import "../../../../Utilities/StringUtils.sol";
import "../../../../Utilities/OpcodeMap.sol";

contract BatchMintTokensExpressionFunction is MachineStateManager {

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,14 @@ contract OperatorExpressionFunctions is MachineStateManager {
}
}

/**
* @notice Check if the operator address is equal to the operator address of the condition node
* @param bIsBeforeOperation: a boolean value to indicate if the machine state is in the sandbox
* @param operation: the operation struct of the current machine state
* @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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ enum EnumConditionExpression{
* @notice the expression related to the operator and expressions
*/

OPERATOR_NAME_EQUALS, //ID: 2 params: string operatorName
OPERATOR_ROLE_INDEX_EQUALS, //ID:3 params: uint256 operatorRoleIndex
OPERATOR_ADDRESS_EQUALS, //ID:4 params: address operatorAddress
OPERATOR_NAME_EQUALS, //ID: 1 params: string operatorName
OPERATOR_ROLE_INDEX_EQUALS, //ID:2 params: uint256 operatorRoleIndex
OPERATOR_ADDRESS_EQUALS, //ID:3 params: address operatorAddress
OPERATOR_ROLE_LARGER_THAN, // params: uint256 operatorRoleIndex
OPERATOR_ROLE_LESS_THAN, // params: uint256 operatorRoleIndex
OPERATOR_ROLE_IN_RANGE, // params: uint256 operatorRoleIndex
Expand All @@ -38,6 +38,7 @@ enum EnumConditionExpression{
OPERATOR_CASH_LARGER_THAN, // params: uint256 amount
OPERATOR_CASH_LESS_THAN, // params: uint256 amount
OPERATOR_CASH_IN_RANGE, // params: uint256 amount
OPERATOR_ADDRESS_IN_LIST, // params: address[] the list of addresses

// ----------------------------------------------------------
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
import { expect } from "chai";
import { ethers } from "hardhat";
import { BigNumber } from "ethers";

// test for batch create token class instruction on DARC

const programOperatorAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";

const target1 = '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC';

const target2 = '0x90F79bf6EB2c4f870365E785982E1f101E93b906';

const target3 = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65';

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


it ("batch batch add and enable plugins", async function () {

const DARC = await ethers.getContractFactory("DARC");
const darc = await DARC.deploy();
console.log("DARC address: ", darc.address);
await darc.deployed();
await darc.initialize();

const numberOfTokenClasses = await darc.getNumberOfTokenClasses();

expect (numberOfTokenClasses).to.equal(0);

const initProgram = {
programOperatorAddress: "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
opeartions: []
};

const result_entrance = await darc.entrance({
programOperatorAddress: initProgram.programOperatorAddress,
operations: [{
operatorAddress: initProgram.programOperatorAddress,
opcode: 2, // create token class
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],
STRING_ARRAY: ["Class1", "Class2"],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
PARAMETER_ARRAY: [],
PLUGIN_ARRAY: [],
UINT256_2DARRAY: [
[BigNumber.from(0), BigNumber.from(1)],
[BigNumber.from(10), BigNumber.from(1)],
[BigNumber.from(10), BigNumber.from(1)],
],
ADDRESS_2DARRAY: []
}
}],
});

// add and enable a before-operation plugin: user with address = target1 cannnot operate the darc
await darc.entrance(
{
programOperatorAddress: initProgram.programOperatorAddress,
operations: [{
operatorAddress: initProgram.programOperatorAddress,
opcode: 15, // create token class
param: {
UINT256_ARRAY: [],
ADDRESS_ARRAY: [],
STRING_ARRAY: [],
BOOL_ARRAY: [],
VOTING_RULE_ARRAY: [],
PARAMETER_ARRAY: [],
PLUGIN_ARRAY: [
{
returnType: BigNumber.from(2), // NO
level: 100,
conditionNodes: ConditionNodeStruct[];
votingRuleIndex: 0,
note: "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC should not operate",
bIsEnabled: true,
bIsInitialized: true,
bIsBeforeOperation: true,
}
],
UINT256_2DARRAY: [],
ADDRESS_2DARRAY: []
}
}],
}
);

const numberOfTokenClasses2 = await darc.getNumberOfTokenClasses();

expect(numberOfTokenClasses2 ).to.equal(2);

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);
});
});

0 comments on commit c7201f7

Please sign in to comment.