From 2c948c103e8a206711e6c47ecda7b32ad04e24df Mon Sep 17 00:00:00 2001 From: Aaron Sutula Date: Mon, 20 Jul 2020 19:50:24 -0500 Subject: [PATCH 1/5] chore: update to latest pg, only return objects Signed-off-by: Aaron Sutula --- package-lock.json | 6 +- package.json | 4 +- src/asks/index.spec.ts | 6 +- src/asks/index.ts | 4 +- src/faults/index.spec.ts | 2 +- src/faults/index.ts | 2 +- src/ffs/index.spec.ts | 164 +++++++++++++++++++---------------- src/ffs/index.ts | 78 +++++++---------- src/ffs/options.ts | 13 ++- src/reputation/index.spec.ts | 4 +- src/reputation/index.ts | 2 +- src/wallet/index.spec.ts | 8 +- src/wallet/index.ts | 6 +- 13 files changed, 152 insertions(+), 147 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5dcf40e5..10924678 100644 --- a/package-lock.json +++ b/package-lock.json @@ -464,9 +464,9 @@ "integrity": "sha512-+Kjz+Dktfz5LKTZA9ZW/Vlww6HF9KaKz4x2mVe1O8CJdOP2WfzC+KY8L6EWMqVLrV4MvdBuQdSgDmvSJz+OGuA==" }, "@textile/grpc-powergate-client": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-0.1.1.tgz", - "integrity": "sha512-PJ1VIKALEvYxGHi70y1tIBOFrpK7e4XvAGOfDnBpiVXqzjlTiNijDxzgJIWjNXLugkp4e1QZVrbJ7LG0+EQfBg==", + "version": "0.2.0-pre.1", + "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-0.2.0-pre.1.tgz", + "integrity": "sha512-gU3nMMk7+SmhyrdlcNu+aLWfiwZ70WZUl9wZDUYy/rxzLWsJWT0j0imxF076PNM+raYW4UWYgCfoqlOFz31ztQ==", "requires": { "@improbable-eng/grpc-web": "^0.13.0", "@types/google-protobuf": "^3.7.2", diff --git a/package.json b/package.json index 8d9d086b..e2952d34 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,6 @@ }, "dependencies": { "@improbable-eng/grpc-web-node-http-transport": "^0.12.0", - "@textile/grpc-powergate-client": "0.1.1" + "@textile/grpc-powergate-client": "0.2.0-pre.1" } -} \ No newline at end of file +} diff --git a/src/asks/index.spec.ts b/src/asks/index.spec.ts index de45bdff..80cf36d8 100644 --- a/src/asks/index.spec.ts +++ b/src/asks/index.spec.ts @@ -7,13 +7,13 @@ describe("asks", () => { const c = createAsks({ host, transport: getTransport() }) it("should get", async () => { - const index = await c.get() + const { index } = await c.get() expect(index).not.undefined }) it("should query", async () => { const q = new asksTypes.Query().toObject() - const res = await c.query(q) - expect(res).not.undefined + const { asksList } = await c.query(q) + expect(asksList).not.undefined }) }) diff --git a/src/asks/index.ts b/src/asks/index.ts index 58c58bd5..b44a6669 100644 --- a/src/asks/index.ts +++ b/src/asks/index.ts @@ -19,7 +19,7 @@ export const createAsks = (config: Config) => { get: () => promise( (cb) => client.get(new asksTypes.GetRequest(), cb), - (resp: asksTypes.GetResponse) => resp.toObject().index, + (resp: asksTypes.GetResponse) => resp.toObject(), ), /** @@ -32,7 +32,7 @@ export const createAsks = (config: Config) => { req.setQuery(queryObjectToMsg(query)) return promise( (cb) => client.query(req, cb), - (resp: asksTypes.QueryResponse) => resp.toObject().asksList, + (resp: asksTypes.QueryResponse) => resp.toObject(), ) }, } diff --git a/src/faults/index.spec.ts b/src/faults/index.spec.ts index 11f0e87d..af071923 100644 --- a/src/faults/index.spec.ts +++ b/src/faults/index.spec.ts @@ -6,7 +6,7 @@ describe("faults", () => { const c = createFaults({ host, transport: getTransport() }) it("should get", async () => { - const index = await c.get() + const { index } = await c.get() expect(index).not.undefined }) }) diff --git a/src/faults/index.ts b/src/faults/index.ts index 0818df17..8e780ebf 100644 --- a/src/faults/index.ts +++ b/src/faults/index.ts @@ -18,7 +18,7 @@ export const createFaults = (config: Config) => { get: () => promise( (cb) => client.get(new faultsTypes.GetRequest(), cb), - (resp: faultsTypes.GetResponse) => resp.toObject().index, + (resp: faultsTypes.GetResponse) => resp.toObject(), ), } } diff --git a/src/ffs/index.spec.ts b/src/ffs/index.spec.ts index d09359eb..0f7818b7 100644 --- a/src/ffs/index.spec.ts +++ b/src/ffs/index.spec.ts @@ -3,13 +3,7 @@ import fs from "fs" import { createFFS } from "." import { ffsTypes } from "../types" import { getTransport, host, useToken } from "../util" -import { - PushConfigOption, - withConfig, - withHistory, - withIncludeFinal, - withOverrideConfig, -} from "./options" +import { PushStorageConfigOption, withConfig, withHistory, withOverrideConfig } from "./options" describe("ffs", function () { this.timeout(180000) @@ -41,7 +35,7 @@ describe("ffs", function () { it("should get the default config", async () => { await expectNewInstance() - await expectDefaultConfig() + await expectDefaultStorageConfig() }) it("should create a new addr", async () => { @@ -53,8 +47,8 @@ describe("ffs", function () { it("should set default config", async () => { await expectNewInstance() - const defaultConfig = await expectDefaultConfig() - await c.setDefaultConfig(defaultConfig) + const defaultConfig = await expectDefaultStorageConfig() + await c.setDefaultStorageConfig(defaultConfig) }) it("should get info", async () => { @@ -65,35 +59,29 @@ describe("ffs", function () { it("should add to hot", async () => { await expectNewInstance() - await expectAddToHot("sample-data/samplefile") - }) - - it("should get default cid config", async () => { - await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - await expectDefaultCidConfig(cid) + await expectStage("sample-data/samplefile") }) it("should push config", async () => { await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - const config = await expectDefaultCidConfig(cid) - await expectPushConfig(cid, false, config) + const cid = await expectStage("sample-data/samplefile") + const config = await expectDefaultStorageConfig() + await expectPushStorageConfig(cid, false, config) }) it("should watch job", async () => { await expectNewInstance() const addrs = await expectAddrs(1) await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) }) it("should watch logs", async () => { await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + await expectPushStorageConfig(cid) await new Promise((resolve, reject) => { const cancel = c.watchLogs( (logEvent) => { @@ -111,35 +99,74 @@ describe("ffs", function () { }) }) - it("should get a storage deal record", async () => { - await expectNewInstance() - const addrs = await expectAddrs(1) - await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) - await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) - const res = await c.listStorageDealRecords(withIncludeFinal(true)) - expect(res).length.greaterThan(0) - }) + // it("should get a storage deal record", async () => { + // await expectNewInstance() + // const addrs = await expectAddrs(1) + // await waitForBalance(addrs[0].addr, 0) + + // const [cid1, cid2, cid3] = await Promise.all([ + // expectStage("sample-data/samplefile"), + // expectStage("sample-data/samplefile2"), + // expectStage("sample-data/samplefile3"), + // ]) + + // const [jobId1, jobId2, jobId3] = await Promise.all([ + // expectPushStorageConfig(cid1), + // expectPushStorageConfig(cid2), + // expectPushStorageConfig(cid3), + // ]) + + // await Promise.all([ + // waitForJobStatus(jobId1, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + // waitForJobStatus(jobId2, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + // waitForJobStatus(jobId3, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + // ]) + + // const res1 = await c.listStorageDealRecords( + // withIncludePending(true), + // // withAscending(true), + // // withFromAddresses(addrs[0].addr), + // // withDataCids(cid, cid2, cid3), + // ) + // expect(res1, "pending").length(3) + + // const res2 = await c.listStorageDealRecords( + // withIncludeFinal(true), + // // withAscending(true), + // // withFromAddresses(addrs[0].addr), + // // withDataCids(cid, cid2, cid3), + // ) + // expect(res2, "final").empty + + // // const res = await c.listStorageDealRecords( + // // withIncludeFinal(true), + // // withIncludePending(true), + // // withAscending(true), + // // withFromAddresses(addrs[0].addr), + // // // withDataCids(cid, cid2, cid3), + // // ) + // // expect(res).length(3) + // }) it("should get a retrieval deal record", async () => { // ToDo: Figure out hot to make sure the data in the previous push isn't cached in hot }) - it("should get cid config", async () => { + it("should get storage config", async () => { await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - await expectPushConfig(cid) - const res = await c.getCidConfig(cid) - expect(res.config?.cid).equal(cid) + const cid = await expectStage("sample-data/samplefile") + await expectPushStorageConfig(cid) + const res = await c.getStorageConfig(cid) + expect(res.config?.cold).not.undefined + expect(res.config?.hot).not.undefined }) it("should show", async () => { await expectNewInstance() const addrs = await expectAddrs(1) await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) const res = await c.show(cid) expect(res.cidInfo).not.undefined @@ -149,21 +176,21 @@ describe("ffs", function () { await expectNewInstance() const addrs = await expectAddrs(1) await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) const res = await c.showAll() - expect(res).not.empty + expect(res.cidInfosList).not.empty }) it("should replace", async () => { await expectNewInstance() const addrs = await expectAddrs(1) await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) - const cid2 = await expectAddToHot("sample-data/samplefile2") + const cid2 = await expectStage("sample-data/samplefile2") const res = await c.replace(cid, cid2) expect(res.jobId).length.greaterThan(0) }) @@ -172,8 +199,8 @@ describe("ffs", function () { await expectNewInstance() const addrs = await expectAddrs(1) await waitForBalance(addrs[0].addr, 0) - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) const bytes = await c.get(cid) expect(bytes.byteLength).greaterThan(0) @@ -181,8 +208,8 @@ describe("ffs", function () { it("should cancel a job", async () => { await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - const jobId = await expectPushConfig(cid) + const cid = await expectStage("sample-data/samplefile") + const jobId = await expectPushStorageConfig(cid) await c.cancelJob(jobId) }) @@ -200,9 +227,8 @@ describe("ffs", function () { it("should remove", async () => { await expectNewInstance() - const cid = await expectAddToHot("sample-data/samplefile") - const conf: ffsTypes.CidConfig.AsObject = { - cid, + const cid = await expectStage("sample-data/samplefile") + const conf: ffsTypes.StorageConfig.AsObject = { repairable: false, cold: { enabled: false, @@ -212,7 +238,7 @@ describe("ffs", function () { enabled: false, }, } - const jobId = await expectPushConfig(cid, false, conf) + const jobId = await expectPushStorageConfig(cid, false, conf) await waitForJobStatus(jobId, ffsTypes.JobStatus.JOB_STATUS_SUCCESS) await c.remove(cid) }) @@ -250,39 +276,31 @@ describe("ffs", function () { return res.addr } - async function expectDefaultConfig() { - const res = await c.defaultConfig() - expect(res.defaultConfig).not.undefined + async function expectDefaultStorageConfig() { + const res = await c.defaultStorageConfig() + expect(res.defaultStorageConfig).not.undefined // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return res.defaultConfig! + return res.defaultStorageConfig! } - async function expectAddToHot(path: string) { + async function expectStage(path: string) { const buffer = fs.readFileSync(path) - const res = await c.addToHot(buffer) + const res = await c.stage(buffer) expect(res.cid).length.greaterThan(0) return res.cid } - async function expectDefaultCidConfig(cid: string) { - const res = await c.getDefaultCidConfig(cid) - expect(res.config).not.undefined - expect(res.config?.cid).equal(cid) - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - return res.config! - } - - async function expectPushConfig( + async function expectPushStorageConfig( cid: string, override: boolean = false, - config?: ffsTypes.CidConfig.AsObject, + config?: ffsTypes.StorageConfig.AsObject, ) { - const opts: PushConfigOption[] = [] + const opts: PushStorageConfigOption[] = [] opts.push(withOverrideConfig(override)) if (config) { opts.push(withConfig(config)) } - const res = await c.pushConfig(cid, ...opts) + const res = await c.pushStorageConfig(cid, ...opts) expect(res.jobId).length.greaterThan(0) return res.jobId } diff --git a/src/ffs/index.ts b/src/ffs/index.ts index 918da4f9..ef7ed0f3 100644 --- a/src/ffs/index.ts +++ b/src/ffs/index.ts @@ -5,7 +5,7 @@ import { } from "@textile/grpc-powergate-client/dist/ffs/rpc/rpc_pb_service" import { Config, ffsTypes } from "../types" import { promise } from "../util" -import { ListDealRecordsOption, PushConfigOption, WatchLogsOption } from "./options" +import { ListDealRecordsOption, PushStorageConfigOption, WatchLogsOption } from "./options" import { coldObjToMessage, hotObjToMessage } from "./util" /** @@ -58,13 +58,14 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { ), /** - * Get the default storage config associates with the current auth token + * Get the default storage config associated with the current auth token * @returns The default storage config */ - defaultConfig: () => + defaultStorageConfig: () => promise( - (cb) => client.defaultConfig(new ffsTypes.DefaultConfigRequest(), getMeta(), cb), - (res: ffsTypes.DefaultConfigResponse) => res.toObject(), + (cb) => + client.defaultStorageConfig(new ffsTypes.DefaultStorageConfigRequest(), getMeta(), cb), + (res: ffsTypes.DefaultStorageConfigResponse) => res.toObject(), ), /** @@ -85,31 +86,17 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { ) }, - /** - * Get a cid storage configuration prepped for the provided cid - * @param cid The cid to make the storage config for - * @returns The storage config prepped for the provided cid - */ - getDefaultCidConfig: (cid: string) => { - const req = new ffsTypes.GetDefaultCidConfigRequest() - req.setCid(cid) - return promise( - (cb) => client.getDefaultCidConfig(req, getMeta(), cb), - (res: ffsTypes.GetDefaultCidConfigResponse) => res.toObject(), - ) - }, - /** * Get the desired storage config for the provided cid, this config may not yet be realized * @param cid The cid of the desired storage config * @returns The storage config for the provided cid */ - getCidConfig: (cid: string) => { - const req = new ffsTypes.GetCidConfigRequest() + getStorageConfig: (cid: string) => { + const req = new ffsTypes.GetStorageConfigRequest() req.setCid(cid) return promise( - (cb) => client.getCidConfig(req, getMeta(), cb), - (res: ffsTypes.GetCidConfigResponse) => res.toObject(), + (cb) => client.getStorageConfig(req, getMeta(), cb), + (res: ffsTypes.GetStorageConfigResponse) => res.toObject(), ) }, @@ -117,8 +104,8 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { * Set the default storage config for this FFS instance * @param config The new default storage config */ - setDefaultConfig: (config: ffsTypes.DefaultConfig.AsObject) => { - const c = new ffsTypes.DefaultConfig() + setDefaultStorageConfig: (config: ffsTypes.StorageConfig.AsObject) => { + const c = new ffsTypes.StorageConfig() c.setRepairable(config.repairable) if (config.hot) { c.setHot(hotObjToMessage(config.hot)) @@ -126,10 +113,10 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { if (config.cold) { c.setCold(coldObjToMessage(config.cold)) } - const req = new ffsTypes.SetDefaultConfigRequest() + const req = new ffsTypes.SetDefaultStorageConfigRequest() req.setConfig(c) return promise( - (cb) => client.setDefaultConfig(req, getMeta(), cb), + (cb) => client.setDefaultStorageConfig(req, getMeta(), cb), () => { // nothing to return }, @@ -216,9 +203,10 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { }, /** - * Replace smth? - * @param cid1 smth - * @param cid2 hrmmm + * Replace pushes a StorageConfig for cid2 equal to that of cid1, and removes cid1. This operation + * is more efficient than manually removing and adding in two separate operations. + * @param cid1 The cid to replace + * @param cid2 The new cid * @returns The job id of the job executing the storage configuration */ replace: (cid1: string, cid2: string) => { @@ -235,17 +223,17 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { * Push a storage config for the specified cid * @param cid The cid to store * @param opts Options controlling the behavior storage config execution - * @returns The job id of the job executing the storage configuration + * @returns An object containing the job id of the job executing the storage configuration */ - pushConfig: (cid: string, ...opts: PushConfigOption[]) => { - const req = new ffsTypes.PushConfigRequest() + pushStorageConfig: (cid: string, ...opts: PushStorageConfigOption[]) => { + const req = new ffsTypes.PushStorageConfigRequest() req.setCid(cid) opts.forEach((opt) => { opt(req) }) return promise( - (cb) => client.pushConfig(req, getMeta(), cb), - (res: ffsTypes.PushConfigResponse) => res.toObject(), + (cb) => client.pushStorageConfig(req, getMeta(), cb), + (res: ffsTypes.PushStorageConfigResponse) => res.toObject(), ) }, @@ -326,16 +314,16 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { /** * A helper method to cache data in IPFS in preparation for storing in ffsTypes. - * This doesn't actually store data in FFS, you'll want to call pushConfig for that. + * This doesn't actually store data in FFS, you'll want to call pushStorageConfig for that. * @param input The raw data to add * @returns The cid of the added data */ - addToHot: (input: Uint8Array) => { + stage: (input: Uint8Array) => { // TODO: figure out how to stream data in here, or at least stream to the server - return new Promise((resolve, reject) => { - const client = grpc.client(RPCService.AddToHot, config) + return new Promise((resolve, reject) => { + const client = grpc.client(RPCService.Stage, config) client.onMessage((message) => { - resolve(message.toObject() as ffsTypes.AddToHotResponse.AsObject) + resolve(message.toObject() as ffsTypes.StageResponse.AsObject) }) client.onEnd((code, msg) => { if (code !== grpc.Code.OK) { @@ -345,7 +333,7 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { } }) client.start(getMeta()) - const req = new ffsTypes.AddToHotRequest() + const req = new ffsTypes.StageRequest() req.setChunk(input) client.send(req) client.finishSend() @@ -359,7 +347,7 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { listPayChannels: () => promise( (cb) => client.listPayChannels(new ffsTypes.ListPayChannelsRequest(), getMeta(), cb), - (res: ffsTypes.ListPayChannelsResponse) => res.toObject().payChannelsList, + (res: ffsTypes.ListPayChannelsResponse) => res.toObject(), ), /** @@ -409,7 +397,7 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { req.setConfig(conf) return promise( (cb) => client.listStorageDealRecords(req, getMeta(), cb), - (res: ffsTypes.ListStorageDealRecordsResponse) => res.toObject().recordsList, + (res: ffsTypes.ListStorageDealRecordsResponse) => res.toObject(), ) }, @@ -427,7 +415,7 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { req.setConfig(conf) return promise( (cb) => client.listRetrievalDealRecords(req, getMeta(), cb), - (res: ffsTypes.ListRetrievalDealRecordsResponse) => res.toObject().recordsList, + (res: ffsTypes.ListRetrievalDealRecordsResponse) => res.toObject(), ) }, @@ -438,7 +426,7 @@ export const createFFS = (config: Config, getMeta: () => grpc.Metadata) => { showAll: () => promise( (cb) => client.showAll(new ffsTypes.ShowAllRequest(), getMeta(), cb), - (res: ffsTypes.ShowAllResponse) => res.toObject().cidInfosList, + (res: ffsTypes.ShowAllResponse) => res.toObject(), ), } } diff --git a/src/ffs/options.ts b/src/ffs/options.ts index c5b00b7c..0a34c8b6 100644 --- a/src/ffs/options.ts +++ b/src/ffs/options.ts @@ -1,15 +1,15 @@ import { ffsTypes } from "../types" import { coldObjToMessage, hotObjToMessage } from "./util" -export type PushConfigOption = (req: ffsTypes.PushConfigRequest) => void +export type PushStorageConfigOption = (req: ffsTypes.PushStorageConfigRequest) => void /** * Allows you to override an existing storage configuration * @param override Whether or not to override any existing storage configuration * @returns The resulting option */ -export const withOverrideConfig = (override: boolean): PushConfigOption => { - return (req: ffsTypes.PushConfigRequest) => { +export const withOverrideConfig = (override: boolean): PushStorageConfigOption => { + return (req: ffsTypes.PushStorageConfigRequest) => { req.setHasOverrideConfig(true) req.setOverrideConfig(override) } @@ -20,10 +20,9 @@ export const withOverrideConfig = (override: boolean): PushConfigOption => { * @param config The storage configuration to use * @returns The resulting option */ -export const withConfig = (config: ffsTypes.CidConfig.AsObject): PushConfigOption => { - return (req: ffsTypes.PushConfigRequest) => { - const c = new ffsTypes.CidConfig() - c.setCid(config.cid) +export const withConfig = (config: ffsTypes.StorageConfig.AsObject): PushStorageConfigOption => { + return (req: ffsTypes.PushStorageConfigRequest) => { + const c = new ffsTypes.StorageConfig() c.setRepairable(config.repairable) if (config.hot) { c.setHot(hotObjToMessage(config.hot)) diff --git a/src/reputation/index.spec.ts b/src/reputation/index.spec.ts index eee059e1..31976ad1 100644 --- a/src/reputation/index.spec.ts +++ b/src/reputation/index.spec.ts @@ -6,7 +6,7 @@ describe("reputation", () => { const c = createReputation({ host, transport: getTransport() }) it("should get top miners", async () => { - const scores = await c.getTopMiners(10) - expect(scores).not.undefined + const { topMinersList } = await c.getTopMiners(10) + expect(topMinersList).not.undefined }) }) diff --git a/src/reputation/index.ts b/src/reputation/index.ts index 470d5d94..98fda0cb 100644 --- a/src/reputation/index.ts +++ b/src/reputation/index.ts @@ -38,7 +38,7 @@ export const createReputation = (config: Config) => { req.setLimit(limit) return promise( (cb) => client.getTopMiners(req, cb), - (resp: reputationTypes.GetTopMinersResponse) => resp.toObject().topMinersList, + (resp: reputationTypes.GetTopMinersResponse) => resp.toObject(), ) }, } diff --git a/src/wallet/index.spec.ts b/src/wallet/index.spec.ts index 12e97b46..5b579fa5 100644 --- a/src/wallet/index.spec.ts +++ b/src/wallet/index.spec.ts @@ -25,13 +25,13 @@ describe("wallet", () => { }) async function expectAddresses(lengthGreaterThan: number) { - const addresses = await c.list() - expect(addresses).length.greaterThan(lengthGreaterThan) - return addresses + const { addressesList } = await c.list() + expect(addressesList).length.greaterThan(lengthGreaterThan) + return addressesList } async function expectNewAddress() { - const address = await c.newAddress() + const { address } = await c.newAddress() expect(address).length.greaterThan(0) return address } diff --git a/src/wallet/index.ts b/src/wallet/index.ts index 235b68fe..f46799bb 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -21,7 +21,7 @@ export const createWallet = (config: Config) => { req.setType(type) return promise( (cb) => client.newAddress(req, cb), - (resp: walletTypes.NewAddressResponse) => resp.toObject().address, + (resp: walletTypes.NewAddressResponse) => resp.toObject(), ) }, @@ -32,7 +32,7 @@ export const createWallet = (config: Config) => { list: () => promise( (cb) => client.list(new walletTypes.ListRequest(), cb), - (resp: walletTypes.ListResponse) => resp.toObject().addressesList, + (resp: walletTypes.ListResponse) => resp.toObject(), ), /** @@ -45,7 +45,7 @@ export const createWallet = (config: Config) => { req.setAddress(address) return promise( (cb) => client.balance(req, cb), - (resp: walletTypes.BalanceResponse) => resp.toObject().balance, + (resp: walletTypes.BalanceResponse) => resp.toObject(), ) }, From 63bbf12b21148e2e171182df9a9895d69fcccb39 Mon Sep 17 00:00:00 2001 From: Aaron Sutula Date: Mon, 20 Jul 2020 22:50:56 -0500 Subject: [PATCH 2/5] fix: correct localnet-down command Signed-off-by: Aaron Sutula --- package.json | 4 ++-- src/index.spec.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e2952d34..dca3f44d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "lint": "eslint --fix --ext .js,.ts src/**/*", "docs": "typedoc", "localnet:up": "cd powergate-docker && make localnet", - "localnet:down": "cd powergate-docker && make down", + "localnet:down": "cd powergate-docker && make localnet-down", "powergate-docker": "./powergate-docker.sh" }, "keywords": [ @@ -67,4 +67,4 @@ "@improbable-eng/grpc-web-node-http-transport": "^0.12.0", "@textile/grpc-powergate-client": "0.2.0-pre.1" } -} +} \ No newline at end of file diff --git a/src/index.spec.ts b/src/index.spec.ts index 9178f592..bffb0fd0 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -20,7 +20,7 @@ beforeEach(async function () { afterEach(async function () { this.timeout(120000) await new Promise((resolve, reject) => { - cp.exec(`cd powergate-docker && make down`, (err, stdout) => { + cp.exec(`cd powergate-docker && make localnet-down`, (err, stdout) => { if (err) { reject(err) } From f245ad6d9617776572ff867f0ac5fe2404434be9 Mon Sep 17 00:00:00 2001 From: Aaron Sutula Date: Tue, 21 Jul 2020 09:54:39 -0500 Subject: [PATCH 3/5] fix: update option name Signed-off-by: Aaron Sutula --- src/ffs/index.spec.ts | 6 +++--- src/ffs/options.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ffs/index.spec.ts b/src/ffs/index.spec.ts index 0f7818b7..954575e1 100644 --- a/src/ffs/index.spec.ts +++ b/src/ffs/index.spec.ts @@ -3,7 +3,7 @@ import fs from "fs" import { createFFS } from "." import { ffsTypes } from "../types" import { getTransport, host, useToken } from "../util" -import { PushStorageConfigOption, withConfig, withHistory, withOverrideConfig } from "./options" +import { PushStorageConfigOption, withHistory, withOverride, withStorageConfig } from "./options" describe("ffs", function () { this.timeout(180000) @@ -296,9 +296,9 @@ describe("ffs", function () { config?: ffsTypes.StorageConfig.AsObject, ) { const opts: PushStorageConfigOption[] = [] - opts.push(withOverrideConfig(override)) + opts.push(withOverride(override)) if (config) { - opts.push(withConfig(config)) + opts.push(withStorageConfig(config)) } const res = await c.pushStorageConfig(cid, ...opts) expect(res.jobId).length.greaterThan(0) diff --git a/src/ffs/options.ts b/src/ffs/options.ts index 0a34c8b6..c5aae348 100644 --- a/src/ffs/options.ts +++ b/src/ffs/options.ts @@ -8,7 +8,7 @@ export type PushStorageConfigOption = (req: ffsTypes.PushStorageConfigRequest) = * @param override Whether or not to override any existing storage configuration * @returns The resulting option */ -export const withOverrideConfig = (override: boolean): PushStorageConfigOption => { +export const withOverride = (override: boolean): PushStorageConfigOption => { return (req: ffsTypes.PushStorageConfigRequest) => { req.setHasOverrideConfig(true) req.setOverrideConfig(override) @@ -20,7 +20,9 @@ export const withOverrideConfig = (override: boolean): PushStorageConfigOption = * @param config The storage configuration to use * @returns The resulting option */ -export const withConfig = (config: ffsTypes.StorageConfig.AsObject): PushStorageConfigOption => { +export const withStorageConfig = ( + config: ffsTypes.StorageConfig.AsObject, +): PushStorageConfigOption => { return (req: ffsTypes.PushStorageConfigRequest) => { const c = new ffsTypes.StorageConfig() c.setRepairable(config.repairable) From 17f9b121c0ff30d8731663836a269ff382b79855 Mon Sep 17 00:00:00 2001 From: Aaron Sutula Date: Tue, 21 Jul 2020 11:59:17 -0500 Subject: [PATCH 4/5] test: good test for deal records Signed-off-by: Aaron Sutula --- src/ffs/index.spec.ts | 118 ++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 49 deletions(-) diff --git a/src/ffs/index.spec.ts b/src/ffs/index.spec.ts index 954575e1..b045bf5f 100644 --- a/src/ffs/index.spec.ts +++ b/src/ffs/index.spec.ts @@ -3,7 +3,17 @@ import fs from "fs" import { createFFS } from "." import { ffsTypes } from "../types" import { getTransport, host, useToken } from "../util" -import { PushStorageConfigOption, withHistory, withOverride, withStorageConfig } from "./options" +import { + PushStorageConfigOption, + withAscending, + withDataCids, + withFromAddresses, + withHistory, + withIncludeFinal, + withIncludePending, + withOverride, + withStorageConfig, +} from "./options" describe("ffs", function () { this.timeout(180000) @@ -99,54 +109,64 @@ describe("ffs", function () { }) }) - // it("should get a storage deal record", async () => { - // await expectNewInstance() - // const addrs = await expectAddrs(1) - // await waitForBalance(addrs[0].addr, 0) - - // const [cid1, cid2, cid3] = await Promise.all([ - // expectStage("sample-data/samplefile"), - // expectStage("sample-data/samplefile2"), - // expectStage("sample-data/samplefile3"), - // ]) - - // const [jobId1, jobId2, jobId3] = await Promise.all([ - // expectPushStorageConfig(cid1), - // expectPushStorageConfig(cid2), - // expectPushStorageConfig(cid3), - // ]) - - // await Promise.all([ - // waitForJobStatus(jobId1, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), - // waitForJobStatus(jobId2, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), - // waitForJobStatus(jobId3, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), - // ]) - - // const res1 = await c.listStorageDealRecords( - // withIncludePending(true), - // // withAscending(true), - // // withFromAddresses(addrs[0].addr), - // // withDataCids(cid, cid2, cid3), - // ) - // expect(res1, "pending").length(3) - - // const res2 = await c.listStorageDealRecords( - // withIncludeFinal(true), - // // withAscending(true), - // // withFromAddresses(addrs[0].addr), - // // withDataCids(cid, cid2, cid3), - // ) - // expect(res2, "final").empty - - // // const res = await c.listStorageDealRecords( - // // withIncludeFinal(true), - // // withIncludePending(true), - // // withAscending(true), - // // withFromAddresses(addrs[0].addr), - // // // withDataCids(cid, cid2, cid3), - // // ) - // // expect(res).length(3) - // }) + it("should get storage deal records", async () => { + await expectNewInstance() + const addrs = await expectAddrs(1) + await waitForBalance(addrs[0].addr, 0) + + const [cid1, cid2, cid3] = await Promise.all([ + expectStage("sample-data/samplefile"), + expectStage("sample-data/samplefile2"), + expectStage("sample-data/samplefile3"), + ]) + + const jobId1 = await expectPushStorageConfig(cid1) + await new Promise((r) => setTimeout(r, 1000)) + const jobId2 = await expectPushStorageConfig(cid2) + await new Promise((r) => setTimeout(r, 1000)) + const jobId3 = await expectPushStorageConfig(cid3) + + await Promise.all([ + waitForJobStatus(jobId1, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + waitForJobStatus(jobId2, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + waitForJobStatus(jobId3, ffsTypes.JobStatus.JOB_STATUS_EXECUTING), + ]) + + // wait for a second so some async work of actually starting a deal happens + await new Promise((r) => setTimeout(r, 1000)) + + const { recordsList: pendingRecords } = await c.listStorageDealRecords( + withIncludePending(true), + withAscending(true), + withFromAddresses(addrs[0].addr), + withDataCids(cid1, cid2, cid3), + ) + expect(pendingRecords, "pending length").length(3) + expect(pendingRecords[0].time).lessThan(pendingRecords[1].time).lessThan(pendingRecords[2].time) + + const { recordsList: finalRecords } = await c.listStorageDealRecords(withIncludeFinal(true)) + expect(finalRecords, "final empty").empty + + await Promise.all([ + waitForJobStatus(jobId1, ffsTypes.JobStatus.JOB_STATUS_SUCCESS), + waitForJobStatus(jobId2, ffsTypes.JobStatus.JOB_STATUS_SUCCESS), + waitForJobStatus(jobId3, ffsTypes.JobStatus.JOB_STATUS_SUCCESS), + ]) + + const { recordsList: pendingRecords2 } = await c.listStorageDealRecords( + withIncludePending(true), + ) + expect(pendingRecords2, "pending2 empty").empty + + const { recordsList: finalRecords2 } = await c.listStorageDealRecords( + withIncludeFinal(true), + withAscending(true), + withFromAddresses(addrs[0].addr), + withDataCids(cid1, cid2, cid3), + ) + expect(finalRecords2, "final2 length").length(3) + expect(finalRecords2[0].time).lessThan(finalRecords2[1].time).lessThan(finalRecords2[2].time) + }) it("should get a retrieval deal record", async () => { // ToDo: Figure out hot to make sure the data in the previous push isn't cached in hot From 5ce7a56a05060b9f4eb95874f242d5f3bea0a0a0 Mon Sep 17 00:00:00 2001 From: Aaron Sutula Date: Tue, 21 Jul 2020 13:01:33 -0500 Subject: [PATCH 5/5] chore: update to release grpc bindings Signed-off-by: Aaron Sutula --- package-lock.json | 6 +++--- package.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 10924678..564e2d54 100644 --- a/package-lock.json +++ b/package-lock.json @@ -464,9 +464,9 @@ "integrity": "sha512-+Kjz+Dktfz5LKTZA9ZW/Vlww6HF9KaKz4x2mVe1O8CJdOP2WfzC+KY8L6EWMqVLrV4MvdBuQdSgDmvSJz+OGuA==" }, "@textile/grpc-powergate-client": { - "version": "0.2.0-pre.1", - "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-0.2.0-pre.1.tgz", - "integrity": "sha512-gU3nMMk7+SmhyrdlcNu+aLWfiwZ70WZUl9wZDUYy/rxzLWsJWT0j0imxF076PNM+raYW4UWYgCfoqlOFz31ztQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@textile/grpc-powergate-client/-/grpc-powergate-client-0.2.0.tgz", + "integrity": "sha512-h/AHAPVGQwL6QPoBCCAdqF+bbfRl6Q0eTw4a3mJnjD0F3ILG+zH8qjJ6dNOSPMOcEJjTGUzma0GqN/+nCvI00g==", "requires": { "@improbable-eng/grpc-web": "^0.13.0", "@types/google-protobuf": "^3.7.2", diff --git a/package.json b/package.json index dca3f44d..0f440daa 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,6 @@ }, "dependencies": { "@improbable-eng/grpc-web-node-http-transport": "^0.12.0", - "@textile/grpc-powergate-client": "0.2.0-pre.1" + "@textile/grpc-powergate-client": "0.2.0" } -} \ No newline at end of file +}