-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: send-anywhere
pfm scenarios
#10591
Merged
+572
−118
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env -S node --import ts-blank-space/register | ||
/* eslint-env node */ | ||
|
||
import '@endo/init'; | ||
import starshipChainInfo from '../starship-chain-info.js'; | ||
import { makeAssetInfo } from '../tools/asset-info.ts'; | ||
|
||
const main = () => { | ||
if (!starshipChainInfo) { | ||
throw new Error( | ||
'starshipChainInfo not found. run `./scripts/fetch-starship-chain-info.ts` first.', | ||
); | ||
} | ||
|
||
const assetInfo = makeAssetInfo(starshipChainInfo) | ||
.filter( | ||
([_, { chainName, baseName }]) => | ||
chainName === 'agoric' && baseName !== 'agoric', | ||
) | ||
.map(([denom, { baseDenom }]) => ({ | ||
denom, | ||
issuerName: baseDenom.replace(/^u/, '').toUpperCase(), | ||
decimalPlaces: 6, // TODO do not assume 6 | ||
})); | ||
|
||
// Directly output JSON string for proposal builder options | ||
process.stdout.write(JSON.stringify(assetInfo)); | ||
}; | ||
|
||
main(); |
51 changes: 51 additions & 0 deletions
51
multichain-testing/src/register-interchain-bank-assets.builder.js
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* global harden */ | ||
/// <reference types="ses" /> | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
import { parseArgs } from 'node:util'; | ||
|
||
/** | ||
* @import {ParseArgsConfig} from 'node:util'; | ||
* @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js'; | ||
*/ | ||
|
||
/** @type {ParseArgsConfig['options']} */ | ||
const parserOpts = { | ||
assets: { type: 'string' }, | ||
}; | ||
|
||
/** @type {CoreEvalBuilder} */ | ||
export const defaultProposalBuilder = async (_, options) => { | ||
return harden({ | ||
sourceSpec: | ||
'@agoric/builders/scripts/testing/register-interchain-bank-assets.js', | ||
getManifestCall: ['getManifestCall', options], | ||
}); | ||
}; | ||
|
||
/** @type {DeployScriptFunction} */ | ||
export default async (homeP, endowments) => { | ||
const { scriptArgs } = endowments; | ||
|
||
const { | ||
values: { assets }, | ||
} = parseArgs({ | ||
args: scriptArgs, | ||
options: parserOpts, | ||
}); | ||
|
||
const parseAssets = () => { | ||
if (typeof assets !== 'string') { | ||
throw Error( | ||
'must provide --assets=JSON.stringify({ denom: Denom; issuerName: string; decimalPlaces: number; }[])', | ||
); | ||
} | ||
return JSON.parse(assets); | ||
}; | ||
|
||
const opts = harden({ assets: parseAssets() }); | ||
|
||
const { writeCoreEval } = await makeHelpers(homeP, endowments); | ||
await writeCoreEval('eval-register-interchain-bank-assets', utils => | ||
defaultProposalBuilder(utils, opts), | ||
); | ||
}; |
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
30 changes: 30 additions & 0 deletions
30
multichain-testing/test/scripts/make-bank-asset-info.test.ts
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import test from 'ava'; | ||
import { execFileSync } from 'node:child_process'; | ||
|
||
test('make-bank-asset-info', async t => { | ||
const stdout = execFileSync('./scripts/make-bank-asset-info.ts', { | ||
encoding: 'utf8', | ||
}); | ||
|
||
const assetInfo = JSON.parse(stdout); | ||
|
||
t.like(assetInfo, [ | ||
{ | ||
issuerName: 'ATOM', | ||
decimalPlaces: 6, | ||
}, | ||
{ | ||
issuerName: 'OSMO', | ||
decimalPlaces: 6, | ||
}, | ||
{ | ||
issuerName: 'ION', | ||
decimalPlaces: 6, | ||
}, | ||
]); | ||
|
||
for (const { denom } of assetInfo) { | ||
t.regex(denom, /^ibc\//); | ||
t.is(denom.length, 68); | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -21,7 +21,8 @@ const contractBuilder = | |
|
||
test.before(async t => { | ||
const { setupTestKeys, ...common } = await commonSetup(t); | ||
const { assetInfo, chainInfo, deleteTestKeys, startContract } = common; | ||
const { assetInfo, chainInfo, deleteTestKeys, faucetTools, startContract } = | ||
common; | ||
deleteTestKeys(accounts).catch(); | ||
const wallets = await setupTestKeys(accounts); | ||
t.context = { ...common, wallets }; | ||
|
@@ -30,19 +31,26 @@ test.before(async t => { | |
chainInfo, | ||
assetInfo, | ||
}); | ||
|
||
await faucetTools.fundFaucet([ | ||
['cosmoshub', 'uatom'], | ||
['osmosis', 'uosmo'], | ||
]); | ||
}); | ||
|
||
test.after(async t => { | ||
const { deleteTestKeys } = t.context; | ||
deleteTestKeys(accounts); | ||
}); | ||
|
||
type BrandKW = 'IST' | 'OSMO' | 'ATOM'; | ||
|
||
const sendAnywhereScenario = test.macro({ | ||
title: (_, chainName: string, acctIdx: number) => | ||
`send-anywhere ${chainName}${acctIdx}`, | ||
exec: async (t, chainName: string, acctIdx: number) => { | ||
const config = chainConfig[chainName]; | ||
if (!config) return t.fail(`Unknown chain: ${chainName}`); | ||
title: (_, destChainName: string, acctIdx: number, brandKw: BrandKW) => | ||
`send-anywhere ${brandKw} from agoric to ${destChainName}${acctIdx}`, | ||
exec: async (t, destChainName: string, acctIdx: number, brandKw: BrandKW) => { | ||
const config = chainConfig[destChainName]; | ||
if (!config) return t.fail(`Unknown chain: ${destChainName}`); | ||
|
||
const { | ||
wallets, | ||
|
@@ -53,13 +61,13 @@ const sendAnywhereScenario = test.macro({ | |
} = t.context; | ||
|
||
t.log('Create a receiving wallet for the send-anywhere transfer'); | ||
const chain = useChain(chainName).chain; | ||
const chain = useChain(destChainName).chain; | ||
|
||
t.log('Create an agoric smart wallet to initiate send-anywhere transfer'); | ||
const agoricAddr = wallets[`${chainName}${acctIdx}`]; | ||
const agoricAddr = wallets[`${destChainName}${acctIdx}`]; | ||
const wdUser1 = await provisionSmartWallet(agoricAddr, { | ||
BLD: 100_000n, | ||
IST: 100_000n, | ||
BLD: 1_000n, | ||
[brandKw]: 1_000n, | ||
}); | ||
t.log(`provisioning agoric smart wallet for ${agoricAddr}`); | ||
|
||
|
@@ -68,11 +76,11 @@ const sendAnywhereScenario = test.macro({ | |
const brands = await vstorageClient.queryData( | ||
'published.agoricNames.brand', | ||
); | ||
const istBrand = Object.fromEntries(brands).IST; | ||
const brand = Object.fromEntries(brands)[brandKw]; | ||
|
||
const apiUrl = await useChain(chainName).getRestEndpoint(); | ||
const apiUrl = await useChain(destChainName).getRestEndpoint(); | ||
const queryClient = makeQueryClient(apiUrl); | ||
t.log(`Made ${chainName} query client`); | ||
t.log(`Made ${destChainName} query client`); | ||
|
||
const doSendAnywhere = async (amount: Amount) => { | ||
t.log(`Sending ${amount.value} ${amount.brand}.`); | ||
|
@@ -83,16 +91,16 @@ const sendAnywhereScenario = test.macro({ | |
encoding: 'bech32', | ||
}; | ||
t.log('Will send payment to:', receiver); | ||
t.log(`${chainName} offer`); | ||
const offerId = `${chainName}-makeSendInvitation-${Date.now()}`; | ||
t.log(`${destChainName} offer`); | ||
const offerId = `${destChainName}-makeSendInvitation-${Date.now()}`; | ||
await doOffer({ | ||
id: offerId, | ||
invitationSpec: { | ||
source: 'agoricContract', | ||
instancePath: [contractName], | ||
callPipe: [['makeSendInvitation']], | ||
}, | ||
offerArgs: { destAddr: receiver.value, chainName }, | ||
offerArgs: { destAddr: receiver.value, chainName: destChainName }, | ||
proposal: { give: { Send: amount } }, | ||
}); | ||
|
||
|
@@ -123,12 +131,12 @@ const sendAnywhereScenario = test.macro({ | |
console.log(`${agoricAddr} offer amounts:`, offerAmounts); | ||
|
||
for (const value of offerAmounts) { | ||
await doSendAnywhere(AmountMath.make(istBrand, value)); | ||
await doSendAnywhere(AmountMath.make(brand, value)); | ||
} | ||
}, | ||
}); | ||
|
||
test.serial(sendAnywhereScenario, 'osmosis', 1); | ||
test.serial(sendAnywhereScenario, 'osmosis', 2); | ||
test.serial(sendAnywhereScenario, 'cosmoshub', 1); | ||
test.serial(sendAnywhereScenario, 'cosmoshub', 2); | ||
test.serial(sendAnywhereScenario, 'osmosis', 1, 'IST'); | ||
test.serial(sendAnywhereScenario, 'osmosis', 2, 'ATOM'); // exercises PFM (agoric -> cosmoshub -> osmosis) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it took me a while to grok what this test does, but I think I get it now. |
||
test.serial(sendAnywhereScenario, 'cosmoshub', 1, 'IST'); | ||
test.serial(sendAnywhereScenario, 'cosmoshub', 2, 'OSMO'); // exercises PFM (agoric -> osmosis -> cosmoshub) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
deploy-cli.ts
know how to run multiple evals in one chain governance proposal? How about combiningoverride-chain-registry
andregister-bank-assets
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I won't tackle that here but I'll hope to make this update soon