-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): sendAnywhere contract (#9898)
refs: #9193 closes: #9901 ## Description Adds an e2e test for `sendAnywhere.contract.js`, ensuring `zoeTools.localTransfer()` and `localOrchestrationAccount.transfer()` are working as expected. Fixes a bug in `zoeTools.transfer()` where a vow chain was broken (we used `Promise.all()` on an array of vows instead of `vowTools.allVows()`. Also satisfies this requirement in #9193: - As new user of an orchestration contract, I need to “deposit” (move) my fungible funds into a place controlled by orchestration so it can do things with it. - for assets available through vbank starting on Agoric in a smart-wallet ### Security Considerations n/a ### Scaling Considerations n/a ### Documentation Considerations n/a ### Testing Considerations Includes tests for paths where bugs were discovered. ### Upgrade Considerations n/a
- Loading branch information
Showing
12 changed files
with
169 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import anyTest from '@endo/ses-ava/prepare-endo.js'; | ||
import type { TestFn } from 'ava'; | ||
import { makeDoOffer } from '../tools/e2e-tools.js'; | ||
import { | ||
commonSetup, | ||
SetupContextWithWallets, | ||
chainConfig, | ||
} from './support.js'; | ||
import { createWallet } from '../tools/wallet.js'; | ||
import { AmountMath } from '@agoric/ertp'; | ||
import { makeQueryClient } from '../tools/query.js'; | ||
import type { Amount } from '@agoric/ertp/src/types.js'; | ||
|
||
const test = anyTest as TestFn<SetupContextWithWallets>; | ||
|
||
const accounts = ['osmosis1', 'osmosis2', 'cosmoshub1', 'cosmoshub2']; | ||
|
||
const contractName = 'sendAnywhere'; | ||
const contractBuilder = | ||
'../packages/builders/scripts/testing/start-sendAnywhere.js'; | ||
|
||
test.before(async t => { | ||
const { deleteTestKeys, setupTestKeys, ...rest } = await commonSetup(t); | ||
deleteTestKeys(accounts).catch(); | ||
const wallets = await setupTestKeys(accounts); | ||
t.context = { ...rest, wallets, deleteTestKeys }; | ||
|
||
t.log('bundle and install contract', contractName); | ||
await t.context.deployBuilder(contractBuilder); | ||
const { vstorageClient } = t.context; | ||
await t.context.retryUntilCondition( | ||
() => vstorageClient.queryData(`published.agoricNames.instance`), | ||
res => contractName in Object.fromEntries(res), | ||
`${contractName} instance is available`, | ||
); | ||
}); | ||
|
||
test.after(async t => { | ||
const { deleteTestKeys } = t.context; | ||
deleteTestKeys(accounts); | ||
}); | ||
|
||
const sendAnywhereScenario = test.macro({ | ||
title: (_, chainName: string, acctIdx: number) => | ||
`sendAnywhere ${chainName}${acctIdx}`, | ||
exec: async (t, chainName: string, acctIdx: number) => { | ||
const config = chainConfig[chainName]; | ||
if (!config) return t.fail(`Unknown chain: ${chainName}`); | ||
|
||
const { | ||
wallets, | ||
provisionSmartWallet, | ||
vstorageClient, | ||
retryUntilCondition, | ||
useChain, | ||
} = t.context; | ||
|
||
t.log('Create a receiving wallet for the sendAnywhere transfer'); | ||
const chain = useChain(chainName).chain; | ||
|
||
t.log('Create an agoric smart wallet to initiate sendAnywhere transfer'); | ||
const agoricAddr = wallets[`${chainName}${acctIdx}`]; | ||
const wdUser1 = await provisionSmartWallet(agoricAddr, { | ||
BLD: 100_000n, | ||
IST: 100_000n, | ||
}); | ||
t.log(`provisioning agoric smart wallet for ${agoricAddr}`); | ||
|
||
const doOffer = makeDoOffer(wdUser1); | ||
|
||
const brands = await vstorageClient.queryData( | ||
'published.agoricNames.brand', | ||
); | ||
const istBrand = Object.fromEntries(brands).IST; | ||
|
||
const apiUrl = await useChain(chainName).getRestEndpoint(); | ||
const queryClient = makeQueryClient(apiUrl); | ||
t.log(`Made ${chainName} query client`); | ||
|
||
const doSendAnywhere = async (amount: Amount) => { | ||
t.log(`Sending ${amount.value} ${amount.brand}.`); | ||
const wallet = await createWallet(chain.bech32_prefix); | ||
const receiver = { | ||
chainId: chain.chain_id, | ||
value: (await wallet.getAccounts())[0].address, | ||
encoding: 'bech32', | ||
}; | ||
t.log('Will send payment to:', receiver); | ||
t.log(`${chainName} offer`); | ||
const offerId = `${chainName}-makeSendInvitation-${Date.now()}`; | ||
await doOffer({ | ||
id: offerId, | ||
invitationSpec: { | ||
source: 'agoricContract', | ||
instancePath: [contractName], | ||
callPipe: [['makeSendInvitation']], | ||
}, | ||
offerArgs: { destAddr: receiver.value, chainName }, | ||
proposal: { give: { Send: amount } }, | ||
}); | ||
|
||
const { balances } = await retryUntilCondition( | ||
() => queryClient.queryBalances(receiver.value), | ||
({ balances }) => 'amount' in balances[0], | ||
`${receiver.value} ${amount.value} balance available from sendAnywhere`, | ||
); | ||
|
||
t.log(`${receiver.value} Balances`, balances); | ||
t.like(balances, [ | ||
{ | ||
// XXX consider verifying uist hash | ||
amount: String(amount.value), | ||
}, | ||
]); | ||
}; | ||
|
||
const makeRandomValue = (min: number, max: number) => | ||
BigInt(Math.floor(Math.random() * (max - min + 1)) + min); | ||
// send 3 offers from each account. different values help distinguish | ||
// one offer/result from another. | ||
const offerAmounts = [ | ||
makeRandomValue(1, 33), | ||
makeRandomValue(34, 66), | ||
makeRandomValue(67, 100), | ||
]; | ||
console.log(`${agoricAddr} offer amounts:`, offerAmounts); | ||
|
||
for (const value of offerAmounts) { | ||
await doSendAnywhere(AmountMath.make(istBrand, value)); | ||
} | ||
}, | ||
}); | ||
|
||
test.serial(sendAnywhereScenario, 'osmosis', 1); | ||
test.serial(sendAnywhereScenario, 'osmosis', 2); | ||
test.serial(sendAnywhereScenario, 'cosmoshub', 1); | ||
test.serial(sendAnywhereScenario, 'cosmoshub', 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,6 @@ export const sendIt = async ( | |
chainId, | ||
}, | ||
); | ||
seat.exit(); | ||
}; | ||
harden(sendIt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters