Skip to content

Commit 2eaafaf

Browse files
committed
chore: WIP basic use case multichain testing
Refs: #8863
1 parent a2cd020 commit 2eaafaf

File tree

6 files changed

+275
-9
lines changed

6 files changed

+275
-9
lines changed

multichain-testing/config.xcs-swap-anything.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ relayers:
106106
- osmosislocal
107107
config:
108108
global:
109-
log_level: "debug"
109+
log_level: 'debug'
110110
telemetry:
111111
enabled: true
112112
- name: agoric-cosmoshub

multichain-testing/scripts/update-config-logs.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ set -eux
88

99
ls $CHAIN_DIR
1010

11-
1211
echo "Update config.toml file"
1312
sed -i -e 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' $CHAIN_DIR/config/config.toml
1413
sed -i -e 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/config/config.toml
@@ -21,7 +20,6 @@ sed -i -e 's#keyring-backend = "os"#keyring-backend = "test"#g' $CHAIN_DIR/confi
2120
sed -i -e 's#output = "text"#output = "json"#g' $CHAIN_DIR/config/client.toml
2221
sed -i -e "s#chain-id = \"\"#chain-id = \"$CHAIN_ID\"#g" $CHAIN_DIR/config/client.toml
2322

24-
2523
echo "Update app.toml file"
2624
sed -i -e "s#minimum-gas-prices = \".*\"#minimum-gas-prices = \"0$DENOM\"#g" $CHAIN_DIR/config/app.toml
2725
sed -i -e "s#pruning = \".*\"#pruning = \"default\"#g" $CHAIN_DIR/config/app.toml
@@ -32,7 +30,6 @@ sed -i -e 's/swagger = false/swagger = true/g' $CHAIN_DIR/config/app.toml
3230
sed -i -e 's/enable = false/enable = true/g' $CHAIN_DIR/config/app.toml
3331
sed -i -e 's/enabled = false/enabled = true/g' $CHAIN_DIR/config/app.toml
3432

35-
3633
function get_next_line_number() {
3734
local txt=$1
3835
local file=$2
@@ -66,4 +63,4 @@ sed -i -e "s#timeout_precommit_delta = \".*\"#timeout_precommit_delta = \"$TIMEO
6663
sed -i -e "s#timeout_commit = \".*\"#timeout_commit = \"$TIMEOUT_COMMIT\"#g" $CHAIN_DIR/config/config.toml
6764

6865
echo "Update config.toml file log level"
69-
sed -i -E 's/^(log_level\s*=\s*)".*"/\1"debug"/' $CHAIN_DIR/config/config.toml
66+
sed -i -E 's/^(log_level\s*=\s*)".*"/\1"debug"/' $CHAIN_DIR/config/config.toml

multichain-testing/test/xcs-swap-anything/Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ CHANNEL_INFO=$(shell $(cli-hermes) --json query channels --show-counterparty --c
1616
AGORIC_OSMOSIS_CHANNEL=$(shell echo '$(CHANNEL_INFO)' | jq -r '.channel_a')
1717
OSMOSIS_AGORIC_CHANNEL=$(shell echo '$(CHANNEL_INFO)' | jq -r '.channel_b')
1818

19-
REGISTRY_ADDRESS="osmo1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqvlx82r"
20-
SWAPROUTER_ADDRESS="osmo14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sq2r9g9"
21-
SWAP_ADDRESS="osmo17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs5yczr8"
19+
REGISTRY_ADDRESS="osmo1wkwy0xh89ksdgj9hr347dyd2dw7zesmtrue6kfzyml4vdtz6e5wsfdyyaj"
20+
SWAPROUTER_ADDRESS="osmo1hrpna9v7vs3stzyd4z3xf00676kf78zpe2u5ksvljswn2vnjp3ysgnqrud"
21+
SWAP_ADDRESS="osmo1ufs3tlq4umljk0qfe8k5ya0x6hpavn897u2cnf9k0en9jr7qarqq7fzxcr"
2222

2323
POOL_ASSET_1_DENOM="uosmo"
2424
POOL_ASSET_1_AMOUNT="250000"
2525
POOL_ASSET_2_DENOM="ibc/E7827844CB818EE9C4DB2C159F1543FF62B26213B44CE8029D5CEFE52F0EE596"
2626

2727
GET_ROUTE_JSON = '{"get_route":{"input_denom":$(POOL_ASSET_2_DENOM),"output_denom":$(POOL_ASSET_1_DENOM)}}'
28-
SET_CHAIN_CHANNEL_LINKS='{"modify_chain_channel_links":{"operations":[{"operation":"set","source_chain":"agoric","destination_chain":"osmosis","channel_id":$(AGORIC_OSMOSIS_CHANNEL)},{"operation":"set","source_chain":"osmosis","destination_chain":"agoric","channel_id":$(OSMOSIS_AGORIC_CHANNEL)}]}}'
28+
SET_CHAIN_CHANNEL_LINKS='{"modify_chain_channel_links":{"operations":[{"operation":"set","source_chain":"agoric","destination_chain":"osmosis","channel_id":"$(AGORIC_OSMOSIS_CHANNEL)"},{"operation":"set","source_chain":"osmosis","destination_chain":"agoric","channel_id":"$(OSMOSIS_AGORIC_CHANNEL)"}]}}'
2929
SET_PREFIXES_MSG='{"modify_bech32_prefixes":{"operations":[{"operation":"set","chain_name":"osmosis","prefix":"osmo"},{"operation":"set","chain_name":"agoric","prefix":"agoric"}]}}'
3030
GET_CHANNEL_FROM_CHAINS_MSG='{"get_channel_from_chain_pair":{"source_chain":"osmosis","destination_chain":"agoric"}}'
3131
GET_PREFIX_FROM_CHAIN_MSG='{"get_bech32_prefix_from_chain_name":{"chain_name":"osmosis"}}'
@@ -50,6 +50,9 @@ BAD_SWAP_MEMO=' \
5050
} \
5151
}}'
5252

53+
print-wasm-info:
54+
$(cli-osmo) "cat /contract-info.json"
55+
5356
print-channel-info:
5457
@echo $(CHANNEL_INFO)
5558

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import anyTest from '@endo/ses-ava/prepare-endo.js';
2+
import type { TestFn } from 'ava';
3+
import { makeDoOffer } from '../../tools/e2e-tools.js';
4+
import {
5+
commonSetup,
6+
type SetupContextWithWallets,
7+
} from '../support.js';
8+
import { AmountMath } from '@agoric/ertp';
9+
import { makeQueryClient } from '../../tools/query.js';
10+
11+
const test = anyTest as TestFn<SetupContextWithWallets>;
12+
13+
const accounts = ['agoricSender', 'agoricReceiver'];
14+
15+
const contractName = 'swapAnything';
16+
const contractBuilder =
17+
'../packages/builders/scripts/testing/init-swap-anything.js';
18+
19+
test.before(async t => {
20+
const { setupTestKeys, ...common } = await commonSetup(t);
21+
const { commonBuilderOpts, deleteTestKeys, startContract } = common;
22+
await deleteTestKeys(accounts).catch();
23+
const wallets = await setupTestKeys(accounts);
24+
console.log('WALLETS', wallets);
25+
t.context = { ...common, wallets };
26+
await startContract(contractName, contractBuilder, commonBuilderOpts);
27+
});
28+
29+
test('BLD for OSMO, receiver on Agoric', async t => {
30+
const {
31+
wallets,
32+
provisionSmartWallet,
33+
vstorageClient,
34+
retryUntilCondition,
35+
useChain,
36+
} = t.context;
37+
38+
// Provision the Agoric smart wallet
39+
const agoricAddr = wallets.agoricSender;
40+
const wdUser = await provisionSmartWallet(agoricAddr, {
41+
BLD: 1000n,
42+
IST: 1000n,
43+
});
44+
t.log(`Provisioned Agoric smart wallet for ${agoricAddr}`);
45+
46+
// const osmosisChainId = useChain('osmosis').chain.chain_id;
47+
48+
// const {
49+
// transferChannel: { counterPartyChannelId, channelId },
50+
// } = starshipChainInfo.agoric.connections[osmosisChainId];
51+
52+
const doOffer = makeDoOffer(wdUser);
53+
54+
// Verify deposit
55+
const apiUrl = await useChain('agoric').getRestEndpoint();
56+
const queryClient = makeQueryClient(apiUrl);
57+
58+
const brands = await vstorageClient.queryData('published.agoricNames.brand');
59+
const bldBrand = Object.fromEntries(brands).BLD;
60+
const swapInAmount = AmountMath.make(bldBrand, 125n);
61+
const { balances: balancesBefore } = await queryClient.queryBalances(
62+
wallets.agoricReceiver,
63+
);
64+
65+
// Send swap offer
66+
const makeAccountOfferId = `swap-ubld-uosmo-${Date.now()}`;
67+
await doOffer({
68+
id: makeAccountOfferId,
69+
invitationSpec: {
70+
source: 'agoricContract',
71+
instancePath: [contractName],
72+
callPipe: [['makeSendInvitation']],
73+
},
74+
offerArgs: {
75+
destAddr: 'osmo1ufs3tlq4umljk0qfe8k5ya0x6hpavn897u2cnf9k0en9jr7qarqq7fzxcr',
76+
receiverAddr: wallets.agoricReceiver,
77+
outDenom: 'uosmo',
78+
slippage: { slippagePercentage: '20', windowSeconds: 10 },
79+
onFailedDelivery: 'do_nothing',
80+
},
81+
proposal: { give: { Send: swapInAmount } },
82+
});
83+
84+
const agoricReceiverBalance = await retryUntilCondition(
85+
() => queryClient.queryBalances(wallets.agoricReceiver),
86+
({ balances }) => balances.length > balancesBefore.length,
87+
'Deposit reflected in localOrchAccount balance',
88+
);
89+
t.log(agoricReceiverBalance);
90+
91+
t.pass();
92+
});
93+
94+
test.after(async t => {
95+
const { deleteTestKeys } = t.context;
96+
deleteTestKeys(accounts);
97+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { makeHelpers } from '@agoric/deploy-script-support';
2+
import {
3+
getManifest,
4+
startSwapAnything,
5+
} from '@agoric/orchestration/src/proposals/start-swap-anything.js';
6+
import { parseChainHubOpts } from '../orchestration/helpers.js';
7+
8+
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */
9+
export const defaultProposalBuilder = async (
10+
{ publishRef, install },
11+
options,
12+
) =>
13+
harden({
14+
sourceSpec: '@agoric/orchestration/src/proposals/start-swap-anything.js',
15+
getManifestCall: [
16+
getManifest.name,
17+
{
18+
installationRef: publishRef(
19+
install(
20+
'@agoric/orchestration/src/examples/swap-anything.contract.js',
21+
),
22+
),
23+
options,
24+
},
25+
],
26+
});
27+
28+
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
29+
export default async (homeP, endowments) => {
30+
const { scriptArgs } = endowments;
31+
const opts = parseChainHubOpts(scriptArgs);
32+
const { writeCoreEval } = await makeHelpers(homeP, endowments);
33+
await writeCoreEval(startSwapAnything.name, utils =>
34+
defaultProposalBuilder(utils, opts),
35+
);
36+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import {
2+
deeplyFulfilledObject,
3+
makeTracer,
4+
NonNullish,
5+
} from '@agoric/internal';
6+
import { E } from '@endo/far';
7+
8+
/// <reference types="@agoric/vats/src/core/types-ambient"/>
9+
10+
/**
11+
* @import {Installation} from '@agoric/zoe/src/zoeService/utils.js';
12+
* @import {CosmosChainInfo, Denom, DenomDetail} from '@agoric/orchestration';
13+
* @import {start as StartFn} from '@agoric/orchestration/src/examples/send-anywhere.contract.js';
14+
*/
15+
16+
const trace = makeTracer('StartSA', true);
17+
18+
/**
19+
* @param {BootstrapPowers & {
20+
* installation: {
21+
* consume: {
22+
* swapAnything: Installation<StartFn>;
23+
* };
24+
* };
25+
* instance: {
26+
* produce: {
27+
* swapAnything: Producer<Instance>;
28+
* };
29+
* };
30+
* issuer: {
31+
* consume: {
32+
* BLD: Issuer<'nat'>;
33+
* IST: Issuer<'nat'>;
34+
* };
35+
* };
36+
* }} powers
37+
* @param {{
38+
* options: {
39+
* chainInfo: Record<string, CosmosChainInfo>;
40+
* assetInfo: [Denom, DenomDetail & { brandKey?: string }][];
41+
* };
42+
* }} config
43+
*/
44+
export const startSwapAnything = async (
45+
{
46+
consume: {
47+
agoricNames,
48+
board,
49+
chainStorage,
50+
chainTimerService,
51+
cosmosInterchainService,
52+
localchain,
53+
startUpgradable,
54+
},
55+
installation: {
56+
consume: { swapAnything },
57+
},
58+
instance: {
59+
produce: { swapAnything: produceInstance },
60+
},
61+
issuer: {
62+
consume: { BLD, IST },
63+
},
64+
},
65+
{ options: { chainInfo, assetInfo } },
66+
) => {
67+
trace(startSwapAnything.name);
68+
69+
const marshaller = await E(board).getReadonlyMarshaller();
70+
71+
const privateArgs = await deeplyFulfilledObject(
72+
harden({
73+
agoricNames,
74+
localchain,
75+
marshaller,
76+
orchestrationService: cosmosInterchainService,
77+
storageNode: E(NonNullish(await chainStorage)).makeChildNode(
78+
'send-anywhere',
79+
),
80+
timerService: chainTimerService,
81+
chainInfo,
82+
assetInfo,
83+
}),
84+
);
85+
86+
const issuerKeywordRecord = harden({
87+
BLD: await BLD,
88+
IST: await IST,
89+
});
90+
trace('issuerKeywordRecord', issuerKeywordRecord);
91+
92+
const { instance } = await E(startUpgradable)({
93+
label: 'swap-anything',
94+
installation: swapAnything,
95+
issuerKeywordRecord,
96+
privateArgs,
97+
});
98+
produceInstance.resolve(instance);
99+
trace('done');
100+
};
101+
harden(startSwapAnything);
102+
103+
export const getManifest = ({ restoreRef }, { installationRef, options }) => {
104+
return {
105+
manifest: {
106+
[startSwapAnything.name]: {
107+
consume: {
108+
agoricNames: true,
109+
board: true,
110+
chainStorage: true,
111+
chainTimerService: true,
112+
cosmosInterchainService: true,
113+
localchain: true,
114+
115+
startUpgradable: true,
116+
},
117+
installation: {
118+
consume: { swapAnything: true },
119+
},
120+
instance: {
121+
produce: { swapAnything: true },
122+
},
123+
issuer: {
124+
consume: { BLD: true, IST: true },
125+
},
126+
},
127+
},
128+
installations: {
129+
swapAnything: restoreRef(installationRef),
130+
},
131+
options,
132+
};
133+
};

0 commit comments

Comments
 (0)