update hubv3

main
cyl19970726 2 years ago
parent df50b32098
commit 23c06f456f

@ -1,15 +1,14 @@
//SPDX-License-Identifier: GLP-3.0 //SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./EnumerableSet.sol";
import "./Repolib.sol"; import "./Repolib.sol";
import "./database/database.sol"; import "./database/database.sol";
import "./database/ethstorage.sol"; import "./database/ethstorage.sol";
import "./database/filecoin.sol"; import "./database/filecoin.sol";
contract Hubv3 is AccessControl, Initializable { contract Hubv3 is AccessControlEnumerable, Initializable {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
using Repolib for Repolib.BranchInfo; using Repolib for Repolib.BranchInfo;
@ -55,7 +54,7 @@ contract Hubv3 is AccessControl, Initializable {
} }
// ===== hub operator functions====== // ===== hub operator functions======
function openPermissonlessJoin(bool open) public { function setPermissonlessJoin(bool open) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender())); require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()));
permissionless = open; permissionless = open;
} }
@ -89,6 +88,14 @@ contract Hubv3 is AccessControl, Initializable {
return false; return false;
} }
function roleToMembers(bytes32 role) public view returns(address[] memory members){
uint256 count = getRoleMemberCount(role);
members = new address[](count);
for (uint i = 0; i < count; i++){
members[i] = getRoleMember(role, i);
}
}
function addManager(address member) public { function addManager(address member) public {
grantRole(MANAGER, member); grantRole(MANAGER, member);
} }
@ -112,6 +119,11 @@ contract Hubv3 is AccessControl, Initializable {
} }
// ===== repository operator functions====== // ===== repository operator functions======
function repoList() public view returns(bytes[] memory rn){
return repoNames;
}
//createRepository can be invoked by anyone within Hub //createRepository can be invoked by anyone within Hub
function createRepo(bytes memory repoName) public { function createRepo(bytes memory repoName) public {
require(membership(_msgSender())); require(membership(_msgSender()));
@ -260,6 +272,15 @@ contract Hubv3 is AccessControl, Initializable {
return db.upload(repoName, path, data); return db.upload(repoName, path, data);
} }
function uploadChunk(
bytes memory repoName,
bytes memory path,
uint256 chunkId,
bytes calldata data
) external payable {
return db.uploadChunk(repoName, path,chunkId, data);
}
function batchUpload( function batchUpload(
bytes memory repoName, bytes memory repoName,
bytes[] memory path, bytes[] memory path,

@ -12,4 +12,11 @@ interface database {
bytes memory path, bytes memory path,
bytes calldata data bytes calldata data
) external payable; ) external payable;
function uploadChunk(
bytes memory repoName,
bytes memory path,
uint256 chunkId,
bytes calldata data
) external payable;
} }

@ -23,4 +23,13 @@ contract filecoin is database {
bytes32 fullName = keccak256(bytes.concat(repoName, "/", path)); bytes32 fullName = keccak256(bytes.concat(repoName, "/", path));
pathToHash[fullName] = data; pathToHash[fullName] = data;
} }
function uploadChunk(
bytes memory repoName,
bytes memory path,
uint256 chunkId,
bytes calldata data
) external payable override {
revert("unsupport uploadChunk");
}
} }

@ -12,7 +12,7 @@ describe("Hub V3 Test", function () {
it("Hub Access Control", async function () { it("Hub Access Control", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory"); const hubfacFac = await ethers.getContractFactory("HubFactory");
const hubFac = await hubfacFac.deploy(); const hubFac = await hubfacFac.deploy(false);
await hubFac.deployed(); await hubFac.deployed();
await hubFac.newHubImp(); await hubFac.newHubImp();
@ -29,6 +29,10 @@ describe("Hub V3 Test", function () {
expect(IsManager).to.equal(true); expect(IsManager).to.equal(true);
expect(IsContributor).to.equal(false); expect(IsContributor).to.equal(false);
let ADMIN_ROLE = await git3.DEFAULT_ADMIN_ROLE();
let addrs = await git3.roleToMembers(ADMIN_ROLE);
expect(addrs[0]).to.equal(singer.address);
await git3.addManager(manager1.address) await git3.addManager(manager1.address)
await git3.addManager(manager2.address) await git3.addManager(manager2.address)
let roles = await git3.memberRole(manager1.address) let roles = await git3.memberRole(manager1.address)
@ -36,6 +40,13 @@ describe("Hub V3 Test", function () {
expect(roles[1]).to.equal(true); expect(roles[1]).to.equal(true);
expect(roles[2]).to.equal(false); expect(roles[2]).to.equal(false);
let MANAGER_ROLE = await git3.MANAGER();
let m_addrs = await git3.roleToMembers(MANAGER_ROLE);
expect(m_addrs[0]).to.equal(singer.address);
expect(m_addrs[1]).to.equal(manager1.address);
expect(m_addrs[2]).to.equal(manager2.address);
roles = await git3.memberRole(manager2.address) roles = await git3.memberRole(manager2.address)
expect(roles[0]).to.equal(false); expect(roles[0]).to.equal(false);
expect(roles[1]).to.equal(true); expect(roles[1]).to.equal(true);
@ -46,6 +57,10 @@ describe("Hub V3 Test", function () {
expect(roles[0]).to.equal(false); expect(roles[0]).to.equal(false);
expect(roles[1]).to.equal(false); expect(roles[1]).to.equal(false);
expect(roles[2]).to.equal(false); expect(roles[2]).to.equal(false);
m_addrs = await git3.roleToMembers(MANAGER_ROLE);
expect(m_addrs.length).to.equal(2);
expect(m_addrs[0]).to.equal(singer.address);
expect(m_addrs[1]).to.equal(manager1.address);
// power no enough // power no enough
await expect( await expect(
@ -118,7 +133,7 @@ describe("Hub V3 Test", function () {
it("upload/download/remove", async function () { it("upload/download/remove", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory"); const hubfacFac = await ethers.getContractFactory("HubFactory");
const hubFac = await hubfacFac.deploy(); const hubFac = await hubfacFac.deploy(true);
await hubFac.deployed(); await hubFac.deployed();
await hubFac.newHubImp(); await hubFac.newHubImp();
@ -158,7 +173,7 @@ describe("Hub V3 Test", function () {
it("set/update/list/remove Branch", async function () { it("set/update/list/remove Branch", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory"); const hubfacFac = await ethers.getContractFactory("HubFactory");
const hubFac = await hubfacFac.deploy(); const hubFac = await hubfacFac.deploy(true);
await hubFac.deployed(); await hubFac.deployed();
await hubFac.newHubImp(); await hubFac.newHubImp();
@ -214,9 +229,8 @@ describe("Hub V3 Test", function () {
it("HubFactory", async function () { it("HubFactory", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory"); const hubfacFac = await ethers.getContractFactory("HubFactory");
const hubFac = await hubfacFac.deploy(); const hubFac = await hubfacFac.deploy(true);
await hubFac.deployed(); await hubFac.deployed();
await hubFac.newHubImp(); await hubFac.newHubImp();

Loading…
Cancel
Save