diff --git a/README.md b/README.md index f9ca914..2b807b3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/contracts/Git3.sol b/contracts/Git3.sol index cc2d5e7..3d3364c 100644 --- a/contracts/Git3.sol +++ b/contracts/Git3.sol @@ -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, diff --git a/local.config b/local.config deleted file mode 100644 index e69de29..0000000 diff --git a/test/git3-test.js b/test/git3-test.js index 7cdac86..66afdce 100644 --- a/test/git3-test.js +++ b/test/git3-test.js @@ -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) diff --git a/test/test-create.ts b/test/test-create.ts new file mode 100644 index 0000000..b41f408 --- /dev/null +++ b/test/test-create.ts @@ -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); +}); diff --git a/test/test-up.ts b/test/test-up.ts index 95771f2..8947447 100644 --- a/test/test-up.ts +++ b/test/test-up.ts @@ -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");