-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
248 additions
and
3 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
a3p-integration/proposals/a:upgrade-next/core-eval-support.js
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,53 @@ | ||
// @ts-check | ||
|
||
import { voteLatestProposalAndWait } from '@agoric/synthetic-chain'; | ||
|
||
// copy-pasta from @agoric/synthetic-chain | ||
// XXX import from '@agoric/synthetic-chain/src/lib/core-eval-support.js'; | ||
|
||
/** | ||
* @param { Record<string, string>} record - e.g. { color: 'blue' } | ||
* @returns {string[]} e.g. ['--color', 'blue'] | ||
*/ | ||
export const flags = record => { | ||
return Object.entries(record) | ||
.map(([k, v]) => [`--${k}`, v]) | ||
.flat(); | ||
}; | ||
|
||
export const txAbbr = tx => { | ||
const { txhash, code, height, gas_used } = tx; | ||
return { txhash, code, height, gas_used }; | ||
}; | ||
|
||
// XXX overlaps with passCoreEvalProposal from synthetic chain | ||
export const passCoreEvalProposal = async (t, opts) => { | ||
const { | ||
agd, | ||
script, | ||
permit, | ||
title, | ||
chainId, | ||
description = 'run some code', | ||
from = 'validator', | ||
deposit = '10000000ubld', | ||
} = opts; | ||
const result = await agd.tx( | ||
[ | ||
'gov', | ||
'submit-proposal', | ||
'swingset-core-eval', | ||
permit, | ||
script, | ||
...flags({ title, description, deposit }), | ||
...flags({ gas: 'auto', 'gas-adjustment': '1.2' }), | ||
], | ||
{ from, chainId, yes: true }, | ||
); | ||
console.log(txAbbr(result)); | ||
t.is(result.code, 0); | ||
|
||
const detail = await voteLatestProposalAndWait(); | ||
console.log(detail.proposal_id, detail.voting_end_time, detail.status); | ||
t.is(detail.status, 'PROPOSAL_STATUS_PASSED'); | ||
}; |
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
79 changes: 79 additions & 0 deletions
79
a3p-integration/proposals/a:upgrade-next/provisioning.test.js
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,79 @@ | ||
// @ts-check | ||
|
||
import test from 'ava'; | ||
import { createRequire } from 'module'; | ||
import { execFileSync } from 'child_process'; | ||
import tmp from 'tmp'; | ||
import { readFile as readFileAmbient, writeFile } from 'fs/promises'; | ||
|
||
import { | ||
getIncarnation, | ||
makeAgd, | ||
waitForBlock, | ||
agoric, | ||
GOV1ADDR, | ||
CHAINID, | ||
} from '@agoric/synthetic-chain'; | ||
import { passCoreEvalProposal } from './core-eval-support.js'; | ||
|
||
const nodeRequire = createRequire(import.meta.url); | ||
const asset = { | ||
sendScript: nodeRequire.resolve('./send-script.js'), | ||
}; | ||
|
||
test.before(async t => { | ||
const readAsset = name => readFileAmbient(asset[name], 'utf-8'); | ||
|
||
const saveToTemp = text => | ||
new Promise((resolve, reject) => | ||
tmp.tmpName((err, path) => { | ||
if (err != null) return reject(err); | ||
return writeFile(path, text).then(() => resolve(path)); | ||
}), | ||
); | ||
|
||
const agd = makeAgd({ execFileSync }).withOpts({ | ||
keyringBackend: 'test', | ||
}); | ||
|
||
const env = { | ||
GOV1ADDR, | ||
CHAINID, | ||
}; | ||
|
||
t.context = { env, readAsset, agd, saveToTemp, agoric }; | ||
}); | ||
|
||
test(`provisioning vat was upgraded`, async t => { | ||
const incarnation = await getIncarnation('provisioning'); | ||
|
||
t.is(incarnation, 1); | ||
}); | ||
|
||
test(`send invitation via namesByAddress`, async t => { | ||
const io = t.context; | ||
const template = await io.readAsset('sendScript'); | ||
const addr = io.env.GOV1ADDR; | ||
const code = template.replace('{{ADDRESS}}', addr); | ||
const script = await io.saveToTemp(code); | ||
const permit = await io.saveToTemp('true'); | ||
|
||
const title = `send Add Collateral invitation to ${addr}`; | ||
t.log('proposal:', title); | ||
await passCoreEvalProposal(t, { | ||
agd: io.agd, | ||
script, | ||
permit, | ||
title, | ||
chainId: io.env.CHAINID, | ||
}); | ||
|
||
await waitForBlock(2); // enough time for invitation to arrive? | ||
const update = await agoric.follow('-lF', `:published.wallet.${addr}`); | ||
t.is(update.updated, 'balance'); | ||
t.notDeepEqual(update.currentAmount.value, []); | ||
t.log('balance value', update.currentAmount.value); | ||
t.log('balance brand', update.currentAmount.brand); | ||
// XXX agoric follow returns brands as strings | ||
t.regex(update.currentAmount.brand, /Invitation/); | ||
}); |
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,25 @@ | ||
// @ts-nocheck | ||
/* global E */ | ||
|
||
/** | ||
* Send a payment by looking up deposit facet via namesByAddress. | ||
* | ||
* see ./post.test.js | ||
* | ||
* @param {BootstrapPowers} powers | ||
*/ | ||
const sendIt = async powers => { | ||
const addr = '{{ADDRESS}}'; | ||
const { | ||
consume: { namesByAddress, zoe }, | ||
instance: { | ||
consume: { reserve }, | ||
}, | ||
} = powers; | ||
const pf = E(zoe).getPublicFacet(reserve); | ||
const anInvitation = await E(pf).makeAddCollateralInvitation(); | ||
const addressDepositFacet = E(namesByAddress).lookup(addr, 'depositFacet'); | ||
await E(addressDepositFacet).receive(anInvitation); | ||
}; | ||
|
||
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