diff --git a/packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts b/packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts index d74360da..86572c32 100644 --- a/packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts +++ b/packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts @@ -1,5 +1,5 @@ import { stopAll, startAll } from "../src/docker"; export default async () => { - await startAll(); + // await startAll(); }; diff --git a/packages/axelar-local-dev-cosmos/jest/jest.global-teardown.ts b/packages/axelar-local-dev-cosmos/jest/jest.global-teardown.ts index f6c8f634..57627c49 100644 --- a/packages/axelar-local-dev-cosmos/jest/jest.global-teardown.ts +++ b/packages/axelar-local-dev-cosmos/jest/jest.global-teardown.ts @@ -1,5 +1,5 @@ import { stopAll } from "../src/docker"; export default async () => { - await stopAll(); + // await stopAll(); }; diff --git a/packages/axelar-local-dev-cosmos/src/__tests__/CosmosClient.spec.ts b/packages/axelar-local-dev-cosmos/src/__tests__/CosmosClient.spec.ts index 63e5c600..bc62962e 100644 --- a/packages/axelar-local-dev-cosmos/src/__tests__/CosmosClient.spec.ts +++ b/packages/axelar-local-dev-cosmos/src/__tests__/CosmosClient.spec.ts @@ -1,17 +1,16 @@ -import fs from "fs"; import path from "path"; -import { CosmosClient } from "../CosmosClient"; +import { CosmosClient } from "../"; describe("CosmosClient", () => { let cosmosClient: CosmosClient; beforeAll(async () => { - const config = JSON.parse(fs.readFileSync("./config.json", "utf-8")); - cosmosClient = await CosmosClient.create(config); + cosmosClient = await CosmosClient.create(); }); it("should query the balance", async () => { - const balance = await cosmosClient.getOwnerAccount(); + const owner = await cosmosClient.getOwnerAccount(); + const balance = await cosmosClient.getBalance(owner); expect(parseInt(balance || "0")).toBeGreaterThan(0); }); @@ -22,7 +21,16 @@ describe("CosmosClient", () => { expect(response).toBeDefined(); }); - it.only("should be able to execute the wasm contract", async () => { + it("should be able to send tokens to given address", async () => { + const recipient = "wasm1kmfc98hsz9cxq9lyezlpr8d0sh5ct244krg6u5"; + const amount = "1000000"; + const initialBalance = await cosmosClient.getBalance(recipient); + await cosmosClient.fundWallet(recipient, amount); + const balance = await cosmosClient.getBalance(recipient); + expect(parseInt(balance)).toBe(parseInt(initialBalance) + parseInt(amount)); + }); + + it.skip("should be able to execute the wasm contract", async () => { const _path = path.resolve(__dirname, "../..", "wasm/multi_send.wasm"); const response = await cosmosClient.uploadWasm(_path); diff --git a/packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts b/packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts index 5f738482..06eb9bdc 100644 --- a/packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts +++ b/packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts @@ -2,7 +2,6 @@ import fs from "fs"; import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { GasPrice } from "@cosmjs/stargate"; import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"; -import { Decimal } from "@cosmjs/math"; import { CosmosChainInfo } from "../types"; import { getOwnerAccount } from "../docker"; @@ -10,15 +9,18 @@ export class CosmosClient { chainInfo: Required; owner: DirectSecp256k1HdWallet; public client: SigningCosmWasmClient; + gasPrice: GasPrice; private constructor( chainInfo: Required, owner: DirectSecp256k1HdWallet, - client: SigningCosmWasmClient + client: SigningCosmWasmClient, + gasPrice: GasPrice ) { this.chainInfo = chainInfo; this.owner = owner; this.client = client; + this.gasPrice = gasPrice; } static async create(config: Omit = {}) { @@ -31,8 +33,10 @@ export class CosmosClient { const walletOptions = { prefix: "wasm", }; + + const gasPrice = GasPrice.fromString(`1${chainInfo.denom}`); const clientOptions = { - gasPrice: new GasPrice(Decimal.fromAtomics("1", 6), chainInfo.denom), + gasPrice, }; const { address, mnemonic } = await getOwnerAccount("wasm"); @@ -57,7 +61,8 @@ export class CosmosClient { }, }, owner, - client + client, + gasPrice ); } @@ -78,6 +83,8 @@ export class CosmosClient { async fundWallet(address: string, amount: string) { const ownerAddress = await this.getOwnerAccount(); + const gasPrice = GasPrice.fromString(`1${this.chainInfo.denom}`); + return this.client.sendTokens( ownerAddress, address, @@ -87,7 +94,15 @@ export class CosmosClient { denom: this.chainInfo.denom, }, ], - "auto" + { + amount: [ + { + amount: gasPrice.amount.toString(), + denom: gasPrice.denom, + }, + ], + gas: "100000", + } ); }