-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
orchestration package with stakeBLD #9078
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
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,5 @@ | ||
CoreEvalProposal to install stakeBld contract | ||
|
||
The `submission` for the proposal is automatically generated during `yarn build` | ||
in `a3p-integration` using the code in agoric-sdk through | ||
`script/generate-a3p-submissions.sh`. and `script/generate-a3p-submission.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"agoricProposal": { | ||
"type": "/agoric.swingset.CoreEvalProposal", | ||
"source": "subdir", | ||
"sdk-generate": [ | ||
"orchestration/init-stakeBld.js" | ||
] | ||
}, | ||
"type": "module", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@agoric/internal": "0.3.3-dev-5676146.0", | ||
"@agoric/synthetic-chain": "^0.0.7", | ||
"@cosmjs/stargate": "^0.32.3", | ||
"@cosmjs/tendermint-rpc": "^0.32.3", | ||
"@endo/errors": "^1.1.0", | ||
"@endo/far": "^1.0.4", | ||
"@endo/init": "^1.0.4", | ||
"agoric": "0.21.2-dev-5676146.0", | ||
"ava": "^5.3.1", | ||
"execa": "^8.0.1", | ||
"node-fetch": "^3.3.2" | ||
}, | ||
"ava": { | ||
"concurrency": 1 | ||
}, | ||
"packageManager": "yarn@4.1.0" | ||
} |
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,75 @@ | ||
/* eslint-disable @jessie.js/safe-await-separator -- buggy version */ | ||
import test from 'ava'; | ||
|
||
import { QueryClient, setupStakingExtension } from '@cosmjs/stargate'; // fails to import after Endo/init | ||
|
||
import '@endo/init'; | ||
|
||
import { GOV1ADDR } from '@agoric/synthetic-chain'; | ||
import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; | ||
import assert from 'node:assert'; | ||
import process from 'node:process'; | ||
import { networkConfig, walletUtils } from './test-lib/index.js'; | ||
|
||
// XXX not the same as VALIDATOR_ADDRESS, which is actually the delegator | ||
const VALIDATOR_ADDRESS = process.env.VALIDATOR_ADDRESS; | ||
assert(VALIDATOR_ADDRESS, 'Missing VALIDATOR_ADDRESS in env'); | ||
|
||
const currentDelegation = async () => { | ||
const endpoint = networkConfig.rpcAddrs[0]; | ||
const tmClient = await Tendermint34Client.connect(endpoint); | ||
const query = QueryClient.withExtensions(tmClient, setupStakingExtension); | ||
const res = await query.staking.validatorDelegations(VALIDATOR_ADDRESS); | ||
|
||
return res.delegationResponses; | ||
}; | ||
|
||
test('basic', async t => { | ||
assert(GOV1ADDR); | ||
|
||
const { brand } = walletUtils.agoricNames; | ||
|
||
t.is((await currentDelegation()).length, 1, 'just the initial delegation'); | ||
|
||
await walletUtils.broadcastBridgeAction(GOV1ADDR, { | ||
method: 'executeOffer', | ||
offer: { | ||
id: 'request-stake', | ||
invitationSpec: { | ||
source: 'agoricContract', | ||
instancePath: ['stakeBld'], | ||
callPipe: [['makeStakeBldInvitation']], | ||
}, | ||
proposal: { | ||
give: { | ||
In: { brand: brand.BLD, value: 10n }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await walletUtils.broadcastBridgeAction(GOV1ADDR, { | ||
method: 'executeOffer', | ||
offer: { | ||
id: 'request-delegate-6', | ||
invitationSpec: { | ||
source: 'continuing', | ||
previousOffer: 'request-stake', | ||
invitationMakerName: 'Delegate', | ||
invitationArgs: [VALIDATOR_ADDRESS, { brand: brand.BLD, value: 10n }], | ||
}, | ||
proposal: { | ||
give: { | ||
In: { brand: brand.BLD, value: 10n }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const postDelegation = await currentDelegation(); | ||
t.is(postDelegation.length, 2, 'new delegation now'); | ||
t.like(postDelegation[1], { | ||
balance: { amount: '10', denom: 'ubld' }, | ||
// omit 'delegation' because it has 'delgatorAddress' which is different every test run | ||
}); | ||
}); |
140 changes: 140 additions & 0 deletions
140
a3p-integration/proposals/c:stake-bld/test-lib/chain.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,140 @@ | ||
/** @file copied from packages/agoric-cli */ | ||
// TODO DRY in https://github.com/Agoric/agoric-sdk/issues/9109 | ||
// @ts-check | ||
/* global process */ | ||
|
||
const agdBinary = 'agd'; | ||
|
||
/** | ||
* @param {ReadonlyArray<string>} swingsetArgs | ||
* @param {import('./rpc.js').MinimalNetworkConfig & { | ||
* from: string, | ||
* fees?: string, | ||
* dryRun?: boolean, | ||
* verbose?: boolean, | ||
* keyring?: {home?: string, backend: string} | ||
* stdout?: Pick<import('stream').Writable, 'write'> | ||
* execFileSync: typeof import('child_process').execFileSync | ||
* }} opts | ||
*/ | ||
export const execSwingsetTransaction = (swingsetArgs, opts) => { | ||
const { | ||
from, | ||
fees, | ||
dryRun = false, | ||
verbose = true, | ||
keyring = undefined, | ||
chainName, | ||
rpcAddrs, | ||
stdout = process.stdout, | ||
execFileSync, | ||
} = opts; | ||
const homeOpt = keyring?.home ? [`--home=${keyring.home}`] : []; | ||
const backendOpt = keyring?.backend | ||
? [`--keyring-backend=${keyring.backend}`] | ||
: []; | ||
const feeOpt = fees ? ['--fees', fees] : []; | ||
const cmd = [`--node=${rpcAddrs[0]}`, `--chain-id=${chainName}`].concat( | ||
homeOpt, | ||
backendOpt, | ||
feeOpt, | ||
[`--from=${from}`, 'tx', 'swingset'], | ||
swingsetArgs, | ||
); | ||
|
||
if (dryRun) { | ||
stdout.write(`Run this interactive command in shell:\n\n`); | ||
stdout.write(`${agdBinary} `); | ||
stdout.write(cmd.join(' ')); | ||
stdout.write('\n'); | ||
} else { | ||
const yesCmd = cmd.concat(['--yes']); | ||
if (verbose) console.log('Executing ', yesCmd); | ||
const out = execFileSync(agdBinary, yesCmd, { encoding: 'utf-8' }); | ||
|
||
// agd puts this diagnostic on stdout rather than stderr :-/ | ||
// "Default sign-mode 'direct' not supported by Ledger, using sign-mode 'amino-json'. | ||
if (out.startsWith('Default sign-mode')) { | ||
const stripDiagnostic = out.replace(/^Default[^\n]+\n/, ''); | ||
return stripDiagnostic; | ||
} | ||
return out; | ||
} | ||
}; | ||
harden(execSwingsetTransaction); | ||
|
||
/** | ||
* @param {import('./rpc.js').MinimalNetworkConfig & { | ||
* execFileSync: typeof import('child_process').execFileSync, | ||
* delay: (ms: number) => Promise<void>, | ||
* period?: number, | ||
* retryMessage?: string, | ||
* }} opts | ||
* @returns {<T>(l: (b: { time: string, height: string }) => Promise<T>) => Promise<T>} | ||
*/ | ||
export const pollBlocks = opts => async lookup => { | ||
const { execFileSync, delay, rpcAddrs, period = 3 * 1000 } = opts; | ||
assert(execFileSync, 'missing execFileSync'); | ||
const { retryMessage } = opts; | ||
|
||
const nodeArgs = [`--node=${rpcAddrs[0]}`]; | ||
|
||
await null; // separate sync prologue | ||
|
||
for (;;) { | ||
const sTxt = execFileSync(agdBinary, ['status', ...nodeArgs]); | ||
const status = JSON.parse(sTxt.toString()); | ||
const { | ||
SyncInfo: { latest_block_time: time, latest_block_height: height }, | ||
} = status; | ||
try { | ||
// see await null above | ||
const result = await lookup({ time, height }); | ||
return result; | ||
} catch (_err) { | ||
console.error( | ||
time, | ||
retryMessage || 'not in block', | ||
height, | ||
'retrying...', | ||
); | ||
await delay(period); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* @param {string} txhash | ||
* @param {import('./rpc.js').MinimalNetworkConfig & { | ||
* execFileSync: typeof import('child_process').execFileSync, | ||
* delay: (ms: number) => Promise<void>, | ||
* period?: number, | ||
* }} opts | ||
*/ | ||
export const pollTx = async (txhash, opts) => { | ||
const { execFileSync, rpcAddrs, chainName } = opts; | ||
assert(execFileSync, 'missing execFileSync in pollTx'); | ||
|
||
const nodeArgs = [`--node=${rpcAddrs[0]}`]; | ||
const outJson = ['--output', 'json']; | ||
|
||
const lookup = async () => { | ||
const out = execFileSync( | ||
agdBinary, | ||
[ | ||
'query', | ||
'tx', | ||
txhash, | ||
`--chain-id=${chainName}`, | ||
...nodeArgs, | ||
...outJson, | ||
], | ||
{ stdio: ['ignore', 'pipe', 'ignore'] }, | ||
); | ||
// XXX this type is defined in a .proto file somewhere | ||
/** @type {{ height: string, txhash: string, code: number, timestamp: string }} */ | ||
const info = JSON.parse(out.toString()); | ||
return info; | ||
}; | ||
return pollBlocks({ ...opts, retryMessage: 'tx not in block' })(lookup); | ||
}; |
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,23 @@ | ||
/* global setTimeout */ | ||
import fetch from 'node-fetch'; | ||
import { execFileSync } from 'child_process'; | ||
import { makeWalletUtils } from './wallet.js'; | ||
|
||
export const networkConfig = { | ||
rpcAddrs: ['http://0.0.0.0:26657'], | ||
chainName: 'agoriclocal', | ||
}; | ||
|
||
/** | ||
* Resolve after a delay in milliseconds. | ||
* | ||
* @param {number} ms | ||
* @returns {Promise<void>} | ||
*/ | ||
const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms)); | ||
|
||
// eslint-disable-next-line @jessie.js/safe-await-separator -- buggy version | ||
export const walletUtils = await makeWalletUtils( | ||
{ delay, execFileSync, fetch }, | ||
networkConfig, | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the files in this directory are mostly from packages/agoric-cli. I think we'll want to DRY it but I don't know when. I'm reluctant to have more exports from agoric-cli. I could see them going in ui-kit though. Or @agoric/contracts as support tools. I figure it's okay to duplicate for tests .
I put them in "test-lib" instead of "lib" in service of Agoric/agoric-3-proposals#115
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lean that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Punting to #9109