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