Skip to content

Commit

Permalink
fix(Channel): Make getOutboundRAMFAddress() return a promise (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Jul 19, 2022
1 parent cc755af commit a53ad7d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/Channel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ describe('wrapMessagePayload', () => {
});

class StubChannel extends Channel {
getOutboundRAMFAddress(): string {
async getOutboundRAMFAddress(): Promise<string> {
throw new Error('not implemented');
}
}
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export abstract class Channel {
return envelopedData.serialize();
}

public abstract getOutboundRAMFAddress(): string;
public abstract getOutboundRAMFAddress(): Promise<string>;

protected async getNodePrivateAddress(): Promise<string> {
return getPrivateAddressFromIdentityKey(this.nodePrivateKey);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/GatewayChannel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class StubGatewayChannel extends GatewayChannel {
);
}

public getOutboundRAMFAddress(): string {
async getOutboundRAMFAddress(): Promise<string> {
return StubGatewayChannel.OUTBOUND_RAMF_ADDRESS;
}
}
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/GatewayChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class GatewayChannel extends Channel {
public async *generateCargoes(messages: CargoMessageStream): AsyncIterable<Buffer> {
const messagesAsArrayBuffers = convertBufferMessagesToArrayBuffer(messages);
const cargoMessageSets = CargoMessageSet.batchMessagesSerialized(messagesAsArrayBuffers);
const recipientAddress = this.getOutboundRAMFAddress();
const recipientAddress = await this.getOutboundRAMFAddress();
for await (const { messageSerialized, expiryDate } of cargoMessageSets) {
const creationDate = getCargoCreationTime();
const ttl = getSecondsBetweenDates(creationDate, expiryDate);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/nodes/channels/PrivateGatewayChannel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class StubPrivateGatewayChannel extends PrivateGatewayChannel {
);
}

public getOutboundRAMFAddress(): string {
async getOutboundRAMFAddress(): Promise<string> {
throw new Error('not implemented');
}
}
6 changes: 4 additions & 2 deletions src/lib/nodes/channels/PrivatePublicGatewayChannel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ beforeEach(() => {
);
});

test('getOutboundRAMFAddress should return public address of public gateway', () => {
expect(channel.getOutboundRAMFAddress()).toEqual(`https://${PUBLIC_GATEWAY_PUBLIC_ADDRESS}`);
test('getOutboundRAMFAddress should return public address of public gateway', async () => {
await expect(channel.getOutboundRAMFAddress()).resolves.toEqual(
`https://${PUBLIC_GATEWAY_PUBLIC_ADDRESS}`,
);
});

describe('Endpoint registration', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/nodes/channels/PrivatePublicGatewayChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PrivatePublicGatewayChannel extends PrivateGatewayChannel {
);
}

getOutboundRAMFAddress(): string {
async getOutboundRAMFAddress(): Promise<string> {
return `https://${this.publicGatewayPublicAddress}`;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ export class PrivatePublicGatewayChannel extends PrivateGatewayChannel {
const ccr = new CargoCollectionRequest(cargoDeliveryAuthorization);
const ccaPayload = await this.wrapMessagePayload(ccr);
const cca = new CargoCollectionAuthorization(
this.getOutboundRAMFAddress(),
await this.getOutboundRAMFAddress(),
this.nodeDeliveryAuth,
Buffer.from(ccaPayload),
{ creationDate: startDate, ttl: differenceInSeconds(endDate, startDate) },
Expand Down

0 comments on commit a53ad7d

Please sign in to comment.