Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to upload any amount of items #293

Merged
merged 34 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca47aaa
feat: ability to upload any amount of pods
IgorShadurin Dec 6, 2023
1c20597
feat: unlimited pods list
IgorShadurin Dec 11, 2023
3f584d0
refactor: upgraded version of fairos and bee
IgorShadurin Jan 2, 2024
a6fee00
feat: unlimited directories and files
IgorShadurin Jan 2, 2024
e88a258
Merge branch 'master' into feat/290-increase-limits
IgorShadurin Jan 2, 2024
da1cabe
feat: fairos tests runs in parallel with nodejs
IgorShadurin Jan 2, 2024
ad2473f
refactor: set a bee version to 1.13.0 for tests
IgorShadurin Jan 3, 2024
fa5cfd5
refactor: add --without-bees for the fdp-play
IgorShadurin Jan 8, 2024
145293d
fix: fixed recursive data reading
IgorShadurin Jan 12, 2024
804a35a
fix: removed --without-bees flag
IgorShadurin Jan 12, 2024
be0e14d
fix: using the correct variable name in the runner
IgorShadurin Jan 12, 2024
9e59e7d
refactor: puppeteer headless
IgorShadurin Jan 12, 2024
bbfce1b
feat: install chrome for puppeteer
IgorShadurin Jan 12, 2024
1612a2b
feat: install chrome for puppeteer
IgorShadurin Jan 12, 2024
ab3d73c
feat: install chrome for puppeteer
IgorShadurin Jan 12, 2024
ceda802
feat: puppeteer config
IgorShadurin Jan 15, 2024
bce4b94
feat: puppeteer config
IgorShadurin Jan 15, 2024
706c990
feat: puppeteer config
IgorShadurin Jan 15, 2024
830e8ff
feat: puppeteer config
IgorShadurin Jan 15, 2024
f6f4a91
feat: puppeteer config
IgorShadurin Jan 15, 2024
a79cc0f
feat: puppeteer config
IgorShadurin Jan 15, 2024
62791b2
feat: puppeteer config
IgorShadurin Jan 15, 2024
14596ac
feat: puppeteer config
IgorShadurin Jan 15, 2024
34e68f5
feat: puppeteer config
IgorShadurin Jan 15, 2024
77d73d1
feat: puppeteer config
IgorShadurin Jan 15, 2024
7ef0727
feat: puppeteer config
IgorShadurin Jan 15, 2024
a21aa97
refactor: disable delete fairos tests
IgorShadurin Jan 18, 2024
55a833e
refactor: removed logs
IgorShadurin Jan 19, 2024
4592e44
refactor: removed comments
IgorShadurin Jan 19, 2024
511fa9c
feat: v2 migration
tomicvladan Feb 21, 2024
3cd1389
test: v2 migration tests
tomicvladan Feb 22, 2024
0731b06
chore: readme update
tomicvladan Feb 22, 2024
657fc1a
feat: data migration improvement
tomicvladan Feb 22, 2024
f06dbc7
test: additional v2 migration test
tomicvladan Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
- '**'

env:
BEE_VERSION: '1.11.1'
FAIROS_IMAGE: 'fairdatasociety/fairos-dfs:v0.9.6'
BEE_VERSION: '1.13.0'
FAIROS_IMAGE: 'fairdatasociety/fairos-dfs:v0.10.0-rc6'

jobs:
nodejs:
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
run: npm install -g @fairdatasociety/fdp-play

- name: Run fdp-play
run: fdp-play start -d --fairos --fairos-image $FAIROS_IMAGE --bee-version $BEE_VERSION
run: fdp-play start -d --bee-version $BEE_VERSION

## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v3
Expand All @@ -48,8 +48,8 @@ jobs:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.OS }}-node-${{ matrix.node }}-
${{ runner.os }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.os }}-node-${{ matrix.node }}-

- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
Expand All @@ -58,6 +58,51 @@ jobs:
- name: Run unit and integration tests for node
run: npm run test:node -- --detectOpenHandles

- name: Run migration tests for node
run: npm run test:migration -- --detectOpenHandles

fairos:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Auth to Github Package Docker Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin

- name: Install fdp-play
run: npm install -g @fairdatasociety/fdp-play

- name: Run fdp-play
run: fdp-play start -d --fairos --fairos-image $FAIROS_IMAGE --bee-version $BEE_VERSION

## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v3
id: cache-npm
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.os }}-node-${{ matrix.node }}-

- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci

- name: Run unit and integration tests for FairOS
run: npm run test:fairos -- --detectOpenHandles

Expand Down Expand Up @@ -96,8 +141,8 @@ jobs:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.OS }}-node-${{ matrix.node }}-
${{ runner.os }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.os }}-node-${{ matrix.node }}-

- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ node_modules
docs

.vscode

test/fdp-storage
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const blocks = []
for (let i = 0; i < blocksCount; i++) {
const dataBlock = getDataBlock(data, blockSize, i)
// fdp instance with or without logged in user
blocks.push(await fdp.file.uploadDataBlock(dataBlock, i))
blocks.push(await fdp.file.uploadDataBlock(dataBlock, i, dataBlock.length))
}

// fdp instance with logged in user
Expand Down Expand Up @@ -335,6 +335,18 @@ const fdpCache = new FdpStorage('https://localhost:1633', batchId, {
fdpCache.cache.object = JSON.parse(cache)
```

## Data migration

Starting from the version `0.18.0`, pods and directories are stored in different format than the older versions. For all new accounts this doesn't have any impact. But to access pods and folders from existing accounts, migration is required.

Migration is done transparently, but there are some requirements that users should follow.

Pod list is converted to V2 when the `fdp.personalStorage.list()` method is invoked. So before working with existing pods, call the `fdp.personalStorage.list()` method first.

Directories are converted on the fly. Here the same principle applies as for pods. The `fdp.directory.read()` method must be invoked first, before invoking any other operation on the provided directory. The read method will convert not only the provided directory, but also all parent directories. That process happens only once, and all subsequent accesses will work with V2 data instantly.

Existing files are accessible in the new version. But from the `0.18.0` version, files are compressed before upload, which wasn't the case before. To compress files, they must be reuploaded.

## Documentation

You can generate API docs locally with:
Expand Down
2 changes: 2 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module.exports = {
launch: {
dumpio: true, // Forwards browser console into test console for easier debugging
headless: 'new', // Opt-in to the new headless mode for Chrome
channel: 'chrome',
},
}
7 changes: 7 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default async (): Promise<Config.InitialOptions> => {
// An array of directory names to be searched recursively up from the requiring module's location
moduleDirectories: ['node_modules'],

testTimeout: 90000,

// Run tests from one or more projects
projects: [
{
Expand All @@ -67,6 +69,11 @@ export default async (): Promise<Config.InitialOptions> => {
testEnvironment: 'node',
testRegex: 'test/integration/((?!\\.(browser|fairos)).)*\\.spec\\.ts',
},
{
displayName: 'node:migration',
testEnvironment: 'node',
testRegex: 'test/migration/((?!\\.(browser|fairos)).)*\\.spec\\.ts',
},
] as unknown[] as string[], // bad types

// The root directory that Jest should scan for tests and modules within
Expand Down
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test:unit:browser": "npm run compile:browser && jest --verbose --selectProjects=dom:unit:browser --config=jest.config.ts",
"test:integration:node": "jest --verbose --selectProjects=node:integration --config=jest.config.ts",
"test:integration": "npm run compile:browser && jest --verbose --selectProjects=node:integration dom:integration --config=jest.config.ts",
"test:migration": "jest --verbose --selectProjects=node:migration --config=jest.config.ts",
"test:unit": "jest --verbose --selectProjects=node:unit --config=jest.config.ts ",
"test:node": "jest --verbose --selectProjects=node:unit node:integration --config=jest.config.ts",
"test:fairos": "jest --verbose --selectProjects=node:fairos --config=jest.config.ts",
Expand All @@ -57,7 +58,8 @@
"@fairdatasociety/fdp-contracts-js": "^3.10.0",
"crypto-js": "^4.2.0",
"ethers": "^5.5.2",
"js-sha3": "^0.9.2"
"js-sha3": "^0.9.2",
"pako": "^2.1.0"
},
"devDependencies": {
"@babel/core": "^7.23.2",
Expand All @@ -79,6 +81,7 @@
"@types/jest": "^29.5.6",
"@types/jest-environment-puppeteer": "^5.0.5",
"@types/node": "^20.8.9",
"@types/pako": "^2.0.3",
"@types/webpack-bundle-analyzer": "^4.6.2",
"@types/ws": "^8.5.8",
"@typescript-eslint/eslint-plugin": "^6.9.0",
Expand Down
11 changes: 11 additions & 0 deletions puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { join } = require('path')

/**
* @type {import("puppeteer").Configuration}
*/
module.exports = {
// Changes the cache location for Puppeteer.
cacheDirectory: join(__dirname, '.cache', 'puppeteer-data'),
skipDownload: false,
}
5 changes: 3 additions & 2 deletions src/account/account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Bee, PrivateKeyBytes, Reference, Utils } from '@ethersphere/bee-js'
import { Bee, PrivateKeyBytes, Reference } from '@ethersphere/bee-js'
import { utils, Wallet } from 'ethers'
import { IV_LENGTH, decryptBytes, encryptBytes } from '../utils/encryption'
import { assertChunkSizeLength, CHUNK_SIZE, SEED_SIZE, createCredentialsTopic, HD_PATH } from './utils'
import { Connection } from '../connection/connection'
import CryptoJS from 'crypto-js'
import { wordArrayToBytes } from '../utils/bytes'
import { EthAddress } from '../utils/eth'

/**
* User account with seed phrase
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function uploadPortableAccount(
*/
export async function downloadPortableAccount(
bee: Bee,
address: Utils.EthAddress,
address: EthAddress,
username: string,
password: string,
): Promise<UserAccountWithSeed> {
Expand Down
1 change: 0 additions & 1 deletion src/account/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * as Account from './account'
export * as Encryption from '../utils/encryption'
export * as Utils from './utils'
//TODO export every exportable
Loading
Loading