Skip to content

Commit

Permalink
test(orchestration): greater async fidelity and tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 5, 2024
1 parent 5b22805 commit a884285
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ test.serial(
{ version: 'ics27-2', ordering: 'unordered', encoding: 'json' },
);

await eventLoopIteration(); // propagate channelOpenAck
const { bridgeEvents: bridgeEvents0, bridgeDowncalls: bridgeDowncalls0 } =
await inspectDibcBridge();

Expand All @@ -278,7 +279,8 @@ test.serial(
const { event, ...channelInfo } = bridgeEvents0[0];
// simulate channel closing from remote chain
await E(ibcBridge).fromBridge(buildChannelCloseConfirmEvent(channelInfo));
await eventLoopIteration();
await eventLoopIteration(); // To propagate channelCloseConfirm
await eventLoopIteration(); // To propagate automatic channelOpenInit

const { bridgeEvents: bridgeEvents1, bridgeDowncalls: bridgeDowncalls1 } =
await inspectDibcBridge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ test('make accounts, register tap, return invitationMakers', async t => {
'tokens transferred from LOA to COA',
);
await transmitTransferAck();
await eventLoopIteration(); // propagate the ack
const { acknowledgement } = (await inspectDibcBridge()).bridgeEvents.at(
-1,
) as IBCEvent<'acknowledgementPacket'>;
Expand Down
40 changes: 22 additions & 18 deletions packages/orchestration/test/network-fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ibcBridgeMocks: {
) => IBCEvent<'channelOpenAck'>
: T extends 'acknowledgementPacket'
? (
obj: IBCMethod<'sendPacket'>,
obj: IBCEvent<'sendPacket'>,
opts: { sequence: bigint; acknowledgement: string },
) => IBCEvent<'acknowledgementPacket'>
: never;
Expand Down Expand Up @@ -102,13 +102,11 @@ export const ibcBridgeMocks: {
address: mockChainAddress,
}),
connectionHops: obj.hops,
order: obj.order,
version: obj.version,
};
},

acknowledgementPacket: (
obj: IBCMethod<'sendPacket'>,
obj: IBCEvent<'sendPacket'>,
opts: { sequence: bigint; acknowledgement: string },
): IBCEvent<'acknowledgementPacket'> => {
const { sequence, acknowledgement } = opts;
Expand Down Expand Up @@ -236,19 +234,23 @@ export const makeFakeIBCBridge = (
: `${bech32Prefix}1test`;
addressMap.set(addressKey, mockChainAddress);
}
const ackEvent = ibcBridgeMocks.channelOpenAck(obj, {
mockChainAddress,
channelID: `channel-${channelCount}`,
counterpartyChannelID: `channel-${connectionChannelCount}`,
const channelID = `channel-${channelCount}` as const;

setImmediate(() => {
const ackEvent = ibcBridgeMocks.channelOpenAck(obj, {
mockChainAddress,
channelID,
counterpartyChannelID: `channel-${connectionChannelCount}`,
});
bridgeHandler?.fromBridge(ackEvent);
bridgeEvents = bridgeEvents.concat(ackEvent);
channelCount += 1;
if (obj.packet.source_port.includes('icacontroller')) {
icaAccountCount += 1;
}
remoteChannelMap[obj.hops[0]] = connectionChannelCount + 1;
});
bridgeHandler?.fromBridge(ackEvent);
bridgeEvents = bridgeEvents.concat(ackEvent);
channelCount += 1;
if (obj.packet.source_port.includes('icacontroller')) {
icaAccountCount += 1;
}
remoteChannelMap[obj.hops[0]] = connectionChannelCount + 1;
return undefined;
return channelID;
}
case 'sendPacket': {
const mockAckMapHasData = obj.packet.data in mockAckMap;
Expand All @@ -274,9 +276,11 @@ export const makeFakeIBCBridge = (
? mockAckMap[obj.packet.data]
: errorAcknowledgments.error5,
});
bridgeEvents = bridgeEvents.concat(ackEvent);
ibcSequenceNonce += 1n;
bridgeHandler?.fromBridge(ackEvent);
setImmediate(() => {
bridgeEvents = bridgeEvents.concat(ackEvent);
bridgeHandler?.fromBridge(ackEvent);
});
return ackEvent.packet;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/test/utils/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test('findAddressField', t => {
'/ibc-hop/connection-0/ibc-port/icahost/ordered/{"version":"ics27-1","controller_connection_id":"connection-0","host_connection_id":"connection-1","address":"osmo1m30khedzqy9msu4502u74ugmep30v69pzee370jkas57xhmjfgjqe67ayq","encoding":"proto3","tx_type":"sdk_multi_msg"}/ibc-channel/channel-1',
),
'osmo1m30khedzqy9msu4502u74ugmep30v69pzee370jkas57xhmjfgjqe67ayq',
'returns address when localAddrr is appended to version string',
'returns address when localAddr is appended to version string',
);
t.is(
findAddressField(
Expand Down Expand Up @@ -103,7 +103,7 @@ test('makeICQChannelAddress', t => {
),
{
message:
/must be '\(\/ibc-hop\/CONNECTION\)\*\/ibc-port\/PORT\/\(ordered\|unordered\)\/VERSION'/,
/must be '\(\/ibc-hop\/CONNECTION\)\*\/ibc-port\/PORT\/\(pipelining\/\(true|false\)\/\)?\(ordered\|unordered\)\/VERSION'/,
},
'makeICQChannelAddress not hardened against malformed version. use `validateRemoteIbcAddress` to detect this, or expect IBC ProtocolImpl to throw',
);
Expand Down

0 comments on commit a884285

Please sign in to comment.