diff --git a/a3p-integration/proposals/p:upgrade-19/.gitignore b/a3p-integration/proposals/p:upgrade-19/.gitignore index 59e3519121b..b74655149d1 100644 --- a/a3p-integration/proposals/p:upgrade-19/.gitignore +++ b/a3p-integration/proposals/p:upgrade-19/.gitignore @@ -3,4 +3,4 @@ testUpgradedBoard/ addUsdLemons/ upgradeProvisionPool/ upgradeAgoricNames/ - +appendChainInfo/ diff --git a/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js b/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js index d15a8c3beaa..255eec2d139 100644 --- a/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js +++ b/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js @@ -5,29 +5,25 @@ * Ideas: * - write something new to agoricNames and check vstorage * - can you add a new chain for orc? - * - can you add a new psm? * - can you open a vault? */ import '@endo/init'; import test from 'ava'; -import { - evalBundles, - agd as agdAmbient, - agoric, - getDetailsMatchingVats, -} from '@agoric/synthetic-chain'; -import { makeVstorageKit } from '@agoric/client-utils'; +import { evalBundles, getDetailsMatchingVats } from '@agoric/synthetic-chain'; +import { makeVstorageKit, retryUntilCondition } from '@agoric/client-utils'; const AGORIC_NAMES_UPGRADE_DIR = 'upgradeAgoricNames'; -const WRITE_AGORIC_NAMES = 'writeToAgoricNames'; - -const ambientAuthority = { - query: agdAmbient.query, - follow: agoric.follow, - setTimeout, - log: console.log, -}; +const WRITE_AGORIC_NAMES_DIR = 'writeToAgoricNames'; +const APPEND_CHAIN_DIR = 'appendChainInfo'; + +const makeWaitUntilKeyFound = (keyFinder, vstorage) => (path, targetKey) => + retryUntilCondition( + () => vstorage.keys(path), + keys => keyFinder(keys, targetKey), + 'Key not found.', + { maxRetries: 5, retryIntervalMs: 2000, log: console.log, setTimeout }, + ); test.before(async t => { const vstorageKit = await makeVstorageKit( @@ -40,7 +36,7 @@ test.before(async t => { }; }); -test.serial.only('upgrade agoricNames', async t => { +test.serial('upgrade agoricNames', async t => { await evalBundles(AGORIC_NAMES_UPGRADE_DIR); const vatDetailsAfter = await getDetailsMatchingVats('agoricNames'); @@ -53,7 +49,7 @@ test.serial.only('upgrade agoricNames', async t => { t.pass(); }); -test.serial.only('check all existing values are preserved', async t => { +test.serial('check all existing values are preserved', async t => { // @ts-expect-error const { vstorageKit } = t.context; const agoricNamesChildren = [ @@ -78,7 +74,7 @@ test.serial.only('check all existing values are preserved', async t => { const agoricNamesBefore = await getAgoricNames(); console.log('AGORIC_NAMES_BEFORE', agoricNamesBefore); - await evalBundles(WRITE_AGORIC_NAMES); + await evalBundles(WRITE_AGORIC_NAMES_DIR); const agoricNamesAfter = await getAgoricNames(); t.like(agoricNamesAfter, agoricNamesBefore); @@ -91,8 +87,55 @@ test.serial.only('check all existing values are preserved', async t => { ); }); -test.serial.only('check we can add new chains', async t => { - await evalBundles('chainInfoTest'); +test.serial('check we can add new chains', async t => { + // @ts-expect-error + const { vstorageKit } = t.context; + await evalBundles(APPEND_CHAIN_DIR); + + const waitUntilKeyFound = makeWaitUntilKeyFound( + (keys, targetKey) => keys.includes(targetKey), + vstorageKit.vstorage, + ); + await Promise.all([ + waitUntilKeyFound('published.agoricNames.chain', 'hot'), + waitUntilKeyFound( + 'published.agoricNames.chainConnection', + 'cosmoshub-4_hot-1', + ), + ]); + + const [chainInfo, connectionInfo] = await Promise.all([ + vstorageKit.readLatestHead('published.agoricNames.chain.hot'), + vstorageKit.readLatestHead( + 'published.agoricNames.chainConnection.cosmoshub-4_hot-1', + ), + ]); + + t.log({ + chainInfo, + connectionInfo, + }); + + t.deepEqual(chainInfo, { allegedName: 'Hot New Chain', chainId: 'hot-1' }); + t.deepEqual(connectionInfo, { + client_id: '07-tendermint-2', + counterparty: { + client_id: '07-tendermint-3', + connection_id: 'connection-99', + }, + id: 'connection-1', + state: 3, + transferChannel: { + channelId: 'channel-1', + counterPartyChannelId: 'channel-1', + counterPartyPortId: 'transfer', + ordering: 1, + portId: 'transfer', + state: 3, + version: 'ics20-1', + }, + }); + t.pass(); }); diff --git a/a3p-integration/proposals/p:upgrade-19/package.json b/a3p-integration/proposals/p:upgrade-19/package.json index 5b120f2b804..53a8b1e74fc 100644 --- a/a3p-integration/proposals/p:upgrade-19/package.json +++ b/a3p-integration/proposals/p:upgrade-19/package.json @@ -8,7 +8,8 @@ "vats/upgrade-paRegistry.js", "vats/upgrade-board.js", "testing/test-upgraded-board.js testUpgradedBoard", - "vats/upgrade-agoricNames.js upgradeAgoricNames" + "vats/upgrade-agoricNames.js upgradeAgoricNames", + "testing/append-chain-info appendChainInfo" ] }, "type": "module",