-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: verify that vaults and auctions upgrade correctly
- Loading branch information
1 parent
1bdcda1
commit 7bad3e3
Showing
7 changed files
with
327 additions
and
112 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 |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
"doctor": "yarn synthetic-chain doctor" | ||
}, | ||
"dependencies": { | ||
"@agoric/synthetic-chain": "^0.0.7" | ||
"@agoric/synthetic-chain": "^0.0.10", | ||
"@types/better-sqlite3": "^7.6.9" | ||
}, | ||
"packageManager": "[email protected]", | ||
"license": "Apache-2.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,138 @@ | ||
import { | ||
agd, | ||
agops, | ||
agopsLocation, | ||
executeCommand, | ||
VALIDATORADDR, | ||
executeOffer, | ||
GOV1ADDR, | ||
GOV2ADDR, | ||
GOV3ADDR, | ||
newOfferId, | ||
CHAINID, | ||
} from '@agoric/synthetic-chain'; | ||
|
||
const ORACLE_ADDRESSES = [GOV1ADDR, GOV2ADDR, GOV3ADDR]; | ||
|
||
export const BID_OFFER_ID = 'bid-vaultUpgrade-test3'; | ||
|
||
const agdQuery = path => | ||
agd.query('vstorage', 'data', '--output', 'json', path); | ||
|
||
const getQuoteBody = async path => { | ||
const queryout = await agdQuery(path); | ||
|
||
const body = JSON.parse(JSON.parse(queryout.value).values[0]); | ||
return JSON.parse(body.body.substring(1)); | ||
}; | ||
|
||
export const getOracleInstance = async price => { | ||
const instanceRec = await agdQuery(`published.agoricNames.instance`); | ||
|
||
const value = JSON.parse(instanceRec.value); | ||
const body = JSON.parse(value.values.at(-1)); | ||
|
||
const feeds = JSON.parse(body.body.substring(1)); | ||
const feedName = `${price}-USD price feed`; | ||
|
||
const key = Object.keys(feeds).find(k => feeds[k][0] === feedName); | ||
if (key) { | ||
return body.slots[key]; | ||
} | ||
return null; | ||
}; | ||
|
||
export const checkForOracle = async (t, name) => { | ||
const instance = await getOracleInstance(name); | ||
t.truthy(instance); | ||
}; | ||
|
||
export const addOraclesForBrand = async (brandIn, oraclesByBrand) => { | ||
await null; | ||
const promiseArray = []; | ||
|
||
const oraclesWithID = []; | ||
// newOfferId() waits 1 second | ||
const offerIdBase = await newOfferId(); | ||
for (let i = 0; i < ORACLE_ADDRESSES.length; i += 1) { | ||
const oracleAddress = ORACLE_ADDRESSES[i]; | ||
const offerId = `${offerIdBase}.${i}`; | ||
oraclesWithID.push({ address: oracleAddress, offerId }); | ||
|
||
promiseArray.push( | ||
executeOffer( | ||
oracleAddress, | ||
agops.oracle('accept', '--offerId', offerId, `--pair ${brandIn}.USD`), | ||
), | ||
); | ||
} | ||
oraclesByBrand.set(brandIn, oraclesWithID); | ||
|
||
return Promise.all(promiseArray); | ||
}; | ||
|
||
export const pushPrices = (price, brandIn, oraclesByBrand) => { | ||
const promiseArray = []; | ||
|
||
for (const oracle of oraclesByBrand.get(brandIn)) { | ||
promiseArray.push( | ||
executeOffer( | ||
oracle.address, | ||
agops.oracle( | ||
'pushPriceRound', | ||
'--price', | ||
price, | ||
'--oracleAdminAcceptOfferId', | ||
oracle.offerId, | ||
), | ||
), | ||
); | ||
} | ||
|
||
return Promise.all(promiseArray); | ||
}; | ||
|
||
export const getPriceQuote = async price => { | ||
const path = `published.priceFeed.${price}-USD_price_feed`; | ||
const body = await getQuoteBody(path); | ||
return body.amountOut.value; | ||
}; | ||
|
||
export const agopsInter = (...params) => { | ||
const newParams = ['inter', ...params]; | ||
return executeCommand(agopsLocation, newParams); | ||
}; | ||
|
||
export const createBid = (price, addr, offerId) => { | ||
return agopsInter( | ||
'bid', | ||
'by-price', | ||
`--price ${price}`, | ||
`--give 1.0IST`, | ||
'--from', | ||
addr, | ||
'--keyring-backend test', | ||
`--offer-id ${offerId}`, | ||
); | ||
}; | ||
|
||
export const getLiveOffers = async addr => { | ||
const path = `published.wallet.${addr}.current`; | ||
const body = await getQuoteBody(path); | ||
return body.liveOffers; | ||
}; | ||
|
||
export const getAuctionCollateral = async index => { | ||
const path = `published.auction.book${index}`; | ||
const body = await getQuoteBody(path); | ||
return body.collateralAvailable.value; | ||
}; | ||
|
||
export const bankSend = (addr, wanted) => { | ||
const chain = ['--chain-id', CHAINID]; | ||
const from = ['--from', VALIDATORADDR]; | ||
const testKeyring = ['--keyring-backend', 'test']; | ||
const noise = [...from, ...chain, ...testKeyring, '--yes']; | ||
|
||
return agd.tx('bank', 'send', VALIDATORADDR, addr, wanted, ...noise); | ||
}; |
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,15 @@ | ||
import test from 'ava'; | ||
|
||
import { USER1ADDR, waitForBlock } from '@agoric/synthetic-chain'; | ||
|
||
import { getAuctionCollateral, getLiveOffers } from './agd-tools.js'; | ||
|
||
test.serial('trigger auction', async t => { | ||
const collatBefore = await getAuctionCollateral('0'); | ||
t.log({ collatBefore }); | ||
|
||
await waitForBlock(2); | ||
|
||
const liveOffer = await getLiveOffers(USER1ADDR); | ||
t.true(liveOffer.isEmpty()); | ||
}); |
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
Oops, something went wrong.