diff --git a/test/auction.test.ts b/test/auction.test.ts index fec2b8a..976f3e2 100644 --- a/test/auction.test.ts +++ b/test/auction.test.ts @@ -1,11 +1,33 @@ -import {cliTest} from './helper'; +import {cliTest,createAuthority} from './helper'; -const args= "auction " +const args= "auction "; +const quantity=25000000 +const type="aphoton" + + +var auctionId: string; +var filepath: string; describe("test auction",() => { + beforeAll(async () => { + // get auction id + auctionId = createAuthority("laconic-auction") + }); + it("bid commit",async ()=>{ - // const resp=JSON.parse(cliTest(args+" bid commit")); - // expect(resp).toBeDefined; - expect(0).toEqual(0); + const resp=JSON.parse(cliTest(args+"bid commit "+auctionId+" "+quantity+" "+type)); + expect(resp).toBeDefined; + + filepath = resp.substring(resp.indexOf("./out")) + }); + + it("bid reveal", async ()=>{ + const resp=JSON.parse(cliTest(args+"bid reveal "+auctionId+" "+filepath)); + expect(resp).toBeDefined; + }); + + it("get auction",async ()=>{ + const resp=JSON.parse(cliTest(args+"get "+auctionId)); + expect(resp).toBeDefined; }); }); \ No newline at end of file diff --git a/test/authority.test.ts b/test/authority.test.ts new file mode 100644 index 0000000..a362061 --- /dev/null +++ b/test/authority.test.ts @@ -0,0 +1,31 @@ +import {cliTest,createBond} from './helper'; + +const args= "authority " + +var bondId: string; +var name: string; + +describe("test authority",() => { + + beforeAll(async () => { + // get bond id + bondId=createBond("aphoton","1000000000") + }); + + + it("reserve authority",async ()=>{ + name="laconic" + const resp=cliTest(args+"reserve "+name); + expect(resp).toBeDefined; + }); + + it("lookup authority information.",async ()=>{ + const resp=cliTest(args+"whois "+ name); + expect(resp).toBeDefined; + }); + + it("set authority bond",async ()=>{ + const resp=cliTest(args+"bond set "+name+" "+bondId); + expect(resp).toBeDefined; + }); +}); \ No newline at end of file diff --git a/test/bond.test.ts b/test/bond.test.ts index fbacb11..b76629e 100644 --- a/test/bond.test.ts +++ b/test/bond.test.ts @@ -1,7 +1,7 @@ -import {cliTest} from './helper'; +import {cliTest,createBond,createRecord} from './helper'; const args= "bond " -const quantity=1000000000 +const quantity="1000000000" const refillQuantity=100 const withdrawQuantity=100 const type="aphoton" @@ -15,10 +15,7 @@ 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 + address=resp[0].address }); @@ -59,6 +56,11 @@ describe("test bond",() => { }); it("associate bond with record",async ()=>{ + // get new bond Id + 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; }); @@ -74,6 +76,8 @@ describe("test bond",() => { }); it("reassociate all records from bond",async ()=>{ + // TODO: get 2 bondids (old, new) + const resp=cliTest(args+"records reassociate --old-bond-id "+bondId+" --new-bond-id "+bondId); expect(resp).toBeDefined; }); diff --git a/test/examples/watcher.yml b/test/examples/watcher.yml new file mode 100644 index 0000000..58502aa --- /dev/null +++ b/test/examples/watcher.yml @@ -0,0 +1,7 @@ +record: + type: WebsiteRegistrationRecord + url: 'https://cerc.io' + repo_registration_record_cid: QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D + build_artifact_cid: QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9 + tls_cert_cid: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR + version: 1.0.35 diff --git a/test/helper.ts b/test/helper.ts index efa06a4..1961442 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -3,3 +3,30 @@ const { execSync } = require("child_process"); export const cliTest = (args: any) => { return execSync(`./bin/laconic cns ${args}`).toString(); }; + +export function createBond(type: string, quantity: string):string{ + const resp=cliTest("bond create --type aphoton --quantity 1000000000"); + expect(resp).toBeDefined; + + // refactor to get bondId from create resp + const list=cliTest("bond list"); + const bondId=JSON.parse(list)[0].id + expect(resp).toBeDefined; + return bondId +}; + +export function createRecord(filepath: string, bondId: string):string{ + const resp=cliTest("record publish --filename "+filepath+" --bond-id "+bondId); + const recordId = resp.substring(resp.indexOf(":")+3,resp.indexOf("}")-2) + return recordId +} + +export function createAuthority(name:string):string{ + const resp=cliTest("authority reserve "+name); + expect(resp).toBeDefined; + + const jsonResp = JSON.parse(cliTest("authority whois "+name)) + expect(jsonResp).toBeDefined; + + return jsonResp[0].auction.id +} \ No newline at end of file diff --git a/test/name.test.ts b/test/name.test.ts index 73b37eb..f26c070 100644 --- a/test/name.test.ts +++ b/test/name.test.ts @@ -1,4 +1,4 @@ -import {cliTest} from './helper'; +import {cliTest,createBond,createRecord} from './helper'; const args= "name " @@ -8,7 +8,11 @@ var name: string; describe("test names",() => { beforeAll(async () => { + // get bond id + const bondId = createBond("aphoton","10000000") + // get record id + recordId=createRecord("./test/examples/watcher.yml",bondId) }); diff --git a/test/record.test.ts b/test/record.test.ts index fecdd72..eb5555d 100644 --- a/test/record.test.ts +++ b/test/record.test.ts @@ -1,15 +1,16 @@ -import {cliTest} from './helper'; +import {cliTest,createBond} from './helper'; const args= "record " +const filename = "./test/examples/watcher.yml" var recordId: string; -var filename: string; var bondId: string; -describe("test names",() => { +describe("test record",() => { beforeAll(async () => { - // get bond id + // get bondId + bondId=createBond("aphoton","1000000000") }); it("publish record",async ()=>{ diff --git a/test/status.test.ts b/test/status.test.ts new file mode 100644 index 0000000..28d6bd9 --- /dev/null +++ b/test/status.test.ts @@ -0,0 +1,14 @@ +import {cliTest} from './helper'; + +const args= "status " + +var recordId: string; +var name: string; + +describe("test status",() => { + + it("get status",async ()=>{ + const resp=cliTest(args); + expect(resp).toBeDefined; + }); +}); \ No newline at end of file