Skip to content

Commit

Permalink
chore: naming fixes and separation of DemandRequestBody and DemandBod…
Browse files Browse the repository at this point in the history
…yPrototype
  • Loading branch information
grisha87 committed May 8, 2024
1 parent 84103ef commit 68b7e3a
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 158 deletions.
2 changes: 1 addition & 1 deletion src/experimental/new-api/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Deployment {

const proposalSubscription = this.modules.market
.startCollectingProposals({
demandSpecification: demandSpecification,
demandSpecification,
bufferSize: 10,
})
.subscribe({
Expand Down
2 changes: 1 addition & 1 deletion src/golem-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class GolemNetwork {

const proposalSubscription = this.market
.startCollectingProposals({
demandSpecification: demandSpecification,
demandSpecification,
})
.subscribe((proposalsBatch) => proposalsBatch.forEach((proposal) => proposalPool.add(proposal)));

Expand Down
2 changes: 1 addition & 1 deletion src/market/demand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActivityDemandDirectorConfigOptions } from "./demand/options";
import { BasicDemandDirectorConfigOptions } from "./demand/directors/basic-demand-director-config";
import { PaymentDemandDirectorConfigOptions } from "./demand/directors/payment-demand-director-config";
import { DemandBodyPrototype } from "./demand/demand-details-builder";
import { DemandBodyPrototype } from "./demand/demand-body-builder";

/**
* This type represents a set of *parameters* that the SDK can set to particular *properties* and *constraints*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export enum ComparisonOperator {
*
* Demand -> DemandSpecification -> DemandPrototype -> DemandDTO
*/
export class DemandDetailsBuilder {
export class DemandBodyBuilder {
private properties: Array<DemandProperty> = [];
private constraints: Array<DemandConstraint> = [];

Expand Down
6 changes: 3 additions & 3 deletions src/market/demand/directors/activity-demand-director.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DemandDetailsBuilder } from "../demand-details-builder";
import { DemandBodyBuilder } from "../demand-body-builder";
import { ActivityDemandDirector } from "./activity-demand-director";
import { ActivityDemandDirectorConfig } from "./activity-demand-director-config";

describe("ActivityDemandDirector", () => {
test("should create properties with task_package and package_format", async () => {
const builder = new DemandDetailsBuilder();
const builder = new DemandBodyBuilder();

const director = new ActivityDemandDirector(
new ActivityDemandDirectorConfig({
Expand All @@ -28,7 +28,7 @@ describe("ActivityDemandDirector", () => {
});

test("should create package with manifest decorations", async () => {
const builder = new DemandDetailsBuilder();
const builder = new DemandBodyBuilder();

const manifest = "XNBdCI6ICIyMTAwLTAxLTAxVDAwOjAxOjAwLjAwMDAwMFoiLAogICJtZXRhZGF0YSI6IHsKICAgICJuYW1lI=";
const manifestSig = "GzbdJDaW6FTajVYCKKZZvwpwVNBK3o40r/okna87wV9CVWW0+WUFwe=";
Expand Down
6 changes: 3 additions & 3 deletions src/market/demand/directors/activity-demand-director.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ActivityDemandDirectorConfig } from "./activity-demand-director-config";
import { ComparisonOperator, DemandDetailsBuilder } from "../demand-details-builder";
import { ComparisonOperator, DemandBodyBuilder } from "../demand-body-builder";
import { GolemError, GolemPlatformError } from "../../../shared/error/golem-error";
import { IDemandDirector } from "../../market.module";
import { EnvUtils } from "../../../shared/utils";

export class ActivityDemandDirector implements IDemandDirector {
constructor(private config: ActivityDemandDirectorConfig) {}

public async apply(builder: DemandDetailsBuilder) {
public async apply(builder: DemandBodyBuilder) {
builder
.addProperty("golem.srv.comp.vm.package_format", this.config.packageFormat)
.addConstraint("golem.runtime.name", this.config.engine);
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ActivityDemandDirector implements IDemandDirector {
}
}

private addManifestDecorations(builder: DemandDetailsBuilder): void {
private addManifestDecorations(builder: DemandBodyBuilder): void {
if (!this.config.manifest) return;
builder.addProperty("golem.srv.comp.payload", this.config.manifest);
if (this.config.manifestSig) builder.addProperty("golem.srv.comp.payload.sig", this.config.manifestSig);
Expand Down
4 changes: 2 additions & 2 deletions src/market/demand/directors/basic-demand-director.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DemandDetailsBuilder } from "../demand-details-builder";
import { DemandBodyBuilder } from "../demand-body-builder";
import { IDemandDirector } from "../../market.module";
import { BasicDemandDirectorConfig } from "./basic-demand-director-config";

export class BasicDemandDirector implements IDemandDirector {
constructor(private config: BasicDemandDirectorConfig = new BasicDemandDirectorConfig()) {}

apply(builder: DemandDetailsBuilder) {
apply(builder: DemandBodyBuilder) {
builder
.addProperty("golem.srv.caps.multi-activity", true)
.addProperty("golem.srv.comp.expiration", Date.now() + this.config.expirationSec * 1000)
Expand Down
4 changes: 2 additions & 2 deletions src/market/demand/directors/payment-demand-director.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PayerDetails } from "../../../payment/PayerDetails";
import { ComparisonOperator, DemandDetailsBuilder } from "../demand-details-builder";
import { ComparisonOperator, DemandBodyBuilder } from "../demand-body-builder";
import { IDemandDirector } from "../../market.module";
import { PaymentDemandDirectorConfig } from "./payment-demand-director-config";

Expand All @@ -9,7 +9,7 @@ export class PaymentDemandDirector implements IDemandDirector {
private config: PaymentDemandDirectorConfig = new PaymentDemandDirectorConfig(),
) {}

apply(builder: DemandDetailsBuilder) {
apply(builder: DemandBodyBuilder) {
// Configure mid-agreement payments
builder
.addProperty("golem.com.scheme.payu.debit-note.interval-sec?", this.config.midAgreementDebitNoteIntervalSec)
Expand Down
62 changes: 46 additions & 16 deletions src/market/market.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,54 @@ describe("Market module", () => {
"(golem.inf.cpu.threads>=1)",
"(golem.com.payment.platform.erc20-holesky-tglm.address=*)",
"(golem.com.payment.protocol.version>1)",
].join("\n\t");
];

const expectedProperties = {
"golem.srv.comp.vm.package_format": "gvmkit-squash",
"golem.srv.comp.task_package": "hash:sha3:AAAAHASHAAAA:https://custom.image.url/",
"golem.com.payment.platform.erc20-holesky-tglm.address": "0x123",
"golem.com.payment.protocol.version": "2",
"golem.srv.caps.multi-activity": true,
"golem.srv.comp.expiration": Date.now() + 42 * 1000,
"golem.node.debug.subnet": "public",
"golem.com.payment.debit-notes.accept-timeout?": 42,
"golem.com.scheme.payu.debit-note.interval-sec?": 42,
"golem.com.scheme.payu.payment-timeout-sec?": 42,
};
const expectedProperties = [
{
key: "golem.srv.caps.multi-activity",
value: true,
},
{
key: "golem.srv.comp.expiration",
value: Date.now() + 42 * 1000,
},
{
key: "golem.node.debug.subnet",
value: "public",
},
{
key: "golem.srv.comp.vm.package_format",
value: "gvmkit-squash",
},
{
key: "golem.srv.comp.task_package",
value: "hash:sha3:AAAAHASHAAAA:https://custom.image.url/",
},
{
key: "golem.com.scheme.payu.debit-note.interval-sec?",
value: 42,
},
{
key: "golem.com.scheme.payu.payment-timeout-sec?",
value: 42,
},
{
key: "golem.com.payment.debit-notes.accept-timeout?",
value: 42,
},
{
key: "golem.com.payment.platform.erc20-holesky-tglm.address",
value: "0x123",
},
{
key: "golem.com.payment.protocol.version",
value: "2",
},
];

expect(demandSpecification.paymentPlatform).toBe(payerDetails.getPaymentPlatform());
expect(demandSpecification.expirationSec).toBe(42);
expect(demandSpecification.prototype.constraints).toEqual(`(&${expectedConstraints})`);
expect(demandSpecification.prototype.constraints).toEqual(expect.arrayContaining(expectedConstraints));
expect(demandSpecification.prototype.properties).toEqual(expectedProperties);
});
});
Expand Down Expand Up @@ -293,7 +323,7 @@ describe("Market module", () => {
const draftProposals: ProposalNew[] = [];
marketModule
.startCollectingProposals({
demandSpecification: demandSpecification,
demandSpecification,
bufferSize: 1,
proposalsBatchReleaseTimeoutMs: 10,
})
Expand Down Expand Up @@ -390,7 +420,7 @@ describe("Market module", () => {
const draftProposals: ProposalNew[] = [];
marketModule
.startCollectingProposals({
demandSpecification: demandSpecification,
demandSpecification,
bufferSize: 1,
proposalsBatchReleaseTimeoutMs: 10,
})
Expand Down
6 changes: 3 additions & 3 deletions src/market/market.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { defaultLogger, Logger, YagnaApi } from "../shared/utils";
import { Allocation } from "../payment";
import { bufferTime, filter, map, Observable, OperatorFunction, switchMap, tap } from "rxjs";
import { IProposalRepository, ProposalFilterNew, ProposalNew } from "./proposal";
import { DemandDetailsBuilder } from "./demand/demand-details-builder";
import { DemandBodyBuilder } from "./demand/demand-body-builder";
import { IAgreementApi } from "../agreement/agreement";
import { BuildDemandOptions, DemandSpecification, IDemandRepository } from "./demand";
import { ProposalsBatch } from "./proposals_batch";
Expand Down Expand Up @@ -168,7 +168,7 @@ export interface MarketModule {
* all the final demand request body properties in a more controlled and organized manner.
*/
export interface IDemandDirector {
apply(builder: DemandDetailsBuilder): Promise<void> | void;
apply(builder: DemandBodyBuilder): Promise<void> | void;
}

export class MarketModuleImpl implements MarketModule {
Expand Down Expand Up @@ -206,7 +206,7 @@ export class MarketModuleImpl implements MarketModule {
}

async buildDemandDetails(options: BuildDemandOptions, payerDetails: PayerDetails): Promise<DemandSpecification> {
const builder = new DemandDetailsBuilder();
const builder = new DemandBodyBuilder();

// Instruct the builder what's required
const basicConfig = new BasicDemandDirectorConfig(options.basic);
Expand Down
2 changes: 1 addition & 1 deletion src/market/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ProviderInfo } from "../agreement";
import { Demand } from "./demand";
import { withTimeout } from "../shared/utils/timeout";
import { EventEmitter } from "eventemitter3";
import { DemandBodyPrototype, DemandPropertyValue } from "./demand/demand-details-builder";
import { DemandBodyPrototype, DemandPropertyValue } from "./demand/demand-body-builder";
import { DemandRequestBody } from "../shared/yagna";

export type ProposalFilterNew = (proposal: ProposalNew) => boolean;
Expand Down
Loading

0 comments on commit 68b7e3a

Please sign in to comment.