Skip to content

Commit

Permalink
test(network): port assignment invariants (#9715)
Browse files Browse the repository at this point in the history
refs: #XXXX

## Description

This PR tests additional invariants related to port assignments. Namely:

* Automatic port assignment doesn't collide
* Custom port assignment can't intentionally collide with automatic port assignment (e.g. you can't squat an auto assigned port via a custom one)

### Security Considerations
This validates assumptions that may have security consequences if they break in the future.

### Scaling Considerations
N/A

### Documentation Considerations


### Testing Considerations
N/A

### Upgrade Considerations
N/A
  • Loading branch information
mergify[bot] authored Jul 17, 2024
2 parents 0889e20 + ee66fb4 commit c7a5fd7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/network/test/network-misc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,29 @@ test('verify port allocation', async t => {

const ibcPort = await when(portAllocator.allocateCustomIBCPort());
t.is(ibcPort.getLocalAddress(), '/ibc-port/port-1');
const ibcPort2 = await when(portAllocator.allocateCustomIBCPort());
t.not(
ibcPort.getLocalAddress(),
ibcPort2.getLocalAddress(),
'unique ports must not collide',
);
t.is(ibcPort2.getLocalAddress(), '/ibc-port/port-2');

const namedIbcPort = await when(
portAllocator.allocateCustomIBCPort('test-1'),
);
t.is(namedIbcPort.getLocalAddress(), '/ibc-port/custom-test-1');

const ibcDuplicatePort = await when(
portAllocator.allocateCustomIBCPort('port-1'),
);
t.not(
ibcPort.getLocalAddress(),
ibcDuplicatePort.getLocalAddress(),
'named ports should not collide with unique ports',
);
t.is(ibcDuplicatePort.getLocalAddress(), '/ibc-port/custom-port-1');

const icaControllerPort1 = await when(
portAllocator.allocateICAControllerPort(),
);
Expand All @@ -99,12 +116,21 @@ test('verify port allocation', async t => {
t.is(icaControllerPort2.getLocalAddress(), '/ibc-port/icacontroller-2');

const localPort = await when(portAllocator.allocateCustomLocalPort());
t.is(localPort.getLocalAddress(), '/local/port-5');
t.is(localPort.getLocalAddress(), '/local/port-7');

const namedLocalPort = await when(
portAllocator.allocateCustomLocalPort('local-1'),
);
t.is(namedLocalPort.getLocalAddress(), '/local/custom-local-1');
const namedDuplicatePort = await when(
portAllocator.allocateCustomLocalPort('port-7'),
);
t.not(
namedLocalPort.getLocalAddress(),
namedDuplicatePort.getLocalAddress(),
'named ports should not collide with unique ports',
);
t.is(namedDuplicatePort.getLocalAddress(), '/local/custom-port-7');

await t.throwsAsync(when(portAllocator.allocateCustomIBCPort('/test-1')), {
message: 'Invalid IBC port name: /test-1',
Expand Down

0 comments on commit c7a5fd7

Please sign in to comment.