-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test of replacing fast-usdc operators (#10834)
closes: #10754 ## Description Adds a test for adding new operators after removing ### Security Considerations ### Scaling Considerations ### Documentation Considerations ### Testing Considerations ### Upgrade Considerations
- Loading branch information
Showing
18 changed files
with
379 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add-operators |
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,78 @@ | ||
/* eslint-env node */ | ||
import unknownTest from 'ava'; | ||
|
||
import '@endo/init/legacy.js'; // axios compat | ||
|
||
import { LOCAL_CONFIG, makeVstorageKit } from '@agoric/client-utils'; | ||
import { evalBundles, waitForBlock } from '@agoric/synthetic-chain'; | ||
|
||
// XXX ~copied to not take a dependency on Zoe | ||
/** | ||
* @typedef {object} InvitationDetails | ||
* @property {unknown} installation | ||
* @property {unknown} instance | ||
* @property {InvitationHandle} handle | ||
* @property {string} description | ||
* @property {Record<string, any>} [customDetails] | ||
*/ | ||
|
||
/** | ||
* @import {VstorageKit} from '@agoric/client-utils'; | ||
*/ | ||
|
||
const test = /** @type {import('ava').TestFn<{ vstorageKit: VstorageKit}>} */ ( | ||
unknownTest | ||
); | ||
|
||
const ADD_OPERATORS_DIR = 'add-operators'; | ||
|
||
/** | ||
* @typedef {import('@agoric/ertp').NatAmount} NatAmount | ||
* @typedef {{ | ||
* allocations: { Fee: NatAmount, USD_LEMONS: NatAmount }, | ||
* }} ReserveAllocations | ||
*/ | ||
|
||
test.before(async t => { | ||
const vstorageKit = makeVstorageKit({ fetch }, LOCAL_CONFIG); | ||
|
||
t.context = { | ||
vstorageKit, | ||
}; | ||
}); | ||
|
||
test.serial('add operators', async t => { | ||
const { vstorageKit } = t.context; | ||
|
||
const walletPath = | ||
// account mem3 in test of crabble-start proposal (64) | ||
// This must match the oracleNew value in the add-operators builder argument | ||
'wallet.agoric1hmdue96vs0p6zj42aa26x6zrqlythpxnvgsgpr.current'; | ||
|
||
const readInvitationsPurseBalance = async () => { | ||
const curr = await vstorageKit.readPublished(walletPath); | ||
return /** @type {InvitationDetails[]} */ (curr.purses[0].balance.value); | ||
}; | ||
|
||
let numInvitationsBefore = 0; | ||
{ | ||
const invBalance = await readInvitationsPurseBalance(); | ||
numInvitationsBefore = invBalance.length; | ||
t.false( | ||
invBalance.some(inv => inv.description === 'oracle operator invitation'), | ||
); | ||
} | ||
|
||
await evalBundles(ADD_OPERATORS_DIR); | ||
// give time for the invitations to be deposited | ||
await waitForBlock(5); | ||
|
||
{ | ||
const invBalance = await readInvitationsPurseBalance(); | ||
console.log('after', invBalance); | ||
t.is(invBalance.length, numInvitationsBefore + 1); | ||
t.true( | ||
invBalance.some(inv => inv.description === 'oracle operator 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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
echo AVAILABLE WALLETs | ||
agd query vstorage children published.wallet | ||
|
||
yarn ava | ||
|
||
./test-cli.sh |
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
83 changes: 83 additions & 0 deletions
83
packages/builders/scripts/fast-usdc/add-operators.build.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,83 @@ | ||
// @ts-check | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
import { getManifestForAddOperators } from '@agoric/fast-usdc/src/add-operators.core.js'; | ||
import { toExternalConfig } from '@agoric/fast-usdc/src/utils/config-marshal.js'; | ||
import { configurations } from '@agoric/fast-usdc/src/utils/deploy-config.js'; | ||
import { Far } from '@endo/far'; | ||
import { parseArgs } from 'node:util'; | ||
|
||
/** | ||
* @import {CoreEvalBuilder, DeployScriptFunction} from '@agoric/deploy-script-support/src/externalTypes.js'; | ||
* @import {ParseArgsConfig} from 'node:util'; | ||
* @import {FastUSDCConfig, FeedPolicy} from '@agoric/fast-usdc/src/types.js'; | ||
* @import {FastUSDCOpts} from './start-fast-usdc.build.js'; | ||
*/ | ||
|
||
const { keys } = Object; | ||
|
||
/** @type {ParseArgsConfig['options']} */ | ||
const options = { | ||
net: { type: 'string' }, | ||
oracle: { type: 'string', multiple: true }, | ||
}; | ||
const oraclesUsage = 'use --oracle name:address ...'; | ||
|
||
const crossVatContext = /** @type {const} */ ({ | ||
/** @type {Brand<'nat'>} */ | ||
USDC: Far('USDC Brand'), | ||
}); | ||
|
||
/** @type {CoreEvalBuilder} */ | ||
export const defaultProposalBuilder = async ( | ||
powers, | ||
/** @type {FastUSDCConfig} */ config, | ||
) => { | ||
return harden({ | ||
sourceSpec: '@agoric/fast-usdc/src/add-operators.core.js', | ||
/** @type {[string, Parameters<typeof getManifestForAddOperators>[1]]} */ | ||
getManifestCall: [ | ||
getManifestForAddOperators.name, | ||
{ | ||
options: toExternalConfig(config, crossVatContext), | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
/** @type {DeployScriptFunction} */ | ||
export default async (homeP, endowments) => { | ||
const { writeCoreEval } = await makeHelpers(homeP, endowments); | ||
const { scriptArgs } = endowments; | ||
|
||
/** @type {{ values: FastUSDCOpts }} */ | ||
// @ts-expect-error ensured by options | ||
const { | ||
values: { oracle: oracleArgs, net }, | ||
} = parseArgs({ args: scriptArgs, options }); | ||
|
||
const parseOracleArgs = () => { | ||
if (net) { | ||
if (!(net in configurations)) { | ||
throw Error(`${net} not in ${keys(configurations)}`); | ||
} | ||
return configurations[net].oracles; | ||
} | ||
if (!oracleArgs) throw Error(oraclesUsage); | ||
return Object.fromEntries( | ||
oracleArgs.map(arg => { | ||
const result = arg.match(/(?<name>[^:]+):(?<address>.+)/); | ||
if (!(result && result.groups)) throw Error(oraclesUsage); | ||
const { name, address } = result.groups; | ||
return [name, address]; | ||
}), | ||
); | ||
}; | ||
|
||
const config = harden({ | ||
oracles: parseOracleArgs(), | ||
}); | ||
|
||
await writeCoreEval('add-operators', utils => | ||
defaultProposalBuilder(utils, config), | ||
); | ||
}; |
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
Oops, something went wrong.