Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 3 additions & 27 deletions .github/workflows/tests-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,16 @@ jobs:
run: npm ci

- name: Install global dependencies
run: npm install --global bee-dev @fairdatasociety/fdp-play @ethersphere/swarm-cli npxie

- name: Clone fdp-play
run: git clone https://github.com/fairDataSociety/fdp-play

- name: Install fdp-play dependencies
run: |
cd fdp-play && npm install
cd orchestrator && npm install

- name: Build fdp-play images
run: |
cd fdp-play/orchestrator
npm run build:env -- --build-base-bee --bee-repository=ethersphere/bee.git

- name: Clean up fdp-play
run: rm -rf fdp-play/test
run: npm install --global bee-dev @ethersphere/bee-factory @ethersphere/swarm-cli npxie

- name: Run bee-dev
run: bee-dev --port 16337 &

- name: Run bee-dev with --no-swap
run: bee-dev --port 16338 --no-swap &

- name: Start fdp-play environment
run: fdp-play start --detach --blockchain-image ethereum/client-go:release-1.13 --bee-version HEAD-commit

- name: Deposit to chequebook
run: |
swarm-cli cheque deposit 10
swarm-cli cheque deposit 10 --bee-api-url http://localhost:11633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:21633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:31633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:41633
- name: Start bee-factory
run: bee-factory start --tag master

- name: Print swarm-cli status
continue-on-error: true
Expand Down
14 changes: 3 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,16 @@ jobs:
run: npm ci

- name: Install global dependencies
run: npm install --global bee-dev @fairdatasociety/fdp-play @ethersphere/swarm-cli npxie
run: npm install --global bee-dev @ethersphere/bee-factory @ethersphere/swarm-cli npxie

- name: Run bee-dev
run: bee-dev --port 16337 &

- name: Run bee-dev with --no-swap
run: bee-dev --port 16338 --no-swap &

- name: Start fdp-play environment
run: fdp-play start --detach --fresh --bee-version d0aa8b9-commit

- name: Deposit to chequebook
run: |
swarm-cli cheque deposit 10
swarm-cli cheque deposit 10 --bee-api-url http://localhost:11633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:21633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:31633
swarm-cli cheque deposit 10 --bee-api-url http://localhost:41633
- name: Start bee-factory
run: bee-factory start --tag v2.8.0

- name: Print swarm-cli status
continue-on-error: true
Expand Down
3 changes: 3 additions & 0 deletions src/command/access/access-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RootCommand } from '../root-command'

export class AccessCommand extends RootCommand {}
10 changes: 10 additions & 0 deletions src/command/access/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GroupCommand } from 'furious-commander'
import { Init } from './init'

export class Access implements GroupCommand {
public readonly name = 'access'

public readonly description = 'Share access to your uploaded files/folders'

public subCommandClasses = [Init]
}
67 changes: 67 additions & 0 deletions src/command/access/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { LeafCommand, Option } from 'furious-commander'
import { exit } from 'process'
import { AccessHistory } from '../../service/access'
import { AccessHistoryOperation } from '../../service/access/types/history-event'
import { createKeyValue } from '../../utils/text'
import { AccessCommand } from './access-command'

export class Init extends AccessCommand implements LeafCommand {
public readonly name = 'init'

public readonly description = 'Initialize a new access grantee list'

@Option({
key: 'stamp',
alias: 's',
description: 'Postage stamp ID',
required: true,
type: 'string',
})
public stamp!: string

@Option({
key: 'list-name',
alias: 'n',
description: 'Name of the grantee list',
required: true,
type: 'string',
})
public listName!: string

@Option({
key: 'grantee',
alias: 'g',
description: 'Public address of the grantee',
type: 'string',
array: true,
})
public grantees!: string[]

public async run(): Promise<void> {
super.init()

const accessHistory = new AccessHistory(this.commandConfig, this.console)

if (accessHistory.getEventsByType(this.listName, AccessHistoryOperation.Init).length > 0) {
this.console.error(`Grantee list with name '${this.listName}' has already been initialized!`)

exit(1)
}

const response = await this.bee.createGrantees(this.stamp, this.grantees)
this.console.log(`Grantee list '${this.listName}' initialized successfully!`)

accessHistory.addEvent(this.listName, {
stampId: this.stamp,
historyAddress: response.historyref.toHex(),
granteeListRef: response.ref.toHex(),
operation: AccessHistoryOperation.Init,
createdAt: Date.now(),
})

if (this.verbose) {
this.console.log(createKeyValue('Grantee list reference', response.ref.toHex()))
this.console.log(createKeyValue('History address', response.historyref.toHex()))
}
}
}
6 changes: 5 additions & 1 deletion src/command/root-command/command-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs'
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
import { homedir, platform } from 'os'
import { join } from 'path'
import { exit } from 'process'
Expand Down Expand Up @@ -54,6 +54,10 @@ export class CommandConfig {
return true
}

public getAccessHistoryFilePath(): string {
return process.env.SWARM_CLI_ACCESS_HISTORY_FILE_PATH || join(this.configFolderPath, 'access-history.json')
}

public getHistoryFilePath(): string {
return process.env.SWARM_CLI_HISTORY_FILE_PATH || join(this.configFolderPath, 'upload-history.json')
}
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { IOption } from 'furious-commander'
import PackageJson from '../package.json'
import { Access } from './command/access'
import { Addresses } from './command/addresses'
import { Cheque } from './command/cheque'
import { Download } from './command/download'
import { Feed } from './command/feed'
import { Grantee } from './command/grantee'
import { Hash } from './command/hash'
import { History } from './command/history'
import { Identity } from './command/identity'
import { Manifest } from './command/manifest'
import { Pinning } from './command/pinning'
Expand All @@ -17,7 +19,6 @@
import { Upload } from './command/upload'
import { Utility } from './command/utility'
import { Wallet } from './command/wallet'
import { History } from './command/history'

export const beeApiUrl: IOption<string> = {
key: 'bee-api-url',
Expand Down Expand Up @@ -102,7 +103,7 @@
default: false,
}

export const optionParameters: IOption<any>[] = [

Check warning on line 106 in src/config.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Unexpected any. Specify a different type
beeApiUrl,
configFolder,
configFile,
Expand Down Expand Up @@ -135,4 +136,5 @@
Grantee,
Quickstart,
History,
Access,
]
61 changes: 61 additions & 0 deletions src/service/access/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { exit } from 'process'
import { CommandConfig } from '../../command/root-command/command-config'
import { CommandLog } from '../../command/root-command/command-log'
import { AccessHistoryEvent, AccessHistoryLog, AccessHistoryOperation } from './types/history-event'

export class AccessHistory {
private commandConfig: CommandConfig
private console: CommandLog

constructor(commandConfig: CommandConfig, console: CommandLog) {
this.commandConfig = commandConfig
this.console = console
}

public getHistory(): AccessHistoryLog {
const historyFilePath = this.commandConfig.getAccessHistoryFilePath()

if (!existsSync(historyFilePath)) {
return {}
}
const historyData = readFileSync(historyFilePath)
try {
const historyLog = JSON.parse(historyData.toString()) as AccessHistoryLog

return historyLog
} catch (err) {
this.console.error(`There has been an error parsing access history JSON from path: '${historyFilePath}'`)

exit(1)
}
}

public getEventsByType(granteeListName: string, eventType: AccessHistoryOperation): AccessHistoryEvent[] {
const history = this.getHistory()

if (!history[granteeListName]) {
return []
}

return history[granteeListName].filter(event => event.operation === eventType)
}

public addEvent(granteeListName: string, event: AccessHistoryEvent) {
const history = this.getHistory()

if (!history[granteeListName]) {
history[granteeListName] = []
}

history[granteeListName].push({
stampId: event.stampId,
historyAddress: event.historyAddress,
granteeListRef: event.granteeListRef,
operation: event.operation,
createdAt: event.createdAt,
})

writeFileSync(this.commandConfig.getAccessHistoryFilePath(), JSON.stringify(history))
}
}
15 changes: 15 additions & 0 deletions src/service/access/types/history-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum AccessHistoryOperation {
Init = 'init',
Grant = 'grant',
Revoke = 'revoke',
}

export type AccessHistoryEvent = {
stampId: string
historyAddress: string
granteeListRef: string
operation: AccessHistoryOperation
createdAt: number
}

export type AccessHistoryLog = { [name: string]: AccessHistoryEvent[] }
38 changes: 38 additions & 0 deletions test/command/access.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { unlinkSync } from 'fs'
import { describeCommand, invokeTestCli } from '../utility'
import { getPssAddress } from '../utility/address'
import { getStampOption } from '../utility/stamp'

describeCommand(
'Test Access command',
({ consoleMessages, getLastMessage }) => {
afterEach(() => {
unlinkSync(`${__dirname}/../testconfig/access-access-history.json`)
})
describe('init', () => {
it('should initialize access with pss address as grantee', async () => {
const pssAddress = await getPssAddress('http://localhost:21633')
await invokeTestCli([
'access',
'init',
...getStampOption(),
'--list-name',
'test-access',
'--grantee',
pssAddress.toHex(),
])
expect(getLastMessage()).toEqual("Grantee list 'test-access' initialized successfully!")
})

describe('when grantee list with the same name already exists', () => {
it('should show error message', async () => {
await invokeTestCli(['access', 'init', ...getStampOption(), '-n', 'test-access'])
await invokeTestCli(['access', 'init', ...getStampOption(), '-n', 'test-access'])
expect(consoleMessages[1]).toEqual("Grantee list with name 'test-access' has already been initialized!")
expect(consoleMessages[2]).toContain('process.exit() was called with code 1')
})
})
})
},
{ configFileName: 'access' },
)
13 changes: 8 additions & 5 deletions test/command/create-batch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ expect.extend({
toMatchLinesInOrder,
})

const FUNDER_KEY = '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba'
const JSON_RPC_URL = 'http://localhost:8545'

describeCommand('Test `utility create-batch` command', ({ consoleMessages }) => {
it('should create batch', async () => {
process.env.SWARM_CLI_NETWORK_ID = '4020'
process.env.SWARM_CLI_BZZ_ADDRESS = '0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab'
process.env.SWARM_CLI_POSTAGE_STAMP_ADDRESS = '0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B'
process.env.SWARM_CLI_NETWORK_ID = '1337'
process.env.SWARM_CLI_BZZ_ADDRESS = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
process.env.SWARM_CLI_POSTAGE_STAMP_ADDRESS = '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
await invokeTestCli([
'utility',
'create-batch',
'--private-key',
'0x566058308ad5fa3888173c741a1fb902c9f1f19559b11fc2738dfc53637ce4e9',
FUNDER_KEY,
'--depth',
'17',
'--amount',
'10B',
'--json-rpc-url',
'http://localhost:9545',
JSON_RPC_URL,
'--yes',
])
expect(consoleMessages).toMatchLinesInOrder([
Expand Down
8 changes: 4 additions & 4 deletions test/command/redeem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ expect.extend({
toMatchLinesInOrder,
})

const FUNDER_KEY = '0x566058308ad5fa3888173c741a1fb902c9f1f19559b11fc2738dfc53637ce4e9'
const JSON_RPC_URL = 'http://localhost:9545'
const FUNDER_KEY = '0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba'
const JSON_RPC_URL = 'http://localhost:8545'
const ETH_01 = 100_000_000_000_000_000n.toString()
const BZZ_5 = 50_000_000_000_000_000n.toString()

describeCommand('Test `utility redeem` command', ({ consoleMessages }) => {
it('should redeem funds to target address', async () => {
process.env.SWARM_CLI_NETWORK_ID = '4020'
process.env.SWARM_CLI_BZZ_ADDRESS = '0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab'
process.env.SWARM_CLI_NETWORK_ID = '1337'
process.env.SWARM_CLI_BZZ_ADDRESS = '0x5FbDB2315678afecb367f032d93F642f64180aa3'

const sourceWallet = Wallet.createRandom()
const targetWallet = Wallet.createRandom()
Expand Down
6 changes: 3 additions & 3 deletions test/command/stamp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BatchId, Bee } from '@ethersphere/bee-js'
import { Types } from 'cafe-utility'
import { randomBytes } from 'crypto'
import inquirer from 'inquirer'
import { Buy } from '../../src/command/stamp/buy'
import { toMatchLinesInOrder } from '../custom-matcher'
import { describeCommand, invokeTestCli } from '../utility'
import { BatchId, Bee } from '@ethersphere/bee-js'
import { randomBytes } from 'crypto'

expect.extend({
toMatchLinesInOrder,
Expand Down Expand Up @@ -105,7 +105,7 @@ describeCommand(
})

it('should print custom message when there are no stamps', async () => {
await invokeTestCli(['stamp', 'list', '--bee-api-url', 'http://localhost:11633'])
await invokeTestCli(['stamp', 'list', '--bee-api-url', 'http://localhost:21633'])
expect(getNthLastMessage(4)).toContain('You do not have any stamps.')
})

Expand Down
Loading
Loading