1- // import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
2- // import { LumWalletFactory, LumMessages, LumUtils, LumConstants } from '../src';
1+ import axios from 'axios' ;
2+ import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' ;
3+ import { LumWalletFactory , LumMessages , LumUtils , LumConstants , LumWallet } from '../src' ;
34
45import { LumClient } from '../src' ;
56
7+ const requestCoinsIfNeeded = async ( clt : LumClient , w : LumWallet , microLumMinAmount ?: number ) => {
8+ const balance = await clt . getBalance ( w . getAddress ( ) , LumConstants . MicroLumDenom ) ;
9+ if ( balance && parseInt ( balance . amount ) > microLumMinAmount ) {
10+ return ;
11+ }
12+ const res = await axios . get ( `https://bridge.testnet.lum.network/faucet/${ w . getAddress ( ) } ` ) ;
13+ expect ( res . status ) . toEqual ( 200 ) ;
14+ const faucetResult = new Promise ( ( resolve , reject ) => {
15+ let it = 0 ;
16+ const rec = setInterval ( async ( ) => {
17+ const balance = await clt . getBalance ( w . getAddress ( ) , LumConstants . MicroLumDenom ) ;
18+ if ( balance && parseInt ( balance . amount ) > microLumMinAmount ) {
19+ clearInterval ( rec ) ;
20+ resolve ( true ) ;
21+ } else if ( it >= 60 ) {
22+ clearInterval ( rec ) ;
23+ reject ( ) ;
24+ }
25+ it ++ ;
26+ } , 1000 ) ;
27+ } ) ;
28+ await expect ( faucetResult ) . resolves . toBeTruthy ( ) ;
29+ } ;
30+
631describe ( 'Ledger' , ( ) => {
732 let clt : LumClient ;
833
@@ -14,47 +39,117 @@ describe('Ledger', () => {
1439 await expect ( clt . disconnect ( ) ) . resolves . toBeTruthy ( ) ;
1540 } ) ;
1641
17- it ( 'Manual signature must work' , async ( ) => {
42+ // Remove the .skip part of the function to run the ledger tests manually
43+ it . skip ( 'Cosmos App Manual signature must work' , async ( ) => {
44+ // Manual testing using ledger device
45+ // Ledger device must be unlocked and Cosmos app opened prior to running those tests
46+ const transport = await TransportNodeHid . create ( ) ;
47+ const w = await LumWalletFactory . fromLedgerTransport ( transport , `m/44'/118'/0'/0/0` , 'lum' ) ;
48+ expect ( w ) . toBeTruthy ( ) ;
49+
50+ await requestCoinsIfNeeded ( clt , w , 1000 ) ;
51+
52+ const acc = await clt . getAccount ( w . getAddress ( ) ) ;
53+ expect ( acc ) . toBeTruthy ( ) ;
54+
55+ const balance = await clt . getBalance ( acc . address , LumConstants . MicroLumDenom ) ;
56+ expect ( parseInt ( balance . amount ) ) . toBeGreaterThan ( 0 ) ;
57+
58+ const chainId = await clt . getChainId ( ) ;
59+ const doc = {
60+ accountNumber : acc . accountNumber ,
61+ chainId,
62+ fee : {
63+ amount : [ { denom : LumConstants . MicroLumDenom , amount : '1' } ] ,
64+ gas : '100000' ,
65+ } ,
66+ memo : 'Send LUM using Ledger App' ,
67+ messages : [ LumMessages . BuildMsgSend ( w . getAddress ( ) , 'lum1lsagfzrm4gz28he4wunt63sts5xzmczwjttsr9' , [ { denom : LumConstants . MicroLumDenom , amount : '1' } ] ) ] ,
68+ signers : [
69+ {
70+ accountNumber : acc . accountNumber ,
71+ sequence : acc . sequence ,
72+ publicKey : w . getPublicKey ( ) ,
73+ } ,
74+ ] ,
75+ } ;
76+ const res = await clt . signAndBroadcastTx ( w , doc ) ;
77+ expect ( LumUtils . broadcastTxCommitSuccess ( res ) ) . toBeTruthy ( ) ;
78+ } ) ;
79+
80+ // Remove the .skip part of the function to run the ledger tests manually
81+ it . skip ( 'Cosmos App Signature verification should work' , async ( ) => {
1882 // Manual testing using ledger device
1983 // Ledger device must be unlocked and Cosmos app opened prior to running those tests
20- // const transport = await TransportNodeHid.create();
21- // const w1 = await LumWalletFactory.fromLedgerTransport(transport, `m/44'/118'/0'/0/0`, 'lum');
22- // expect(w1).toBeTruthy();
23- // const acc = await clt.getAccount(w1.getAddress());
24- // expect(acc).toBeTruthy();
25- // const balance = await clt.getBalance(acc.address, 'lum');
26- // expect(parseInt(balance.amount)).toBeGreaterThan(0);
27- // const chainId = await clt.getChainId();
28- // const sendMsg = LumMessages.BuildMsgSend(w1.getAddress(), 'lum1lsagfzrm4gz28he4wunt63sts5xzmczwjttsr9', [{ denom: 'lum', amount: '3' }]);
29- // const fee = {
30- // amount: [{ denom: LumConstants.MicroLumDenom, amount: '1' }],
31- // gas: '100000',
32- // };
33- // const doc = {
34- // accountNumber: acc.accountNumber,
35- // chainId,
36- // fee: fee,
37- // memo: 'Just a ledger transaction',
38- // messages: [sendMsg],
39- // sequence: acc.sequence,
40- // };
41- // const res = await clt.signAndBroadcastTx(w1, doc);
42- // expect(LumUtils.broadcastTxCommitSuccess(res)).toBeTruthy();
84+ const message = 'Lum network is an awesome decentralized protocol' ;
85+ const transport = await TransportNodeHid . create ( ) ;
86+ const w1 = await LumWalletFactory . fromLedgerTransport ( transport , `m/44'/118'/0'/0/0` , 'lum' ) ;
87+ const w2 = await LumWalletFactory . fromMnemonic ( LumUtils . generateMnemonic ( ) ) ;
88+ const signed = await w1 . signMessage ( message ) ;
89+ const v1 = await LumUtils . verifySignMsg ( signed ) ;
90+ expect ( v1 ) . toBeTruthy ( ) ;
91+ const v2 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { msg : 'Wrong message input' } ) ) ;
92+ expect ( v2 ) . toBeFalsy ( ) ;
93+ const v3 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { publicKey : w2 . getPublicKey ( ) } ) ) ;
94+ expect ( v3 ) . toBeFalsy ( ) ;
95+ const v4 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { address : w2 . getAddress ( ) } ) ) ;
96+ expect ( v4 ) . toBeFalsy ( ) ;
4397 } ) ;
4498
45- it ( 'Signature verification should work' , async ( ) => {
46- // const message = 'Lum network is an awesome decentralized protocol';
47- // const transport = await TransportNodeHid.create();
48- // const w1 = await LumWalletFactory.fromLedgerTransport(transport, `m/44'/118'/0'/0/0`, 'lum');
49- // const w2 = await LumWalletFactory.fromMnemonic(LumUtils.generateMnemonic());
50- // const signed = await w1.signMessage(message);
51- // const v1 = await LumUtils.verifySignMsg(signed);
52- // expect(v1).toBeTruthy();
53- // const v2 = await LumUtils.verifySignMsg(Object.assign({}, signed, { msg: 'Wrong message input' }));
54- // expect(v2).toBeFalsy();
55- // const v3 = await LumUtils.verifySignMsg(Object.assign({}, signed, { publicKey: w2.getPublicKey() }));
56- // expect(v3).toBeFalsy();
57- // const v4 = await LumUtils.verifySignMsg(Object.assign({}, signed, { address: w2.getAddress() }));
58- // expect(v4).toBeFalsy();
99+ // Remove the .skip part of the function to run the ledger tests manually
100+ it . skip ( 'Lum App Manual signature must work' , async ( ) => {
101+ // Manual testing using ledger device
102+ // Ledger device must be unlocked and Lum app opened prior to running those tests
103+ const transport = await TransportNodeHid . create ( ) ;
104+ const w = await LumWalletFactory . fromLedgerTransport ( transport , `m/44'/837'/0'/0/0` , 'lum' ) ;
105+ expect ( w ) . toBeTruthy ( ) ;
106+
107+ await requestCoinsIfNeeded ( clt , w , 1000 ) ;
108+
109+ const acc = await clt . getAccount ( w . getAddress ( ) ) ;
110+ expect ( acc ) . toBeTruthy ( ) ;
111+
112+ const balance = await clt . getBalance ( acc . address , LumConstants . MicroLumDenom ) ;
113+ expect ( parseInt ( balance . amount ) ) . toBeGreaterThan ( 0 ) ;
114+
115+ const chainId = await clt . getChainId ( ) ;
116+ const doc = {
117+ accountNumber : acc . accountNumber ,
118+ chainId,
119+ fee : {
120+ amount : [ { denom : LumConstants . MicroLumDenom , amount : '1' } ] ,
121+ gas : '100000' ,
122+ } ,
123+ memo : 'Send LUM using Ledger App' ,
124+ messages : [ LumMessages . BuildMsgSend ( w . getAddress ( ) , 'lum1lsagfzrm4gz28he4wunt63sts5xzmczwjttsr9' , [ { denom : LumConstants . MicroLumDenom , amount : '1' } ] ) ] ,
125+ signers : [
126+ {
127+ accountNumber : acc . accountNumber ,
128+ sequence : acc . sequence ,
129+ publicKey : w . getPublicKey ( ) ,
130+ } ,
131+ ] ,
132+ } ;
133+ const res = await clt . signAndBroadcastTx ( w , doc ) ;
134+ expect ( LumUtils . broadcastTxCommitSuccess ( res ) ) . toBeTruthy ( ) ;
135+ } ) ;
136+
137+ // Remove the .skip part of the function to run the ledger tests manually
138+ it . skip ( 'Lum App Signature verification should work' , async ( ) => {
139+ // Manual testing using ledger device
140+ // Ledger device must be unlocked and Lum app opened prior to running those tests
141+ const message = 'Lum network is an awesome decentralized protocol' ;
142+ const transport = await TransportNodeHid . create ( ) ;
143+ const w1 = await LumWalletFactory . fromLedgerTransport ( transport , `m/44'/837'/0'/0/0` , 'lum' ) ;
144+ const w2 = await LumWalletFactory . fromMnemonic ( LumUtils . generateMnemonic ( ) ) ;
145+ const signed = await w1 . signMessage ( message ) ;
146+ const v1 = await LumUtils . verifySignMsg ( signed ) ;
147+ expect ( v1 ) . toBeTruthy ( ) ;
148+ const v2 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { msg : 'Wrong message input' } ) ) ;
149+ expect ( v2 ) . toBeFalsy ( ) ;
150+ const v3 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { publicKey : w2 . getPublicKey ( ) } ) ) ;
151+ expect ( v3 ) . toBeFalsy ( ) ;
152+ const v4 = await LumUtils . verifySignMsg ( Object . assign ( { } , signed , { address : w2 . getAddress ( ) } ) ) ;
153+ expect ( v4 ) . toBeFalsy ( ) ;
59154 } ) ;
60155} ) ;
0 commit comments