2023-03-26 20:12:52 +00:00
|
|
|
import {cliTest,createBond,createRecord} from './helper';
|
2023-03-24 11:32:38 +00:00
|
|
|
|
|
|
|
const args= "bond "
|
2023-03-29 11:40:16 +00:00
|
|
|
const quantity=1000000000
|
2023-03-24 11:32:38 +00:00
|
|
|
const refillQuantity=100
|
|
|
|
const withdrawQuantity=100
|
|
|
|
const type="aphoton"
|
|
|
|
|
|
|
|
var bondId: string;
|
|
|
|
var address: string;
|
|
|
|
var recordId: string;
|
|
|
|
|
|
|
|
describe("test bond",() => {
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2023-03-29 11:40:16 +00:00
|
|
|
const resp=cliTest("account get");
|
|
|
|
expect(resp).toBeDefined();
|
2023-03-26 20:12:52 +00:00
|
|
|
address=resp[0].address
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("create bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"create --type "+type+" --quantity "+quantity);
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.bondId).toBeDefined();
|
|
|
|
bondId=resp.bondId
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("list bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"list");
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.length).toBeGreaterThan(0);
|
|
|
|
const lenghtBefore=resp.length
|
|
|
|
|
|
|
|
createBond(type,quantity+"")
|
|
|
|
|
|
|
|
const respAfter=cliTest(args+"list");
|
|
|
|
expect(respAfter.length-lenghtBefore).toEqual(1)
|
|
|
|
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("get bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"get --id "+bondId);
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.length).toEqual(1);
|
|
|
|
expect(resp[0].id).toEqual(bondId);
|
|
|
|
expect(Number(resp[0].balance[0].quantity)).toEqual(quantity);
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("list bonds by owner",async ()=>{
|
|
|
|
const resp=cliTest(args+"list --owner "+address);
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp).toBeDefined();
|
|
|
|
expect(resp.length).toBeGreaterThan(0);
|
|
|
|
expect(resp[0].owner).toEqual(address);
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("refill bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"refill --id "+bondId+" --type "+type+" --quantity "+refillQuantity);
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp).toBeDefined();
|
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
const getResp=cliTest(args+"get --id "+bondId);
|
|
|
|
expect(getResp.length).toEqual(1);
|
|
|
|
expect(getResp[0].id).toEqual(bondId);
|
|
|
|
expect(Number(getResp[0].balance[0].quantity)).toEqual(quantity+refillQuantity);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("withdraw funds from bond, insufficient",async ()=>{
|
|
|
|
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity+quantity*2);
|
|
|
|
expect(resp.stderr).toBeDefined();
|
|
|
|
expect(resp.stderr.toString()).toContain("Insufficient bond balance.: insufficient funds")
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("withdraw funds from bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity);
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp).toBeDefined();
|
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
const getResp=cliTest(args+"get --id "+bondId);
|
|
|
|
expect(getResp.length).toEqual(1);
|
|
|
|
expect(getResp[0].id).toEqual(bondId);
|
|
|
|
expect(Number(getResp[0].balance[0].quantity)).toEqual(quantity+refillQuantity-withdrawQuantity);
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("cancel bond",async ()=>{
|
|
|
|
const resp=cliTest(args+"cancel --id "+bondId);
|
|
|
|
expect(resp).toBeDefined;
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
const getResp=cliTest(args+"get --id "+bondId);
|
|
|
|
expect(getResp.length).toEqual(1);
|
|
|
|
expect(getResp[0].id).toEqual("");
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("associate bond with record",async ()=>{
|
2023-03-26 20:12:52 +00:00
|
|
|
// get new bond Id
|
2023-03-29 11:40:16 +00:00
|
|
|
bondId=createBond(type,quantity+"")
|
2023-03-26 20:12:52 +00:00
|
|
|
// get record Id
|
|
|
|
recordId=createRecord("./test/examples/watcher.yml",bondId)
|
|
|
|
|
2023-03-29 11:40:16 +00:00
|
|
|
// dissociate bond from record
|
|
|
|
const dissociate=cliTest(args+"dissociate --id "+recordId);
|
|
|
|
expect(dissociate).toBeDefined;
|
|
|
|
expect(dissociate.success).toBeTruthy();
|
|
|
|
|
|
|
|
// get new bond Id
|
|
|
|
const newbondId=createBond(type,quantity+"")
|
|
|
|
|
|
|
|
const resp=cliTest(args+"associate --id "+recordId+" --bond-id "+newbondId);
|
|
|
|
expect(resp).toBeDefined();
|
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
// check for bond id in record
|
|
|
|
const getRecord=cliTest(" record get --id "+recordId)
|
|
|
|
expect(getRecord).toBeDefined();
|
|
|
|
expect(getRecord.length).toEqual(1);
|
|
|
|
expect(getRecord[0].id).toEqual(recordId);
|
|
|
|
expect(getRecord[0].bondId).toEqual(newbondId);
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("dissociate bond from record",async ()=>{
|
|
|
|
const resp=cliTest(args+"dissociate --id "+recordId);
|
|
|
|
expect(resp).toBeDefined;
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
// check for bond id in record
|
|
|
|
const getRecord=cliTest(" record get --id "+recordId)
|
|
|
|
expect(getRecord).toBeDefined();
|
|
|
|
expect(getRecord.length).toEqual(1);
|
|
|
|
expect(getRecord[0].id).toEqual(recordId);
|
|
|
|
expect(getRecord[0].bondId).toEqual("");
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("dissociate all records from bond",async ()=>{
|
2023-03-29 11:40:16 +00:00
|
|
|
// associate bond to record
|
|
|
|
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
|
|
|
expect(associate).toBeDefined;
|
|
|
|
expect(associate.success).toBeTruthy();
|
|
|
|
|
2023-03-24 11:32:38 +00:00
|
|
|
const resp=cliTest(args+"records dissociate --bond-id "+bondId);
|
|
|
|
expect(resp).toBeDefined;
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
// check for bond id in record
|
|
|
|
const getRecord=cliTest(" record get --id "+recordId)
|
|
|
|
expect(getRecord).toBeDefined();
|
|
|
|
expect(getRecord.length).toEqual(1);
|
|
|
|
expect(getRecord[0].id).toEqual(recordId);
|
|
|
|
expect(getRecord[0].bondId).toEqual("");
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("reassociate all records from bond",async ()=>{
|
2023-03-29 11:40:16 +00:00
|
|
|
// get new bondid
|
|
|
|
const newBondId =createBond(type,quantity+"")
|
|
|
|
|
|
|
|
// associate bond to record
|
|
|
|
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
|
|
|
expect(associate).toBeDefined;
|
|
|
|
expect(associate.success).toBeTruthy();
|
2023-03-26 20:12:52 +00:00
|
|
|
|
2023-03-29 11:40:16 +00:00
|
|
|
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+newBondId);
|
2023-03-24 11:32:38 +00:00
|
|
|
expect(resp).toBeDefined;
|
2023-03-29 11:40:16 +00:00
|
|
|
expect(resp.success).toBeTruthy();
|
|
|
|
|
|
|
|
// check for bond id in record
|
|
|
|
const getRecord=cliTest(" record get --id "+recordId)
|
|
|
|
expect(getRecord).toBeDefined();
|
|
|
|
expect(getRecord.length).toEqual(1);
|
|
|
|
expect(getRecord[0].id).toEqual(recordId);
|
|
|
|
expect(getRecord[0].bondId).toEqual(newBondId);
|
2023-03-24 11:32:38 +00:00
|
|
|
});
|
|
|
|
});
|