Skip to content

Commit

Permalink
chore: added tests and improved coverage for base transfer class in `…
Browse files Browse the repository at this point in the history
…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
saadahmsiddiqui authored Aug 29, 2024
1 parent 3ddafe9 commit bb4f7b3
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 19 deletions.
17 changes: 0 additions & 17 deletions packages/core/src/errors/customErrors.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/index.ts
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';
72 changes: 72 additions & 0 deletions packages/core/test/baseTransfer.test.ts
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();
});
});
40 changes: 40 additions & 0 deletions packages/core/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,45 @@ export const mockedDevnetConfig = {
},
],
},
{
chainId: 222,
id: 221,
caipId: 'ethereum:1',
name: 'ethereum:1',
type: 'evm',
bridge: '0xb36C801f644908bAAe89b7C28ad57Af18638A6a9',
handlers: [
{
type: 'erc20',
address: '0xAf2DB8059Bd69ba9Ac4c59D25de1C87931e62448',
},
],
parachainId: undefined,
nativeTokenSymbol: 'eth',
nativeTokenFullName: 'ether',
nativeTokenDecimals: 18,
blockConfirmations: 5,
startBlock: 7225328,
feeHandlers: [
{
address: '0x81bbFC4aC5E731d9EAdb749a7e7A6E973CF7E399',
type: 'basic',
},
{
address: '0xF5703Fcf2bfFC33625857D8ae8994b3260AA3c1f',
type: 'oracle',
},
],
resources: [
{
resourceId: '0x0000000000000000000000000000000000000000000000000000000000000000',
caip19: 'caip19',
type: 'erc20',
address: '0x3D151A97A446C9ea6893038e7C0db73466f3f3af',
symbol: 'ERC20TST',
decimals: 18,
},
],
},
],
};
9 changes: 8 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
},
"references": [
{ "path": "packages/core" },
{ "path": "packages/evm" },
{ "path": "packages/substrate" },
{ "path": "packages/utils" }
],
"exclude": ["**/node_modules/**"]
}

0 comments on commit bb4f7b3

Please sign in to comment.