unit tests

This commit is contained in:
0xmuralik
2023-03-24 17:02:38 +05:30
parent 495bbfdb3c
commit 84df789ccd
9 changed files with 2284 additions and 257 deletions
+12
View File
@@ -0,0 +1,12 @@
import {cliTest} from './helper';
const args= "account "
export var address=""
describe("test account",() => {
it("get account should return account details",async ()=>{
const resp=JSON.parse(cliTest(args+"get"));
expect(resp).toBeDefined;
address=resp[0].address
});
});
+11
View File
@@ -0,0 +1,11 @@
import {cliTest} from './helper';
const args= "auction "
describe("test auction",() => {
it("bid commit",async ()=>{
// const resp=JSON.parse(cliTest(args+" bid commit"));
// expect(resp).toBeDefined;
expect(0).toEqual(0);
});
});
+80
View File
@@ -0,0 +1,80 @@
import {cliTest} from './helper';
const args= "bond "
const quantity=1000000000
const refillQuantity=100
const withdrawQuantity=100
const type="aphoton"
var bondId: string;
var address: string;
var recordId: string;
describe("test bond",() => {
beforeAll(async () => {
const resp=JSON.parse(cliTest("account get"));
expect(resp).toBeDefined;
address=resp[0].address
// get 2 bondids (old, new)
// get record id
});
it("create bond",async ()=>{
const resp=cliTest(args+"create --type "+type+" --quantity "+quantity);
expect(resp).toBeDefined;
});
it("list bond",async ()=>{
const resp=cliTest(args+"list");
bondId=JSON.parse(resp)[0].id
expect(resp).toBeDefined;
});
it("get bond",async ()=>{
const resp=cliTest(args+"get --id "+bondId);
expect(resp).toBeDefined;
});
it("list bonds by owner",async ()=>{
const resp=cliTest(args+"list --owner "+address);
expect(resp).toBeDefined;
});
it("refill bond",async ()=>{
const resp=cliTest(args+"refill --id "+bondId+" --type "+type+" --quantity "+refillQuantity);
expect(resp).toBeDefined;
});
it("withdraw funds from bond",async ()=>{
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity);
expect(resp).toBeDefined;
});
it("cancel bond",async ()=>{
const resp=cliTest(args+"cancel --id "+bondId);
expect(resp).toBeDefined;
});
it("associate bond with record",async ()=>{
const resp=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
expect(resp).toBeDefined;
});
it("dissociate bond from record",async ()=>{
const resp=cliTest(args+"dissociate --id "+recordId);
expect(resp).toBeDefined;
});
it("dissociate all records from bond",async ()=>{
const resp=cliTest(args+"records dissociate --bond-id "+bondId);
expect(resp).toBeDefined;
});
it("reassociate all records from bond",async ()=>{
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+bondId);
expect(resp).toBeDefined;
});
});
+5
View File
@@ -0,0 +1,5 @@
const { execSync } = require("child_process");
export const cliTest = (args: any) => {
return execSync(`./bin/laconic cns ${args}`).toString();
};
+34
View File
@@ -0,0 +1,34 @@
import {cliTest} from './helper';
const args= "name "
var recordId: string;
var name: string;
describe("test names",() => {
beforeAll(async () => {
// get record id
});
it("set name",async ()=>{
const resp=cliTest(args+"set "+name+" "+recordId);
expect(resp).toBeDefined;
});
it("lookup name",async ()=>{
const resp=cliTest(args+"lookup "+ name);
expect(resp).toBeDefined;
});
it("resolve name",async ()=>{
const resp=cliTest(args+"resolve "+name);
expect(resp).toBeDefined;
});
it("delelte name",async ()=>{
const resp=cliTest(args+"delete "+name);
expect(resp).toBeDefined;
});
});
+29
View File
@@ -0,0 +1,29 @@
import {cliTest} from './helper';
const args= "record "
var recordId: string;
var filename: string;
var bondId: string;
describe("test names",() => {
beforeAll(async () => {
// get bond id
});
it("publish record",async ()=>{
const resp=cliTest(args+"publish --filename "+filename+" --bond-id "+bondId);
expect(resp).toBeDefined;
});
it("get record",async ()=>{
const resp=cliTest(args+"get --id "+recordId);
expect(resp).toBeDefined;
});
it("list records",async ()=>{
const resp=cliTest(args+"list");
expect(resp).toBeDefined;
});
});