Skip to content

Commit a2f0fae

Browse files
author
Enguerrand Pinot
committed
Added basic beam test
1 parent ca75ae3 commit a2f0fae

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"@babel/preset-typescript": "^7.8.3",
6868
"@types/jest": "^26.0.20",
6969
"@types/ledgerhq__hw-transport-node-hid": "^4.22.2",
70+
"axios": "^0.21.1",
7071
"cross-env": "^7.0.3",
7172
"eslint": "^7.19.0",
7273
"gts": "^3.1.0",

tests/client.test.ts

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,78 @@
1-
import { LumWallet, LumWalletFactory, LumClient, LumUtils, LumConstants, LumRegistry, LumTypes } from '../src';
1+
import { LumWallet, LumWalletFactory, LumClient, LumUtils, LumConstants, LumRegistry, LumTypes, LumMessages } from "../src";
2+
import axios from "axios";
3+
import Long from "long";
24

3-
describe('LumClient', () => {
5+
const sleep = (millis: number): Promise<void> => {
6+
return new Promise(resolve => setTimeout(resolve, millis));
7+
};
8+
9+
const randomString = (): string => {
10+
return Math.random().toString(36).substring(7);
11+
}
12+
13+
describe("LumClient", () => {
414
let clt: LumClient;
515
let w1: LumWallet;
616
let w2: LumWallet;
717

818
beforeAll(async () => {
9-
clt = await LumClient.connect('http://node0.testnet.lum.network/rpc');
19+
clt = await LumClient.connect("http://node0.testnet.lum.network/rpc");
20+
21+
// Prepare the wallets
1022
w1 = await LumWalletFactory.fromMnemonic(LumUtils.generateMnemonic());
1123
w2 = await LumWalletFactory.fromMnemonic(LumUtils.generateMnemonic());
1224
expect(w1.getAddress()).not.toEqual(w2.getAddress());
25+
26+
// Seed them with faucet coins each
27+
await axios.get(`https://bridge.testnet.lum.network/faucet/${w1.getAddress()}`);
28+
await axios.get(`https://bridge.testnet.lum.network/faucet/${w2.getAddress()}`);
1329
});
1430

1531
afterAll(async () => {
1632
await expect(clt.disconnect()).resolves.toBeTruthy();
1733
});
1834

19-
it('Should expose basic information', async () => {
35+
it("Should be able to use beam features", async () => {
36+
const beamId = randomString();
37+
38+
// Here we wait until the faucet transaction get dispatched and the account finally exists on the blockchain
39+
// This should be improved since... you know...
40+
let acc: LumTypes.Account = null;
41+
while(acc === null){
42+
acc = await clt.getAccount(w1.getAddress());
43+
await sleep(1000);
44+
}
45+
expect(acc).toBeTruthy();
46+
47+
const chainId = await clt.getChainId();
48+
49+
const openBeamMsg = LumMessages.BuildMsgOpenBeam(beamId, w1.getAddress(), new Long(100), "test", null, null);
50+
51+
const fee = {
52+
amount: [{ denom: LumConstants.MicroLumDenom, amount: '1' }],
53+
gas: '100000',
54+
};
55+
const doc = {
56+
accountNumber: acc.accountNumber,
57+
chainId,
58+
fee: fee,
59+
memo: 'Just a open beam transaction',
60+
messages: [openBeamMsg],
61+
sequence: acc.sequence,
62+
};
63+
64+
const tx = await clt.signAndBroadcastTx(w1, doc);
65+
expect(tx.deliverTx.code).toBe(0);
66+
})
67+
68+
it("Should expose basic information", async () => {
2069
const height = (await clt.getBlockHeight()) - 1;
21-
expect(clt.getChainId()).resolves.toEqual('lumnetwork-testnet');
70+
expect(clt.getChainId()).resolves.toEqual("lumnetwork-testnet");
2271
expect(height).toBeGreaterThan(0);
2372
expect(clt.getBlock(height)).resolves.toBeTruthy();
2473
});
2574

26-
it('should expose tendermint rpcs', async () => {
75+
it("should expose tendermint rpcs", async () => {
2776
const height = (await clt.getBlockHeight()) - 1;
2877
expect(height).toBeGreaterThan(0);
2978
expect(clt.tmClient.health()).resolves.toBeNull();
@@ -36,7 +85,7 @@ describe('LumClient', () => {
3685
expect(clt.tmClient.validatorsAll(height)).resolves.toBeTruthy();
3786
});
3887

39-
it('Should expose bank module', async () => {
88+
it("Should expose bank module", async () => {
4089
const supplies = await clt.queryClient.bank.unverified.totalSupply();
4190
expect(supplies).toBeTruthy();
4291
expect(supplies.length).toBeGreaterThan(0);
@@ -45,7 +94,7 @@ describe('LumClient', () => {
4594
expect(parseFloat(lumSupply.amount)).toBeGreaterThan(0);
4695
});
4796

48-
it('Should expose staking module', async () => {
97+
it("Should expose staking module", async () => {
4998
const validators = await clt.tmClient.validatorsAll();
5099
expect(validators.validators.length).toBeGreaterThanOrEqual(1);
51100
const block = await clt.getBlock();
@@ -67,7 +116,7 @@ describe('LumClient', () => {
67116
expect(bootVal).toBeTruthy();
68117

69118
// Get staking validator by matching it using pubkeys
70-
const stakers = await clt.queryClient.staking.unverified.validators('BOND_STATUS_BONDED');
119+
const stakers = await clt.queryClient.staking.unverified.validators("BOND_STATUS_BONDED");
71120
const bootStak = stakers.validators.filter((s) => LumUtils.toHex((LumRegistry.decode(s.consensusPubkey) as LumTypes.PubKey).key) === LumUtils.toHex(bootVal.pubkey.data))[0];
72121
expect(bootVal).toBeTruthy();
73122

@@ -85,7 +134,7 @@ describe('LumClient', () => {
85134
expect(parseFloat(lumBalance.amount)).toBeGreaterThan(0);
86135
});
87136

88-
it('Should expose distribution module', async () => {
137+
it("Should expose distribution module", async () => {
89138
// Get validators
90139
const validators = await clt.tmClient.validatorsAll();
91140
expect(validators.validators.length).toBeGreaterThanOrEqual(1);
@@ -98,7 +147,7 @@ describe('LumClient', () => {
98147
expect(bootVal).toBeTruthy();
99148

100149
// Get genesis validator account address
101-
const stakers = await clt.queryClient.staking.unverified.validators('BOND_STATUS_BONDED');
150+
const stakers = await clt.queryClient.staking.unverified.validators("BOND_STATUS_BONDED");
102151
const bootStak = stakers.validators.filter((s) => LumUtils.toHex((LumRegistry.decode(s.consensusPubkey) as LumTypes.PubKey).key) === LumUtils.toHex(bootVal.pubkey.data))[0];
103152
expect(bootVal).toBeTruthy();
104153

@@ -114,4 +163,8 @@ describe('LumClient', () => {
114163
expect(delegValidators).toBeTruthy();
115164
expect(delegValidators.validators.length).toBeGreaterThan(0);
116165
});
166+
167+
it("Should open a beam", async () => {
168+
169+
});
117170
});

0 commit comments

Comments
 (0)