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

Add/update cross chain tests #9007

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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