Skip to content

Commit

Permalink
feat(multichain-testing): stakeIca contract e2e test (#9534)
Browse files Browse the repository at this point in the history
closes: #8896

## Description

Adds e2e tests and relevant tooling for `stakeIca.contract.js` to `multichain-testing`. More specifically:
- Adds `multichain-testing/tools/deploy.ts` to: 1) build a contract and proposal with `agoric run` (local bin), 2) copy files to container 3) run `installBundles` and `runCoreEval`
- Adds logic to gather **chain info** from the starship environment (`registry` node on localhost:8081) and execute `revise-chain-info` proposal in local testing and CI
- Tests happy-path wallet flows of `stakeIca` via `stakeOsmo` and `stakeAtom` instances
  
  
Areas for improvement:
  - Notifiers for wallet offer results are not working correctly here. Instead of relying on them for wallet offer results we are polling vstorage on an interval (see `makeRetryUntilCondition`) for the initial offer, and verify the behavior by querying state on remote chains. If an offer result results in an error, that is not currently captured until #9643
  • Loading branch information
mergify[bot] authored Jul 3, 2024
2 parents c2222f8 + 55f1896 commit bfa47d1
Show file tree
Hide file tree
Showing 22 changed files with 1,750 additions and 227 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/multichain-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
node-version: 18.x
path: ./agoric-sdk

- name: yarn link
run: |
yarn link-cli ~/bin/agoric
echo "/home/runner/bin" >> $GITHUB_PATH
working-directory: ./agoric-sdk

- name: Enable Corepack
run: corepack enable
working-directory: ./agoric-sdk/multichain-testing
Expand Down Expand Up @@ -62,6 +68,10 @@ jobs:
curl --fail --retry 3 --retry-delay 10 http://localhost:8081/chains/osmosislocal || (echo "osmosislocal URL check failed")
curl --fail --retry 3 --retry-delay 10 http://localhost:8081/chains/gaialocal || (echo "gaialocal URL check failed")
- name: Override Chain Registry
run: make override-chain-registry
working-directory: ./agoric-sdk/multichain-testing

- name: Run @agoric/multichain-testing E2E Tests
run: yarn test
working-directory: ./agoric-sdk/multichain-testing
2 changes: 2 additions & 0 deletions multichain-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.tsimp
.yarn/*
!.yarn/patches/*
revise-chain-info*
start-*
12 changes: 10 additions & 2 deletions multichain-testing/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# see https://github.com/cosmology-tech/starship/blob/0e18757b8393357fc66426c5ee23da4ccf760e74/examples/getting-started/Makefile

NAME = starship-getting-started
NAME = agoric-multichain-testing
FILE = config.yaml

HELM_REPO = starship
Expand Down Expand Up @@ -53,7 +53,7 @@ stop-forward:
###############################################################################
### Local Kind Setup ###
###############################################################################
KIND_CLUSTER=starship
KIND_CLUSTER=agship

.PHONY: setup-kind
setup-kind:
Expand All @@ -68,9 +68,17 @@ clean-kind:
###############################################################################
PROVISION_POOL_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346

# add address
add-address:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd keys add user1

fund-provision-pool:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet $(PROVISION_POOL_ADDR) 1000000000uist -y -b block

override-chain-registry:
node_modules/.bin/tsx scripts/fetch-starship-chain-info.ts && \
node_modules/.bin/tsx scripts/deploy-cli.ts src/revise-chain-info.builder.js

ADDR=agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce
COIN=1000000000uist

Expand Down
48 changes: 31 additions & 17 deletions multichain-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ The `agoric` software revision includes the vats necessary for building and test

## Initial Setup

Ensure you have `kubectl`, `kind`, `helm`, and `yq` installed on your machine. For convenience, the following command will install dependencies:
Ensure you have `kubectl`, `kind`, `helm`, and `yq` installed on your machine.

```sh
make setup-deps
```

You will need a `kind` cluster:

```sh
make setup-kind
make setup
```

## Getting Started
Expand All @@ -34,21 +28,31 @@ make setup-kind
# install helm chart and start starship service
make install

# NOTE: it takes about 10-12 minutes for the above to finish setting up. Use `watch kubectl get pods` to confirm all pods are up and running before running the next command.

# expose ports on your local machine. useful for testing dapps
make port-forward

# stop the containers and port-forwarding
make stop
```

To setup finish setting up Agoric, also run:
**Wait 10-12** minutes. It takes some time for the above to finish setting up. Use `watch kubectl get pods` to confirm all pods are up and running before running the next command.

To setup finish setting up Agoric, then run:

```bash
make fund-provision-pool
make fund-provision-pool override-chain-registry
```

If you get an error like "connection refused", you need to wait longer, until all the pods are Running.

# Cleanup

```sh
# stop the containers and port-forwarding
make stop

# delete the clusters
make clean
```


## Logs

You can use the following commmands to view logs:
Expand All @@ -61,8 +65,8 @@ make tail-slog
kubectl logs agoriclocal-genesis-0 --container=validator --follow

# relayer logs
kubectl logs hermes-agoric-gaia-0 --container=validator --follow
kubectl logs hermes-agoric-gaia-0 --container=validator --follow
kubectl logs hermes-agoric-gaia-0 --container=relayer --follow
kubectl logs hermes-osmosis-gaia-0 --container=relayer --follow
```

## Agoric Smart Wallet
Expand All @@ -82,3 +86,13 @@ make fund-wallet COIN=20000000ubld ADDR=$ADDR
# provision the smart wallet
make provision-smart-wallet ADDR=$ADDR
```

# Chain Registry

These only work if you've done `make port-forward`.

http://localhost:8081/chains/agoriclocal
http://localhost:8081/chains/osmosislocal
http://localhost:8081/chains/gaialocal
http://localhost:8081/chains/agoriclocal/keys
http://localhost:8081/ibc
9 changes: 7 additions & 2 deletions multichain-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,30 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@endo/errors": "^1.2.2",
"@agoric/cosmic-proto": "0.4.1-dev-08f8549.0",
"@cosmjs/crypto": "^0.32.2",
"@cosmjs/proto-signing": "^0.32.2",
"@cosmjs/stargate": "^0.32.2",
"@endo/errors": "^1.2.2",
"@endo/far": "^1.1.2",
"@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",
"tsimp": "^2.0.10",
"tsx": "^4.15.6",
"typescript": "^5.3.3"
},
"resolutions": {
Expand All @@ -56,7 +60,8 @@
"**/*.test.ts"
],
"concurrency": 1,
"serial": true
"serial": true,
"timeout": "125s"
},
"prettier": {
"arrowParens": "avoid",
Expand Down
29 changes: 29 additions & 0 deletions multichain-testing/scripts/deploy-cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env tsx
import '@endo/init/debug.js';

import { execa } from 'execa';
import fse from 'fs-extra';
import childProcess from 'node:child_process';

import { makeAgdTools } from '../tools/agd-tools.js';
import { makeDeployBuilder } from '../tools/deploy.js';

async function main() {
const builder = process.argv[2];

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

try {
const agdTools = await makeAgdTools(console.log, childProcess);
const deployBuilder = makeDeployBuilder(agdTools, fse.readJSON, execa);
await deployBuilder(builder);
} catch (err) {
console.error(err);
process.exit(1);
}
}

main();
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);
3 changes: 1 addition & 2 deletions multichain-testing/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ HELM_REPO="starship"
HELM_CHART="starship/devnet"
HELM_REPO_URL="https://cosmology-tech.github.io/starship/"
HELM_CHART_VERSION="0.2.2"
HELM_NAME="starship-getting-started"
HELM_NAME="agoric-multichain-testing"

# check_helm function verifies the helm binary is installed
function check_helm() {
Expand Down Expand Up @@ -124,4 +124,3 @@ done
check_helm
setup_helm
install_chart

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);
};
Loading

0 comments on commit bfa47d1

Please sign in to comment.