Merge branch 'main' of github.com:git3protocol/git3-contract

main^2
cyhhao 2 years ago
commit beeb0268c8

@ -269,7 +269,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
bytes memory path, bytes memory path,
bytes calldata data bytes calldata data
) external payable { ) external payable {
return db.upload(repoName, path, data); return db.upload{value:msg.value}(repoName, path, data);
} }
function uploadChunk( function uploadChunk(
@ -278,7 +278,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
uint256 chunkId, uint256 chunkId,
bytes calldata data bytes calldata data
) external payable { ) external payable {
return db.uploadChunk(repoName, path,chunkId, data); return db.uploadChunk{value:msg.value}(repoName, path,chunkId, data);
} }
function batchUpload( function batchUpload(

@ -22,12 +22,13 @@ contract LargeStorageManagerV2 {
function _preparePut(bytes32 key, uint256 chunkId) private { function _preparePut(bytes32 key, uint256 chunkId) private {
bytes32 metadata = keyToMetadata[key][chunkId]; bytes32 metadata = keyToMetadata[key][chunkId];
if (metadata == bytes32(0)) { // Remove the following code to support out-of-order upload chunks
require( // if (metadata == bytes32(0)) {
chunkId == 0 || keyToMetadata[key][chunkId - 1] != bytes32(0x0), // require(
"must replace or append" // chunkId == 0 || keyToMetadata[key][chunkId - 1] != bytes32(0x0),
); // "must replace or append"
} // );
// }
if (!metadata.isInSlot()) { if (!metadata.isInSlot()) {
address addr = metadata.bytes32ToAddr(); address addr = metadata.bytes32ToAddr();

@ -5,6 +5,7 @@ import "./Memory.sol";
import "./StorageSlotFactory.sol"; import "./StorageSlotFactory.sol";
library StorageHelperV2 { library StorageHelperV2 {
uint256 public constant STORAGE_SLOT_CODE_V2_PREFIX_LEN = 280;
// StorageSlotSelfDestructableV2 compiled via solc 0.8.7 optimized 200 // StorageSlotSelfDestructableV2 compiled via solc 0.8.7 optimized 200
bytes internal constant STORAGE_SLOT_CODE_V2 = bytes internal constant STORAGE_SLOT_CODE_V2 =
hex"6080604052348015600f57600080fd5b506004361060285760003560e01c80632b68b9c614602d575b600080fd5b60336035565b005b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161460965760405162461bcd60e51b81526020600482015260036024820152624e464f60e81b604482015260640160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316fffea2646970667358221220154417754813d1989858c876ab2ded2ba1aa380679fff7a4c8faea076ba020e664736f6c63430008070033"; hex"6080604052348015600f57600080fd5b506004361060285760003560e01c80632b68b9c614602d575b600080fd5b60336035565b005b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161460965760405162461bcd60e51b81526020600482015260036024820152624e464f60e81b604482015260640160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316fffea2646970667358221220154417754813d1989858c876ab2ded2ba1aa380679fff7a4c8faea076ba020e664736f6c63430008070033";

@ -57,7 +57,7 @@ contract ethstorage is LargeStorageManagerV2, database {
bytes memory path, bytes memory path,
uint256 chunkId, uint256 chunkId,
bytes calldata data bytes calldata data
) external payable { ) external payable override{
_putChunkFromCalldata( _putChunkFromCalldata(
keccak256(bytes.concat(repoName, "/", path)), keccak256(bytes.concat(repoName, "/", path)),
chunkId, chunkId,

@ -227,6 +227,37 @@ describe("Hub V3 Test", function () {
expect(refs[0]).to.eql([data3, concatHexStr(repoName, key2)]); expect(refs[0]).to.eql([data3, concatHexStr(repoName, key2)]);
}); });
it("upload chunks", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory");
const hubFac = await hubfacFac.deploy(true);
await hubFac.deployed();
await hubFac.newHubImp();
expect(await hubFac.createHub(true)).to.emit(hubFac,"CreateHub");
let hub = await hubFac.hubs(0);
console.log(hub);
let git3 = await ethers.getContractAt("Hubv3",hub)
let chunk = Buffer.alloc(10 * 1024, Math.random(1024).toString());
console.log(chunk);
let chunk_1 = Buffer.alloc(5*1024)
let chunk_2 = Buffer.alloc(2*1024)
chunk.copy(chunk_1,0,0,5*1024)
chunk.copy(chunk_2,0,5*1024,7*1024)
expect(chunk.compare(chunk_1,0,5*1024,0,5*1024)).to.eq(0);
expect(chunk.compare(chunk_2,0,2*1024,5*1024,7*1024)).to.eq(0);
expect(chunk.length).to.eq(10 * 1024);
let tx = await git3.uploadChunk(Buffer.from("git3"),Buffer.from("git3/test") ,0,"0x"+chunk.toString("hex"),{value:ethers.utils.parseEther("1")})
let rec = await tx.wait();
console.log("Receipt:",rec)
let context = await git3.download(Buffer.from("git3"),Buffer.from("git3/test"))
expect(context[0]).to.equal("0x"+chunk.toString("hex"));
})
it("HubFactory", async function () { it("HubFactory", async function () {
const hubfacFac = await ethers.getContractFactory("HubFactory"); const hubfacFac = await ethers.getContractFactory("HubFactory");

Loading…
Cancel
Save