Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Dec 22, 2023
1 parent f2a1532 commit 13cf352
Show file tree
Hide file tree
Showing 25 changed files with 1,714 additions and 10 deletions.
45 changes: 43 additions & 2 deletions darc-js/src/darcBinary/DARC-test.json

Large diffs are not rendered by default.

1,381 changes: 1,381 additions & 0 deletions darc-js/src/darcBinary/DARC-test.json_

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions darc-protocol/contracts/protocol/Opcodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ enum EnumOpcode {

/**
* @notice Call a contract with the given abi
* @param address contractAddress: the address of the contract to call
* @param bytes abi: the abi of the function to call
* @param ADDRESS_2D[0][0] address contractAddress: the address of the contract to call
* @param bytes abi the encodedWithSignature abi of the function to call
* @param UINT256_2DARRAY[0][0] uint256 the value to send to the contract
* ID:25
*/
CALL_CONTRACT_ABI,
Expand Down
2 changes: 1 addition & 1 deletion darc-protocol/contracts/protocol/Plugin/Plugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct VotingRule {
/**
* the note of the voting policy
*/
string note;
string notes;

/**
* the voting policy is absolute majority or relative majority.
Expand Down
5 changes: 5 additions & 0 deletions darc-protocol/contracts/protocol/Program.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ struct Program {
* @notice operations: the array of the operations to be executed
*/
Operation[] operations;

/**
* @notice notes: the notes of the program
*/
string notes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,45 @@ contract UtilityInstructions is MachineStateManager {
}
}
}


/**
* @notice The implementation of the operation CALL_CONTRACT_ABI
* @param operation The operation index to be executed
* @param bIsSandbox The boolean flag that indicates if the operation is executed in sandbox
*/
function op_CALL_CONTRACT_ABI(Operation memory operation, bool bIsSandbox) internal {
/**
* @notice Call a contract with the given abi
* @param ADDRESS_2D[0][0] address contractAddress: the address of the contract to call
* @param bytes abi the encodedWithSignature abi of the function to call
* @param UINT256_2DARRAY[0][0] uint256 the value to send to the contract
* ID:25
*/
if (bIsSandbox) {
// do not execute the operation, just do nothing, it's ok
}

else {
// initialize the valueEthers, the value that will be sent to the contract
uint256 valueEthers = 0;
if (operation.param.UINT256_2DARRAY.length > 0) {
if (operation.param.UINT256_2DARRAY[0].length > 0) {
valueEthers = operation.param.UINT256_2DARRAY[0][0];
}
}

// get the abi
bytes memory abidata = operation.param.BYTES;
// get the address of the contract to call
address contractAddress = operation.param.ADDRESS_2DARRAY[0][0];

// call the contract
(bool success, bytes memory returnData) = contractAddress.call{value: valueEthers}(abidata);
// check if the call is successful
if (!success) {
revert(string(abi.encodePacked("The call to the contract is not successful. Return data: ", returnData)));
}
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.9;
contract ABICallTestContract {
uint256 public value1;
uint256 public value2;
string public str1;
string public str2;
address public addr1;
address public addr2;

function testCall1(
uint256 _value1,
uint256 _value2,
string memory _str1,
string memory _str2,
address _addr1,
address _addr2
) public {
value1 = _value1;
value2 = _value2;
str1 = _str1;
str2 = _str2;
addr1 = _addr1;
addr2 = _addr2;
}

function testCall2(
uint256 _value1,
uint256 _value2,
string memory _str1,
string memory _str2,
address _addr1,
address _addr2
) public payable {
value1 = _value1;
value2 = _value2;
str1 = _str1;
str2 = _str2;
addr1 = _addr1;
addr2 = _addr2;
}

function getValues() public view returns (
uint256,
uint256,
string memory,
string memory,
address,
address
) {
return (value1, value2, str1, str2, addr1, addr2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ contract DelegateCallTest {

Program memory mintTokenProgram = Program({
programOperatorAddress: address(this),
operations: new Operation[](2)
operations: new Operation[](2),
notes: "test program for delegate call"
});

mintTokenProgram.operations[0] = Operation({
Expand Down
3 changes: 2 additions & 1 deletion darc-protocol/test/ABITest/ABITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const program = {
[target1,target1], // to = target 1
],
BYTES: []
}
},
},
{
operatorAddress: programOperatorAddress,
Expand All @@ -60,6 +60,7 @@ const program = {
BYTES: []
}
}],
notes: "batch mint token test"
};

describe.skip("ABI test", function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("test for batch add and enable plugins", function () {
BYTES: []
}
}],
notes: "create token class"
});

// add and enable a before-operation plugin: user with address = target1 cannnot operate the darc
Expand All @@ -79,6 +80,7 @@ describe("test for batch add and enable plugins", function () {
await darc.entrance(
{
programOperatorAddress: initProgram.programOperatorAddress,
notes: "add and enable a before-operation plugin: user with address = target1 cannnot operate the darc",
operations: [{
operatorAddress: initProgram.programOperatorAddress,
opcode: 15, // create token class
Expand Down Expand Up @@ -157,6 +159,7 @@ describe("test for batch add and enable plugins", function () {
try {
const result = await darc2.entrance({
programOperatorAddress: target_addr,
notes: "try to run a batch mint token instruction with target1 as the operator",
operations: [{
operatorAddress: target_addr,
opcode: 1, // mint token
Expand Down Expand Up @@ -198,6 +201,7 @@ describe("test for batch add and enable plugins", function () {
try {
const result3 = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "try to run a batch mint token instruction with target1 as the operator",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("batch_add_membership_test", function () {

await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "add 4 membership",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 7, // add membership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("batch_add_withdrawable_balances_test", function () {
// target 3: 300
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "add withdrawable balances",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 17, // BATCH_ADD_WITHDRAWABLE_BALANCES
Expand Down Expand Up @@ -68,6 +69,7 @@ describe("batch_add_withdrawable_balances_test", function () {

await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "add withdrawable balances",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 17, // BATCH_ADD_WITHDRAWABLE_BALANCES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("batch_burn_tokens_from_to_test", function () {
// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
Expand All @@ -62,6 +63,7 @@ describe("batch_burn_tokens_from_to_test", function () {
// mint tokens
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down Expand Up @@ -117,6 +119,7 @@ describe("batch_burn_tokens_from_to_test", function () {

// next burn all tokens from target 2 and target 3, make sure they are removed from the token owners list
await darc.entrance({
notes: "burn all tokens from target 2 and target 3",
programOperatorAddress: programOperatorAddress,
operations: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe("batch_burn_tokens_test", function () {

// create a token class first
await darc.entrance({
notes: "create token class",
programOperatorAddress: programOperatorAddress,
operations: [{
operatorAddress: programOperatorAddress,
Expand All @@ -58,6 +59,7 @@ describe("batch_burn_tokens_test", function () {

// mint tokens
await darc.entrance({
notes: "mint tokens and burn some tokens",
programOperatorAddress: programOperatorAddress,
operations: [{
operatorAddress: programOperatorAddress,
Expand Down Expand Up @@ -113,6 +115,7 @@ describe("batch_burn_tokens_test", function () {
// burn remaining tokens and check balance
// mint tokens
await darc.entrance({
notes: "burn remaining tokens",
programOperatorAddress: programOperatorAddress,
operations: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("test for batch create token class instruction", function () {

const result_entrance = await darc.entrance({
programOperatorAddress: initProgram.programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: initProgram.programOperatorAddress,
opcode: 2, // create token class
Expand Down
4 changes: 4 additions & 0 deletions darc-protocol/test/operationUnitTest/batch_mint_token_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("batch_mint_token_test", function () {
// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
Expand All @@ -69,6 +70,7 @@ describe("batch_mint_token_test", function () {

const result_entrance = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down Expand Up @@ -113,6 +115,7 @@ describe("batch_mint_token_test", function () {

const result_entrance2 = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down Expand Up @@ -153,6 +156,7 @@ describe("batch_mint_token_test", function () {

const result_entrance3 = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("batch_pay_to_mint_token_test", function () {
// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
Expand All @@ -62,6 +63,7 @@ describe("batch_pay_to_mint_token_test", function () {

const result_entrance = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "pay to mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 20, // pay to mint token
Expand Down Expand Up @@ -96,6 +98,7 @@ describe("batch_pay_to_mint_token_test", function () {

const result_entrance2 = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "pay to mint tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 20, // pay to mint token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe("batch_pay_to_transfer_token_test", function () {
// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
Expand All @@ -59,6 +60,7 @@ describe("batch_pay_to_transfer_token_test", function () {

const result_entrance = await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "pay to mint and transfer tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 20, // pay to mint token
Expand Down
3 changes: 3 additions & 0 deletions darc-protocol/test/operationUnitTest/batch_transfer_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("batch_transfer_tokens_test", function () {
// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "create token class",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 2, // create token class
Expand Down Expand Up @@ -68,6 +69,7 @@ describe("batch_transfer_tokens_test", function () {
// mint tokens
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "mint and transfer tokens",
operations: [{
operatorAddress: programOperatorAddress,
opcode: 1, // mint token
Expand Down Expand Up @@ -131,6 +133,7 @@ describe("batch_transfer_tokens_test", function () {
// transfer all remaining tokens from programOperatorAddress to target1
await darc.entrance({
programOperatorAddress: programOperatorAddress,
notes: "transfer all remaining tokens from programOperatorAddress to target1",
operations: [
{
operatorAddress: programOperatorAddress,
Expand Down
Loading

0 comments on commit 13cf352

Please sign in to comment.