Skip to content

Commit

Permalink
update tests for starship e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Jan 31, 2025
1 parent 2b98f0e commit 30aaa62
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 119 deletions.
24 changes: 12 additions & 12 deletions packages/starship/__tests__/v0/gov.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
import Long from 'long';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import BigNumber from 'bignumber.js';

import { cosmos, getSigningOsmosisClient } from '../../src/codegen';
import { useChain, waitUntil } from '../../src';
import { useChain } from 'starshipjs';
import { waitUntil } from "../../src";
import './setup.test';

describe('Governance tests for osmosis', () => {
Expand All @@ -20,7 +20,7 @@ describe('Governance tests for osmosis', () => {
beforeAll(async () => {
({ chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } =
useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

// Initialize wallet
protoSigner = await DirectSecp256k1HdWallet.fromMnemonic(
Expand All @@ -33,7 +33,7 @@ describe('Governance tests for osmosis', () => {

// Create custom cosmos interchain client
queryClient = await cosmos.ClientFactory.createRPCQueryClient({
rpcEndpoint: getRpcEndpoint()
rpcEndpoint: await getRpcEndpoint()
});

// Transfer osmosis to address
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Governance tests for osmosis', () => {

it('stake tokens to genesis validator', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: protoSigner
});

Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Governance tests for osmosis', () => {

it('submit a txt proposal', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: protoSigner
});

Expand Down Expand Up @@ -158,7 +158,7 @@ describe('Governance tests for osmosis', () => {

it('query proposal', async () => {
const result = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId)
});

expect(result.proposal.proposalId.toString()).toEqual(proposalId);
Expand All @@ -167,13 +167,13 @@ describe('Governance tests for osmosis', () => {
it('vote on proposal from genesis address', async () => {
// create genesis address signing client
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: protoSigner
});

// Vote on proposal from genesis mnemonic address
const msg = cosmos.gov.v1beta1.MessageComposer.withTypeUrl.vote({
proposalId: Long.fromString(proposalId),
proposalId: BigInt(proposalId),
voter: address,
option: cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES
});
Expand All @@ -194,7 +194,7 @@ describe('Governance tests for osmosis', () => {

it('verify vote', async () => {
const { vote } = await queryClient.cosmos.gov.v1beta1.vote({
proposalId: Long.fromString(proposalId),
proposalId: BigInt(proposalId),
voter: address
});

Expand All @@ -205,15 +205,15 @@ describe('Governance tests for osmosis', () => {
it('wait for voting period to end', async () => {
// wait for the voting period to end
const { proposal } = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId)
});

await expect(waitUntil(proposal.votingEndTime)).resolves.not.toThrow();
}, 200000);

it('verify proposal passed', async () => {
const { proposal } = await queryClient.cosmos.gov.v1beta1.proposal({
proposalId: Long.fromString(proposalId)
proposalId: BigInt(proposalId)
});

expect(proposal.status).toEqual(
Expand Down
13 changes: 7 additions & 6 deletions packages/starship/__tests__/v0/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// @ts-nocheck
import path from 'path';

import { Config, useChain, useRegistry } from '../../src';
import { ConfigContext, useChain, useRegistry } from 'starshipjs';
import { StargateClient } from '@cosmjs/stargate';

beforeAll(async () => {
const configFile = path.join(__dirname, '../..', 'configs', 'config.yaml');
Config.setConfigFile = configFile;
Config.setRegistry = await useRegistry(configFile);
ConfigContext.setConfigFile(configFile);
ConfigContext.setRegistry(await useRegistry(configFile));
}, 200000);

describe('Test clients', () => {
let client;

beforeAll(async () => {
const { getStargateClient } = useChain('osmosis');
client = await getStargateClient();
const { getRpcEndpoint } = useChain('osmosis');
client = await StargateClient.connect(await getRpcEndpoint());
}, 200000);

it('check chain height', async () => {
Expand Down
15 changes: 7 additions & 8 deletions packages/starship/__tests__/v0/staking.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import BigNumber from 'bignumber.js';
import { BigNumber } from 'bignumber.js';

import { cosmos, getSigningOsmosisClient } from '../../src/codegen';
import { useChain } from '../../src';
import { useChain, generateMnemonic } from 'starshipjs';
import './setup.test';

describe('Staking tokens testing', () => {
let wallet, denom, address;
let chainInfo, getCoin, getStargateClient, getRpcEndpoint, creditFromFaucet;
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;

// Variables used accross testcases
let queryClient;
Expand All @@ -18,13 +17,13 @@ describe('Staking tokens testing', () => {

beforeAll(async () => {
({
// @ts-ignore
chainInfo,
getCoin,
getStargateClient,
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

// Initialize wallet
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
Expand All @@ -34,7 +33,7 @@ describe('Staking tokens testing', () => {

// Create custom cosmos interchain client
queryClient = await cosmos.ClientFactory.createRPCQueryClient({
rpcEndpoint: getRpcEndpoint()
rpcEndpoint: await getRpcEndpoint()
});

// Transfer osmosis and ibc tokens to address, send only osmo to address
Expand Down Expand Up @@ -71,7 +70,7 @@ describe('Staking tokens testing', () => {

it('stake tokens to genesis validator', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: wallet
});

Expand Down
24 changes: 11 additions & 13 deletions packages/starship/__tests__/v0/token.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { generateMnemonic } from '@confio/relayer/build/lib/helpers';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
import {assertIsDeliverTxSuccess, StargateClient} from '@cosmjs/stargate';

import { ibc, getSigningOsmosisClient } from '../../src/codegen';
import { useChain } from '../../src';
import { useChain } from 'starshipjs';
import './setup.test';

describe('Token transfers', () => {
let wallet, denom, address;
let chainInfo, getCoin, getStargateClient, getRpcEndpoint, creditFromFaucet;
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;

beforeAll(async () => {
({
chainInfo,
getCoin,
getStargateClient,
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

// Initialize wallet
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
Expand All @@ -38,7 +37,7 @@ describe('Token transfers', () => {
const address2 = (await wallet2.getAccounts())[0].address;

const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: wallet
});

Expand Down Expand Up @@ -74,13 +73,12 @@ describe('Token transfers', () => {

it('send ibc osmo tokens to address on cosmos chain', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: wallet
});

const {
chainInfo: cosmosChainInfo,
getStargateClient: cosmosGetStargateClient,
getRpcEndpoint: cosmosRpcEndpoint
} = useChain('cosmoshub');

Expand Down Expand Up @@ -139,23 +137,23 @@ describe('Token transfers', () => {
assertIsDeliverTxSuccess(resp);

// Check osmos in address on cosmos chain
const cosmosClient = await cosmosGetStargateClient();
const cosmosClient = await StargateClient.connect(await cosmosRpcEndpoint());
const balances = await cosmosClient.getAllBalances(cosmosAddress);

// check balances
expect(balances.length).toEqual(1);
const ibcBalance = balances.find((balance) => {
return balance.denom.startsWith('ibc/');
});
expect(ibcBalance!.amount).toEqual(token.amount);
expect(ibcBalance!.denom).toContain('ibc/');
expect(ibcBalance.amount).toEqual(token.amount);
expect(ibcBalance.denom).toContain('ibc/');

// check ibc denom trace of the same
const queryClient = await ibc.ClientFactory.createRPCQueryClient({
rpcEndpoint: cosmosRpcEndpoint()
rpcEndpoint: await cosmosRpcEndpoint()
});
const trace = await queryClient.ibc.applications.transfer.v1.denomTrace({
hash: ibcBalance!.denom.replace('ibc/', '')
hash: ibcBalance.denom.replace('ibc/', '')
});
expect(trace?.denomTrace?.baseDenom).toEqual(denom);
}, 200000);
Expand Down
Loading

0 comments on commit 30aaa62

Please sign in to comment.