Skip to content

Commit 12e62c8

Browse files
committed
chore(a3p-integration): retain verifyPushedPrice
1 parent db3c25f commit 12e62c8

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/* eslint-env node */
2+
3+
import {
4+
agoric,
5+
getContractInfo,
6+
pushPrices,
7+
getPriceQuote,
8+
} from '@agoric/synthetic-chain';
9+
import { retryUntilCondition } from '@agoric/client-utils';
10+
11+
export const scale6 = x => BigInt(x * 1_000_000);
12+
13+
/**
14+
*
15+
* @param {number} price
16+
* @param {string} brand
17+
* @param {Map<any, any>} oraclesByBrand
18+
* @param {number} roundId
19+
* @returns {Promise<void>}
20+
*/
21+
export const verifyPushedPrice = async (
22+
price,
23+
brand,
24+
oraclesByBrand,
25+
roundId,
26+
) => {
27+
const pushPriceRetryOpts = {
28+
maxRetries: 5, // arbitrary
29+
retryIntervalMs: 5000, // in ms
30+
};
31+
32+
await pushPrices(price, brand, oraclesByBrand, roundId);
33+
console.log(`Pushing price ${price} for ${brand}`);
34+
35+
await retryUntilCondition(
36+
() => getPriceQuote(brand),
37+
res => res === `+${scale6(price).toString()}`,
38+
'price not pushed yet',
39+
{
40+
log: console.log,
41+
setTimeout: global.setTimeout,
42+
...pushPriceRetryOpts,
43+
},
44+
);
45+
console.log(`Price ${price} pushed for ${brand}`);
46+
};
47+
48+
/**
49+
*
50+
* @param {string} brand
51+
* @returns {Promise<number>}
52+
*/
53+
export const getPriceFeedRoundId = async brand => {
54+
const latestRoundPath = `published.priceFeed.${brand}-USD_price_feed.latestRound`;
55+
const latestRound = await getContractInfo(latestRoundPath, {
56+
agoric,
57+
prefix: '',
58+
});
59+
60+
console.log(latestRoundPath, latestRound);
61+
return Number(latestRound.roundId);
62+
};
63+
64+
/**
65+
* Copy from https://github.com/Agoric/agoric-sdk/blob/745f2a82cc94e246f98dd1bd69cb679b608a7170/a3p-integration/proposals/p%3Aupgrade-19/test-lib/psm-lib.js#L277
66+
*
67+
* Checking IST balances can be tricky because of the execution fee mentioned in
68+
* https://github.com/Agoric/agoric-sdk/issues/6525. So we first check for
69+
* equality, but if that fails we recheck against an assumption that a fee of
70+
* the default "minFeeDebit" has been charged.
71+
*
72+
* @param {import('ava').ExecutionContext} t
73+
* @param {number} actualBalance
74+
* @param {number} expectedBalance
75+
*/
76+
export const tryISTBalances = async (t, actualBalance, expectedBalance) => {
77+
const firstTry = await t.try(tt => {
78+
tt.is(actualBalance, expectedBalance);
79+
});
80+
if (firstTry.passed) {
81+
firstTry.commit();
82+
return;
83+
}
84+
85+
firstTry.discard();
86+
t.log('tryISTBalances assuming no batched IST fee', ...firstTry.errors);
87+
// See golang/cosmos/x/swingset/types/default-params.go
88+
// and `ChargeBeans` in golang/cosmos/x/swingset/keeper/keeper.go.
89+
const minFeeDebit = 200_000;
90+
t.is(actualBalance + minFeeDebit, expectedBalance);
91+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
3+
import '@endo/init/debug.js';
4+
import {
5+
registerOraclesForBrand,
6+
generateOracleMap,
7+
} from '@agoric/synthetic-chain';
8+
import { argv } from 'node:process';
9+
import { verifyPushedPrice } from './test-lib/price-feed.js';
10+
11+
const brand = argv[2];
12+
const price = Number(argv[3]);
13+
14+
const BASE_ID = 'n-upgrade';
15+
const ROUND_ID = 1;
16+
17+
const oraclesByBrand = generateOracleMap(BASE_ID, [brand]);
18+
await registerOraclesForBrand(brand, oraclesByBrand);
19+
console.log(`Registering Oracle for ${brand}`);
20+
21+
await verifyPushedPrice(price, brand, oraclesByBrand, ROUND_ID);
22+
console.log(`Price pushed for ${brand}`);

0 commit comments

Comments
 (0)