11// @ts -nocheck
2- import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing' ;
3- import { assertIsDeliverTxSuccess } from '@cosmjs/stargate' ;
2+ import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd" ;
3+ import { assertIsDeliverTxSuccess } from "@interchainjs/cosmos/utils" ;
44
55import path from "path" ;
6- import fs from 'fs' ;
7- import { getSigningJsdClient , jsd } from ' hyperwebjs'
8- import { useChain , generateMnemonic } from ' starshipjs' ;
9- import { sleep } from ' ../test-utils/sleep' ;
10- import ' ./setup.test' ;
6+ import fs from "fs" ;
7+ import { getSigningJsdClient , jsd } from " hyperwebjs" ;
8+ import { useChain , generateMnemonic } from " starshipjs" ;
9+ import { sleep } from " ../test-utils/sleep" ;
10+ import " ./setup.test" ;
1111
12- describe ( ' Contract 2: AMM contract test' , ( ) => {
12+ describe ( " Contract 2: AMM contract test" , ( ) => {
1313 let wallet , denom , address , queryClient , signingClient ;
1414 let chainInfo , getCoin , getRpcEndpoint , creditFromFaucet ;
1515 let contractCode , contractIndex ;
1616
1717 let wallet2 , address2 ;
1818 let fee ;
1919
20- const denom2 = "uhypweb" , uatom = "uatom" , uusdc = "uusdc" ;
20+ const denom2 = "uhypweb" ,
21+ uatom = "uatom" ,
22+ uusdc = "uusdc" ;
2123
2224 beforeAll ( async ( ) => {
23- ( {
24- chainInfo,
25- getCoin,
26- getRpcEndpoint,
27- creditFromFaucet
28- } = useChain ( 'hyperweb' ) ) ;
25+ ( { chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } =
26+ useChain ( "hyperweb" ) ) ;
2927 denom = ( await getCoin ( ) ) . base ;
3028
29+ const commonPrefix = chainInfo . chain . bech32_prefix ;
30+ const cosmosHdPath = "m/44'/118'/0'/0/0" ;
31+
3132 // Initialize wallet
32- wallet = await DirectSecp256k1HdWallet . fromMnemonic ( generateMnemonic ( ) , {
33- prefix : chainInfo . chain . bech32_prefix
34- } ) ;
33+ wallet = Secp256k1HDWallet . fromMnemonic ( generateMnemonic ( ) , [
34+ {
35+ prefix : commonPrefix ,
36+ hdPath : cosmosHdPath ,
37+ } ,
38+ ] ) ;
3539 address = ( await wallet . getAccounts ( ) ) [ 0 ] . address ;
36- console . log ( `contract creator address for amm: ${ address } ` )
40+ console . log ( `contract creator address for amm: ${ address } ` ) ;
3741
3842 // Initialize wallet2
39- wallet2 = await DirectSecp256k1HdWallet . fromMnemonic ( generateMnemonic ( ) , {
40- prefix : chainInfo . chain . bech32_prefix
41- } ) ;
43+ wallet2 = Secp256k1HDWallet . fromMnemonic ( generateMnemonic ( ) , [
44+ {
45+ prefix : commonPrefix ,
46+ hdPath : cosmosHdPath ,
47+ } ,
48+ ] ) ;
4249 address2 = ( await wallet2 . getAccounts ( ) ) [ 0 ] . address ;
43- console . log ( `contract creator address2 for amm: ${ address2 } ` )
50+ console . log ( `contract creator address2 for amm: ${ address2 } ` ) ;
4451
4552 // Create custom cosmos interchain client
4653 queryClient = await jsd . ClientFactory . createRPCQueryClient ( {
47- rpcEndpoint : await getRpcEndpoint ( )
54+ rpcEndpoint : await getRpcEndpoint ( ) ,
4855 } ) ;
4956
5057 signingClient = await getSigningJsdClient ( {
5158 rpcEndpoint : await getRpcEndpoint ( ) ,
52- signer : wallet
59+ signer : wallet ,
5360 } ) ;
5461
5562 await creditFromFaucet ( address , denom ) ;
@@ -60,21 +67,24 @@ describe('Contract 2: AMM contract test', () => {
6067 await creditFromFaucet ( address2 , denom ) ;
6168 await creditFromFaucet ( address2 , denom2 ) ;
6269
63- fee = { amount : [ { denom, amount : ' 100000' } ] , gas : ' 550000' } ;
70+ fee = { amount : [ { denom, amount : " 100000" } ] , gas : " 550000" } ;
6471
6572 await sleep ( 2000 ) ; // sleep for 1 sec to get tokens transferred from faucet successfully
6673 } ) ;
6774
68- it ( ' check balance' , async ( ) => {
75+ it ( " check balance" , async ( ) => {
6976 const balance = await signingClient . getBalance ( address , denom ) ;
7077 expect ( balance . amount ) . toEqual ( "10000000000" ) ;
7178 expect ( balance . denom ) . toEqual ( denom ) ;
7279 } ) ;
7380
74- it ( ' instantiate contract' , async ( ) => {
81+ it ( " instantiate contract" , async ( ) => {
7582 // Read contract code from external file
76- const contractPath = path . join ( __dirname , '../dist/contracts/ammContract.js' ) ;
77- contractCode = fs . readFileSync ( contractPath , 'utf8' ) ;
83+ const contractPath = path . join (
84+ __dirname ,
85+ "../dist/contracts/ammContract.js"
86+ ) ;
87+ contractCode = fs . readFileSync ( contractPath , "utf8" ) ;
7888
7989 const msg = jsd . jsd . MessageComposer . fromPartial . instantiate ( {
8090 creator : address ,
@@ -85,20 +95,24 @@ describe('Contract 2: AMM contract test', () => {
8595 assertIsDeliverTxSuccess ( result ) ;
8696
8797 // Parse the response to get the contract index
88- const response = jsd . jsd . MsgInstantiateResponse . fromProtoMsg ( result . msgResponses [ 0 ] ) ;
98+ const response = jsd . jsd . MsgInstantiateResponse . fromProtoMsg (
99+ result . msgResponses [ 0 ]
100+ ) ;
89101 contractIndex = response . index ;
90102 expect ( contractIndex ) . toBeGreaterThan ( 0 ) ;
91103 console . log ( `contract index: ${ contractIndex } ` ) ;
92104 } ) ;
93105
94- it ( 'query for contract based on index' , async ( ) => {
95- const response = await queryClient . jsd . jsd . contracts ( { index : contractIndex } ) ;
106+ it ( "query for contract based on index" , async ( ) => {
107+ const response = await queryClient . jsd . jsd . contracts ( {
108+ index : contractIndex ,
109+ } ) ;
96110 expect ( response . contracts . code ) . toEqual ( contractCode ) ;
97111 expect ( response . contracts . index ) . toEqual ( contractIndex ) ;
98112 expect ( response . contracts . creator ) . toEqual ( address ) ;
99113 } ) ;
100114
101- it ( ' perform getTotalSupply eval' , async ( ) => {
115+ it ( " perform getTotalSupply eval" , async ( ) => {
102116 const msg = jsd . jsd . MessageComposer . fromPartial . eval ( {
103117 creator : address ,
104118 index : contractIndex ,
@@ -109,11 +123,13 @@ describe('Contract 2: AMM contract test', () => {
109123 const result = await signingClient . signAndBroadcast ( address , [ msg ] , fee ) ;
110124 assertIsDeliverTxSuccess ( result ) ;
111125
112- const response = jsd . jsd . MsgEvalResponse . fromProtoMsg ( result . msgResponses [ 0 ] ) ;
126+ const response = jsd . jsd . MsgEvalResponse . fromProtoMsg (
127+ result . msgResponses [ 0 ]
128+ ) ;
113129 expect ( response . result ) . toEqual ( "0" ) ;
114130 } ) ;
115131
116- it ( ' perform addLiquidity eval' , async ( ) => {
132+ it ( " perform addLiquidity eval" , async ( ) => {
117133 const msg = jsd . jsd . MessageComposer . fromPartial . eval ( {
118134 creator : address ,
119135 index : contractIndex ,
@@ -124,19 +140,21 @@ describe('Contract 2: AMM contract test', () => {
124140 const result = await signingClient . signAndBroadcast ( address , [ msg ] , fee ) ;
125141 assertIsDeliverTxSuccess ( result ) ;
126142
127- const response = jsd . jsd . MsgEvalResponse . fromProtoMsg ( result . msgResponses [ 0 ] ) ;
143+ const response = jsd . jsd . MsgEvalResponse . fromProtoMsg (
144+ result . msgResponses [ 0 ]
145+ ) ;
128146 expect ( response . result ) . toEqual ( "null" ) ;
129147 } ) ;
130148
131- it ( ' check balance after addLiquidity' , async ( ) => {
149+ it ( " check balance after addLiquidity" , async ( ) => {
132150 const usdcBalance = await signingClient . getBalance ( address , uusdc ) ;
133151 expect ( usdcBalance . amount ) . toEqual ( "9950000000" ) ;
134152
135153 const atomBalance = await signingClient . getBalance ( address , uatom ) ;
136154 expect ( atomBalance . amount ) . toEqual ( "9950000000" ) ;
137155 } ) ;
138156
139- it ( ' perform swap eval' , async ( ) => {
157+ it ( " perform swap eval" , async ( ) => {
140158 const msg = jsd . jsd . MessageComposer . fromPartial . eval ( {
141159 creator : address ,
142160 index : contractIndex ,
@@ -147,7 +165,9 @@ describe('Contract 2: AMM contract test', () => {
147165 const result = await signingClient . signAndBroadcast ( address , [ msg ] , fee ) ;
148166 assertIsDeliverTxSuccess ( result ) ;
149167
150- const response = jsd . jsd . MsgEvalResponse . fromProtoMsg ( result . msgResponses [ 0 ] ) ;
168+ const response = jsd . jsd . MsgEvalResponse . fromProtoMsg (
169+ result . msgResponses [ 0 ]
170+ ) ;
151171 expect ( response . result ) . toEqual ( "9969998.011982398" ) ;
152172 } ) ;
153173} ) ;
0 commit comments