Skip to content

Commit

Permalink
testcase: create public data failed
Browse files Browse the repository at this point in the history
  • Loading branch information
streetycat committed Dec 30, 2023
1 parent e1eeac7 commit bd3f337
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/test_public_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { generateProof } from "../scripts/generate_proof";
* 1: data sponser
* 2-10: data supplier
* 19: Foundation
* 15: failed owner
*/

describe("PublicDataStorage", function () {
Expand Down Expand Up @@ -61,6 +62,44 @@ describe("PublicDataStorage", function () {
expect(await contract.dataBalance(TestDatas[0].hash)).to.equal(ethers.parseEther("614.4"));
});

it("create public data failed", async () => {
// duplicate create
await expect(contract.connect(signers[15]).createPublicData(TestDatas[0].hash, 64, ethers.parseEther("768"), ethers.ZeroAddress, 0))
.to.be.revertedWith("public data already exists")

// invalid hash
await expect(contract.connect(signers[15]).createPublicData(ethers.ZeroHash, 64, ethers.parseEther("768"), ethers.ZeroAddress, 0))
.to.be.revertedWith("data hash is empty")

// // too little
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 0, ethers.parseEther("768"), ethers.ZeroAddress, 0))
.to.be.revertedWith("deposit ratio is too small")
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 63, ethers.parseEther("768"), ethers.ZeroAddress, 0))
.to.be.revertedWith("deposit ratio is too small")
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 64, ethers.parseEther("0"), ethers.ZeroAddress, 0))
.to.be.revertedWith("deposit amount is too small")
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 64, ethers.parseEther("767.9"), ethers.ZeroAddress, 0))
.to.be.revertedWith("deposit amount is too small")

// // more then total gwt amounts
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 64, ethers.parseEther("210001"), ethers.ZeroAddress, 0))
.to.be.reverted;

// cut the appropriate amount
await (await gwtToken.connect(signers[15]).approve(await contract.getAddress(), ethers.parseEther("767"))).wait();
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 64, ethers.parseEther("768"), ethers.ZeroAddress, 0))
.to.be.reverted;

// cost all gwts
await (await gwtToken.connect(signers[15]).approve(await contract.getAddress(), ethers.parseEther("210000"))).wait();
await expect(contract.connect(signers[15]).createPublicData(TestDatas[9].hash, 64, ethers.parseEther("210000"), ethers.ZeroAddress, 0))
.emit(contract, "PublicDataCreated").withArgs(TestDatas[9].hash)
.emit(contract, "SponsorChanged").withArgs(TestDatas[9].hash, ethers.ZeroAddress, signers[15].address)
.emit(contract, "DepositData").withArgs(signers[15].address, TestDatas[9].hash, ethers.parseEther("168000"), ethers.parseEther("42000"));

expect(await contract.dataBalance(TestDatas[9].hash)).to.equal(ethers.parseEther("168000"));
});

it("deposit data", async () => {
await expect(contract.connect(signers[1]).addDeposit(TestDatas[0].hash, ethers.parseEther("100")))
.emit(contract, "DepositData").withArgs(signers[1].address, TestDatas[0].hash, ethers.parseEther("80"), ethers.parseEther("20"));
Expand Down Expand Up @@ -152,4 +191,12 @@ describe("PublicDataStorage", function () {
.changeTokenBalance(gwtToken, signers[index], ethers.parseEther("2.68992"));
}
});

it("show data failed", async() => {
// TODO
});

it("show data failed", async() => {
// TODO
});
});

0 comments on commit bd3f337

Please sign in to comment.