bond tests
This commit is contained in:
parent
b7a8e7c234
commit
2ceb7d8483
@ -9,10 +9,10 @@ describe("test account",() => {
|
||||
it("get account should return account details",async ()=>{
|
||||
// send tokens to account to avoid account not found error
|
||||
const sendResp=cliTest("tokens send --address "+address+" --type "+type+" --quantity "+quantity)
|
||||
expect(sendResp).toBeDefined;
|
||||
expect(sendResp).toBeDefined();
|
||||
|
||||
const resp=cliTest(args+"get --address "+address);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp).toBeDefined();
|
||||
expect(resp[0].address).toEqual(address)
|
||||
});
|
||||
});
|
@ -1,7 +1,7 @@
|
||||
import {cliTest,createBond,createRecord} from './helper';
|
||||
|
||||
const args= "bond "
|
||||
const quantity="1000000000"
|
||||
const quantity=1000000000
|
||||
const refillQuantity=100
|
||||
const withdrawQuantity=100
|
||||
const type="aphoton"
|
||||
@ -13,72 +13,157 @@ var recordId: string;
|
||||
describe("test bond",() => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const resp=JSON.parse(cliTest("account get"));
|
||||
expect(resp).toBeDefined;
|
||||
const resp=cliTest("account get");
|
||||
expect(resp).toBeDefined();
|
||||
address=resp[0].address
|
||||
});
|
||||
|
||||
|
||||
it("create bond",async ()=>{
|
||||
const resp=cliTest(args+"create --type "+type+" --quantity "+quantity);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp.bondId).toBeDefined();
|
||||
bondId=resp.bondId
|
||||
});
|
||||
|
||||
it("list bond",async ()=>{
|
||||
const resp=cliTest(args+"list");
|
||||
bondId=JSON.parse(resp)[0].id
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp.length).toBeGreaterThan(0);
|
||||
const lenghtBefore=resp.length
|
||||
|
||||
createBond(type,quantity+"")
|
||||
|
||||
const respAfter=cliTest(args+"list");
|
||||
expect(respAfter.length-lenghtBefore).toEqual(1)
|
||||
|
||||
});
|
||||
|
||||
it("get bond",async ()=>{
|
||||
const resp=cliTest(args+"get --id "+bondId);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp.length).toEqual(1);
|
||||
expect(resp[0].id).toEqual(bondId);
|
||||
expect(Number(resp[0].balance[0].quantity)).toEqual(quantity);
|
||||
});
|
||||
|
||||
it("list bonds by owner",async ()=>{
|
||||
const resp=cliTest(args+"list --owner "+address);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp).toBeDefined();
|
||||
expect(resp.length).toBeGreaterThan(0);
|
||||
expect(resp[0].owner).toEqual(address);
|
||||
});
|
||||
|
||||
it("refill bond",async ()=>{
|
||||
const resp=cliTest(args+"refill --id "+bondId+" --type "+type+" --quantity "+refillQuantity);
|
||||
expect(resp).toBeDefined;
|
||||
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")
|
||||
});
|
||||
|
||||
it("withdraw funds from bond",async ()=>{
|
||||
const resp=cliTest(args+"withdraw --id "+bondId+" --type "+type+" --quantity "+withdrawQuantity);
|
||||
expect(resp).toBeDefined;
|
||||
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);
|
||||
});
|
||||
|
||||
it("cancel bond",async ()=>{
|
||||
const resp=cliTest(args+"cancel --id "+bondId);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp.success).toBeTruthy();
|
||||
|
||||
const getResp=cliTest(args+"get --id "+bondId);
|
||||
expect(getResp.length).toEqual(1);
|
||||
expect(getResp[0].id).toEqual("");
|
||||
});
|
||||
|
||||
it("associate bond with record",async ()=>{
|
||||
// get new bond Id
|
||||
bondId=createBond(type,quantity)
|
||||
bondId=createBond(type,quantity+"")
|
||||
// get record Id
|
||||
recordId=createRecord("./test/examples/watcher.yml",bondId)
|
||||
|
||||
const resp=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
||||
expect(resp).toBeDefined;
|
||||
// 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);
|
||||
});
|
||||
|
||||
it("dissociate bond from record",async ()=>{
|
||||
const resp=cliTest(args+"dissociate --id "+recordId);
|
||||
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("");
|
||||
});
|
||||
|
||||
it("dissociate all records from bond",async ()=>{
|
||||
// associate bond to record
|
||||
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
||||
expect(associate).toBeDefined;
|
||||
expect(associate.success).toBeTruthy();
|
||||
|
||||
const resp=cliTest(args+"records dissociate --bond-id "+bondId);
|
||||
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("");
|
||||
});
|
||||
|
||||
it("reassociate all records from bond",async ()=>{
|
||||
// TODO: get 2 bondids (old, new)
|
||||
// get new bondid
|
||||
const newBondId =createBond(type,quantity+"")
|
||||
|
||||
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+bondId);
|
||||
// associate bond to record
|
||||
const associate=cliTest(args+"associate --id "+recordId+" --bond-id "+bondId);
|
||||
expect(associate).toBeDefined;
|
||||
expect(associate.success).toBeTruthy();
|
||||
|
||||
const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-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);
|
||||
});
|
||||
});
|
@ -6,7 +6,7 @@ describe("test status",() => {
|
||||
|
||||
it("get status",async ()=>{
|
||||
const resp=cliTest(args);
|
||||
expect(resp).toBeDefined;
|
||||
expect(resp).toBeDefined();
|
||||
expect(resp.node.network).toContain("laconic")
|
||||
});
|
||||
});
|
@ -19,7 +19,7 @@ describe("test account",() => {
|
||||
|
||||
// send tokens to account
|
||||
const sendResp=cliTest(args+"send --address "+address+" --type "+type+" --quantity "+quantity)
|
||||
expect(sendResp).toBeDefined;
|
||||
expect(sendResp).toBeDefined();
|
||||
|
||||
// balance after
|
||||
var balanceAfter;
|
||||
|
Loading…
Reference in New Issue
Block a user