add some test

main
cyhhao 2 years ago
parent b8ce46d3b5
commit 3c07525028

@ -11,6 +11,8 @@ This project demonstrates a basic Hardhat use case. It comes with a sample contr
Try running some of the following tasks:
```shell
cp demo.config.ts local.config.ts
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test

@ -38,6 +38,37 @@ contract Git3 is LargeStorageManager {
_;
}
function createRepo(bytes memory repoName) external {
require(
repoName.length > 0 && repoName.length <= 100,
"RepoName length must be 1-100"
);
for (uint i; i < repoName.length; i++) {
bytes1 char = repoName[i];
require(
(char >= 0x61 && char <= 0x7A) || //a-z
(char >= 0x41 && char <= 0x5A) || //A-Z
(char >= 0x30 && char <= 0x39) || //0-9
(char == 0x2D || char == 0x2E || char == 0x5F), //-._
"RepoName must be alphanumeric or -._"
);
}
require(
repoNameToOwner[repoName] == address(0),
"RepoName already exist"
);
repoNameToOwner[repoName] = msg.sender;
}
function transferOwnership(bytes memory repoName, address newOwner)
external
onlyOwner(repoName)
{
require(newOwner != address(0), "newOwner must not be zero address");
repoNameToOwner[repoName] = newOwner;
}
function stakeTokens(
bytes memory repoName,
bytes memory path
@ -64,29 +95,6 @@ contract Git3 is LargeStorageManager {
return _get(keccak256(bytes.concat(repoName, "/", path)));
}
function createRepo(bytes memory repoName) external {
require(
repoName.length > 0 && repoName.length <= 100,
"RepoName length must be 1-100"
);
for (uint i; i < repoName.length; i++) {
bytes1 char = repoName[i];
require(
(char >= 0x61 && char <= 0x7A) || //a-z
(char >= 0x41 && char <= 0x5A) || //A-Z
(char >= 0x30 && char <= 0x39) || //0-9
(char == 0x2D || char == 0x2E || char == 0x5F), //-._
"RepoName must be alphanumeric or -._"
);
}
require(
repoNameToOwner[repoName] == address(0),
"RepoName already exist"
);
repoNameToOwner[repoName] = msg.sender;
}
function upload(
bytes memory repoName,
bytes memory path,

@ -200,8 +200,8 @@ describe("Git3 Test", function () {
const repoName = Buffer.from("test");
await git3.createRepo(repoName);
stakeNum1 = ETH;
stakeNum2 = ToBig(2).mul(ETH);
let stakeNum1 = ETH;
let stakeNum2 = ToBig(2).mul(ETH);
let data0 = Array.from({ length: 1024 }, () =>
Math.floor(Math.random() * 256)

@ -0,0 +1,27 @@
import hre from "hardhat";
const { ethers } = hre;
import fs from "fs";
async function main() {
const accounts = await ethers.getSigners();
console.log(accounts[0].address);
const Git3 = await hre.ethers.getContractAt(
"Git3",
"0x0068bD3ec8D16402690C1Eddff06ACb913A209ef"
);
let rept
let owner = await Git3.repoNameToOwner(Buffer.from("helloworld1"))
console.log(owner)
// return
rept = await Git3.createRepo(Buffer.from("helloworld1"))
console.log("rept", "https://explorer.galileo.web3q.io/tx/" + rept.hash);
// rept = await Git3.transferOwnership(Buffer.from("helloworld"), "0x1eD9c2F6814eA5225Bb78f2F2CA802Ded120077A")
// console.log("rept", "https://explorer.galileo.web3q.io/tx/" + rept.hash)
}
main().catch((error) => {
console.error(error);
process.exit(1);
});

@ -10,13 +10,6 @@ async function main() {
"Git3",
"0xa709975Bc01e745432f8898499E7b9a60f420117"
);
let storageManager = await Git3.storageManager();
console.log("storageManager", storageManager);
const flat = await hre.ethers.getContractAt("FlatDirectory", storageManager);
let owner = await flat.owner();
console.log("owner", owner);
return;
let file = fs.readFileSync("test/git3.png");

Loading…
Cancel
Save