This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ceceb7
commit 9fe727c
Showing
4 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
framework/test/unit/modules/interoperability/sidechain/endpoint.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
import { createTransientModuleEndpointContext } from '../../../../../src/testing'; | ||
import { SidechainInteroperabilityEndpoint } from '../../../../../src/modules/interoperability/sidechain/endpoint'; | ||
import { ModuleEndpointContext } from '../../../../../src'; | ||
|
||
describe('SidechainInteroperabilityEndpoint', () => { | ||
let endpoint: SidechainInteroperabilityEndpoint; | ||
|
||
const storesMock = {}; | ||
const offchainStoresMock = {}; | ||
|
||
beforeEach(() => { | ||
endpoint = new SidechainInteroperabilityEndpoint(storesMock as any, offchainStoresMock as any); | ||
}); | ||
|
||
describe('getMainchainID', () => { | ||
let context: ModuleEndpointContext; | ||
|
||
it('should throw error for chainID having less than 8 chars', () => { | ||
context = createTransientModuleEndpointContext({ | ||
params: { | ||
chainID: '1234', | ||
}, | ||
}); | ||
|
||
// https://stackoverflow.com/questions/47397208/error-is-thrown-but-jests-tothrow-does-not-capture-the-error | ||
expect(() => endpoint.getMainchainID(context)).toThrow( | ||
"Property '.chainID' must NOT have fewer than 8 characters", | ||
); | ||
}); | ||
|
||
it('should throw error for chainID having more than 8 chars', () => { | ||
context = createTransientModuleEndpointContext({ | ||
params: { | ||
chainID: '123456789', | ||
}, | ||
}); | ||
|
||
expect(() => endpoint.getMainchainID(context)).toThrow( | ||
"Property '.chainID' must NOT have more than 8 characters", | ||
); | ||
}); | ||
|
||
it('should return 00000000 for chainID 00123456', () => { | ||
context = createTransientModuleEndpointContext({ | ||
params: { | ||
chainID: '00123456', | ||
}, | ||
}); | ||
|
||
const { mainchainID } = endpoint.getMainchainID(context); | ||
expect(mainchainID).toBe('00000000'); | ||
}); | ||
|
||
it('should return 02000000 for chainID 02345678', () => { | ||
context = createTransientModuleEndpointContext({ | ||
params: { | ||
chainID: '02345678', | ||
}, | ||
}); | ||
|
||
const { mainchainID } = endpoint.getMainchainID(context); | ||
expect(mainchainID).toBe('02000000'); | ||
}); | ||
}); | ||
}); |