Merge pull request #22 from harmony-one/return-interface

[harmony-account] make getBalance return Balance interface instead of object
pull/25/head
Jong Hyuck Won 5 years ago committed by GitHub
commit 0e1a4ba6e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/harmony-account/src/account.ts
  2. 25
      packages/harmony-account/test/testAccount.test.ts

@ -30,6 +30,12 @@ import { Messenger, RPCMethod } from '@harmony-js/network';
import { Shards } from './types';
import { defaultMessenger } from './utils';
export interface Balance {
balance?: string;
nonce?: number;
shardID?: number;
}
class Account {
/**
* static method create account
@ -218,7 +224,7 @@ class Account {
* });
* ```
*/
async getBalance(blockNumber: string = 'latest'): Promise<object> {
async getBalance(blockNumber: string = 'latest'): Promise<Balance> {
try {
if (this.messenger) {
const balance = await this.messenger.send(

@ -0,0 +1,25 @@
/**
* @packageDocumentation
* @module harmony-account
* @ignore
*/
import { Account } from '../src/account';
import { HttpProvider, Messenger } from '@harmony-js/network';
import { ChainType, ChainID } from '@harmony-js/utils';
const provider = new HttpProvider('http://localhost:9500');
const messenger = new Messenger(provider, ChainType.Harmony, ChainID.HmyLocal);
describe('test account', () => {
it('test Account.getBalance returns object that implements Balance interface', () => {
const acc = Account.new();
acc.setMessenger(messenger);
acc.getBalance().then((res) => {
expect(res).not.toBeNull();
expect(res.balance).not.toBeNull();
expect(res.nonce).not.toBeNull();
expect(res.shardID).not.toBeNull();
});
});
});
Loading…
Cancel
Save