Skip to content

Commit

Permalink
chore(substrate): add more substrate fungible tests (#423)
Browse files Browse the repository at this point in the history
Closes #410
  • Loading branch information
Lykhoyda authored Sep 3, 2024
1 parent bb4f7b3 commit 4c7c098
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 149 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
module.exports = {
root: true,
extends: [
"@chainsafe",
"plugin:require-extensions/recommended"
],
plugins: [
"require-extensions"
]
}
extends: ["@chainsafe", "plugin:require-extensions/recommended"],
plugins: ["require-extensions"],
};
38 changes: 19 additions & 19 deletions examples/substrate-to-evm-fungible-transfer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"compilerOptions": {
"composite": true,
"module": "ES2022",
"allowJs": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
},
"include": [
"src"
]
"compilerOptions": {
"composite": true,
"module": "ES2022",
"allowJs": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
},
"include": [
"src"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"lint": "yarn workspaces foreach -A run lint",
"clean": "yarn workspaces foreach -A run clean",
"build": "yarn run clean && yarn workspaces foreach -A run build:all",
"build": "yarn run clean && yarn workspaces foreach -A -t run build:all",
"test": "yarn workspaces foreach -A run test:unit --ci --silent --coverage",
"core:build": "yarn workspace @buildwithsygma/core build:all",
"core:cleanDist": "yarn workspace @buildwithsygma/core clean",
Expand Down
8 changes: 3 additions & 5 deletions packages/core/src/baseTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from './config/config.js';
import type { Domainlike, EvmResource, Domain, SubstrateResource } from './types.js';
import type { Domain, Domainlike, EvmResource, SubstrateResource } from './types.js';

export interface BaseTransferParams {
source: Domainlike;
Expand All @@ -13,7 +13,6 @@ export abstract class BaseTransfer {
protected sourceDomain: Domain;
protected transferResource: EvmResource | SubstrateResource;
protected sygmaConfiguration: Config;

protected sourceAddress: string;

public get source(): Domain {
Expand Down Expand Up @@ -78,8 +77,7 @@ export abstract class BaseTransfer {
* @param destination
* @returns
*/
setDesinationDomain(destination: Domainlike): void {
const domain = this.config.getDomain(destination);
this.destinationDomain = domain;
setDestinationDomain(destination: Domainlike): void {
this.destinationDomain = this.config.getDomain(destination);
}
}
2 changes: 1 addition & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as process from 'node:process';

import { decodeAddress, encodeAddress } from '@polkadot/keyring';
import { hexToU8a, isHex } from '@polkadot/util';
import validate, { Network as BitcoinNetwork } from 'bitcoin-address-validation';
import { Network as BitcoinNetwork, validate } from 'bitcoin-address-validation';
import { ethers } from 'ethers';

import { ExplorerUrl, IndexerUrl } from './constants.js';
Expand Down
16 changes: 16 additions & 0 deletions packages/evm/src/__test__/fungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,20 @@ describe('Fungible - Deposit', () => {
'Insufficient ERC20 token balance',
);
});

it('should throw ERROR - Insufficient account balance', async () => {
(ERC20__factory.connect as jest.Mock).mockReturnValue({
balanceOf: jest.fn().mockResolvedValue(BigNumber.from(parseEther('1').toBigInt())), // Mock balance less than the required amount
populateTransaction: {
approve: jest.fn().mockResolvedValue({}),
},
allowance: jest.fn().mockResolvedValue(parseEther('0')),
});

const transfer = await createEvmFungibleAssetTransfer(TRANSFER_PARAMS);

await expect(transfer.getTransferTransaction()).rejects.toThrow(
'Insufficient ERC20 token balance',
);
});
});
Empty file removed packages/evm/src/baseTransfer.ts
Empty file.
Loading

0 comments on commit 4c7c098

Please sign in to comment.