Skip to content

Commit 780a874

Browse files
author
Fabrice Bascoulergue
committed
Improve unittests
1 parent d1038da commit 780a874

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

src/client/LumClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { LumWallet } from '../wallet';
1717
import { Message } from '../messages';
1818
import { sha256, generateAuthInfo, generateSignDoc, generateSignDocBytes, generateTxBytes } from '../utils';
19-
import { BroadcastTxCommitResponse, ValidatorsResponse, TxResponse, TxSearchParams, BlockResponse, Account, Coin, Fee } from '../types';
19+
import { BroadcastTxCommitResponse, TxResponse, TxSearchParams, BlockResponse, Account, Coin, Fee } from '../types';
2020

2121
export class LumClient {
2222
readonly tmClient: Tendermint34Client;

tests/client.test.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { LumWallet, LumClient, LumUtils, LumConstants, LumRegistry, LumTypes } from '../src';
22

3-
const genesisAccountAddress = 'lum100hm4tt3z3mj4gc453quvu452dcp2ehqavrtlp';
4-
const genesisValidatorAddress = '23D45E13FF3418D23DF989D78EBE6DE76F3A89EC';
5-
63
describe('LumClient', () => {
74
let clt: LumClient;
85
let w1: LumWallet;
96
let w2: LumWallet;
107

118
beforeAll(async () => {
129
clt = await LumClient.connect('http://node0.testnet.lum.network/rpc');
13-
w1 = await LumWallet.fromMnemonic('noodle hope lounge dismiss erase elephant seek crawl check equal city chest');
14-
w2 = await LumWallet.fromMnemonic('sick hollow lizard train motion eternal mixture rude section tray nice awful');
10+
w1 = await LumWallet.fromMnemonic(LumUtils.generateMnemonic());
11+
w2 = await LumWallet.fromMnemonic(LumUtils.generateMnemonic());
1512
expect(w1.address).not.toEqual(w2.address);
1613
});
1714

@@ -20,20 +17,23 @@ describe('LumClient', () => {
2017
});
2118

2219
it('Should expose basic information', async () => {
23-
expect(clt.getChainId()).resolves.toEqual('lumnetwork'); // TODO: will be update to lumnetwork-testnet
24-
expect(clt.getBlockHeight()).resolves.toBeGreaterThan(0);
25-
expect(clt.getBlock()).resolves.toBeTruthy();
20+
const height = (await clt.getBlockHeight()) - 1;
21+
expect(clt.getChainId()).resolves.toEqual('lumnetwork-testnet');
22+
expect(height).toBeGreaterThan(0);
23+
expect(clt.getBlock(height)).resolves.toBeTruthy();
2624
});
2725

2826
it('should expose tendermint rpcs', async () => {
27+
const height = (await clt.getBlockHeight()) - 1;
28+
expect(height).toBeGreaterThan(0);
2929
expect(clt.tmClient.health()).resolves.toBeNull();
3030
expect(clt.tmClient.status()).resolves.toBeTruthy();
3131
expect(clt.tmClient.genesis()).resolves.toBeTruthy();
3232
expect(clt.tmClient.abciInfo()).resolves.toBeTruthy();
33-
expect(clt.tmClient.block()).resolves.toBeTruthy();
34-
expect(clt.tmClient.blockResults()).resolves.toBeTruthy();
35-
expect(clt.tmClient.blockchain()).resolves.toBeTruthy();
36-
expect(clt.tmClient.validatorsAll()).resolves.toBeTruthy();
33+
expect(clt.tmClient.block(height)).resolves.toBeTruthy();
34+
expect(clt.tmClient.blockResults(height)).resolves.toBeTruthy();
35+
expect(clt.tmClient.blockchain(0, height)).resolves.toBeTruthy();
36+
expect(clt.tmClient.validatorsAll(height)).resolves.toBeTruthy();
3737
});
3838

3939
it('Should expose bank module', async () => {
@@ -59,8 +59,11 @@ describe('LumClient', () => {
5959
}
6060
expect(found).toBeTruthy();
6161

62-
// Get boot val (genesis) with address genesisValidatorAddress
63-
const bootVal = validators.validators.filter((v) => LumUtils.toHex(v.address).toUpperCase() === genesisValidatorAddress)[0];
62+
// Get first available block
63+
const firstBlock = await clt.getBlock(2);
64+
65+
// Get boot val (genesis) with address genesis proposer address
66+
const bootVal = validators.validators.filter((v) => LumUtils.toHex(v.address) === LumUtils.toHex(firstBlock.block.header.proposerAddress))[0];
6467
expect(bootVal).toBeTruthy();
6568

6669
// Get staking validator by matching it using pubkeys
@@ -83,11 +86,32 @@ describe('LumClient', () => {
8386
});
8487

8588
it('Should expose distribution module', async () => {
86-
const deleg = await clt.queryClient.distribution.unverified.delegatorWithdrawAddress(genesisAccountAddress);
89+
// Get validators
90+
const validators = await clt.tmClient.validatorsAll();
91+
expect(validators.validators.length).toBeGreaterThanOrEqual(1);
92+
93+
// Get first available block
94+
const firstBlock = await clt.getBlock(2);
95+
96+
// Get boot val (genesis) with address genesis proposer address
97+
const bootVal = validators.validators.filter((v) => LumUtils.toHex(v.address) === LumUtils.toHex(firstBlock.block.header.proposerAddress))[0];
98+
expect(bootVal).toBeTruthy();
99+
100+
// Get genesis validator account address
101+
const stakers = await clt.queryClient.staking.unverified.validators('BOND_STATUS_BONDED');
102+
const bootStak = stakers.validators.filter((s) => LumUtils.toHex((LumRegistry.decode(s.consensusPubkey) as LumTypes.PubKey).key) === LumUtils.toHex(bootVal.pubkey.data))[0];
103+
expect(bootVal).toBeTruthy();
104+
105+
// Get account information by deriving the address from the operator address
106+
const delegAddress = LumUtils.Bech32.encode(LumConstants.LumBech32PrefixAccAddr, LumUtils.Bech32.decode(bootStak.operatorAddress).data);
107+
const account = await clt.getAccount(delegAddress);
108+
expect(account).toBeTruthy();
109+
110+
const deleg = await clt.queryClient.distribution.unverified.delegatorWithdrawAddress(account.address);
87111
expect(deleg).toBeTruthy();
88-
expect(deleg.withdrawAddress).toEqual(genesisAccountAddress);
89-
const validators = await clt.queryClient.distribution.unverified.delegatorValidators(genesisAccountAddress);
90-
expect(validators).toBeTruthy();
91-
expect(validators.validators.length).toBeGreaterThan(0);
112+
expect(deleg.withdrawAddress).toEqual(account.address);
113+
const delegValidators = await clt.queryClient.distribution.unverified.delegatorValidators(account.address);
114+
expect(delegValidators).toBeTruthy();
115+
expect(delegValidators.validators.length).toBeGreaterThan(0);
92116
});
93117
});

0 commit comments

Comments
 (0)