From 0df96b0cf5681136d5e338a208b267bc093cdb78 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 24 Jul 2024 16:13:04 -0700 Subject: [PATCH] WIP --- .../orchestration/restart-contracts.test.ts | 52 +++++++++++-------- packages/vats/src/localchain.js | 4 ++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/boot/test/orchestration/restart-contracts.test.ts b/packages/boot/test/orchestration/restart-contracts.test.ts index d541f9f923d3..11db5769519f 100644 --- a/packages/boot/test/orchestration/restart-contracts.test.ts +++ b/packages/boot/test/orchestration/restart-contracts.test.ts @@ -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, @@ -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, @@ -55,6 +57,7 @@ test('sendAnywhere', async t => { }, }); // no errors and no resolution + const beforeFlush = wallet.getLatestUpdateRecord(); t.like(wallet.getLatestUpdateRecord(), { updated: 'offerStatus', status: { @@ -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, { @@ -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 = { @@ -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, @@ -113,7 +126,7 @@ test('stakeAtom', async t => { 'agoric1testStakAtom', ); - await wd.executeOffer({ + await wd.sendOffer({ id: 'request-account', invitationSpec: { source: 'agoricContract', @@ -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: { @@ -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())); }); diff --git a/packages/vats/src/localchain.js b/packages/vats/src/localchain.js index b9aae359835f..9bd2cef12779 100644 --- a/packages/vats/src/localchain.js +++ b/packages/vats/src/localchain.js @@ -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; @@ -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`;