Skip to content

Commit

Permalink
test: send-anywhere pfm scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpatrickdev committed Dec 4, 2024
1 parent 5c04514 commit 788cb28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 26 deletions.
50 changes: 29 additions & 21 deletions multichain-testing/test/send-anywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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,
Expand All @@ -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}`);

Expand All @@ -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}.`);
Expand All @@ -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 } },
});

Expand Down Expand Up @@ -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)
29 changes: 24 additions & 5 deletions packages/orchestration/src/proposals/start-send-anywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const trace = makeTracer('StartSA', true);
* consume: {
* BLD: Issuer<'nat'>;
* IST: Issuer<'nat'>;
* USDC: Issuer<'nat'>;
* };
* };
* }} powers
Expand Down Expand Up @@ -84,13 +83,33 @@ export const startSendAnywhere = async (
}),
);

/** @param {() => Promise<Issuer>} 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);
Expand Down

0 comments on commit 788cb28

Please sign in to comment.