Skip to content

Commit

Permalink
upgrade tests to make it work with async
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Jun 20, 2024
1 parent 6f48d15 commit ee144db
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
14 changes: 7 additions & 7 deletions packages/osmojs/starship/__tests__/gov.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { waitUntil } from '../src';
describe('Governance tests for osmosis', () => {
let protoSigner, aminoSigner, denom, address;
let chainInfo: ChainInfo;
let getCoin: () => Asset;
let getRpcEndpoint: () => string;
let getCoin: () => Promise<Asset>;
let getRpcEndpoint: () => Promise<string>;
let creditFromFaucet: (address: string, denom?: string | null) => Promise<void>;

// Variables used accross testcases
Expand All @@ -38,7 +38,7 @@ describe('Governance tests for osmosis', () => {
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

const mnemonic = generateMnemonic();
// Initialize wallet
Expand All @@ -52,7 +52,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 @@ -89,7 +89,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 @@ -126,7 +126,7 @@ describe('Governance tests for osmosis', () => {

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

Expand Down Expand Up @@ -189,7 +189,7 @@ describe('Governance tests for osmosis', () => {
it('vote on proposal from address', async () => {
// create genesis address signing client
const signingClient = await getSigningCosmosClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: protoSigner
});

Expand Down
20 changes: 10 additions & 10 deletions packages/osmojs/starship/__tests__/pools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('Pool testing over IBC tokens', () => {
let protoSigner, aminoSigner, denom, address;

let chainInfo: ChainInfo;
let getCoin: () => Asset;
let getRpcEndpoint: () => string;
let getCoin: () => Promise<Asset>;
let getRpcEndpoint: () => Promise<string>;
let creditFromFaucet: (address: string, denom?: string | null) => Promise<void>;

// Variables used accross testcases
Expand All @@ -33,7 +33,7 @@ describe('Pool testing over IBC tokens', () => {
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

const mnemonic = generateMnemonic();
// Initialize wallet
Expand All @@ -51,7 +51,7 @@ describe('Pool testing over IBC tokens', () => {
}, 200000);

it('check address has tokens', async () => {
const client = await StargateClient.connect(getRpcEndpoint());
const client = await StargateClient.connect(await getRpcEndpoint());
const balances = await client.getAllBalances(address);

expect(balances.length).toEqual(2);
Expand All @@ -62,7 +62,7 @@ describe('Pool testing over IBC tokens', () => {

it('create ibc pools with ibc atom osmo', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: protoSigner
});

Expand Down Expand Up @@ -128,10 +128,10 @@ describe('Pool testing over IBC tokens', () => {
it('query pool via id, verify creation', async () => {
// Query the created pool
const queryClient = await osmosis.ClientFactory.createRPCQueryClient({
rpcEndpoint: getRpcEndpoint()
rpcEndpoint: await getRpcEndpoint()
});

const client = await StargateClient.connect(getRpcEndpoint());
const client = await StargateClient.connect(await getRpcEndpoint());

const poolResponse = await queryClient.osmosis.gamm.v1beta1.pool({
poolId
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('Pool testing over IBC tokens', () => {

it('join pool', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: aminoSigner
});

Expand Down Expand Up @@ -208,7 +208,7 @@ describe('Pool testing over IBC tokens', () => {

it('lock tokens', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: aminoSigner
});

Expand Down Expand Up @@ -251,7 +251,7 @@ describe('Pool testing over IBC tokens', () => {

it('swap tokens using pool, to address without ibc token', async () => {
const signingClient = await getSigningOsmosisClient({
rpcEndpoint: getRpcEndpoint(),
rpcEndpoint: await getRpcEndpoint(),
signer: aminoSigner
});

Expand Down
2 changes: 1 addition & 1 deletion packages/osmojs/starship/__tests__/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Test clients', () => {

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

it('check chain height', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/osmojs/starship/__tests__/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Staking tokens testing', () => {
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

// Initialize wallet
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
Expand All @@ -34,7 +34,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 +71,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
16 changes: 8 additions & 8 deletions packages/osmojs/starship/__tests__/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Token transfers', () => {
getRpcEndpoint,
creditFromFaucet
} = useChain('osmosis'));
denom = getCoin().base;
denom = (await getCoin()).base;

// Initialize wallet
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
Expand All @@ -38,7 +38,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,7 +74,7 @@ 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
});

Expand All @@ -95,12 +95,12 @@ describe('Token transfers', () => {
const cosmosAddress = (await cosmosWallet.getAccounts())[0].address;

const ibcInfos = chainInfo.fetcher.getChainIbcData(
chainInfo.chain.chain_id
chainInfo.chain.chain_name
);
const ibcInfo = ibcInfos.find(
(i) =>
i.chain_1.chain_name === chainInfo.chain.chain_id &&
i.chain_2.chain_name === cosmosChainInfo.chain.chain_id
i.chain_1.chain_name === chainInfo.chain.chain_name &&
i.chain_2.chain_name === cosmosChainInfo.chain.chain_name
);

expect(ibcInfo).toBeTruthy();
Expand Down Expand Up @@ -142,7 +142,7 @@ describe('Token transfers', () => {
assertIsDeliverTxSuccess(resp);

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

// check balances
Expand All @@ -157,7 +157,7 @@ describe('Token transfers', () => {

// 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({
// @ts-ignore
Expand Down
10 changes: 5 additions & 5 deletions packages/osmojs/starship/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const transferIbcTokens = async (fromChain: string, toChain: string, toAd

await fromChainData.creditFromFaucet(fromAddress);

const fromClient = await setupIbcClient(fromChainData.getRpcEndpoint(), wallet);
const token = { denom: fromChainData.getCoin().base, amount };
const fromClient = await setupIbcClient(await fromChainData.getRpcEndpoint(), wallet);
const token = { denom: (await fromChainData.getCoin()).base, amount };

const resp = await sendIbcTokens(fromClient, fromAddress, toAddress, token, ibcInfo, amount);

Expand All @@ -53,10 +53,10 @@ export const transferIbcTokens = async (fromChain: string, toChain: string, toAd

const findIbcInfo = (chainInfo: ChainInfo, toChainInfo: ChainInfo) => {
const registry = ConfigContext.registry;
const ibcInfos = registry!.getChainIbcData(chainInfo.chain.chain_id);
const ibcInfos = registry!.getChainIbcData(chainInfo.chain.chain_name);
const found = ibcInfos.find(
i => i.chain_1.chain_name === chainInfo.chain.chain_id &&
i.chain_2.chain_name === toChainInfo.chain.chain_id
i => i.chain_1.chain_name === chainInfo.chain.chain_name &&
i.chain_2.chain_name === toChainInfo.chain.chain_name
);
if (!found) throw new Error('Cannot find IBC info');
return found;
Expand Down

0 comments on commit ee144db

Please sign in to comment.