-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2968d3c
commit 7ede1e4
Showing
2 changed files
with
40 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,48 @@ | ||
import anyTest from '@endo/ses-ava/prepare-endo.js'; | ||
import type { TestFn } from 'ava'; | ||
import type { Denom } from '@agoric/orchestration'; | ||
import { makeQueryClient } from '../../tools/query.js'; | ||
import { createWallet } from '../../tools/wallet.js'; | ||
import { sleep } from '../../tools/sleep.js'; | ||
import { commonSetup } from '../support.js'; | ||
|
||
const test = anyTest as TestFn<Record<string, never>>; | ||
|
||
const walletScenario = test.macro(async (t, scenario: string) => { | ||
const { useChain } = await commonSetup(t); | ||
|
||
const prefix = useChain(scenario).chain.bech32_prefix; | ||
const wallet = await createWallet(prefix); | ||
const addr = (await wallet.getAccounts())[0].address; | ||
t.regex(addr, new RegExp(`^${prefix}1`)); | ||
t.log('Made temp wallet:', addr); | ||
|
||
const apiUrl = await useChain(scenario).getRestEndpoint(); | ||
const queryClient = makeQueryClient(apiUrl); | ||
t.log('Made query client'); | ||
|
||
const { balances } = await queryClient.queryBalances(addr); | ||
t.log('Beginning balances:', balances); | ||
t.deepEqual(balances, []); | ||
|
||
const { creditFromFaucet } = useChain(scenario); | ||
t.log('Requesting faucet funds'); | ||
|
||
await creditFromFaucet(addr); | ||
// XXX needed to avoid race condition between faucet POST and LCD Query | ||
// see https://github.com/cosmology-tech/starship/issues/417 | ||
await sleep(1000, t.log); | ||
|
||
const { balances: updatedBalances } = await queryClient.queryBalances(addr); | ||
const expectedDenom = scenario === 'osmosis' ? 'uosmo' : 'uatom'; | ||
t.like(updatedBalances, [{ denom: expectedDenom, amount: '10000000000' }]); | ||
t.log('Updated balances:', updatedBalances); | ||
|
||
const bondDenom = useChain(scenario).chain.staking?.staking_tokens?.[0].denom; | ||
t.truthy(bondDenom, 'bond denom found'); | ||
const { balance } = await queryClient.queryBalance(addr, bondDenom!); | ||
t.deepEqual(balance, { denom: bondDenom, amount: '10000000000' }); | ||
const walletScenario = test.macro({ | ||
title: (_, chainName: string, denom: Denom) => | ||
`create a wallet and get ${denom} on ${chainName}`, | ||
exec: async (t, chainName: string, denom: Denom) => { | ||
const { useChain } = await commonSetup(t); | ||
|
||
const prefix = useChain(chainName).chain.bech32_prefix; | ||
const wallet = await createWallet(prefix); | ||
const addr = (await wallet.getAccounts())[0].address; | ||
t.regex(addr, new RegExp(`^${prefix}1`)); | ||
t.log('Made temp wallet:', addr); | ||
|
||
const apiUrl = await useChain(chainName).getRestEndpoint(); | ||
const queryClient = makeQueryClient(apiUrl); | ||
t.log('Made query client'); | ||
|
||
const { balances } = await queryClient.queryBalances(addr); | ||
t.log('Beginning balances:', balances); | ||
t.deepEqual(balances, []); | ||
|
||
const { creditFromFaucet } = useChain(chainName); | ||
t.log('Requesting faucet funds'); | ||
await creditFromFaucet(addr, denom); | ||
// XXX needed to avoid race condition between faucet POST and LCD Query | ||
// see https://github.com/cosmology-tech/starship/issues/417 | ||
await sleep(1000, t.log); | ||
|
||
const { balance } = await queryClient.queryBalance(addr, denom); | ||
t.log('Ending balance:', balance); | ||
t.deepEqual(balance, { denom, amount: '10000000000' }); | ||
}, | ||
}); | ||
|
||
test('create a wallet and get tokens (osmosis)', walletScenario, 'osmosis'); | ||
test('create a wallet and get tokens (cosmoshub)', walletScenario, 'cosmoshub'); | ||
test(walletScenario, 'osmosis', 'uosmo'); | ||
test(walletScenario, 'cosmoshub', 'uatom'); | ||
test(walletScenario, 'agoric', 'ubld'); | ||
test(walletScenario, 'agoric', 'uist'); | ||
test(walletScenario, 'osmosis', 'uion'); |