Skip to content

Commit

Permalink
feat(network): add allocateICQControllerPort to PortAllocator
Browse files Browse the repository at this point in the history
- refs: #9072
  • Loading branch information
0xpatrickdev committed May 3, 2024
1 parent 5ef8daf commit 8450559
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -1463,11 +1463,12 @@ export const preparePortAllocator = (zone, { watch }) =>
.optional(M.string())
.returns(Shape.Vow$(Shape.Port)),
allocateICAControllerPort: M.callWhen().returns(Shape.Vow$(Shape.Port)),
allocateICQControllerPort: M.callWhen().returns(Shape.Vow$(Shape.Port)),
allocateCustomLocalPort: M.callWhen()
.optional(M.string())
.returns(Shape.Vow$(Shape.Port)),
}),
({ protocol }) => ({ protocol, lastICAPortNum: 0n }),
({ protocol }) => ({ protocol, lastICAPortNum: 0n, lastICQPortNum: 0n }),
{
allocateCustomIBCPort(specifiedName = '') {
const { state } = this;
Expand All @@ -1491,6 +1492,15 @@ export const preparePortAllocator = (zone, { watch }) =>
),
);
},
allocateICQControllerPort() {
const { state } = this;
state.lastICQPortNum += 1n;
return watch(
E(state.protocol).bindPort(
`/ibc-port/icqcontroller-${state.lastICQPortNum}`,
),
);
},
allocateCustomLocalPort(specifiedName = '') {
const { state } = this;

Expand Down
10 changes: 10 additions & 0 deletions packages/network/test/test-network-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ test('verify port allocation', async t => {
await t.throwsAsync(when(portAllocator.allocateCustomIBCPort('/test-1')), {
message: 'Invalid IBC port name: /test-1',
});

const icqControllerPort1 = await when(
portAllocator.allocateICQControllerPort(),
);
t.is(icqControllerPort1.getLocalAddress(), '/ibc-port/icqcontroller-1');

const icqControllerPort2 = await when(
portAllocator.allocateICQControllerPort(),
);
t.is(icqControllerPort2.getLocalAddress(), '/ibc-port/icqcontroller-2');
});

test('protocol connection listen', async t => {
Expand Down

0 comments on commit 8450559

Please sign in to comment.