Skip to content

Commit

Permalink
chore(vat-upgrade): improve checking of the existing data and check a…
Browse files Browse the repository at this point in the history
…dding a new chain

Refs: #10408
  • Loading branch information
anilhelvaci committed Dec 4, 2024
1 parent 0ec42bd commit 1886f48
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
2 changes: 1 addition & 1 deletion a3p-integration/proposals/p:upgrade-19/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ testUpgradedBoard/
addUsdLemons/
upgradeProvisionPool/
upgradeAgoricNames/

appendChainInfo/
85 changes: 64 additions & 21 deletions a3p-integration/proposals/p:upgrade-19/agoricNames.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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');
Expand All @@ -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 = [
Expand All @@ -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);
Expand All @@ -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();
});

Expand Down
3 changes: 2 additions & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1886f48

Please sign in to comment.