|
| 1 | +import anyTest from '@endo/ses-ava/prepare-endo.js'; |
| 2 | +import type { TestFn } from 'ava'; |
| 3 | +import { commonSetup, SetupContextWithWallets } from './support.js'; |
| 4 | +import { makeDoOffer } from '../tools/e2e-tools.js'; |
| 5 | +import { chainConfig, chainNames } from './support.js'; |
| 6 | + |
| 7 | +const test = anyTest as TestFn<SetupContextWithWallets>; |
| 8 | + |
| 9 | +const accounts = ['user1', 'user2', 'user3']; // one account for each scenario |
| 10 | + |
| 11 | +const contractName = 'basicFlows'; |
| 12 | +const contractBuilder = |
| 13 | + '../packages/builders/scripts/orchestration/init-basic-flows.js'; |
| 14 | + |
| 15 | +test.before(async t => { |
| 16 | + const { deleteTestKeys, setupTestKeys, ...rest } = await commonSetup(t); |
| 17 | + deleteTestKeys(accounts).catch(); |
| 18 | + const wallets = await setupTestKeys(accounts); |
| 19 | + t.context = { ...rest, wallets, deleteTestKeys }; |
| 20 | + |
| 21 | + t.log('bundle and install contract', contractName); |
| 22 | + await t.context.deployBuilder(contractBuilder); |
| 23 | + const vstorageClient = t.context.makeQueryTool(); |
| 24 | + await t.context.retryUntilCondition( |
| 25 | + () => vstorageClient.queryData(`published.agoricNames.instance`), |
| 26 | + res => contractName in Object.fromEntries(res), |
| 27 | + `${contractName} instance is available`, |
| 28 | + ); |
| 29 | +}); |
| 30 | + |
| 31 | +test.after(async t => { |
| 32 | + const { deleteTestKeys } = t.context; |
| 33 | + deleteTestKeys(accounts); |
| 34 | +}); |
| 35 | + |
| 36 | +const makeAccountScenario = test.macro({ |
| 37 | + title: (_, chainName: string) => `Create account on ${chainName}`, |
| 38 | + exec: async (t, chainName: string) => { |
| 39 | + const config = chainConfig[chainName]; |
| 40 | + if (!config) return t.fail(`Unknown chain: ${chainName}`); |
| 41 | + |
| 42 | + const { |
| 43 | + wallets, |
| 44 | + provisionSmartWallet, |
| 45 | + makeQueryTool, |
| 46 | + retryUntilCondition, |
| 47 | + } = t.context; |
| 48 | + |
| 49 | + const vstorageClient = makeQueryTool(); |
| 50 | + |
| 51 | + const wallet = accounts[chainNames.indexOf(chainName)]; |
| 52 | + const wdUser1 = await provisionSmartWallet(wallets[wallet], { |
| 53 | + BLD: 100n, |
| 54 | + IST: 100n, |
| 55 | + }); |
| 56 | + t.log(`provisioning agoric smart wallet for ${wallets[wallet]}`); |
| 57 | + |
| 58 | + const doOffer = makeDoOffer(wdUser1); |
| 59 | + t.log(`${chainName} makeAccount offer`); |
| 60 | + const offerId = `${chainName}-makeAccount-${Date.now()}`; |
| 61 | + |
| 62 | + // FIXME we get payouts but not an offer result; it times out |
| 63 | + // https://github.com/Agoric/agoric-sdk/issues/9643 |
| 64 | + // chain logs shows an UNPUBLISHED result |
| 65 | + const _offerResult = await doOffer({ |
| 66 | + id: offerId, |
| 67 | + invitationSpec: { |
| 68 | + source: 'agoricContract', |
| 69 | + instancePath: [contractName], |
| 70 | + callPipe: [['makeOrchAccountInvitation']], |
| 71 | + }, |
| 72 | + offerArgs: { chainName }, |
| 73 | + proposal: {}, |
| 74 | + }); |
| 75 | + t.true(_offerResult); |
| 76 | + // t.is(await _offerResult, 'UNPUBLISHED', 'representation of continuing offer'); |
| 77 | + |
| 78 | + // TODO fix above so we don't have to poll for the offer result to be published |
| 79 | + // https://github.com/Agoric/agoric-sdk/issues/9643 |
| 80 | + const currentWalletRecord = await retryUntilCondition( |
| 81 | + () => |
| 82 | + vstorageClient.queryData(`published.wallet.${wallets[wallet]}.current`), |
| 83 | + ({ offerToPublicSubscriberPaths }) => |
| 84 | + Object.fromEntries(offerToPublicSubscriberPaths)[offerId], |
| 85 | + `${offerId} continuing invitation is in vstorage`, |
| 86 | + ); |
| 87 | + |
| 88 | + const offerToPublicSubscriberMap = Object.fromEntries( |
| 89 | + currentWalletRecord.offerToPublicSubscriberPaths, |
| 90 | + ); |
| 91 | + |
| 92 | + const address = offerToPublicSubscriberMap[offerId]?.account |
| 93 | + .split('.') |
| 94 | + .pop(); |
| 95 | + t.log('Got address:', address); |
| 96 | + t.regex( |
| 97 | + address, |
| 98 | + new RegExp(`^${config.expectedAddressPrefix}1`), |
| 99 | + `address for ${chainName} is valid`, |
| 100 | + ); |
| 101 | + |
| 102 | + const latestWalletUpdate = await vstorageClient.queryData( |
| 103 | + `published.wallet.${wallets[wallet]}`, |
| 104 | + ); |
| 105 | + t.log('latest wallet update', latestWalletUpdate); |
| 106 | + t.like( |
| 107 | + latestWalletUpdate.status, |
| 108 | + { |
| 109 | + id: offerId, |
| 110 | + numWantsSatisfied: 1, |
| 111 | + result: 'UNPUBLISHED', |
| 112 | + error: undefined, |
| 113 | + }, |
| 114 | + 'wallet offer satisfied without errors', |
| 115 | + ); |
| 116 | + }, |
| 117 | +}); |
| 118 | + |
| 119 | +test.serial(makeAccountScenario, 'agoric'); |
| 120 | +test.serial(makeAccountScenario, 'cosmoshub'); |
| 121 | +test.serial(makeAccountScenario, 'osmosis'); |
0 commit comments