-
Notifications
You must be signed in to change notification settings - Fork 6
/
wallet-repairs.test.js
executable file
·46 lines (36 loc) · 1.53 KB
/
wallet-repairs.test.js
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
import { readFile, writeFile } from 'node:fs/promises';
import test from 'ava';
import { agd, getUser, evalBundles } from '@agoric/synthetic-chain';
const SUBMISSION_DIR = 'invite-submission';
/**
* @param {string} fileName base file name without .tjs extension
* @param {Record<string, string>} replacements
*/
const replaceTemplateValuesInFile = async (fileName, replacements) => {
let script = await readFile(`${fileName}.tjs`, 'utf-8');
for (const [template, value] of Object.entries(replacements)) {
script = script.replaceAll(`{{${template}}}`, value);
}
await writeFile(`${fileName}.js`, script);
};
test('smartWallet repairs', async t => {
const gov1Address = await getUser('gov1');
await replaceTemplateValuesInFile(`${SUBMISSION_DIR}/sendInvite`, {
ADDRESS: gov1Address,
});
await evalBundles(SUBMISSION_DIR);
// agd query vstorage data published.wallet.$GOV1ADDR.current -o json \
// |& jq '.value | fromjson | .values[0] | fromjson | .body[1:] \
// | fromjson | .purses '
const walletCurrent = await agd.query(
'vstorage',
'data',
`published.wallet.${gov1Address}.current`,
);
const body = JSON.parse(JSON.parse(walletCurrent.value).values[0]);
const bodyTruncated = JSON.parse(body.body.substring(1));
const invitePurseBalance = bodyTruncated.purses[0].balance;
t.truthy(invitePurseBalance.value[0], 'expecting a non-empty purse');
const description = invitePurseBalance.value[0].description;
t.is(description, 'Add Collateral', 'invitation purse should not be empty');
});