Skip to content

Commit

Permalink
refactor: use smartWalletKit readPublished
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 24, 2025
1 parent 0a24c2c commit 4efb74b
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 65 deletions.
12 changes: 8 additions & 4 deletions multichain-testing/test/account-balance-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const queryAccountBalances = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
} = t.context;

Expand All @@ -67,7 +67,8 @@ const queryAccountBalances = test.macro({
});

const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === offerId && (status.result || status.error),
`${offerId} offer result is in vstorage`,
MAKE_ACCOUNT_AND_QUERY_BALANCE_TIMEOUT,
Expand All @@ -83,6 +84,7 @@ const queryAccountBalances = test.macro({
);

const {
// @ts-expect-error UpdateRecord may not have 'status'
status: { result, error },
} = offerResult;
if (expectValidResult) {
Expand Down Expand Up @@ -110,7 +112,7 @@ const queryAccountBalance = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
useChain,
} = t.context;
Expand Down Expand Up @@ -146,7 +148,8 @@ const queryAccountBalance = test.macro({
});

const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === offerId && (status.result || status.error),
`${offerId} offer result is in vstorage`,
MAKE_ACCOUNT_AND_QUERY_BALANCE_TIMEOUT,
Expand All @@ -162,6 +165,7 @@ const queryAccountBalance = test.macro({
);

const {
// @ts-expect-error UpdateRecord may not have 'status'
status: { result, error },
} = offerResult;
if (expectValidResult) {
Expand Down
7 changes: 4 additions & 3 deletions multichain-testing/test/auto-stake-it.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const autoStakeItScenario = test.macro({
// 1. setup
const {
wallets,
vstorageClient,
smartWalletKit,
provisionSmartWallet,
retryUntilCondition,
useChain,
Expand Down Expand Up @@ -98,9 +98,9 @@ const autoStakeItScenario = test.macro({

// FIXME https://github.com/Agoric/agoric-sdk/issues/9643
const currentWalletRecord = await retryUntilCondition(
() =>
vstorageClient.queryData(`published.wallet.${agoricUserAddr}.current`),
() => smartWalletKit.readPublished(`wallet.${agoricUserAddr}.current`),
({ offerToPublicSubscriberPaths }) =>
// @ts-expect-error retryUntilCondition expects a boolean return
Object.fromEntries(offerToPublicSubscriberPaths)[offerId],
`${offerId} continuing invitation is in vstorage`,
);
Expand All @@ -118,6 +118,7 @@ const autoStakeItScenario = test.macro({
.split('.')
.pop();
console.log({ lcaAddress, icaAddress });
assert(lcaAddress && icaAddress);
t.regex(lcaAddress, /^agoric1/, 'LOA address is valid');
t.regex(
icaAddress,
Expand Down
11 changes: 7 additions & 4 deletions multichain-testing/test/basic-flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const makeAccountScenario = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
} = t.context;

Expand Down Expand Up @@ -66,8 +66,9 @@ const makeAccountScenario = test.macro({
// TODO fix above so we don't have to poll for the offer result to be published
// https://github.com/Agoric/agoric-sdk/issues/9643
const currentWalletRecord = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}.current`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}.current`),
({ offerToPublicSubscriberPaths }) =>
// @ts-expect-error retryUntilCondition expects a boolean return
Object.fromEntries(offerToPublicSubscriberPaths)[offerId],
`${offerId} continuing invitation is in vstorage`,
);
Expand All @@ -80,17 +81,19 @@ const makeAccountScenario = test.macro({
.split('.')
.pop();
t.log('Got address:', address);
assert(address);
t.regex(
address,
new RegExp(`^${config.expectedAddressPrefix}1`),
`address for ${chainName} is valid`,
);

const latestWalletUpdate = await vstorageClient.queryData(
`published.wallet.${agoricAddr}`,
const latestWalletUpdate = await smartWalletKit.readPublished(
`wallet.${agoricAddr}`,
);
t.log('latest wallet update', latestWalletUpdate);
t.like(
// @ts-expect-error UpdateRecord may not have 'status'
latestWalletUpdate.status,
{
id: offerId,
Expand Down
18 changes: 12 additions & 6 deletions multichain-testing/test/chain-queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const queryICQChain = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
useChain,
} = t.context;
Expand Down Expand Up @@ -108,7 +108,8 @@ const queryICQChain = test.macro({
});

const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === offerId && (status.result || status.error),
`${offerId} offer result is in vstorage`,
{
Expand All @@ -117,6 +118,7 @@ const queryICQChain = test.macro({
);
t.log('ICQ Query Offer Result', offerResult);
const {
// @ts-expect-error UpdateRecord may not have 'status'
status: { result, error },
} = offerResult;
t.is(error, undefined, 'No error observed');
Expand Down Expand Up @@ -160,7 +162,7 @@ const queryChainWithoutICQ = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
useChain,
} = t.context;
Expand Down Expand Up @@ -200,14 +202,16 @@ const queryChainWithoutICQ = test.macro({
});

const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === offerId && (status.result || status.error),
`${offerId} continuing invitation is in vstorage`,
{
maxRetries: 10,
},
);
t.is(
// @ts-expect-error UpdateRecord may not have 'status'
offerResult.status.error,
`Error: Queries not available for chain "${chain_id}"`,
'Queries not available error returned',
Expand All @@ -216,7 +220,7 @@ const queryChainWithoutICQ = test.macro({
});

test.serial('Send Local Query from chain object', async t => {
const { wallets, provisionSmartWallet, vstorageClient, retryUntilCondition } =
const { wallets, provisionSmartWallet, smartWalletKit, retryUntilCondition } =
t.context;

const agoricAddr = wallets['agoric'];
Expand Down Expand Up @@ -268,14 +272,16 @@ test.serial('Send Local Query from chain object', async t => {
});

const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === offerId && (status.result || status.error),
`${offerId} continuing invitation is in vstorage`,
{
maxRetries: 10,
},
);

// @ts-expect-error UpdateRecord may not have 'status'
const parsedResults = JSON.parse(offerResult.status.result);
t.truthy(parsedResults[0].height, 'query height is returned');
t.is(parsedResults[0].error, '', 'error is empty');
Expand Down
20 changes: 12 additions & 8 deletions multichain-testing/test/deposit-withdraw-lca.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('Deposit IST to orchAccount and then withdraw', async t => {
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
useChain,
} = t.context;
Expand Down Expand Up @@ -61,8 +61,9 @@ test('Deposit IST to orchAccount and then withdraw', async t => {

// Wait for the orchAccount to be created
const { offerToPublicSubscriberPaths } = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}.current`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}.current`),
({ offerToPublicSubscriberPaths }) =>
// @ts-expect-error retryUntilCondition expects a boolean return
Object.fromEntries(offerToPublicSubscriberPaths)[makeAccountOfferId],
'makeAccount offer result is in vstorage',
);
Expand All @@ -72,10 +73,10 @@ test('Deposit IST to orchAccount and then withdraw', async t => {
makeAccountOfferId
]!.account;
const lcaAddress = accountStoragePath.split('.').at(-1);
t.truthy(lcaAddress, 'Account address is in storage path');
assert(lcaAddress, 'Account address is in storage path');

// Get IST brand
const brands = await vstorageClient.queryData('published.agoricNames.brand');
const brands = await smartWalletKit.readPublished('agoricNames.brand');
const istBrand = Object.fromEntries(brands).IST;

// Deposit IST to orchAccount
Expand Down Expand Up @@ -150,7 +151,7 @@ test('Deposit IST to orchAccount and then withdraw', async t => {
test.todo('Deposit and Withdraw ATOM/OSMO to localOrchAccount via offer #9966');

test('Attempt to withdraw more than available balance', async t => {
const { wallets, provisionSmartWallet, vstorageClient, retryUntilCondition } =
const { wallets, provisionSmartWallet, smartWalletKit, retryUntilCondition } =
t.context;

// Provision the Agoric smart wallet
Expand Down Expand Up @@ -178,8 +179,9 @@ test('Attempt to withdraw more than available balance', async t => {

// Wait for the orchAccount to be created
const { offerToPublicSubscriberPaths } = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}.current`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}.current`),
({ offerToPublicSubscriberPaths }) =>
// @ts-expect-error retryUntilCondition expects a boolean return
Object.fromEntries(offerToPublicSubscriberPaths)[makeAccountOfferId],
`${makeAccountOfferId} offer result is in vstorage`,
);
Expand All @@ -191,7 +193,7 @@ test('Attempt to withdraw more than available balance', async t => {
t.truthy(lcaAddress, 'Account address is in storage path');

// Get IST brand
const brands = await vstorageClient.queryData('published.agoricNames.brand');
const brands = await smartWalletKit.readPublished('agoricNames.brand');
const istBrand = Object.fromEntries(brands).IST;

// Attempt to withdraw more than available balance
Expand All @@ -212,11 +214,13 @@ test('Attempt to withdraw more than available balance', async t => {

// Verify that the withdrawal failed
const offerResult = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}`),
// @ts-expect-error UpdateRecord may not have 'status'
({ status }) => status.id === withdrawOfferId && status.error !== undefined,
'Withdrawal offer error is in vstorage',
);
t.is(
// @ts-expect-error UpdateRecord may not have 'status'
offerResult.status.error,
'Error: One or more withdrawals failed ["[Error: cannot grab 200uist coins: 0uist is smaller than 200uist: insufficient funds]"]',
);
Expand Down
13 changes: 6 additions & 7 deletions multichain-testing/test/deposit-withdraw-portfolio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const portfolioAccountScenario = test.macro({
const {
wallets,
provisionSmartWallet,
vstorageClient,
smartWalletKit,
retryUntilCondition,
useChain,
} = t.context;
Expand Down Expand Up @@ -64,8 +64,9 @@ const portfolioAccountScenario = test.macro({
});

const { offerToPublicSubscriberPaths } = await retryUntilCondition(
() => vstorageClient.queryData(`published.wallet.${agoricAddr}.current`),
() => smartWalletKit.readPublished(`wallet.${agoricAddr}.current`),
({ offerToPublicSubscriberPaths }) =>
// @ts-expect-error retryUntilCondition expects a boolean return
Object.fromEntries(offerToPublicSubscriberPaths)[
makePortfolioAcctOfferId
],
Expand All @@ -81,13 +82,11 @@ const portfolioAccountScenario = test.macro({

const agoricLcaAddress = accountPaths.agoric.split('.').at(-1);
const remoteIcaAddress = accountPaths[chainName].split('.').at(-1);
t.truthy(agoricLcaAddress, 'Agoric LCA address is in storage path');
t.truthy(remoteIcaAddress, `${chainName} ICA address is in storage path`);
assert(agoricLcaAddress, 'Agoric LCA address is in storage path');
assert(remoteIcaAddress, `${chainName} ICA address is in storage path`);

// Get IST brand
const brands = await vstorageClient.queryData(
'published.agoricNames.brand',
);
const brands = await smartWalletKit.readPublished('agoricNames.brand');
const istBrand = Object.fromEntries(brands).IST;

// Setup query clients
Expand Down
4 changes: 2 additions & 2 deletions multichain-testing/test/fast-usdc/fast-usdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ const advanceAndSettleScenario = test.macro({
t.log(`EUD wallet created: ${EUD}`);

// parameterize agoric address
const { settlementAccount } = await vstorageClient.queryData(
`published.${contractName}`,
const { settlementAccount } = await smartWalletKit.readPublished(
`${contractName}`,
);
t.log('settlementAccount address', settlementAccount);

Expand Down
4 changes: 2 additions & 2 deletions multichain-testing/test/fast-usdc/noble-forwarding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { makeQueryClient } from '../../tools/query.js';
const test = anyTest as TestFn<SetupContext>;

test('noble forwarding', async t => {
const { nobleTools, retryUntilCondition, useChain, vstorageClient } =
const { nobleTools, retryUntilCondition, useChain, smartWalletKit } =
await commonSetup(t, { config: '../config.fusdc.yaml' });

const agoricWallet = await createWallet('agoric');
Expand All @@ -21,7 +21,7 @@ test('noble forwarding', async t => {
const connInfoPath = `published.agoricNames.chainConnection.${agoricChainId}_${nobleChainId}`;
const {
transferChannel: { counterPartyChannelId, channelId },
}: IBCConnectionInfo = await vstorageClient.queryData(connInfoPath);
} = (await smartWalletKit.readLatestHead(connInfoPath)) as IBCConnectionInfo;

t.regex(
counterPartyChannelId,
Expand Down
Loading

0 comments on commit 4efb74b

Please sign in to comment.