delete-me/test/bond.test.ts

84 lines
2.4 KiB
TypeScript
Raw Normal View History

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-26 20:12:52 +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 () => {
const resp=JSON.parse(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);
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 ()=>{
2023-03-26 20:12:52 +00:00
// get new bond Id
bondId=createBond(type,quantity)
// get record Id
recordId=createRecord("./test/examples/watcher.yml",bondId)
2023-03-24 11:32:38 +00:00
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 ()=>{
2023-03-26 20:12:52 +00:00
// TODO: get 2 bondids (old, new)
2023-03-24 11:32:38 +00:00
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+bondId);
expect(resp).toBeDefined;
});
});