@api3/contracts
Version:
Contracts through which API3 services are delivered
114 lines • 3.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const types_1 = require("./types");
describe('chainSchema', () => {
const validChain = {
alias: 'ethereum',
decimals: 18,
explorer: {
api: {
key: {
hardhatEtherscanAlias: 'mainnet',
required: true,
},
url: 'https://api.etherscan.io/api',
},
browserUrl: 'https://etherscan.io/',
},
id: '1',
name: 'Ethereum',
providers: [
{
alias: 'default',
rpcUrl: 'https://cloudflare-eth.com',
},
],
symbol: 'ETH',
testnet: false,
};
it('should accept a valid chain', () => {
expect(() => types_1.chainSchema.parse(validChain)).not.toThrow();
});
it('should accept a symbol of 6 characters or less', () => {
const validChainWithSymbol = {
...validChain,
symbol: 'ABCDEF',
};
expect(() => types_1.chainSchema.parse(validChainWithSymbol)).not.toThrow();
});
it('should reject an empty symbol', () => {
const invalidChain = {
...validChain,
symbol: '',
};
expect(() => types_1.chainSchema.parse(invalidChain)).toThrow(zod_1.z.ZodError);
});
it('should reject a symbol longer than 6 characters', () => {
const invalidChain = {
...validChain,
symbol: 'ABCDEFG',
};
expect(() => types_1.chainSchema.parse(invalidChain)).toThrow(zod_1.z.ZodError);
});
});
describe('chainAlias', () => {
it('should accept valid chain aliases', () => {
expect(() => types_1.chainAlias.parse('ethereum')).not.toThrow();
expect(() => types_1.chainAlias.parse('bsc')).not.toThrow();
expect(() => types_1.chainAlias.parse('mantle')).not.toThrow();
});
it('should reject chain aliases not in the CHAINS array', () => {
expect(() => types_1.chainAlias.parse('Mantle')).toThrow(new zod_1.ZodError([
{
validation: 'regex',
code: 'invalid_string',
message: 'Invalid',
path: [],
},
{
code: 'custom',
message: 'Invalid chain alias: Mantle',
path: [],
},
]));
expect(() => types_1.chainAlias.parse('ethereum-mainnet')).toThrow(new zod_1.ZodError([
{
code: 'custom',
message: 'Invalid chain alias: ethereum-mainnet',
path: [],
},
]));
});
});
describe('dappSchema', () => {
it('accepts valid chain IDs and throws on invalid ones', () => {
const validChainsDapp = {
aliases: {
'valid-chains': {
chains: ['ethereum', 'bsc', 'polygon'],
title: 'Valid Chains DApp',
},
},
homepageUrl: 'https://example.com',
};
expect(() => types_1.dappSchema.parse(validChainsDapp)).not.toThrow();
const invalidChainsDapp = {
aliases: {
'invalid-chains': {
chains: ['ethereum', 'invalid-chain', 'polygon'],
title: 'Invalid Chains DApp',
},
},
homepageUrl: 'https://example.com',
};
expect(() => types_1.dappSchema.parse(invalidChainsDapp)).toThrow(new zod_1.ZodError([
{
code: 'custom',
message: 'Invalid chain alias: invalid-chain',
path: ['aliases', 'invalid-chains', 'chains', 1],
},
]));
});
});
//# sourceMappingURL=types.test.js.map