Skip to content

Commit

Permalink
refactor: use useChain from test context
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Nov 1, 2024
1 parent a4039dd commit 186baa6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions multichain-testing/test/auto-stake-it.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { CosmosChainInfo } from '@agoric/orchestration';
import anyTest from '@endo/ses-ava/prepare-endo.js';
import type { ExecutionContext, TestFn } from 'ava';
import { useChain } from 'starshipjs';
import chainInfo from '../starship-chain-info.js';
import { makeDoOffer } from '../tools/e2e-tools.js';
import {
Expand Down Expand Up @@ -36,7 +35,7 @@ test.after(async t => {
});

const makeFundAndTransfer = (t: ExecutionContext<SetupContextWithWallets>) => {
const { retryUntilCondition } = t.context;
const { retryUntilCondition, useChain } = t.context;
return async (chainName: string, agoricAddr: string, amount = 100n) => {
const { staking } = useChain(chainName).chainInfo.chain;
const denom = staking?.staking_tokens?.[0].denom;
Expand All @@ -45,6 +44,7 @@ const makeFundAndTransfer = (t: ExecutionContext<SetupContextWithWallets>) => {
const { client, address, wallet } = await createFundedWalletAndClient(
t,
chainName,
useChain,
);
const balancesResult = await retryUntilCondition(
() => client.getAllBalances(address),
Expand All @@ -59,6 +59,7 @@ const makeFundAndTransfer = (t: ExecutionContext<SetupContextWithWallets>) => {
{ address: agoricAddr, chainName: 'agoric' },
{ address: address, chainName },
Date.now(),
useChain,
);
console.log('Transfer Args:', transferArgs);
// TODO #9200 `sendIbcTokens` does not support `memo`
Expand Down Expand Up @@ -89,6 +90,7 @@ const autoStakeItScenario = test.macro({
vstorageClient,
provisionSmartWallet,
retryUntilCondition,
useChain,
} = t.context;

const fundAndTransfer = makeFundAndTransfer(t);
Expand Down
4 changes: 3 additions & 1 deletion multichain-testing/tools/ibc-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ExecutionContext } from 'ava';
import type { StdFee } from '@cosmjs/amino';
import { coins } from '@cosmjs/proto-signing';
import { SigningStargateClient } from '@cosmjs/stargate';
import { useChain } from 'starshipjs';
import type {
CosmosChainInfo,
DenomAmount,
Expand All @@ -16,6 +15,7 @@ import {
import { MsgTransfer } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
import { createWallet } from './wallet.js';
import chainInfo from '../starship-chain-info.js';
import type { UseChainFn } from './registry.js';

interface MakeFeeObjectArgs {
denom?: string;
Expand Down Expand Up @@ -61,6 +61,7 @@ export const makeIBCTransferMsg = (
destination: SimpleChainAddress,
sender: SimpleChainAddress,
currentTime: number,
useChain: UseChainFn,
opts: IBCMsgTransferOptions = {},
) => {
const { timeoutHeight, timeoutTimestamp, memo = '' } = opts;
Expand Down Expand Up @@ -119,6 +120,7 @@ export const makeIBCTransferMsg = (
export const createFundedWalletAndClient = async (
t: ExecutionContext,
chainName: string,
useChain: UseChainFn,
) => {
const { chain, creditFromFaucet, getRpcEndpoint } = useChain(chainName);
const wallet = await createWallet(chain.bech32_prefix);
Expand Down
4 changes: 4 additions & 0 deletions multichain-testing/tools/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const makeGetFile =

type GetFilePathFn = ReturnType<typeof makeGetFile>;

export type UseChainFn = Awaited<
ReturnType<ReturnType<typeof makeSetupRegistry>>
>['useChain'];

export const makeSetupRegistry = (getFile: GetFilePathFn) => {
let initialized = false;
/**
Expand Down

0 comments on commit 186baa6

Please sign in to comment.