Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed May 22, 2023
1 parent c3fbfd1 commit dab7f76
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ Since Hardhat and OpenZeppelin are used, the project can be built using the foll
2. Compile the contracts

```shell
npm run compile
npx hardhat compile
```

3. Run the Darc test network
Expand All @@ -522,7 +522,7 @@ Since Hardhat and OpenZeppelin are used, the project can be built using the foll
4. Test contracts

```shell
npm run test
npx hardhat test
REPORT_GAS=true npm run test
```

Expand Down
134 changes: 134 additions & 0 deletions darc-protocol/test/operationUnitTest/offer_dividends_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
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";

const programOperatorAddress = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";
const addr1 = "0x90F79bf6EB2c4f870365E785982E1f101E93b906";
const addr2 = '0x976EA74026E726554dB657fA54763abd0C3a0aa9';
const addr3 = '0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199';
const addr4 = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65';
const addr5 = '0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc';
const addr6 = '0x14dC79964da2C08b23698B3D3cc7Ca32193d9955';
// test for batch mint token instruction on DARC

function containsAddr(array: string[], addr:string): boolean {
for (let i = 0; i < array.length; i++) {
if (array[i].toLowerCase() === addr.toLowerCase()) {
return true;
}
}
return false;
}

describe("offer_dividends_test", function () {


it ("should offer dividends", 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();


// create a token class first
await darc.entrance({
programOperatorAddress: programOperatorAddress,
operations: [{
operatorAddress: 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: []
}
}],
});


const result_entrance = await darc.entrance({
programOperatorAddress: programOperatorAddress,
operations: [{
operatorAddress: programOperatorAddress,
opcode: 20, // pay to 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)], // token class = 0
[BigNumber.from(100), BigNumber.from(200)], // amount = 100
[BigNumber.from(1), BigNumber.from(1)], // token price
],
ADDRESS_2DARRAY: [
[programOperatorAddress,programOperatorAddress], // to = programOperatorAddress
]
}
}],
},
{value: 300} // 100 * 1 + 200 * 1 = 300 wei, the value should be equal to the total amount of token price
);

let owner0 = await darc.getTokenOwners(1);
let owner1 = await darc.getTokenOwners(0);

expect(containsAddr(owner0, programOperatorAddress)).to.equal(true);
expect(containsAddr(owner1, programOperatorAddress)).to.equal(true);

const result_entrance2 = await darc.entrance({
programOperatorAddress: programOperatorAddress,
operations: [{
operatorAddress: programOperatorAddress,
opcode: 20, // pay to 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)], // token class = 0
[BigNumber.from(100), BigNumber.from(200)], // amount = 100
[BigNumber.from(1), BigNumber.from(1)], // token price
],
ADDRESS_2DARRAY: [
[addr1,addr2], // to = programOperatorAddress
]
}
}],
},
{value: 300} // 100 * 1 + 200 * 1 = 300 wei, the value should be equal to the total amount of token price
);

// get the address balance of token 0 and 1
const balance0 = await darc.getTokenOwnerBalance(0, addr1);
const balance1 = await darc.getTokenOwnerBalance(1, addr2);

expect(balance0.toBigInt().toString()).to.equal("100");
expect(balance1.toBigInt().toString()).to.equal("200");

owner0 = await darc.getTokenOwners(0);
owner1 = await darc.getTokenOwners(1);
expect(containsAddr(owner0, addr1)).to.equal(true);
expect(containsAddr(owner1, addr2)).to.equal(true);
});
});

0 comments on commit dab7f76

Please sign in to comment.