Skip to content

Commit

Permalink
refactor: util feat & testcase update
Browse files Browse the repository at this point in the history
  • Loading branch information
fly33499 committed Oct 13, 2021
1 parent 446a042 commit 4da39a2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
22 changes: 21 additions & 1 deletion sdk/FirmaUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ const sha256 = require('crypto-js/sha256');
const encHex = require('crypto-js/enc-hex');

import { Bech32 } from "@cosmjs/encoding";
import Long from "long";

export class FirmaUtil {

public static Config: FirmaConfig;

public static getUFCTStringFromFCTStr(fctAmount: string): string {
let fct = Number.parseFloat(fctAmount);
let big = fct * 1000000;

return big.toString();
}

public static getFCTStringFromUFCTStr(uFctAmount: string): string {
let ufct = Number.parseInt(uFctAmount);
return (ufct / 1000000).toString();
}

public static getUFCTStringFromFCT(fctAmount: number): string {
return fctAmount + "000000";
let big = fctAmount * 1000000;

return big.toString();
}

public static getFCTStringFromUFCT(uFctAmount: number): string {
let number = uFctAmount;
return (number / 1000000).toString();
}

public static async getFileHash(filePath: string): Promise<string> {
Expand Down
56 changes: 54 additions & 2 deletions test/18.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FirmaUtil } from '..';

describe('[18. util Test]', () => {

it.only('getValOperAddressFromAccAddress test', async () => {
it('getValOperAddressFromAccAddress test', async () => {

const accAddress = "firma134pp6s2nv7pl4mxu58aeufdd6fv5s2zujrrmsa";
const valoperAddress = "firmavaloper134pp6s2nv7pl4mxu58aeufdd6fv5s2zuvsgqsn";
Expand All @@ -12,12 +12,64 @@ describe('[18. util Test]', () => {
expect(result).to.be.equal(valoperAddress);
})

it.only('getAccAddressFromValOperAddress test', async () => {
it('getAccAddressFromValOperAddress test', async () => {

const accAddress = "firma134pp6s2nv7pl4mxu58aeufdd6fv5s2zujrrmsa";
const valoperAddress = "firmavaloper134pp6s2nv7pl4mxu58aeufdd6fv5s2zuvsgqsn";

let result = FirmaUtil.getAccAddressFromValOperAddress(valoperAddress);
expect(result).to.be.equal(accAddress);
})

it('getFCTFromUFCTString test', async () => {

let amountUFCT = 1000000;
let fct = FirmaUtil.getFCTStringFromUFCT(amountUFCT);

expect(fct).to.be.equal("1");

amountUFCT = 1234000;
fct = FirmaUtil.getFCTStringFromUFCT(amountUFCT);

expect(fct).to.be.equal("1.234");
})

it('getUFCTStringFromFCT test', async () => {

let amountUFCT = 1;
let fct = FirmaUtil.getUFCTStringFromFCT(amountUFCT);

expect(fct).to.be.equal("1000000");

amountUFCT = 1.23;
fct = FirmaUtil.getUFCTStringFromFCT(amountUFCT);

expect(fct).to.be.equal("1230000");
})

it('getFCTFromUFCTString test', async () => {

let amountUFCT = "1000000";
let fct = FirmaUtil.getFCTStringFromUFCTStr(amountUFCT);

expect(fct).to.be.equal("1");

amountUFCT = "1234000";
fct = FirmaUtil.getFCTStringFromUFCTStr(amountUFCT);

expect(fct).to.be.equal("1.234");
})

it('getUFCTStringFromFCT test', async () => {

let amountUFCT = "1";
let fct = FirmaUtil.getUFCTStringFromFCTStr(amountUFCT);

expect(fct).to.be.equal("1000000");

amountUFCT = "1.23";
fct = FirmaUtil.getUFCTStringFromFCTStr(amountUFCT);

expect(fct).to.be.equal("1230000");
})
});

0 comments on commit 4da39a2

Please sign in to comment.