Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jun 18, 2024
1 parent d6dde5d commit e4a4693
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 2 deletions.
3 changes: 3 additions & 0 deletions multichain-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ PROVISION_POOL_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346
fund-provision-pool:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet $(PROVISION_POOL_ADDR) 1000000000uist -y -b block

fix-agoric-names:
scripts/deploy.ts src/revise-chain-info.builder.js

ADDR=agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce
COIN=1000000000uist

Expand Down
3 changes: 3 additions & 0 deletions multichain-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
"@endo/nat": "^5.0.7",
"@endo/ses-ava": "^1.2.2",
"@types/eslint": "^8",
"@types/fs-extra": "^11",
"@types/node": "^20.11.13",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"ava": "^6.1.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"execa": "^9.2.0",
"fs-extra": "^11.2.0",
"patch-package": "^8.0.0",
"prettier": "^3.2.4",
"starshipjs": "2.0.0",
Expand Down
50 changes: 50 additions & 0 deletions multichain-testing/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env tsx
/** @file run a builder and deploy it onto the Agoric chain in local Starship cluster */
import '@endo/init/debug.js';

import { execa } from 'execa';
import fse from 'fs-extra';
import fsp from 'node:fs/promises';
import { makeE2ETools } from '../tools/e2e-tools.js';
import { makeNodeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import childProcess from 'child_process';

const builder = process.argv[2];

if (!builder) {
console.error('USAGE: deploy.ts <builder script>');
process.exit(1);
}

const tools = await (async () => {
const bundleCache = await makeNodeBundleCache('bundles', {}, s => import(s));
const { writeFile } = fsp;
const { execFileSync, execFile } = childProcess;
const tools = await makeE2ETools(console, bundleCache, {
execFileSync,
execFile,
fetch,
setTimeout,
writeFile,
});
return tools;
})();

// console.log('refreshing starship chain info');
// await import('./fetch-starship-chain-info.ts');

// build the plan
const { stdout } = await execa`agoric run ${builder}`;
const match = stdout.match(/ (?<name>[-\w]+)-permit.json/);
if (!(match && match.groups)) {
throw new Error('no permit found');
}
const plan = await fse.readJSON(`./${match.groups.name}-plan.json`);

console.log(plan);

console.log('installing bundles');
tools.installBundles(
plan.bundles.map(b => b.bundleID),
console.log,
);
59 changes: 59 additions & 0 deletions multichain-testing/scripts/fetch-starship-chain-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env tsx

import nodeFetch from 'node-fetch';
import fsp from 'node:fs/promises';
import prettier from 'prettier';

import { convertChainInfo } from '@agoric/orchestration/src/utils/registry.js';

import type { IBCInfo, Chains } from '@chain-registry/types';

const fetch = nodeFetch.default;

/**
* Chain registry running in Starship
*
* https://github.com/cosmology-tech/starship/blob/main/starship/proto/registry/service.proto
*
* http://localhost:8081/chains
* http://localhost:8081/chain_ids
* http://localhost:8081/ibc
*/
const BASE_URL = 'http://localhost:8081/';

const { chains }: { chains: Chains } = await fetch(`${BASE_URL}chains`).then(
r => r.json(),
);

const ibc: {
data: IBCInfo[];
} = await fetch(`${BASE_URL}ibc`).then(r => r.json());

// UNTIL https://github.com/cosmology-tech/starship/issues/494
const backmap = {
agoriclocal: 'agoric',
osmosislocal: 'osmosis',
gaialocal: 'cosmoshub',
};
for (const ibcInfo of ibc.data) {
ibcInfo.chain_1.chain_name = backmap[ibcInfo.chain_1.chain_name];
ibcInfo.chain_2.chain_name = backmap[ibcInfo.chain_2.chain_name];
for (const c of ibcInfo.channels) {
// @ts-expect-error XXX bad typedef
c.tags.preferred = c.tags.perferred;
}
}

const chainInfo = await convertChainInfo({
chains,
ibcData: ibc.data,
});

const record = JSON.stringify(chainInfo, null, 2);
const src = `/** @file Generated by fetch-starship-chain-info.ts */\nexport default /** @type {const} } */ (${record});`;
const prettySrc = await prettier.format(src, {
parser: 'babel', // 'typescript' fails to preserve parens for typecast
singleQuote: true,
trailingComma: 'all',
});
await fsp.writeFile('./starship-chain-info.js', prettySrc);
22 changes: 22 additions & 0 deletions multichain-testing/src/revise-chain-info.builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* global harden */
/// <reference types="ses" />
import { makeHelpers } from '@agoric/deploy-script-support';

import chainInfo from '../starship-chain-info.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
export const defaultProposalBuilder = async () =>
harden({
sourceSpec: '@agoric/orchestration/src/proposals/revise-chain-info.js',
getManifestCall: [
'getManifestForReviseChains',
{
chainInfo,
},
],
});

export default async (homeP, endowments) => {
const { writeCoreEval } = await makeHelpers(homeP, endowments);
await writeCoreEval('revise-chain-info', defaultProposalBuilder);
};
162 changes: 162 additions & 0 deletions multichain-testing/starship-chain-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/** @file Generated by fetch-starship-chain-info.ts */
export default /** @type {const} } */ ({
agoric: {
chainId: 'agoriclocal',
stakingTokens: [
{
denom: 'ubld',
},
],
icqEnabled: false,
connections: {
gaialocal: {
id: 'connection-1',
client_id: '07-tendermint-1',
counterparty: {
client_id: '07-tendermint-1',
connection_id: 'connection-1',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-1',
portId: 'transfer',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
osmosislocal: {
id: 'connection-0',
client_id: '07-tendermint-0',
counterparty: {
client_id: '07-tendermint-1',
connection_id: 'connection-1',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-1',
portId: 'transfer',
counterPartyChannelId: 'channel-0',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
},
},
cosmoshub: {
chainId: 'gaialocal',
stakingTokens: [
{
denom: 'uatom',
},
],
icqEnabled: false,
connections: {
agoriclocal: {
id: 'connection-1',
client_id: '07-tendermint-1',
counterparty: {
client_id: '07-tendermint-1',
connection_id: 'connection-1',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-1',
portId: 'transfer',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
osmosislocal: {
id: 'connection-0',
client_id: '07-tendermint-0',
counterparty: {
client_id: '07-tendermint-0',
connection_id: 'connection-0',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-0',
portId: 'transfer',
counterPartyChannelId: 'channel-0',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
},
},
osmosis: {
chainId: 'osmosislocal',
stakingTokens: [
{
denom: 'uosmo',
},
],
icqEnabled: true,
connections: {
agoriclocal: {
id: 'connection-1',
client_id: '07-tendermint-1',
counterparty: {
client_id: '07-tendermint-0',
connection_id: 'connection-0',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-0',
portId: 'transfer',
counterPartyChannelId: 'channel-1',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
gaialocal: {
id: 'connection-0',
client_id: '07-tendermint-0',
counterparty: {
client_id: '07-tendermint-0',
connection_id: 'connection-0',
prefix: {
key_prefix: 'FIXME',
},
},
state: 3,
transferChannel: {
channelId: 'channel-0',
portId: 'transfer',
counterPartyChannelId: 'channel-0',
counterPartyPortId: 'transfer',
ordering: 0,
state: 3,
version: 'ics20-1',
},
},
},
},
});
Loading

0 comments on commit e4a4693

Please sign in to comment.