Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix type issues in tests
  • Loading branch information
alexandre-abrioux committed Feb 20, 2024
commit 5cefa05c446c2a44689080fc307b1079f4eb7ccc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency';
import { ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import { ChainTypes, ExtensionTypes, RequestLogicTypes } from '@requestnetwork/types';
import AddressBasedPaymentNetwork from '../../../src/extensions/payment-network/address-based';
import { ChainManager } from '@requestnetwork/chain';

describe('extensions/payment-network/address-based', () => {
it('address validation should throw when using unsupported currency type', () => {
Expand Down Expand Up @@ -37,7 +38,11 @@ describe('extensions/payment-network/address-based', () => {
super(CurrencyManager.getDefault(), extensionId, currentVersion, supportedCurrencyType);
}
public testIsValidAddress() {
this.isValidAddressForSymbolAndNetwork('test', 'test', 'mainnet');
this.isValidAddressForSymbolAndNetwork(
'test',
'test',
ChainManager.current().fromName('mainnet', [ChainTypes.ECOSYSTEM.EVM]),
);
}
}
expect(() => {
Expand Down
1 change: 0 additions & 1 deletion packages/chain/src/chains/chain-abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export abstract class ChainAbstract implements ChainTypes.IChainCommon {
) {
this.name = this.name.toLowerCase();
}

public eq(chain: ChainTypes.IChain): boolean {
return this === chain || (this.ecosystem === chain.ecosystem && this.id === chain.id);
}
Expand Down
39 changes: 0 additions & 39 deletions packages/chain/test/chain-utils.test.ts

This file was deleted.

50 changes: 50 additions & 0 deletions packages/chain/test/chain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import EvmEcosystem from '../src/chains/evm/evm-ecosystem';
import { ChainManager } from '../src';
import { ChainTypes } from '@requestnetwork/types';
import NearEcosystem from '../src/chains/near/near-ecosystem';

describe('chain equality', () => {
it('Should return true for 2 identical EVMs', () => {
const chain1 = ChainManager.current().fromName('arbitrum-one', [ChainTypes.ECOSYSTEM.EVM]);
const chain2 = ChainManager.current().fromName('arbitrum-one', [ChainTypes.ECOSYSTEM.EVM]);
expect(chain1.eq(chain2)).toBe(true);
});
it('Should return false for 2 different EVMs', () => {
const chain1 = ChainManager.current().fromName('mainnet', [ChainTypes.ECOSYSTEM.EVM]);
const chain2 = ChainManager.current().fromName('arbitrum-one', [ChainTypes.ECOSYSTEM.EVM]);
expect(chain1.eq(chain2)).toBe(false);
});
// FIXME: get rid of all aurora alias and mentions
it('Should return true for 2 identical NEAR', () => {
const chain1 = ChainManager.current().fromName('aurora-testnet', [ChainTypes.ECOSYSTEM.NEAR]);
const chain2 = ChainManager.current().fromName('near-testnet', [ChainTypes.ECOSYSTEM.NEAR]);
expect(chain1.eq(chain2)).toBe(true);
});
it('Should return false for 2 different chains on 2 different ecosystems', () => {
const chain2 = ChainManager.current().fromName('arbitrum-one', [ChainTypes.ECOSYSTEM.EVM]);
const chain1 = ChainManager.current().fromName('aurora-testnet', [ChainTypes.ECOSYSTEM.NEAR]);
expect(chain1.eq(chain2)).toBe(false);
});
});

describe('ecosystem isChainSupported', () => {
describe('NearEcosystem', () => {
it('returns true for near', () => {
expect(NearEcosystem.isChainSupported('near')).toEqual(true);
});
it('returns true for aurora', () => {
expect(NearEcosystem.isChainSupported('aurora')).toEqual(true);
});
it('returns false for mainnet', () => {
expect(NearEcosystem.isChainSupported('mainnet')).toEqual(false);
});
});
describe('EvmEcosystem', () => {
it('returns true for mainnet', () => {
expect(EvmEcosystem.isChainSupported('mainnet')).toEqual(true);
});
it('returns false for near', () => {
expect(EvmEcosystem.isChainSupported('near')).toEqual(false);
});
});
});