Skip to content

Commit

Permalink
chore: revise dir and little bit fix
Browse files Browse the repository at this point in the history
Signed-off-by: MASDXI <[email protected]>
  • Loading branch information
MASDXI committed Oct 6, 2024
1 parent fa5c2dc commit 235a8cc
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 151 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/mocks/MockUtxoCBDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract MockUtxoCBDC is UTXOToken, FreezeAddress, FreezeBalance, FreezeToken {
_mintTransaction(account, value);
}

function burn(address account, uint256 value, bytes32 tokenId) public {
function burn(address account, bytes32 tokenId, uint256 value) public {
_burnTransaction(account, tokenId, value);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/MockeUtxoCBDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract MockeUtxoCBDC is eUTXOToken, FreezeAddress, FreezeBalance, FreezeToken
_mintTransaction(account, value);
}

function burn(address account, uint256 value, bytes32 tokenId) public {
function burn(address account, bytes32 tokenId, uint256 value) public {
_burnTransaction(account, tokenId, value);
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
"license": "Apache-2.0",
"private": "true",
"scripts": {
"besu:start": "cd $(pwd)/test/simulators/besu && $(pwd)/scripts/start.sh",
"besu:stop": "cd $(pwd)/test/simulators/besu && $(pwd)/scripts/stop.sh",
"besu:start": "cd $(pwd)/blockchain/besu && $(pwd)/scripts/start.sh",
"besu:stop": "cd $(pwd)/blockchain/besu && $(pwd)/scripts/stop.sh",
"build": "npx hardhat clean && npx hardhat test && npx hardhat compile",
"clean": "npx hardhat clean",
"compile": "npx hardhat compile",
"coverage": "npx hardhat coverage",
"geth:start": "cd $(pwd)/test/simulators/geth && $(pwd)/scripts/start.sh",
"geth:stop": "cd $(pwd)/test/simulators/geth && $(pwd)/scripts/stop.sh",
"geth:start": "cd $(pwd)/blockchain/geth && $(pwd)/scripts/start.sh",
"geth:stop": "cd $(pwd)/blockchain/geth && $(pwd)/scripts/stop.sh",
"node:start": "npx hardhat node",
"simulation": "echo \"Not implemented yet.\"",
"test": "npx hardhat clean && npx hardhat test",
"test:parallel": "npx hardhat clean && npx hardhat test --parallel",
"install:requirements": "pip install -r requirements.txt"
"install:requirements": "pip install -r requirements.txt",
"format": "npx prettier --write ."
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions test/contracts/UTXO/.prettierrc

This file was deleted.

78 changes: 23 additions & 55 deletions test/contracts/UTXO/UTXOCBDC.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
const {
time,
loadFixture,
} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
const { expect } = require("chai");
const {
encodeBytes32String,
ZeroAddress,
solidityPackedKeccak256,
getBytes,
isBytesLike,
ZeroHash,
} = require("ethers");
const {time, loadFixture} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const {anyValue} = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
const {expect} = require("chai");
const {encodeBytes32String, ZeroAddress, solidityPackedKeccak256, getBytes, isBytesLike, ZeroHash} = require("ethers");

describe("UTXO CBDC", function () {
// We define a fixture to reuse the same setup in every test.
Expand All @@ -24,12 +14,12 @@ describe("UTXO CBDC", function () {
const contract = await ethers.getContractFactory("MockUtxoCBDC");
const token = await contract.deploy("United States dollar", "USD");

return { token, owner, otherAccount };
return {token, owner, otherAccount};
}

describe("Transaction info", function () {
it("Should return right transaction information from given tokenId", async function () {
const { token, owner } = await loadFixture(deployTokenFixture);
const {token, owner} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
let tx = await token.mint(address, 1000n);
tx = await tx.wait();
Expand All @@ -45,7 +35,7 @@ describe("UTXO CBDC", function () {
});

it("Should return right transaction size from given address", async function () {
const { token, owner } = await loadFixture(deployTokenFixture);
const {token, owner} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
await token.mint(address, 1000n);
const txSize = await token.transactionSize(address);
Expand All @@ -55,72 +45,60 @@ describe("UTXO CBDC", function () {

describe("Transfers", function () {
it("Should mint the funds to the owner", async function () {
const { token, owner } = await loadFixture(deployTokenFixture);
const {token, owner} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
let tx = await token.mint(address, 1000n);
tx = await tx.wait();
const tokenId = tx.logs[0].args[0];
const { input, value, spent } = await token.transaction(tokenId);
const {input, value, spent} = await token.transaction(tokenId);
expect(await token.balanceOf(address)).to.equal(1000n);
expect(input).to.equal(ZeroHash);
expect(value).to.equal(1000n);
expect(spent).to.equal(false);
});

it("Should transfer the funds from the account to other account", async function () {
const { token, owner, otherAccount } =
await loadFixture(deployTokenFixture);
const {token, owner, otherAccount} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
const otherAddress = await otherAccount.getAddress();
let tx = await token.mint(address, 1000n);
tx = await tx.wait();
const tokenId = tx.logs[0].args[0];
const hashed = solidityPackedKeccak256(["bytes32"], [tokenId]);
const signature = await owner.signMessage(getBytes(hashed));
await token["transfer(address,bytes32,uint256,bytes)"](
otherAddress,
tokenId,
1000n,
signature,
);
await token["transfer(address,bytes32,uint256,bytes)"](otherAddress, tokenId, 1000n, signature);
expect(await token.balanceOf(otherAddress)).to.equal(1000n);
});

it("Should fail on transfer with standard ERC20 interface", async function () {
const { token, owner, otherAccount } =
await loadFixture(deployTokenFixture);
const {token, owner, otherAccount} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
const otherAddress = await otherAccount.getAddress();
await token.mint(address, 1000n);
await expect(
token["transfer(address,uint256)"](otherAddress, 1000n),
).to.be.revertedWithCustomError(token, "ERC20TransferNotSupported");
await expect(token["transfer(address,uint256)"](otherAddress, 1000n)).to.be.revertedWithCustomError(
token,
"ERC20TransferNotSupported",
);
});

it("Should fail on transferFrom with standard ERC20 interface", async function () {
const { token, owner, otherAccount } =
await loadFixture(deployTokenFixture);
const {token, owner, otherAccount} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
const otherAddress = await otherAccount.getAddress();
await token.mint(address, 1000n);
await expect(
token["transferFrom(address,address,uint256)"](
address,
otherAddress,
1000n,
),
token["transferFrom(address,address,uint256)"](address, otherAddress, 1000n),
).to.be.revertedWithCustomError(token, "ERC20TransferFromNotSupported");
});

it("Should burn transfer with to address zero", async function () {
const { token, owner, otherAccount } =
await loadFixture(deployTokenFixture);
const {token, owner, otherAccount} = await loadFixture(deployTokenFixture);
const amount = 1000n;
const address = await owner.getAddress();
let tx = await token.mint(address, amount);
tx = await tx.wait();
const tokenId = tx.logs[0].args[0];
await token.burn(address, amount, tokenId);
await token.burn(address, tokenId, amount);
expect(await token.balanceOf(address)).to.equal(0);
// TODO: transferFrom(address,address,tokenId,amount)
// TODO: burn(address,tokenId,amount)
Expand All @@ -129,33 +107,23 @@ describe("UTXO CBDC", function () {

describe("Restrict", function () {
it("Should restrict transfer the funds to the other account by frozen tokenId", async function () {
const { token, owner, otherAccount } =
await loadFixture(deployTokenFixture);
const {token, owner, otherAccount} = await loadFixture(deployTokenFixture);
const address = await owner.getAddress();
const otherAddress = await otherAccount.getAddress();
let tx = await token.mint(address, 1000n);
tx = await tx.wait();
let tokenId = tx.logs[0].args[0];
let hashed = solidityPackedKeccak256(["bytes32"], [tokenId]);
let signature = await owner.signMessage(getBytes(hashed));
tx = await token["transfer(address,bytes32,uint256,bytes)"](
otherAddress,
tokenId,
100n,
signature,
);
tx = await token["transfer(address,bytes32,uint256,bytes)"](otherAddress, tokenId, 100n, signature);
tx = await tx.wait();
tokenId = tx.logs[1].args[0];
hashed = solidityPackedKeccak256(["bytes32"], [tokenId]);
signature = await otherAccount.signMessage(getBytes(hashed));
expect(await token.balanceOf(otherAddress)).to.equal(100n);
await token.freezeToken(tokenId);
await expect(
token
.connect(otherAccount)
[
"transfer(address,bytes32,uint256,bytes)"
](address, tokenId, 10n, signature),
token.connect(otherAccount)["transfer(address,bytes32,uint256,bytes)"](address, tokenId, 10n, signature),
).to.be.revertedWithCustomError(token, "TokenFrozen");
});
});
Expand Down
Loading

0 comments on commit 235a8cc

Please sign in to comment.