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

Commit

Permalink
Add/update cross chain tests (#9007)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitetester committed Oct 2, 2023
1 parent 5c689a9 commit 79b8644
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ describe('BaseCrossChainUpdateCommand', () => {
.set(stateStore, params.sendingChainID, chainAccount);
});

it('should reject when ccu params validation fails', async () => {
const nonBufferSendingChainID = 2;
verifyContext = {
...verifyContext,
params: { ...params, sendingChainID: nonBufferSendingChainID } as any,
};

// 2nd param `isMainchain` could be false
await expect(command['verifyCommon'](verifyContext, false)).rejects.toThrow(
`Property '.sendingChainID' should pass "dataType" keyword validation`,
);
});

it('should call validator.validate with crossChainUpdateTransactionParams schema', async () => {
jest.spyOn(validator, 'validate');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('SubmitMainchainCrossChainUpdateCommand', () => {
});
});

it('should verify verifyCommon is called', async () => {
it('should check if verifyCommon is called', async () => {
jest.spyOn(mainchainCCUUpdateCommand, 'verifyCommon' as any);

await expect(mainchainCCUUpdateCommand.verify(verifyContext)).resolves.toEqual({
Expand All @@ -423,6 +423,23 @@ describe('SubmitMainchainCrossChainUpdateCommand', () => {
expect(mainchainCCUUpdateCommand['verifyCommon']).toHaveBeenCalled();
});

it('should call isLive with 3 params', async () => {
jest.spyOn(mainchainCCUUpdateCommand['internalMethod'], 'isLive');

await expect(
mainchainCCUUpdateCommand.verify({
...verifyContext,
params: { ...params } as any,
}),
).resolves.toEqual({ status: VerifyStatus.OK });

expect(mainchainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith(
verifyContext,
verifyContext.params.sendingChainID,
verifyContext.header.timestamp,
);
});

it(`should not verify liveness condition when sendingChainAccount.status == ${ChainStatus.REGISTERED} and inboxUpdate is empty`, async () => {
await expect(
mainchainCCUUpdateCommand.verify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => {
jest.spyOn(sidechainCCUUpdateCommand['internalMethod'], 'isLive').mockResolvedValue(true);
});

it('should verify verifyCommon is called', async () => {
it('should check if verifyCommon is called', async () => {
jest.spyOn(sidechainCCUUpdateCommand, 'verifyCommon' as any);

await expect(sidechainCCUUpdateCommand.verify(verifyContext)).resolves.toEqual({
Expand All @@ -313,15 +313,6 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => {
expect(sidechainCCUUpdateCommand['verifyCommon']).toHaveBeenCalled();
});

it('should reject when ccu params validation fails', async () => {
await expect(
sidechainCCUUpdateCommand.verify({
...verifyContext,
params: { ...params, sendingChainID: 2 } as any,
}),
).rejects.toThrow('.sendingChainID');
});

it('should call isLive with only 2 params', async () => {
jest.spyOn(sidechainCCUUpdateCommand['internalMethod'], 'isLive');

Expand All @@ -332,15 +323,16 @@ describe('SubmitSidechainCrossChainUpdateCommand', () => {
}),
).resolves.toEqual({ status: VerifyStatus.OK });

expect(sidechainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith(
expect(sidechainCCUUpdateCommand['internalMethod'].isLive).not.toHaveBeenCalledWith(
verifyContext,
verifyContext.params.sendingChainID,
verifyContext.header.timestamp,
);

expect(sidechainCCUUpdateCommand['internalMethod'].isLive).not.toHaveBeenCalledWith(
// should be tested later, otherwise, it can pass even if above fails
expect(sidechainCCUUpdateCommand['internalMethod'].isLive).toHaveBeenCalledWith(
verifyContext,
verifyContext.params.sendingChainID,
verifyContext.header.timestamp,
);
});
});
Expand Down

0 comments on commit 79b8644

Please sign in to comment.