Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jul 24, 2024
1 parent 1cb1407 commit 0df96b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
52 changes: 31 additions & 21 deletions packages/boot/test/orchestration/restart-contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import { TestFn } from 'ava';

import type { CosmosValidatorAddress } from '@agoric/orchestration';
import type { UpdateRecord } from '@agoric/smart-wallet/src/smartWallet.js';
import {
makeWalletFactoryContext,
type WalletFactoryTestContext,
Expand All @@ -17,7 +18,8 @@ test.before(async t => {
});
test.after.always(t => t.context.shutdown?.());

test('sendAnywhere', async t => {
// Not interesting because it doesn't wait on other chains. Leaving here because maybe it will before it's done.
test.serial('sendAnywhere', async t => {
const {
walletFactoryDriver,
buildProposal,
Expand Down Expand Up @@ -55,6 +57,7 @@ test('sendAnywhere', async t => {
},
});
// no errors and no resolution
const beforeFlush = wallet.getLatestUpdateRecord();
t.like(wallet.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: {
Expand All @@ -66,14 +69,14 @@ test('sendAnywhere', async t => {
result: undefined,
});

t.is(await flushInboundQueue(), 0);
t.deepEqual(wallet.getLatestUpdateRecord(), beforeFlush);

t.log('restart sendAnywhere');
await evalProposal(
buildProposal('@agoric/builders/scripts/testing/restart-sendAnywhere.js'),
);

// TODO test iteratively with incremental depth
await flushInboundQueue();

const conclusion = wallet.getLatestUpdateRecord();
console.log('conclusion', conclusion);
t.like(conclusion, {
Expand All @@ -82,12 +85,14 @@ test('sendAnywhere', async t => {
id: 'send-somewhere',
error: undefined,
},
numWantsSatisfied: 1,
numWantsSatisfied: undefined,
payouts: undefined,
result: undefined,
});

// TODO confirm in vstorage that the started offer resolves
await flushInboundQueue();

// Nothing interesting to confirm here.
});

const validatorAddress: CosmosValidatorAddress = {
Expand All @@ -96,7 +101,15 @@ const validatorAddress: CosmosValidatorAddress = {
encoding: 'bech32',
};

test('stakeAtom', async t => {
// check for key because the value will be 'undefined' when the result is provided
// TODO should it be something truthy?
const hasResult = (r: UpdateRecord) => {
assert(r.updated === 'offerStatus');
return 'result' in r.status;
};

// XXX doesn't actually test restarting, but this code can be useful for examples
test.skip('stakeAtom', async t => {
const {
buildProposal,
evalProposal,
Expand All @@ -113,7 +126,7 @@ test('stakeAtom', async t => {
'agoric1testStakAtom',
);

await wd.executeOffer({
await wd.sendOffer({
id: 'request-account',
invitationSpec: {
source: 'agoricContract',
Expand All @@ -123,12 +136,15 @@ test('stakeAtom', async t => {
proposal: {},
});
// cosmos1test is from ibc/mocks.js
t.is(readLatest('published.stakeAtom.accounts.cosmos1test'), '');
const accountPath = 'published.stakeAtom.accounts.cosmos1test';
t.throws(() => readLatest(accountPath));
t.is(await flushInboundQueue(), 1);
t.is(readLatest(accountPath), '');
// request-account is complete

const { ATOM } = agoricNamesRemotes.brand;
assert(ATOM);

// Cannot await executeOffer because the offer won't resolve until after we flush the bridge's inbound queue.
await wd.sendOffer({
id: 'request-delegate',
invitationSpec: {
Expand All @@ -139,16 +155,10 @@ test('stakeAtom', async t => {
},
proposal: {},
});
console.log('sent offer request-delegate');
// TODO shouldn't this not be satisfied?
// t.like(wd.getLatestUpdateRecord(), {
// status: { id: 'request-delegate', numWantsSatisfied: undefined },
// });
// no result yet because the IBC incoming messages haven't arrived
// and won't until we flush.
t.false(hasResult(wd.getLatestUpdateRecord()));

// TODO flush after contract restart
await flushInboundQueue();
console.log('flushed inbound queue');
t.like(wd.getLatestUpdateRecord(), {
status: { id: 'request-delegate', numWantsSatisfied: 1 },
});
t.is(await flushInboundQueue(), 1);
t.true(hasResult(wd.getLatestUpdateRecord()));
});
4 changes: 4 additions & 0 deletions packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { E } from '@endo/far';
import { M } from '@endo/patterns';
import { AmountShape, BrandShape, PaymentShape } from '@agoric/ertp';
import { Shape as NetworkShape } from '@agoric/network';
import { makeTracer } from '@agoric/internal';

const trace = makeTracer('LocalChain', true);

const { Vow$ } = NetworkShape;

Expand Down Expand Up @@ -161,6 +164,7 @@ export const prepareLocalChainAccountKit = (zone, { watch }) =>
* }>}
*/
async executeTx(messages) {
trace('executeTx', messages);
const { address, system } = this.state;
messages.length > 0 || Fail`need at least one message to execute`;

Expand Down

0 comments on commit 0df96b0

Please sign in to comment.