From 3c55dbbdb3f89e54313030f96260aa447e96586e Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Sat, 30 Nov 2024 04:38:44 -0500 Subject: [PATCH] test: send-anywhere pfm scenarios --- multichain-testing/test/send-anywhere.test.ts | 50 +++++++++++-------- .../src/proposals/start-send-anywhere.js | 29 +++++++++-- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/multichain-testing/test/send-anywhere.test.ts b/multichain-testing/test/send-anywhere.test.ts index f1a8a720e5f..11508f22cc6 100644 --- a/multichain-testing/test/send-anywhere.test.ts +++ b/multichain-testing/test/send-anywhere.test.ts @@ -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,6 +31,11 @@ test.before(async t => { chainInfo, assetInfo, }); + + await faucetTools.fundFaucet([ + ['cosmoshub', 'uatom'], + ['osmosis', 'uosmo'], + ]); }); test.after(async t => { @@ -37,12 +43,14 @@ test.after(async t => { 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,8 +91,8 @@ 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: { @@ -92,7 +100,7 @@ const sendAnywhereScenario = test.macro({ 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) +test.serial(sendAnywhereScenario, 'cosmoshub', 1, 'IST'); +test.serial(sendAnywhereScenario, 'cosmoshub', 2, 'OSMO'); // exercises PFM (agoric -> osmosis -> cosmoshub) diff --git a/packages/orchestration/src/proposals/start-send-anywhere.js b/packages/orchestration/src/proposals/start-send-anywhere.js index b0db84c3f32..0599f077dd9 100644 --- a/packages/orchestration/src/proposals/start-send-anywhere.js +++ b/packages/orchestration/src/proposals/start-send-anywhere.js @@ -31,7 +31,6 @@ const trace = makeTracer('StartSA', true); * consume: { * BLD: Issuer<'nat'>; * IST: Issuer<'nat'>; - * USDC: Issuer<'nat'>; * }; * }; * }} powers @@ -84,13 +83,33 @@ export const startSendAnywhere = async ( }), ); + /** @param {() => Promise} p */ + const safeFulfill = async p => + E.when( + p(), + i => i, + () => undefined, + ); + + const atomIssuer = await safeFulfill(() => + E(agoricNames).lookup('issuer', 'ATOM'), + ); + const osmoIssuer = await safeFulfill(() => + E(agoricNames).lookup('issuer', 'OSMO'), + ); + + const issuerKeywordRecord = harden({ + BLD: await BLD, + IST: await IST, + ...(atomIssuer && { ATOM: atomIssuer }), + ...(osmoIssuer && { OSMO: osmoIssuer }), + }); + trace('issuerKeywordRecord', issuerKeywordRecord); + const { instance } = await E(startUpgradable)({ label: 'send-anywhere', installation: sendAnywhere, - issuerKeywordRecord: { - Stable: await IST, - Stake: await BLD, - }, + issuerKeywordRecord, privateArgs, }); produceInstance.resolve(instance);