-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 27 additions & 9 deletions
36
smart-contract/assembly/__tests__/deweb-interface/helpers/upload-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import { sha256, Storage } from '@massalabs/massa-as-sdk'; | ||
import { getKeys, sha256 } from '@massalabs/massa-as-sdk'; | ||
import { _getTotalChunk } from '../../../contracts/internals/chunks'; | ||
import { stringToBytes } from '@massalabs/as-types'; | ||
import { fileChunkKeyPrefix } from '../../../contracts/internals/storageKeys/chunksKeys'; | ||
import { getFileChunk } from '../../../contracts/deweb-interface'; | ||
import { FILE_LOCATION_TAG } from '../../../contracts/internals/storageKeys/tags'; | ||
import { chunkGetArgs } from './Uploader'; | ||
|
||
export function _assertFileChunkNbIs(location: string, expectedNb: u32): void { | ||
export function _assertFileChunkCountIsCorrect( | ||
location: string, | ||
expectedNb: u32, | ||
): void { | ||
const locationHash = sha256(stringToBytes(location)); | ||
const totalChunk = _getTotalChunk(locationHash); | ||
|
||
assert(totalChunk === expectedNb, 'Total chunk should be correct'); | ||
} | ||
|
||
const chunksKeys = Storage.getKeys(fileChunkKeyPrefix(locationHash)); | ||
export function _assertFileChunksAreCorrect( | ||
location: string, | ||
chunkData: StaticArray<u8>[], | ||
nbChunks: u32, | ||
): void { | ||
const locationHash = sha256(stringToBytes(location)); | ||
|
||
for (let i = u32(0); i < nbChunks; i++) { | ||
const storedChunk = getFileChunk(chunkGetArgs(locationHash, i)); | ||
assert( | ||
storedChunk.toString() == chunkData[i].toString(), | ||
`Chunk ${i} of ${location} should be correct`, | ||
); | ||
} | ||
} | ||
|
||
assert( | ||
chunksKeys.length === expectedNb, | ||
'Number of chunks should be correct', | ||
); | ||
export function _assertRightNbOfFilesLocations(nb: u32): void { | ||
const dataStoreEntriesLocation = getKeys(FILE_LOCATION_TAG); | ||
assert(dataStoreEntriesLocation.length == nb, 'File count should be correct'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters