Add tests for gas and fees config combinations
This commit is contained in:
parent
7e44af4026
commit
b7fde03bd4
@ -15,7 +15,8 @@ import {
|
||||
getRecordObj,
|
||||
getAuthorityObj,
|
||||
getAuctionObj,
|
||||
getBidObj
|
||||
getBidObj,
|
||||
updateGasAndFeesConfig
|
||||
} from './helpers';
|
||||
|
||||
describe('Test laconic CLI commands', () => {
|
||||
@ -585,5 +586,53 @@ describe('Test laconic CLI commands', () => {
|
||||
expect(resolveOutputObj.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Gas and fees config', () => {
|
||||
const bondAmount = 1000;
|
||||
|
||||
test('gas set, fees set to Xalnt', async () => {
|
||||
// gasPrice not set
|
||||
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
expect(outputObj.bondId).toBeDefined();
|
||||
|
||||
// gasPrice set (lower than min gas price)
|
||||
updateGasAndFeesConfig(undefined, undefined, '0.00001alnt');
|
||||
const result1 = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||
|
||||
const outputObj1 = checkResultAndRetrieveOutput(result1);
|
||||
expect(outputObj1.bondId).toBeDefined();
|
||||
});
|
||||
|
||||
test('gas not set, fees not set, gasPrice set', async () => {
|
||||
updateGasAndFeesConfig(null, null, '1alnt');
|
||||
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
expect(outputObj.bondId).toBeDefined();
|
||||
});
|
||||
|
||||
test('gas not set, fees set without token suffix, gasPrice set', async () => {
|
||||
updateGasAndFeesConfig(null, '1.8', '1alnt');
|
||||
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||
|
||||
const outputObj = checkResultAndRetrieveOutput(result);
|
||||
expect(outputObj.bondId).toBeDefined();
|
||||
});
|
||||
|
||||
test('gas not set, fees not set, gasPrice not set', async () => {
|
||||
updateGasAndFeesConfig(null, null, null);
|
||||
const result = spawnSync('laconic', ['registry', 'bond', 'create', '--type', TOKEN_TYPE, '--quantity', bondAmount.toString()]);
|
||||
|
||||
expect(result.status).toBe(1);
|
||||
|
||||
const output = result.stdout.toString().trim();
|
||||
const errorOutput = result.stderr.toString().trim();
|
||||
|
||||
expect(output).toBe('');
|
||||
expect(errorOutput).toContain('Gas price must be set in the client options when auto gas is used.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,10 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import { SpawnSyncReturns, spawnSync } from 'child_process';
|
||||
|
||||
import { getConfig } from '../src/util';
|
||||
|
||||
export const CHAIN_ID = 'laconic_9000-1';
|
||||
export const TOKEN_TYPE = 'alnt';
|
||||
|
||||
@ -118,3 +121,33 @@ export function getBidObj (params: { bidder: string, status?: string }): any {
|
||||
export async function delay (ms: number): Promise<any> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export function updateGasAndFeesConfig (gas?: string | null, fees?: string | null, gasPrice?: string | null): void {
|
||||
const configFilePath = './config.yml';
|
||||
const config = getConfig(path.resolve(configFilePath));
|
||||
|
||||
if (gas != null) {
|
||||
config.services.registry.gas = gas;
|
||||
} else if (gas === null) {
|
||||
delete config.services.registry.gas;
|
||||
}
|
||||
|
||||
if (fees != null) {
|
||||
config.services.registry.fees = fees;
|
||||
} else if (fees === null) {
|
||||
delete config.services.registry.fees;
|
||||
}
|
||||
|
||||
if (gasPrice != null) {
|
||||
config.services.registry.gasPrice = gasPrice;
|
||||
} else if (gasPrice === null) {
|
||||
delete config.services.registry.gasPrice;
|
||||
}
|
||||
|
||||
try {
|
||||
fs.writeFileSync(configFilePath, yaml.dump(config), 'utf8');
|
||||
} catch (e) {
|
||||
console.error('Error writing config file:', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user