Skip to content

Commit

Permalink
Merge branch 'master' into muneeb/capture-gh-ci-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Muneeb147 authored Oct 31, 2024
2 parents 87f9c48 + fae2710 commit 9b1b527
Show file tree
Hide file tree
Showing 50 changed files with 3,093 additions and 948 deletions.
8 changes: 0 additions & 8 deletions a3p-integration/proposals/n:upgrade-next/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions a3p-integration/proposals/n:upgrade-next/eval.sh

This file was deleted.

2 changes: 1 addition & 1 deletion a3p-integration/proposals/n:upgrade-next/initial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const vats = {
localchain: { incarnation: 1 },
orchestration: { incarnation: 0 },
transfer: { incarnation: 1 },
walletFactory: { incarnation: 4 },
walletFactory: { incarnation: 5 },
zoe: { incarnation: 3 },
};

Expand Down
17 changes: 0 additions & 17 deletions a3p-integration/proposals/n:upgrade-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@
"upgradeInfo": {
"coreProposals": []
},
"sdk-generate": [
"vats/test-localchain.js localchaintest-submission",
"vats/upgrade-bank.js upgrade-bank",
"vats/upgrade-provisionPool.js upgrade-provisionPool",
"testing/add-LEMONS.js add-LEMONS",
"testing/add-OLIVES.js add-OLIVES",
"inter-protocol/replace-electorate-core.js replace-electorate A3P_INTEGRATION",
"inter-protocol/updatePriceFeeds.js price-feeds A3P_INTEGRATION",
"vats/add-auction.js price-feeds",
"vats/upgradeVaults.js price-feeds",
"inter-protocol/updatePriceFeeds.js submission/main main",
"vats/add-auction.js submission/main",
"vats/upgradeVaults.js submission/main",
"inter-protocol/updatePriceFeeds.js submission/devnet devnet",
"vats/add-auction.js submission/devnet",
"vats/upgradeVaults.js submission/devnet"
],
"type": "Software Upgrade Proposal"
},
"type": "module",
Expand Down
30 changes: 19 additions & 11 deletions a3p-integration/proposals/n:upgrade-next/priceFeedUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import {
getVaultPrices,
getVatDetails,
openVault,
pushPrices,
registerOraclesForBrand,
USER1ADDR,
} from '@agoric/synthetic-chain';
import {
getPriceFeedRoundId,
verifyPushedPrice,
} from './test-lib/price-feed.js';

import { BID_OFFER_ID } from './agd-tools.js';

Expand All @@ -37,12 +39,17 @@ const checkPriceFeedVatsUpdated = async t => {
await checkForOracle(t, 'stATOM');
};

console.log('adding oracle for each brand');
const oraclesByBrand = generateOracleMap('f-priceFeeds', ['ATOM', 'stATOM']);
await registerOraclesForBrand('ATOM', oraclesByBrand);
await registerOraclesForBrand('stATOM', oraclesByBrand);
/*
* The Oracle for ATOM and stATOM brands are being registered in the offer made at file:
* a3p-integration/proposals/n:upgrade-next/verifyPushedPrice.js
* which is being executed during the use phase of upgrade-next proposal
*/
const oraclesByBrand = generateOracleMap('n-upgrade', ['ATOM', 'stATOM']);

let roundId = 1;
const latestAtomRoundId = await getPriceFeedRoundId('ATOM');
const latestStAtomRoundId = await getPriceFeedRoundId('stATOM');
let atomRoundId = latestAtomRoundId + 1;
let stAtomRoundId = latestStAtomRoundId + 1;

const tryPushPrices = async t => {
// There are no old prices for the other currencies.
Expand All @@ -52,9 +59,10 @@ const tryPushPrices = async t => {
// t.is(stAtomOutPre, '+12010000');

t.log('pushing new prices');
await pushPrices(13.4, 'ATOM', oraclesByBrand, roundId);
await pushPrices(13.7, 'stATOM', oraclesByBrand, roundId);
roundId += 1;
await verifyPushedPrice(13.4, 'ATOM', oraclesByBrand, atomRoundId);
await verifyPushedPrice(13.7, 'stATOM', oraclesByBrand, stAtomRoundId);
atomRoundId += 1;
stAtomRoundId += 1;

t.log('awaiting new quotes');
const atomOut = await getPriceQuote('ATOM');
Expand Down Expand Up @@ -89,7 +97,7 @@ const openMarginalVault = async t => {
};

const triggerAuction = async t => {
await pushPrices(5.2, 'ATOM', oraclesByBrand, roundId);
await verifyPushedPrice(5.2, 'ATOM', oraclesByBrand, atomRoundId);

const atomOut = await getPriceQuote('ATOM');
t.is(atomOut, '+5200000');
Expand Down
102 changes: 0 additions & 102 deletions a3p-integration/proposals/n:upgrade-next/provisionPool.test.js

This file was deleted.

41 changes: 0 additions & 41 deletions a3p-integration/proposals/n:upgrade-next/resetChargingPeriod.js

This file was deleted.

62 changes: 62 additions & 0 deletions a3p-integration/proposals/n:upgrade-next/test-lib/price-feed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-env node */

import {
agoric,
getContractInfo,
pushPrices,
getPriceQuote,
} from '@agoric/synthetic-chain';
import { retryUntilCondition } from './sync-tools.js';

export const scale6 = x => BigInt(x * 1_000_000);

/**
*
* @param {number} price
* @param {string} brand
* @param {Map<any, any>} oraclesByBrand
* @param {number} roundId
* @returns {Promise<void>}
*/
export const verifyPushedPrice = async (
price,
brand,
oraclesByBrand,
roundId,
) => {
const pushPriceRetryOpts = {
maxRetries: 5, // arbitrary
retryIntervalMs: 5000, // in ms
};

await pushPrices(price, brand, oraclesByBrand, roundId);
console.log(`Pushing price ${price} for ${brand}`);

await retryUntilCondition(
() => getPriceQuote(brand),
res => res === `+${scale6(price).toString()}`,
'price not pushed yet',
{
log: console.log,
setTimeout: global.setTimeout,
...pushPriceRetryOpts,
},
);
console.log(`Price ${price} pushed for ${brand}`);
};

/**
*
* @param {string} brand
* @returns {Promise<number>}
*/
export const getPriceFeedRoundId = async brand => {
const latestRoundPath = `published.priceFeed.${brand}-USD_price_feed.latestRound`;
const latestRound = await getContractInfo(latestRoundPath, {
agoric,
prefix: '',
});

console.log('latestRound: ', latestRound);
return Number(latestRound.roundId);
};
72 changes: 72 additions & 0 deletions a3p-integration/proposals/n:upgrade-next/test-lib/sync-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-env node */

/**
* @file These tools mostly duplicate code that will be added in other PRs
* and eventually migrated to synthetic-chain. Sorry for the duplication.
*/

/**
* @typedef {object} RetryOptions
* @property {number} [maxRetries]
* @property {number} [retryIntervalMs]
* @property {(...arg0: string[]) => void} log
* @property {(object) => void} [setTimeout]
* @property {string} [errorMessage=Error]
*/

const ambientSetTimeout = global.setTimeout;

/**
* From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L10
*
* @param {number} ms
* @param {*} sleepOptions
*/
const sleep = (ms, { log = () => {}, setTimeout = ambientSetTimeout }) =>
new Promise(resolve => {
log(`Sleeping for ${ms}ms...`);
setTimeout(resolve, ms);
});

/**
* From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L24
*
* @param {() => Promise} operation
* @param {(result: any) => boolean} condition
* @param {string} message
* @param {RetryOptions} options
*/
export const retryUntilCondition = async (
operation,
condition,
message,
{ maxRetries = 6, retryIntervalMs = 3500, log, setTimeout },
) => {
console.log({ maxRetries, retryIntervalMs, message });
let retries = 0;

await null;
while (retries < maxRetries) {
try {
const result = await operation();
log('RESULT', result);
if (condition(result)) {
return result;
}
} catch (error) {
if (error instanceof Error) {
log(`Error: ${error.message}`);
} else {
log(`Unknown error: ${String(error)}`);
}
}

retries += 1;
console.log(
`Retry ${retries}/${maxRetries} - Waiting for ${retryIntervalMs}ms for ${message}...`,
);
await sleep(retryIntervalMs, { log, setTimeout });
}

throw Error(`${message} condition failed after ${maxRetries} retries.`);
};
Loading

0 comments on commit 9b1b527

Please sign in to comment.