|
|
@ -4,6 +4,7 @@ const { ethers } = require("hardhat");
|
|
|
|
const { defaultAbiCoder } = require("ethers/lib/utils");
|
|
|
|
const { defaultAbiCoder } = require("ethers/lib/utils");
|
|
|
|
|
|
|
|
|
|
|
|
var ToBig = (x) => ethers.BigNumber.from(x);
|
|
|
|
var ToBig = (x) => ethers.BigNumber.from(x);
|
|
|
|
|
|
|
|
let ETH = ethers.BigNumber.from(10).pow(18);
|
|
|
|
|
|
|
|
|
|
|
|
describe("Git3 Test", function () {
|
|
|
|
describe("Git3 Test", function () {
|
|
|
|
it("upload/download/remove", async function () {
|
|
|
|
it("upload/download/remove", async function () {
|
|
|
@ -18,7 +19,10 @@ describe("Git3 Test", function () {
|
|
|
|
await git3.createRepo(repoName);
|
|
|
|
await git3.createRepo(repoName);
|
|
|
|
|
|
|
|
|
|
|
|
await git3.upload(repoName, "0x616263", "0x112233");
|
|
|
|
await git3.upload(repoName, "0x616263", "0x112233");
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql(["0x112233", true]);
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql([
|
|
|
|
|
|
|
|
"0x112233",
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
let data = Array.from({ length: 40 }, () =>
|
|
|
|
let data = Array.from({ length: 40 }, () =>
|
|
|
|
Math.floor(Math.random() * 256)
|
|
|
|
Math.floor(Math.random() * 256)
|
|
|
@ -126,34 +130,118 @@ describe("Git3 Test", function () {
|
|
|
|
|
|
|
|
|
|
|
|
let singer;
|
|
|
|
let singer;
|
|
|
|
let user1;
|
|
|
|
let user1;
|
|
|
|
[singer, user1,] = await ethers.getSigners();
|
|
|
|
[singer, user1] = await ethers.getSigners();
|
|
|
|
const repoName = Buffer.from("test")
|
|
|
|
const repoName = Buffer.from("test");
|
|
|
|
|
|
|
|
|
|
|
|
await git3.connect(singer).createRepo(repoName);
|
|
|
|
await git3.connect(singer).createRepo(repoName);
|
|
|
|
|
|
|
|
|
|
|
|
await expect(git3.connect(user1).upload(repoName, "0x616263", "0x112233")).to.be.revertedWith("only owner");
|
|
|
|
await expect(
|
|
|
|
await expect(git3.connect(user1).uploadChunk(repoName, "0x616263", 0, "0x112233")).to.be.revertedWith("only owner");
|
|
|
|
git3.connect(user1).upload(repoName, "0x616263", "0x112233")
|
|
|
|
await expect(git3.connect(user1).setRef(repoName, "0x616263", "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")).to.be.revertedWith("only owner");
|
|
|
|
).to.be.revertedWith("only owner");
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
await git3.connect(singer).upload(repoName, "0x616263", "0x112233")
|
|
|
|
git3.connect(user1).uploadChunk(repoName, "0x616263", 0, "0x112233")
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql(["0x112233", true]);
|
|
|
|
).to.be.revertedWith("only owner");
|
|
|
|
await git3.connect(singer).setRef(repoName, "0x616263", "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
|
|
await expect(
|
|
|
|
|
|
|
|
git3
|
|
|
|
|
|
|
|
.connect(user1)
|
|
|
|
|
|
|
|
.setRef(
|
|
|
|
|
|
|
|
repoName,
|
|
|
|
|
|
|
|
"0x616263",
|
|
|
|
|
|
|
|
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
).to.be.revertedWith("only owner");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await git3.connect(singer).upload(repoName, "0x616263", "0x112233");
|
|
|
|
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql([
|
|
|
|
|
|
|
|
"0x112233",
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
await git3
|
|
|
|
|
|
|
|
.connect(singer)
|
|
|
|
|
|
|
|
.setRef(
|
|
|
|
|
|
|
|
repoName,
|
|
|
|
|
|
|
|
"0x616263",
|
|
|
|
|
|
|
|
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
|
|
|
git3.connect(user1).remove(repoName, "0x616263")
|
|
|
|
|
|
|
|
).to.be.revertedWith("only owner");
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
|
|
|
git3.connect(user1).delRef(repoName, "0x616263")
|
|
|
|
|
|
|
|
).to.be.revertedWith("only owner");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await expect(git3.connect(user1).remove(repoName, "0x616263")).to.be.revertedWith("only owner");
|
|
|
|
it("RepoName Check", async function () {
|
|
|
|
await expect(git3.connect(user1).delRef(repoName, "0x616263")).to.be.revertedWith("only owner");
|
|
|
|
const Git3 = await ethers.getContractFactory("Git3");
|
|
|
|
|
|
|
|
const git3 = await Git3.deploy();
|
|
|
|
|
|
|
|
await git3.deployed();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let repoName = Buffer.from(
|
|
|
|
|
|
|
|
"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.-_"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await git3.createRepo(repoName);
|
|
|
|
|
|
|
|
await expect(git3.createRepo(repoName)).to.be.revertedWith(
|
|
|
|
|
|
|
|
"RepoName already exist"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await expect(git3.createRepo(Buffer.from("a/b"))).to.be.revertedWith(
|
|
|
|
|
|
|
|
"RepoName must be alphanumeric or -._"
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
|
|
|
|
git3.createRepo(Buffer.from("a".repeat(101)))
|
|
|
|
|
|
|
|
).to.be.revertedWith("RepoName length must be 1-100");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("RepoName Check", async function () {
|
|
|
|
it("Get the stake number of chunks", async function () {
|
|
|
|
const Git3 = await ethers.getContractFactory("Git3");
|
|
|
|
const Git3 = await ethers.getContractFactory("Git3");
|
|
|
|
const git3 = await Git3.deploy();
|
|
|
|
const git3 = await Git3.deploy();
|
|
|
|
await git3.deployed();
|
|
|
|
await git3.deployed();
|
|
|
|
|
|
|
|
|
|
|
|
let repoName = Buffer.from("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.-_");
|
|
|
|
const repoName = Buffer.from("test");
|
|
|
|
await git3.createRepo(repoName);
|
|
|
|
await git3.createRepo(repoName);
|
|
|
|
await expect(git3.createRepo(repoName)).to.be.revertedWith("RepoName already exist");
|
|
|
|
|
|
|
|
await expect(git3.createRepo(Buffer.from("a/b"))).to.be.revertedWith("RepoName must be alphanumeric or -._");
|
|
|
|
|
|
|
|
await expect(git3.createRepo(Buffer.from("a".repeat(101)))).to.be.revertedWith("RepoName length must be 1-100");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
stakeNum1 = ETH;
|
|
|
|
|
|
|
|
stakeNum2 = ToBig(2).mul(ETH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data0 = Array.from({ length: 1024 }, () =>
|
|
|
|
|
|
|
|
Math.floor(Math.random() * 256)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await git3.uploadChunk(repoName, "0x616263", 0, data0, {
|
|
|
|
|
|
|
|
value: stakeNum1,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql([
|
|
|
|
|
|
|
|
ethers.utils.hexlify(data0),
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data1 = Array.from({ length: 1024 }, () =>
|
|
|
|
|
|
|
|
Math.floor(Math.random() * 256)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await git3.uploadChunk(repoName, "0x616263", 1, data1, {
|
|
|
|
|
|
|
|
value: stakeNum2,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(await git3.download(repoName, "0x616263")).to.eql([
|
|
|
|
|
|
|
|
ethers.utils.hexlify(data0.concat(data1)),
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let stakeNum = await git3.stakeTokens(repoName, "0x616263");
|
|
|
|
|
|
|
|
expect(stakeNum).to.equal(stakeNum1.add(stakeNum2));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let actualStakeNum1 = await git3.chunkStakeTokens(repoName, "0x616263", 0);
|
|
|
|
|
|
|
|
let actualStakeNum2 = await git3.chunkStakeTokens(repoName, "0x616263", 1);
|
|
|
|
|
|
|
|
expect(actualStakeNum1).to.equal(stakeNum1);
|
|
|
|
|
|
|
|
expect(actualStakeNum2).to.equal(stakeNum2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check that the stake numer of chunk after removing chunks
|
|
|
|
|
|
|
|
await git3.remove(repoName, "0x616263"); // should succeed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stakeNum = await git3.stakeTokens(repoName, "0x616263");
|
|
|
|
|
|
|
|
actualStakeNum1 = await git3.chunkStakeTokens(repoName, "0x616263", 0);
|
|
|
|
|
|
|
|
actualStakeNum2 = await git3.chunkStakeTokens(repoName, "0x616263", 1);
|
|
|
|
|
|
|
|
expect(stakeNum).to.equal(ToBig(0));
|
|
|
|
|
|
|
|
expect(actualStakeNum1).to.equal(ToBig(0));
|
|
|
|
|
|
|
|
expect(actualStakeNum2).to.equal(ToBig(0));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|