From a2237f355934cea6144e9bbb5d8f8b1f844c2a7e Mon Sep 17 00:00:00 2001 From: 0xmuralik Date: Wed, 29 Mar 2023 13:47:42 +0530 Subject: [PATCH] account, status and token tests --- test/account.test.ts | 12 +++++++++--- test/status.test.ts | 1 + test/tokens.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 test/tokens.test.ts diff --git a/test/account.test.ts b/test/account.test.ts index c41c583..014268a 100644 --- a/test/account.test.ts +++ b/test/account.test.ts @@ -1,12 +1,18 @@ import {cliTest} from './helper'; const args= "account " -export var address="" +const type= "aphoton" +const quantity="10" +const address="ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu" describe("test account",() => { it("get account should return account details",async ()=>{ - const resp=JSON.parse(cliTest(args+"get")); + // send tokens to account to avoid account not found error + const sendResp=cliTest("tokens send --address "+address+" --type "+type+" --quantity "+quantity) + expect(sendResp).toBeDefined; + + const resp=cliTest(args+"get --address "+address); expect(resp).toBeDefined; - address=resp[0].address + expect(resp[0].address).toEqual(address) }); }); \ No newline at end of file diff --git a/test/status.test.ts b/test/status.test.ts index 8e769a2..1833cde 100644 --- a/test/status.test.ts +++ b/test/status.test.ts @@ -7,5 +7,6 @@ describe("test status",() => { it("get status",async ()=>{ const resp=cliTest(args); expect(resp).toBeDefined; + expect(resp.node.network).toContain("laconic") }); }); \ No newline at end of file diff --git a/test/tokens.test.ts b/test/tokens.test.ts new file mode 100644 index 0000000..31afc79 --- /dev/null +++ b/test/tokens.test.ts @@ -0,0 +1,36 @@ +import {cliTest} from './helper'; + +const args= "tokens " +const type= "aphoton" +const quantity=10 +const address="ethm1vc62ysqu504at932jjq8pwrqgjt67rx6ggn5yu" + +describe("test account",() => { + it("get account should return account details",async ()=>{ + // balance before + var balanceBefore; + const beforeResp=cliTest("account get --address "+address); + if (beforeResp.stderr){ + expect(beforeResp.stderr.toString()).toContain("account "+address+ " not found") + balanceBefore=0 + } else{ + balanceBefore=beforeResp[0].balance[0].quantity + } + + // send tokens to account + const sendResp=cliTest(args+"send --address "+address+" --type "+type+" --quantity "+quantity) + expect(sendResp).toBeDefined; + + // balance after + var balanceAfter; + const afterResp=cliTest("account get --address "+address); + if (afterResp.stderr){ + expect(afterResp.stderr.toString()).toContain("account "+address+ " not found") + balanceAfter=0 + } else{ + balanceAfter=afterResp[0].balance[0].quantity + } + + expect(balanceAfter-balanceBefore).toEqual(quantity) + }); +}); \ No newline at end of file