Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Sending and receiving chains must differ. condition should run for …
Browse files Browse the repository at this point in the history
…both (mainchain & sidechain) cases
  • Loading branch information
sitetester committed Nov 17, 2023
1 parent 23f417d commit 7364be3
Showing 1 changed file with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -983,45 +983,56 @@ describe('BaseCrossChainUpdateCommand', () => {
}
});

it('should return error when receiving chain is the same as sending chain', () => {
const sendingChainID = chainID;
const ccm = {
crossChainCommand: CROSS_CHAIN_COMMAND_REGISTRATION,
fee: BigInt(0),
module: MODULE_NAME_INTEROPERABILITY,
nonce: BigInt(1),
params: utils.getRandomBytes(10),
// must be same as `context.chainID` to pass `!context.chainID.equals(ccm.receivingChainID)` check
receivingChainID: chainID,
// will fail for `Sending and receiving chains must differ`
sendingChainID: chainID,
status: CCMStatusCode.OK,
};

executeContext = createTransactionContext({
chainID: sendingChainID,
stateStore,
transaction: new Transaction({
...defaultTransaction,
command: command.name,
params: codec.encode(crossChainUpdateTransactionParams, {
...params,
inboxUpdate: {
...params.inboxUpdate,
crossChainMessages: [codec.encode(ccmSchema, ccm)],
},
// this is needed to pass `!ccm.sendingChainID.equals(params.sendingChainID)` check (previous test)
sendingChainID,
it.each([
['true', 1],
['false', 0],
])(
'should return error when receiving chain is the same as sending chain && isMainchain = %s',
(_s, isMainchain) => {
const sendingChainID = chainID;
const ccm = {
crossChainCommand: CROSS_CHAIN_COMMAND_REGISTRATION,
fee: BigInt(0),
module: MODULE_NAME_INTEROPERABILITY,
nonce: BigInt(1),
params: utils.getRandomBytes(10),
// must be same as `context.chainID` to pass `!context.chainID.equals(ccm.receivingChainID)` check
receivingChainID: chainID,
// will fail for `Sending and receiving chains must differ`
sendingChainID: chainID,
status: CCMStatusCode.OK,
};

executeContext = createTransactionContext({
chainID: sendingChainID,
stateStore,
transaction: new Transaction({
...defaultTransaction,
command: command.name,
params: codec.encode(crossChainUpdateTransactionParams, {
...params,
inboxUpdate: {
...params.inboxUpdate,
crossChainMessages: [codec.encode(ccmSchema, ccm)],
},
// this is needed to pass `!ccm.sendingChainID.equals(params.sendingChainID)` check (previous test)
sendingChainID,
}),
}),
}),
}).createCommandExecuteContext(command.schema);

try {
command['verifyRoutingRules'](ccm, executeContext.params, executeContext.chainID, false);
} catch (err: any) {
expect((err as Error).message).toBe('Sending and receiving chains must differ.');
}
});
}).createCommandExecuteContext(command.schema);

try {
command['verifyRoutingRules'](
ccm,
executeContext.params,
executeContext.chainID,
Boolean(isMainchain),
);
} catch (err: any) {
expect((err as Error).message).toBe('Sending and receiving chains must differ.');
}
},
);
});

describe('afterCrossChainMessagesExecution', () => {
Expand Down

0 comments on commit 7364be3

Please sign in to comment.