-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added tests and improved coverage for base transfer class in `…
…buildwithsygma/core` package (#502) ## Description added tests and improved coverage for base transfer class in `buildwithsygma/core` package Closes: #505 ## Related Issue Or Context - Added tests ## Types of changes - [X] Improved testing coverage (non-breaking change which fixes an issue) ## Checklist: - [x] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [X] I have added tests to cover my changes. - [X] I have ensured that all the checks are passing and green, I've signed the CLA bot
- Loading branch information
1 parent
3ddafe9
commit bb4f7b3
Showing
5 changed files
with
120 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export * from './baseTransfer.js'; | ||
export * from './config/config.js'; | ||
export * from './constants.js'; | ||
export * from './errors/customErrors.js'; | ||
export * from './types.js'; | ||
export * from './utils.js'; |
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,72 @@ | ||
import { enableFetchMocks } from 'jest-fetch-mock'; | ||
import { BaseTransfer, BaseTransferParams } from '../src/baseTransfer.js'; | ||
import { ConfigUrl } from '../src/constants.js'; | ||
import { Config, Environment, EvmResource, ResourceType } from '../src/index.js'; | ||
import { mockedDevnetConfig } from './constants.js'; | ||
|
||
enableFetchMocks(); | ||
|
||
const TRANSFER_PARAMS: BaseTransferParams = { | ||
source: 111, | ||
destination: 111, | ||
resource: '0x0000000000000000000000000000000000000000000000000000000000000000', | ||
sourceAddress: '0x00', | ||
}; | ||
|
||
class Transfer extends BaseTransfer { | ||
constructor(params: BaseTransferParams, config: Config) { | ||
super(params, config); | ||
} | ||
} | ||
|
||
describe('BaseTransfer', () => { | ||
let config: Config; | ||
|
||
beforeAll(async () => { | ||
jest.clearAllMocks(); | ||
fetchMock.resetMocks(); | ||
fetchMock.doMock(); | ||
fetchMock.mockIf(ConfigUrl.DEVNET.toString(), JSON.stringify(mockedDevnetConfig)); | ||
config = new Config(); | ||
await config.init(Environment.DEVNET); | ||
}); | ||
|
||
it('should be able to instantiate a transfer object', async () => { | ||
const transfer = new Transfer(TRANSFER_PARAMS, config); | ||
expect(transfer).toBeInstanceOf(Transfer); | ||
}); | ||
|
||
it('should not be able to instantiate a transfer object with an invalid domain', async () => { | ||
const config = new Config(); | ||
await config.init(Environment.DEVNET); | ||
|
||
expect(() => new Transfer({ ...TRANSFER_PARAMS, destination: 54 }, config)).toThrow( | ||
'Domain configuration not found.', | ||
); | ||
}); | ||
|
||
it('should be able to set resource', async () => { | ||
const config = new Config(); | ||
await config.init(Environment.DEVNET); | ||
const transfer = new Transfer(TRANSFER_PARAMS, config); | ||
|
||
const resource: EvmResource = { | ||
resourceId: '0x00', | ||
caip19: 'caip:id', | ||
type: ResourceType.FUNGIBLE, | ||
address: '0x00', | ||
}; | ||
|
||
transfer.setResource(resource); | ||
expect(transfer.resource.caip19).toEqual(resource.caip19); | ||
}); | ||
|
||
it('should be able to set destination domain', async () => { | ||
const config = new Config(); | ||
await config.init(Environment.DEVNET); | ||
const transfer = new Transfer(TRANSFER_PARAMS, config); | ||
|
||
transfer.setDesinationDomain('ethereum:1'); | ||
expect(transfer.destination).toBeTruthy(); | ||
}); | ||
}); |
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