2023-04-03 13:24:15 +00:00
|
|
|
import yaml from 'js-yaml'
|
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import semver from 'semver';
|
|
|
|
|
2023-03-24 11:32:38 +00:00
|
|
|
const { execSync } = require("child_process");
|
|
|
|
|
2023-04-03 13:24:15 +00:00
|
|
|
export const updateRecord = (filePath: string) => {
|
|
|
|
const resolvedFilePath = path.resolve(process.cwd(), filePath);
|
|
|
|
const file = fs.readFileSync(resolvedFilePath, 'utf-8')
|
|
|
|
const data = yaml.load(file) as any;
|
|
|
|
console.log("Data====",data)
|
|
|
|
|
|
|
|
data.record.version=semver.inc(data.record.version, 'patch');
|
|
|
|
|
|
|
|
fs.writeFileSync(resolvedFilePath, yaml.dump(data));
|
|
|
|
};
|
|
|
|
|
2023-03-24 11:32:38 +00:00
|
|
|
export const cliTest = (args: any) => {
|
2023-03-29 08:15:51 +00:00
|
|
|
try{
|
|
|
|
return JSON.parse(execSync(`./bin/laconic cns ${args}`));
|
|
|
|
}catch(err){
|
|
|
|
return(err)
|
|
|
|
}
|
2023-03-24 11:32:38 +00:00
|
|
|
};
|
2023-03-26 20:12:52 +00:00
|
|
|
|
|
|
|
export function createBond(type: string, quantity: string):string{
|
|
|
|
const resp=cliTest("bond create --type aphoton --quantity 1000000000");
|
2023-03-29 11:40:00 +00:00
|
|
|
expect(resp.bondId).toBeDefined();
|
|
|
|
return resp.bondId
|
2023-03-26 20:12:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function createRecord(filepath: string, bondId: string):string{
|
|
|
|
const resp=cliTest("record publish --filename "+filepath+" --bond-id "+bondId);
|
2023-03-29 11:40:00 +00:00
|
|
|
expect(resp.id).toBeDefined();
|
|
|
|
return resp.id
|
2023-03-26 20:12:52 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 18:19:16 +00:00
|
|
|
export function createAuthority(name:string):any{
|
2023-03-26 20:12:52 +00:00
|
|
|
const resp=cliTest("authority reserve "+name);
|
|
|
|
expect(resp).toBeDefined;
|
2023-03-31 18:19:16 +00:00
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
return resp
|
|
|
|
}
|
2023-03-26 20:12:52 +00:00
|
|
|
|
2023-03-31 18:19:16 +00:00
|
|
|
export function getAuctionId(name:string):string{
|
|
|
|
const jsonResp = cliTest("authority whois "+name)
|
2023-03-26 20:12:52 +00:00
|
|
|
expect(jsonResp).toBeDefined;
|
|
|
|
return jsonResp[0].auction.id
|
|
|
|
}
|