@api3/contracts
Version:
Contracts through which API3 services are delivered
74 lines • 4.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const node_child_process_1 = require("node:child_process");
const promise_utils_1 = require("@api3/promise-utils");
const CLI_EXECUTABLE = 'dist/src/cli.js';
describe('cli tests', () => {
const execCommand = (command, ...args) => {
const formattedCommand = [command, ...args.flatMap(([c, a]) => [c, String(a)])].join(' ');
const goExecSync = (0, promise_utils_1.goSync)(() => (0, node_child_process_1.execSync)(`node ${CLI_EXECUTABLE} ${formattedCommand}`, {
stdio: ['pipe', 'pipe', 'pipe'],
}));
if (!goExecSync.success) {
// rethrow the output of the CLI
throw new Error(goExecSync.error.reason.stderr.toString().trim());
}
const stdout = goExecSync.data?.toString().trim() || '';
return stdout;
};
it('should throw an error for an unknown chain id', () => {
expect(() => {
execCommand('compute-dapp-id', ['--dapp-alias', 'lendle'], ['--chain-id', '0']);
}).toThrow('⚠️ Chain with ID 0 is not known');
});
it('should throw an error for an unknown dApp alias', () => {
expect(() => {
execCommand('compute-dapp-id', ['--dapp-alias', 'unsupported-dapp'], ['--chain-id', '5000']);
}).toThrow('⚠️ Could not find any record for alias "unsupported-dapp"');
});
it('should throw an error for unsupported chain ID', () => {
expect(() => {
execCommand('compute-dapp-id', ['--dapp-alias', 'lendle'], ['--chain-id', '1']);
}).toThrow('⚠️ dApp alias "lendle" is not available on chain "Ethereum"');
});
it('should return an invalid output if strict is false', () => {
const output = execCommand('compute-dapp-id', ['--dapp-alias', 'unsupported-dapp'], ['--chain-id', '0'], ['--strict', false]);
expect(output).toMatch('dApp alias: unsupported-dapp\nchain: 0\n\n• dApp ID: 113044575011858809962820051290270246401920929513853405225169263442003318378526');
});
it('should compute dApp ID for lendle on mantle', () => {
const output = execCommand('compute-dapp-id', ['--dapp-alias', 'lendle'], ['--chain-id', '5000']);
expect(output).toMatch('dApp alias: lendle\nchain: Mantle\n\n• dApp ID: 3006187377348428698321862179080566497381498372321749245241868771911713393091');
});
it('should compute dApp ID for mach-finance on sonic', () => {
const output = execCommand('compute-dapp-id', ['--dapp-alias', 'mach-finance'], ['--chain-id', '146']);
expect(output).toMatch('dApp alias: mach-finance\nchain: Sonic\n\n• dApp ID: 103191103032841018751746810000516216875988320776131204933373404128958541332502');
});
it('should match help output', () => {
const output = execCommand('help');
expect(output).toMatchSnapshot();
});
it('should throw an error for an unknown chain id while checking Api3ReaderProxyV1 address', () => {
expect(() => {
execCommand('print-api3readerproxyv1-address', ['--dapp-alias', 'unsupported-dapp'], ['--chain-id', '0'], ['--dapi-name', 'ETH/USD']);
}).toThrow('Chain with ID 0 is not known');
});
it('should throw an error for an unknown dApp alias while checking Api3ReaderProxyV1 address', () => {
expect(() => {
execCommand('print-api3readerproxyv1-address', ['--dapp-alias', 'unsupported-dapp'], ['--chain-id', '5000'], ['--dapi-name', 'ETH/USD']);
}).toThrow('⚠️ Could not find any record for alias "unsupported-dapp"');
});
it('should throw an error for an unsupported dApi name', () => {
expect(() => {
execCommand('print-api3readerproxyv1-address', ['--dapp-alias', 'lendle'], ['--chain-id', '5000'], ['--dapi-name', 'UNSUPPORTED/USD']);
}).toThrow('⚠️ Attempted to read the feed and failed');
});
it('should succeed print-api3readerproxyv1-address on mantle', () => {
const output = execCommand('print-api3readerproxyv1-address', ['--dapp-alias', 'lendle'], ['--chain-id', '5000'], ['--dapi-name', 'ETH/USD']);
expect(output).toMatchSnapshot();
});
it('should succeed print-api3readerproxyv1-address on sonic', () => {
const output = execCommand('print-api3readerproxyv1-address', ['--dapp-alias', 'mach-finance'], ['--chain-id', '146'], ['--dapi-name', 'S/USD']);
expect(output).toMatchSnapshot();
});
});
//# sourceMappingURL=cli.test.js.map