-
Notifications
You must be signed in to change notification settings - Fork 214
/
valueVow.test.js
87 lines (76 loc) · 2.32 KB
/
valueVow.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
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
// @ts-check
/* eslint-env node */
import test from 'ava';
import { inspect } from 'node:util';
import { retryUntilCondition } from '@agoric/client-utils';
import {
evalBundles,
getIncarnation,
GOV1ADDR as GETTER, // not particular to governance, just a handy wallet
GOV2ADDR as SETTER,
} from '@agoric/synthetic-chain';
import { agdWalletUtils } from './test-lib/index.js';
const START_VALUEVOW_DIR = 'start-valueVow';
const RESTART_VALUEVOW_DIR = 'restart-valueVow';
test('vow survives restart', async t => {
t.log('start valueVow');
await evalBundles(START_VALUEVOW_DIR);
t.is(await getIncarnation('valueVow'), 0);
t.log('use wallet to get a vow');
await agdWalletUtils.broadcastBridgeAction(GETTER, {
method: 'executeOffer',
offer: {
id: 'get-value',
invitationSpec: {
source: 'agoricContract',
instancePath: ['valueVow'],
callPipe: [['makeGetterInvitation']],
},
proposal: {},
},
});
t.log('confirm the value is not in offer results');
let getterStatus = await retryUntilCondition(
/** @type {() => Promise<any>} */
async () => agdWalletUtils.readLatestHead(`published.wallet.${GETTER}`),
value => value.status.id === 'get-value' && value.updated === 'offerStatus',
'Offer get-value not succeeded',
{
retryIntervalMs: 5000,
maxRetries: 15,
renderResult: status => inspect(status, { depth: 10 }),
log: t.log,
setTimeout,
},
);
t.like(getterStatus, {
status: {
id: 'get-value',
},
updated: 'offerStatus',
});
t.false('result' in getterStatus.status, 'no result yet');
t.log('restart valueVow');
await evalBundles(RESTART_VALUEVOW_DIR);
t.is(await getIncarnation('valueVow'), 1);
const offerArgs = { value: 'Ciao, mondo!' };
t.log('use wallet to set value');
await agdWalletUtils.broadcastBridgeAction(SETTER, {
method: 'executeOffer',
offer: {
id: 'set-value',
invitationSpec: {
source: 'agoricContract',
instancePath: ['valueVow'],
callPipe: [['makeSetterInvitation']],
},
offerArgs,
proposal: {},
},
});
t.log('confirm the value is now in offer results');
getterStatus = await agdWalletUtils.readLatestHead(
`published.wallet.${GETTER}`,
);
t.like(getterStatus, { status: { result: offerArgs.value } });
});