@ -11,25 +11,28 @@ describe("Git3 Test", function () {
const git3 = await Git3 . deploy ( ) ;
await git3 . deployed ( ) ;
await git3 . upload ( "0x616263" , "0x112233" ) ;
expect ( await git3 . download ( "0x616263" ) ) . to . eql ( [ "0x112233" , true ] ) ;
let singer ;
[ singer ] = await ethers . getSigners ( ) ;
await git3 . createRepo ( "0x11" ) ;
await git3 . upload ( "0x11" , "0x616263" , "0x112233" ) ;
expect ( await git3 . download ( "0x11" , "0x616263" ) ) . to . eql ( [ "0x112233" , true ] ) ;
let data = Array . from ( { length : 40 } , ( ) =>
Math . floor ( Math . random ( ) * 256 )
) ;
await git3 . upload ( "0x 616263", data ) ;
expect ( await git3 . download ( "0x 616263") ) . to . eql ( [
await git3 . upload ( "0x 11", "0x 616263", data ) ;
expect ( await git3 . download ( "0x 11", "0x 616263") ) . to . eql ( [
ethers . utils . hexlify ( data ) ,
true ,
] ) ;
expect ( await git3 . size ( "0x616263" ) ) . to . eql ( [ ToBig ( 40 ) , ToBig ( 1 ) ] ) ;
await git3 . remove ( "0x616263" ) ;
expect ( await git3 . size ( "0x616263" ) ) . to . eql ( [ ToBig ( 0 ) , ToBig ( 0 ) ] ) ;
expect ( await git3 . size ( "0x11" , "0x616263" ) ) . to . eql ( [ ToBig ( 40 ) , ToBig ( 1 ) ] ) ;
await git3 . remove ( "0x11" , "0x616263" ) ;
expect ( await git3 . size ( "0x11" , "0x616263" ) ) . to . eql ( [ ToBig ( 0 ) , ToBig ( 0 ) ] ) ;
} ) ;
it ( "upload/download/remove chunks" , async function ( ) {
@ -37,13 +40,15 @@ describe("Git3 Test", function () {
const git3 = await Git3 . deploy ( ) ;
await git3 . deployed ( ) ;
expect ( await git3 . countChunks ( "0x616263" ) ) . to . eql ( ToBig ( 0 ) ) ;
await git3 . createRepo ( "0x11" ) ;
expect ( await git3 . countChunks ( "0x11" , "0x616263" ) ) . to . eql ( ToBig ( 0 ) ) ;
let data0 = Array . from ( { length : 10 } , ( ) =>
Math . floor ( Math . random ( ) * 256 )
) ;
await git3 . uploadChunk ( "0x 616263", 0 , data0 ) ;
expect ( await git3 . download ( "0x 616263") ) . to . eql ( [
await git3 . uploadChunk ( "0x 11", "0x 616263", 0 , data0 ) ;
expect ( await git3 . download ( "0x 11", "0x 616263") ) . to . eql ( [
ethers . utils . hexlify ( data0 ) ,
true ,
] ) ;
@ -51,19 +56,16 @@ describe("Git3 Test", function () {
let data1 = Array . from ( { length : 20 } , ( ) =>
Math . floor ( Math . random ( ) * 256 )
) ;
await git3 . uploadChunk ( "0x 616263", 1 , data1 ) ;
expect ( await git3 . download ( "0x 616263") ) . to . eql ( [
await git3 . uploadChunk ( "0x 11", "0x 616263", 1 , data1 ) ;
expect ( await git3 . download ( "0x 11", "0x 616263") ) . to . eql ( [
ethers . utils . hexlify ( data0 . concat ( data1 ) ) ,
true ,
] ) ;
await git3 . remove ( "0x616263" ) ; // should succeed
expect ( await git3 . size ( "0x616263" ) ) . to . eql ( [ ToBig ( 0 ) , ToBig ( 0 ) ] ) ;
expect ( await git3 . download ( "0x616263" ) ) . to . eql ( [
"0x" ,
false ,
] ) ;
expect ( await git3 . countChunks ( "0x616263" ) ) . to . eql ( ToBig ( 0 ) ) ;
await git3 . remove ( "0x11" , "0x616263" ) ; // should succeed
expect ( await git3 . size ( "0x11" , "0x616263" ) ) . to . eql ( [ ToBig ( 0 ) , ToBig ( 0 ) ] ) ;
expect ( await git3 . download ( "0x11" , "0x616263" ) ) . to . eql ( [ "0x" , false ] ) ;
expect ( await git3 . countChunks ( "0x11" , "0x616263" ) ) . to . eql ( ToBig ( 0 ) ) ;
} ) ;
it ( "set/update/list/remove Reference" , async function ( ) {
@ -71,43 +73,70 @@ describe("Git3 Test", function () {
const git3 = await Git3 . deploy ( ) ;
await git3 . deployed ( ) ;
let repoName = "0x11" ;
await git3 . createRepo ( repoName ) ;
function concatHexStr ( s1 , s2 ) {
return s1 . concat ( "2f" ) . concat ( s2 . slice ( 2 ) ) ;
}
let key0 = "0x616263" ;
let data0 = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
await git3 . setRef ( key0 , data0 ) ;
await git3 . setRef ( repoName, key0, data0 ) ;
let key1 = "0x717273" ;
let data1 = "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ;
await git3 . setRef ( key1 , data1 ) ;
await git3 . setRef ( repoName, key1, data1 ) ;
let key2 = "0x818283" ;
let data2 = "0xcccccccccccccccccccccccccccccccccccccccc" ;
await git3 . setRef ( key2 , data2 ) ;
await git3 . setRef ( repoName , key2 , data2 ) ;
let refs = await git3 . listRefs ( ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data0 , key0 ] ) ;
expect ( refs [ 1 ] ) . to . eql ( [ data1 , key1 ] ) ;
expect ( refs [ 2 ] ) . to . eql ( [ data2 , key2 ] ) ;
let refs = await git3 . listRefs ( repoName ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data0 , concatHexStr ( repoName , key0 ) ] ) ;
expect ( refs [ 1 ] ) . to . eql ( [ data1 , concatHexStr ( repoName , key1 ) ] ) ;
expect ( refs [ 2 ] ) . to . eql ( [ data2 , concatHexStr ( repoName , key2 ) ] ) ;
expect ( refs . length ) . to . eql ( 3 ) ;
// check delRef
await git3 . delRef ( key0) ;
refs = await git3 . listRefs ( ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data2 , key2 ] ) ;
expect ( refs [ 1 ] ) . to . eql ( [ data1 , key1 ] ) ;
await git3 . delRef ( repoName, key0) ;
refs = await git3 . listRefs ( repoName ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data2 , concatHexStr ( repoName , key2 ) ] ) ;
expect ( refs [ 1 ] ) . to . eql ( [ data1 , concatHexStr ( repoName , key1 ) ] ) ;
expect ( refs . length ) . to . eql ( 2 ) ;
await git3 . delRef ( key1) ;
refs = await git3 . listRefs ( ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data2 , key2 ] ) ;
await git3 . delRef ( repoName, key1) ;
refs = await git3 . listRefs ( repoName ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data2 , concatHexStr ( repoName , key2 ) ] ) ;
expect ( refs . length ) . to . eql ( 1 ) ;
// check update
let data3 = "0xdddddddddddddddddddddddddddddddddddddddd" ;
await git3 . setRef ( key2 , data3 ) ;
refs = await git3 . listRefs ( ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data3 , key2 ] ) ;
await git3 . setRef ( repoName , key2 , data3 ) ;
refs = await git3 . listRefs ( repoName ) ;
expect ( refs [ 0 ] ) . to . eql ( [ data3 , concatHexStr ( repoName , key2 ) ] ) ;
} ) ;
it ( "Access Control" , async function ( ) {
const Git3 = await ethers . getContractFactory ( "Git3" ) ;
const git3 = await Git3 . deploy ( ) ;
await git3 . deployed ( ) ;
} )
let singer ;
let user1 ;
[ singer , user1 , ] = await ethers . getSigners ( ) ;
await git3 . connect ( singer ) . createRepo ( "0x11" ) ;
await expect ( git3 . connect ( user1 ) . upload ( "0x11" , "0x616263" , "0x112233" ) ) . to . be . revertedWith ( "only owner" ) ;
await expect ( git3 . connect ( user1 ) . uploadChunk ( "0x11" , "0x616263" , 0 , "0x112233" ) ) . to . be . revertedWith ( "only owner" ) ;
await expect ( git3 . connect ( user1 ) . setRef ( "0x11" , "0x616263" , "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ) . to . be . revertedWith ( "only owner" ) ;
await git3 . connect ( singer ) . upload ( "0x11" , "0x616263" , "0x112233" )
expect ( await git3 . download ( "0x11" , "0x616263" ) ) . to . eql ( [ "0x112233" , true ] ) ;
await git3 . connect ( singer ) . setRef ( "0x11" , "0x616263" , "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
await expect ( git3 . connect ( user1 ) . remove ( "0x11" , "0x616263" ) ) . to . be . revertedWith ( "only owner" ) ;
await expect ( git3 . connect ( user1 ) . delRef ( "0x11" , "0x616263" ) ) . to . be . revertedWith ( "only owner" ) ;
} ) ;
} ) ;