Skip to content

Commit

Permalink
chore: fix gas issue
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Oct 27, 2023
1 parent eabc92b commit 412038a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/axelar-local-dev-cosmos/jest/jest.global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stopAll, startAll } from "../src/docker";

export default async () => {
await startAll();
// await startAll();
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stopAll } from "../src/docker";

export default async () => {
await stopAll();
// await stopAll();
};
Original file line number Diff line number Diff line change
@@ -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);
});

Expand All @@ -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);

Expand Down
25 changes: 20 additions & 5 deletions packages/axelar-local-dev-cosmos/src/clients/CosmosClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ 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";

export class CosmosClient {
chainInfo: Required<CosmosChainInfo>;
owner: DirectSecp256k1HdWallet;
public client: SigningCosmWasmClient;
gasPrice: GasPrice;

private constructor(
chainInfo: Required<CosmosChainInfo>,
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<CosmosChainInfo, "owner"> = {}) {
Expand All @@ -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");
Expand All @@ -57,7 +61,8 @@ export class CosmosClient {
},
},
owner,
client
client,
gasPrice
);
}

Expand All @@ -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,
Expand All @@ -87,7 +94,15 @@ export class CosmosClient {
denom: this.chainInfo.denom,
},
],
"auto"
{
amount: [
{
amount: gasPrice.amount.toString(),
denom: gasPrice.denom,
},
],
gas: "100000",
}
);
}

Expand Down

0 comments on commit 412038a

Please sign in to comment.