diff --git a/test/scripts/cosmos/cosmos_e2e_demo.ts b/test/scripts/cosmos/cosmos_e2e_demo.ts index c8a24e87..9ca1cb49 100644 --- a/test/scripts/cosmos/cosmos_e2e_demo.ts +++ b/test/scripts/cosmos/cosmos_e2e_demo.ts @@ -9,15 +9,15 @@ import { getTestAccountWithStake, } from "./helper"; - if (process.argv.length < 3) { - console.error('Usage: ts-node cosmos_e2e_demo.ts '); + console.error( + 'Usage: ts-node cosmos_e2e_demo.ts ' + ); process.exit(1); } const chainName = process.argv[2]; - // configure dotenv dotenv.config(); @@ -25,13 +25,13 @@ async function main() { // Chain Constants, modify as required let chain1; let chain2; - if (chainName == "archway"){ + if (chainName == "archway") { chain1 = { chainId: "archway-node-0", endpoint: "http://localhost:4564", prefix: "archway", }; - + chain2 = { chainId: "archway-node-1", endpoint: "http://localhost:4566", @@ -43,16 +43,14 @@ async function main() { "Demo on Sending token transfer over IBC from archway to archway" ); console.log("*".repeat(63)); - - } else{ - - chain1 = { + } else { + chain1 = { chainId: "test-chain1", endpoint: "http://localhost:26669", prefix: "neutron", }; - - chain2 = { + + chain2 = { chainId: "test-chain2", endpoint: "http://localhost:26653", prefix: "neutron", @@ -65,9 +63,6 @@ async function main() { console.log("*".repeat(63)); } - - - // ***************************************************************** // Setting up account on chain 1 by getting mnemonics from env file const mnemonic1 = process.env.MNEMONIC1 as string; @@ -78,13 +73,19 @@ async function main() { chain1.prefix, chain1.endpoint ); + console.log("Account on Chain A: ", accountAddress); // To Check if the client is connected to local chain getHeight(signingClient, chain1.chainId); // Get Test Account with stake const testAccount = await getTestAccountWithStake(chainName); - const testAddress = testAccount.substring(8, testAccount.length).trim(); + let testAddress; + if (chainName == "archway") { + testAddress = testAccount.substring(8, testAccount.length).trim(); + } else { + testAddress = testAccount; + } // To Get balance of given account address and transfer balance if 0 const bal = await signingClient.getBalance(accountAddress, "stake"); @@ -97,7 +98,6 @@ async function main() { await new Promise((f) => setTimeout(f, 5000)); await getBalance(signingClient, accountAddress); - // ***************************************************************** // Setting up account on chain 1 by getting mnemonics from env file console.log("Chain 2: " + chain2.chainId); @@ -141,6 +141,7 @@ async function main() { ), }, }; + const broadcastResult = await signingClient.signAndBroadcast( accountAddress, [msgIBCTransfer], diff --git a/test/scripts/cosmos/helper.ts b/test/scripts/cosmos/helper.ts index 5947c44d..557369c0 100644 --- a/test/scripts/cosmos/helper.ts +++ b/test/scripts/cosmos/helper.ts @@ -1,8 +1,7 @@ -import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; -import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"; -import { GasPrice } from "@cosmjs/stargate"; +import { GasPrice, SigningStargateClient } from "@cosmjs/stargate"; import { exec } from "child_process"; import fs from "fs"; +import { Secp256k1HdWallet } from "@cosmjs/launchpad"; const defaultGasPrice = GasPrice.fromString("0stake"); @@ -10,17 +9,16 @@ export async function CreateSigningClient( mnemonic: string, prefix: string, endpoint: string -): Promise<[SigningCosmWasmClient, string]> { - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { - prefix: prefix, - }); +): Promise<[SigningStargateClient, string]> { + + const wallet = await Secp256k1HdWallet.fromMnemonic(mnemonic, { prefix: prefix }); - // Print account address + // Get account address const accounts = await wallet.getAccounts(); const accountAddress = accounts[0].address; // Create an signing client with created wallet - const signingClient = await SigningCosmWasmClient.connectWithSigner( + const signingClient = await SigningStargateClient.connectWithSigner( endpoint, wallet, { @@ -31,7 +29,7 @@ export async function CreateSigningClient( } export async function getHeight( - client: SigningCosmWasmClient, + client: SigningStargateClient, chainId: string ) { // To Check if the client is connected to local chain @@ -41,7 +39,6 @@ export async function getHeight( export async function getStake(testaddress: string, destaddress: string, chainName: string) { const dockerID = await getContainerIdByPartialName(chainName); - console.log(dockerID); let command = ""; @@ -50,7 +47,7 @@ export async function getStake(testaddress: string, destaddress: string, chainNa --chain-id constantine-3 -y`; } else if (chainName == "neutron"){ command = `docker exec ${dockerID} neutrond tx bank send ${testaddress} ${destaddress} 9000000stake --keyring-backend test \ - --chain-id test-chain1 -y`; + --chain-id test-chain1 --home ./data/test-chain1 -y`; } exec(command, (error, stdout, stderr) => { @@ -71,7 +68,7 @@ export async function getTestAccountWithStake(chainName: string): Promise((resolve, reject) => { @@ -93,7 +90,7 @@ export async function getContainerIdByPartialName(chainName: string): Promise((resolve, reject) => { @@ -110,7 +107,7 @@ export async function getContainerIdByPartialName(chainName: string): Promise