Browse Source

storage-node-v2: Change oclif tests.

Shamil Gadelshin 3 years ago
parent
commit
1b7a120386

+ 7 - 6
storage-node-v2/package.json

@@ -8,16 +8,15 @@
   },
   "bugs": "https://github.com/shamil-gadelshin/storage-node-v2/issues",
   "dependencies": {
-    "@joystream/types": "0.17.0",
+    "@joystream/types": "^0.15.0",
     "@oclif/command": "^1",
     "@oclif/config": "^1",
     "@oclif/plugin-help": "^3",
     "@polkadot/api": "4.2.1",
-    "storage-node-v2": "file:.",
-    "tslib": "^1",
     "@types/express": "^4.17.11",
     "express": "^4.17.1",
-    "express-openapi-validator": "^4.12.4"
+    "express-openapi-validator": "^4.12.4",
+    "tslib": "^1"
   },
   "devDependencies": {
     "@oclif/dev-cli": "^1",
@@ -25,6 +24,8 @@
     "@types/chai": "^4",
     "@types/mocha": "^5",
     "@types/node": "^10",
+    "@typescript-eslint/eslint-plugin": "3.8.0",
+    "@typescript-eslint/parser": "3.8.0",
     "chai": "^4",
     "eslint": "^7.0.0",
     "eslint-config-oclif": "^3.1",
@@ -33,7 +34,8 @@
     "mocha": "^5",
     "nyc": "^14",
     "prettier": "^2.3.0",
-    "ts-node": "^8",
+    "sinon": "^11.1.1",
+    "ts-node": "^8.8.2",
     "typescript": "^3.3"
   },
   "engines": {
@@ -53,7 +55,6 @@
   "main": "lib/index.js",
   "oclif": {
     "commands": "./lib/commands",
-    "defaultCommand": "server",
     "bin": "storage-node",
     "plugins": [
       "@oclif/plugin-help"

+ 3 - 0
storage-node-v2/src/services/api/controllers/publicApi.ts

@@ -2,6 +2,7 @@ import * as express from 'express'
 import { acceptPendingDataObjects } from '../../../services/extrinsics'
 import { getAlicePair } from '../../../services/runtimeApi'
 
+//TODO: test api connection
 //TODO: error handling
 //TODO: convert to JSON
 //TODO: bagId
@@ -21,6 +22,8 @@ export async function upload(
   console.log(uploadRequest)
   console.log(req.files)
 
+  //TODO: add file hash check
+
   try {
     //TODO: account
     await acceptPendingDataObjects(

+ 9 - 4
storage-node-v2/src/services/runtimeApi.ts

@@ -1,4 +1,5 @@
-import { ApiPromise, WsProvider } from '@polkadot/api'
+import { ApiPromise, WsProvider} from '@polkadot/api'
+import type { Index } from '@polkadot/types/interfaces/runtime';
 import { CodecArg, ISubmittableResult } from '@polkadot/types/types'
 import { types } from '@joystream/types/'
 import { TypeRegistry } from '@polkadot/types'
@@ -24,11 +25,12 @@ export async function createApi(): Promise<ApiPromise> {
 function sendExtrinsic(
   api: ApiPromise,
   account: KeyringPair,
-  tx: SubmittableExtrinsic<'promise'>
+  tx: SubmittableExtrinsic<'promise'>,
+  nonce: Index
 ): Promise<ISubmittableResult> {
   return new Promise((resolve, reject) => {
     let unsubscribe: () => void
-    tx.signAndSend(account, {}, (result) => {
+    tx.signAndSend(account, { nonce }, (result) => {
       // Implementation loosely based on /pioneer/packages/react-signer/src/Modal.tsx
       if (!result || !result.status) {
         return
@@ -103,7 +105,10 @@ export async function sendAndFollowTx(
   warnOnly = false // If specified - only warning will be displayed in case of failure (instead of error beeing thrown)
 ): Promise<boolean> {
   try {
-    await sendExtrinsic(api, account, tx)
+    // TODO: use async-lock package
+    const nonce = await api.rpc.system.accountNextIndex(account.address);
+
+    await sendExtrinsic(api, account, tx, nonce)
     console.log(chalk.green(`Extrinsic successful!`))
     return true
   } catch (e) {

+ 0 - 17
storage-node-v2/test/commands/dev/init.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('dev:init', () => {
-  test
-  .stdout()
-  .command(['dev:init'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['dev:init', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})

+ 0 - 17
storage-node-v2/test/commands/dev/upload.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('dev:upload', () => {
-  test
-  .stdout()
-  .command(['dev:upload'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['dev:upload', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})

+ 15 - 15
storage-node-v2/test/commands/leader/create-bucket.test.ts

@@ -1,17 +1,17 @@
-import {expect, test} from '@oclif/test'
+// import {expect, test} from '@oclif/test'
 
-describe('wg:leader:create-bucket', () => {
-  test
-  .stdout()
-  .command(['wg:leader:create-bucket'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
+// describe('leader:create-bucket', () => {
+//   test
+//   .stdout()
+//   .command(['leader:create-bucket', '--dev'])
+//   .it('runs hello', ctx => {
+//     expect(ctx.stdout).to.contain('hello world')
+//   })
 
-  test
-  .stdout()
-  .command(['wg:leader:create-bucket', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})
+//   // test
+//   // .stdout()
+//   // .command(['wg:leader:create-bucket', '--name', 'jeff'])
+//   // .it('runs hello --name jeff', ctx => {
+//   //   expect(ctx.stdout).to.contain('hello jeff')
+//   // })
+// })

+ 0 - 17
storage-node-v2/test/commands/leader/update-bags.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('leader:update-bags', () => {
-  test
-  .stdout()
-  .command(['leader:update-bags'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['leader:update-bags', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})

+ 0 - 17
storage-node-v2/test/commands/operator/accept-invitation.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('wg:operator:accept-invitation', () => {
-  test
-  .stdout()
-  .command(['wg:operator:accept-invitation'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['wg:operator:accept-invitation', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})

+ 0 - 17
storage-node-v2/test/commands/server.test.ts

@@ -1,17 +0,0 @@
-import {expect, test} from '@oclif/test'
-
-describe('server', () => {
-  test
-  .stdout()
-  .command(['server'])
-  .it('runs hello', ctx => {
-    expect(ctx.stdout).to.contain('hello world')
-  })
-
-  test
-  .stdout()
-  .command(['server', '--name', 'jeff'])
-  .it('runs hello --name jeff', ctx => {
-    expect(ctx.stdout).to.contain('hello jeff')
-  })
-})

+ 1 - 1
types/package.json

@@ -33,7 +33,7 @@
   },
   "devDependencies": {
     "@polkadot/typegen": "4.2.1",
-    "ts-node": "^8.6.2",
+    "ts-node": "^8.8.2",
     "typescript": "^3.7.2",
     "madge": "^3.9.2",
     "json-schema-to-typescript": "^9.1.1"

+ 3 - 2
types/src/storage.ts

@@ -17,13 +17,14 @@ export class StorageBucketsPerBagValueConstraint
     })
     implements StorageBucketsPerBagValueConstraintType {}
 
+//TODO: implement these types
 export class DynamicBagId extends u64 {}
 export class DynamicBagType extends u64 {}
 export class DynamicBagCreationPolicy extends u64 {}
 export class DynamicBag extends u64 {}
 export class StaticBag extends u64 {}
 export class StorageBucket extends u64 {}
-
+//
 
 export const StaticBagIdDef = {
     Council: Null,
@@ -36,7 +37,7 @@ export class Static extends StaticBagId {}
 
 export const BagIdDef = {
     Static,
-    Dynamic: Null,
+    Dynamic: Null,//TODO: implement dynamic type
 } as const
 export type BagIdKey = keyof typeof BagIdDef
 export class BagId extends JoyEnum(BagIdDef) {}

+ 66 - 22
yarn.lock

@@ -4141,6 +4141,13 @@
   dependencies:
     type-detect "4.0.8"
 
+"@sinonjs/commons@^1.6.0", "@sinonjs/commons@^1.8.3":
+  version "1.8.3"
+  resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.3.tgz#3802ddd21a50a949b6721ddd72da36e67e7f1b2d"
+  integrity sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==
+  dependencies:
+    type-detect "4.0.8"
+
 "@sinonjs/fake-timers@^6.0.1":
   version "6.0.1"
   resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-6.0.1.tgz#293674fccb3262ac782c7aadfdeca86b10c75c40"
@@ -4148,6 +4155,13 @@
   dependencies:
     "@sinonjs/commons" "^1.7.0"
 
+"@sinonjs/fake-timers@^7.0.4", "@sinonjs/fake-timers@^7.1.0":
+  version "7.1.2"
+  resolved "https://registry.yarnpkg.com/@sinonjs/fake-timers/-/fake-timers-7.1.2.tgz#2524eae70c4910edccf99b2f4e6efc5894aff7b5"
+  integrity sha512-iQADsW4LBMISqZ6Ci1dupJL9pprqwcVFTcOsEmQOEhW+KLCVn/Y4Jrvg2k19fIHCp+iFprriYPTdRcQR8NbUPg==
+  dependencies:
+    "@sinonjs/commons" "^1.7.0"
+
 "@sinonjs/formatio@^3.2.1":
   version "3.2.2"
   resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-3.2.2.tgz#771c60dfa75ea7f2d68e3b94c7e888a78781372c"
@@ -4165,6 +4179,15 @@
     array-from "^2.1.1"
     lodash "^4.17.15"
 
+"@sinonjs/samsam@^6.0.2":
+  version "6.0.2"
+  resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-6.0.2.tgz#a0117d823260f282c04bff5f8704bdc2ac6910bb"
+  integrity sha512-jxPRPp9n93ci7b8hMfJOFDPRLFYadN6FSpeROFTR4UNF4i5b+EK6m4QXPO46BDhFgRy1JuS87zAnFOzCUwMJcQ==
+  dependencies:
+    "@sinonjs/commons" "^1.6.0"
+    lodash.get "^4.4.2"
+    type-detect "^4.0.8"
+
 "@sinonjs/text-encoding@^0.7.1":
   version "0.7.1"
   resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5"
@@ -4926,9 +4949,9 @@
     "@types/range-parser" "*"
 
 "@types/express-serve-static-core@^4.17.18":
-  version "4.17.20"
-  resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.20.tgz#44caee029f2c26c46711da5e845cdc12167ad72d"
-  integrity sha512-8qqFN4W53IEWa9bdmuVrUcVkFemQWnt5DKPQ/oa8xKDYgtjCr2OO6NX5TIK49NLFr3mPYU2cLh92DQquC3oWWQ==
+  version "4.17.21"
+  resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.21.tgz#a427278e106bca77b83ad85221eae709a3414d42"
+  integrity sha512-gwCiEZqW6f7EoR8TTEfalyEhb1zA5jQJnRngr97+3pzMaO1RKoI1w2bw07TK72renMUVWcWS5mLI6rk1NqN0nA==
   dependencies:
     "@types/node" "*"
     "@types/qs" "*"
@@ -11281,6 +11304,11 @@ diff@^4.0.1:
   resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
   integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
 
+diff@^5.0.0:
+  version "5.0.0"
+  resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
+  integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==
+
 diffie-hellman@^5.0.0:
   version "5.0.3"
   resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875"
@@ -20756,6 +20784,17 @@ nise@^1.5.2:
     lolex "^5.0.1"
     path-to-regexp "^1.7.0"
 
+nise@^5.1.0:
+  version "5.1.0"
+  resolved "https://registry.yarnpkg.com/nise/-/nise-5.1.0.tgz#713ef3ed138252daef20ec035ab62b7a28be645c"
+  integrity sha512-W5WlHu+wvo3PaKLsJJkgPup2LrsXCcm7AWwyNZkUnn5rwPkuPBi3Iwk5SQtN0mv+K65k7nKKjwNQ30wg3wLAQQ==
+  dependencies:
+    "@sinonjs/commons" "^1.7.0"
+    "@sinonjs/fake-timers" "^7.0.4"
+    "@sinonjs/text-encoding" "^0.7.1"
+    just-extend "^4.0.2"
+    path-to-regexp "^1.7.0"
+
 no-case@^2.2.0:
   version "2.3.2"
   resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
@@ -25841,6 +25880,18 @@ sinon-chai@^3.3.0:
   resolved "https://registry.yarnpkg.com/sinon-chai/-/sinon-chai-3.5.0.tgz#c9a78304b0e15befe57ef68e8a85a00553f5c60e"
   integrity sha512-IifbusYiQBpUxxFJkR3wTU68xzBN0+bxCScEaKMjBvAQERg6FnTTc1F17rseLb1tjmkJ23730AXpFI0c47FgAg==
 
+sinon@^11.1.1:
+  version "11.1.1"
+  resolved "https://registry.yarnpkg.com/sinon/-/sinon-11.1.1.tgz#99a295a8b6f0fadbbb7e004076f3ae54fc6eab91"
+  integrity sha512-ZSSmlkSyhUWbkF01Z9tEbxZLF/5tRC9eojCdFh33gtQaP7ITQVaMWQHGuFM7Cuf/KEfihuh1tTl3/ABju3AQMg==
+  dependencies:
+    "@sinonjs/commons" "^1.8.3"
+    "@sinonjs/fake-timers" "^7.1.0"
+    "@sinonjs/samsam" "^6.0.2"
+    diff "^5.0.0"
+    nise "^5.1.0"
+    supports-color "^7.2.0"
+
 sinon@^7.3.2:
   version "7.5.0"
   resolved "https://registry.yarnpkg.com/sinon/-/sinon-7.5.0.tgz#e9488ea466070ea908fd44a3d6478fd4923c67ec"
@@ -26362,20 +26413,6 @@ stealthy-require@^1.1.1:
   resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
   integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=
 
-"storage-node-v2@file:./storage-node-v2":
-  version "0.1.0"
-  dependencies:
-    "@joystream/types" "0.17.0"
-    "@oclif/command" "^1"
-    "@oclif/config" "^1"
-    "@oclif/plugin-help" "^3"
-    "@polkadot/api" "4.2.1"
-    "@types/express" "^4.17.11"
-    express "^4.17.1"
-    express-openapi-validator "^4.12.4"
-    storage-node-v2 "file:../../../Library/Caches/Yarn/v6/npm-storage-node-v2-0.1.0-0581feac-3ca7-4599-93d3-3cd8cb4e5f16-1622545689288/node_modules/storage-node-v2"
-    tslib "^1"
-
 store2@^2.7.1:
   version "2.11.2"
   resolved "https://registry.yarnpkg.com/store2/-/store2-2.11.2.tgz#a298e5e97b21b3ce7419b732540bc7c79cb007db"
@@ -26959,6 +26996,13 @@ supports-color@^7.0.0, supports-color@^7.1.0:
   dependencies:
     has-flag "^4.0.0"
 
+supports-color@^7.2.0:
+  version "7.2.0"
+  resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
+  integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
+  dependencies:
+    has-flag "^4.0.0"
+
 supports-hyperlinks@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-1.0.1.tgz#71daedf36cc1060ac5100c351bb3da48c29c0ef7"
@@ -27731,7 +27775,7 @@ ts-node@^7.0.1:
     source-map-support "^0.5.6"
     yn "^2.0.0"
 
-ts-node@^8, ts-node@^8.6.2:
+ts-node@^8.6.2:
   version "8.10.2"
   resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d"
   integrity sha512-ISJJGgkIpDdBhWVu3jufsWpK3Rzo7bdiIXJjQc0ynKxVOVcg2oIrf2H2cejminGrptVc6q6/uynAHNCuWGbpVA==
@@ -27860,7 +27904,7 @@ type-check@~0.3.2:
   dependencies:
     prelude-ls "~1.1.2"
 
-type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5:
+type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.5, type-detect@^4.0.8:
   version "4.0.8"
   resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
   integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==
@@ -27992,9 +28036,9 @@ typeorm-typedi-extensions@^0.2.3:
   integrity sha512-T9i1NvRZNjPn9Jb8oT772ihfn6PwdqDVpzPCtKSqjkZGOgXrCkdyD3dDrzfMaoWJ1afU58bVx2CMb95FzT42Ow==
 
 typeorm@^0.2.25, typeorm@^0.2.31:
-  version "0.2.32"
-  resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.32.tgz#544dbfdfe0cd0887548d9bcbd28527ea4f4b3c9b"
-  integrity sha512-LOBZKZ9As3f8KRMPCUT2H0JZbZfWfkcUnO3w/1BFAbL/X9+cADTF6bczDGGaKVENJ3P8SaKheKmBgpt5h1x+EQ==
+  version "0.2.34"
+  resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.34.tgz#637b3cec2de54ee7f423012b813a2022c0aacc8b"
+  integrity sha512-FZAeEGGdSGq7uTH3FWRQq67JjKu0mgANsSZ04j3kvDYNgy9KwBl/6RFgMVgiSgjf7Rqd7NrhC2KxVT7I80qf7w==
   dependencies:
     "@sqltools/formatter" "^1.2.2"
     app-root-path "^3.0.0"