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 2, 2024
1 parent fd9cb7d commit 46e6875
Show file tree
Hide file tree
Showing 2 changed files with 52 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: JSON.stringify(chainInfo),
assetInfo: JSON.stringify(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)
28 changes: 23 additions & 5 deletions packages/orchestration/src/proposals/start-send-anywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const trace = makeTracer('StartSA', true);
* consume: {
* BLD: Issuer<'nat'>;
* IST: Issuer<'nat'>;
* USDC: Issuer<'nat'>;
* };
* };
* }} powers
Expand Down Expand Up @@ -82,13 +81,32 @@ export const startSendAnywhere = async (
}),
);

const safeLookup = async p =>
E.when(
p(),
i => i,
() => undefined,
);

const atomIssuer = await safeLookup(() =>
E(agoricNames).lookup('issuer', 'ATOM'),
);
const osmoIssuer = await safeLookup(() =>
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 46e6875

Please sign in to comment.