-
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
refactor: delay addition of issuer to auctioneer until a good time #8398
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
412cd9e
refactor: delay addition of issuer to auctioneer until a good time
Chris-Hibbert d589ef3
test: test for adding assets at various times
Chris-Hibbert db080ce
chore: clean-ups and clarifications
Chris-Hibbert 539e3dd
test: refactor test context setup to share propsoal mutation.
Chris-Hibbert 6d52bcb
chore: update comment on object comparison breakage
Chris-Hibbert 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import type { TestFn } from 'ava'; | ||
|
||
import { TimeMath } from '@agoric/time'; | ||
import { | ||
LiquidationTestContext, | ||
makeLiquidationTestContext, | ||
} from './liquidation.ts'; | ||
import { makeProposalExtractor } from './supports.ts'; | ||
|
||
const test = anyTest as TestFn< | ||
LiquidationTestContext & { | ||
getCollateralProposal: ( | ||
name: string, | ||
id: string, | ||
) => Awaited<ReturnType<ReturnType<typeof makeProposalExtractor>>>; | ||
} | ||
>; | ||
|
||
const auctioneerPath = 'published.auction'; | ||
|
||
test.before(async t => { | ||
const context = await makeLiquidationTestContext(t); | ||
const proposal = await context.buildProposal({ | ||
package: 'builders', | ||
packageScriptName: 'build:add-STARS-proposal', | ||
}); | ||
|
||
t.log('installing proposal'); | ||
// share a single proposal so tests don't stomp on each other's files; It has | ||
// to be edited by each so as not to re-use keywords. | ||
for await (const bundle of proposal.bundles) { | ||
await context.controller.validateAndInstallBundle(bundle); | ||
} | ||
t.log('installed', proposal.bundles.length, 'bundles'); | ||
|
||
const getCollateralProposal = (name, id) => { | ||
// stringify, modify and parse because modifying a deep copy was fragile. | ||
const proposalJSON = JSON.stringify(proposal); | ||
const proposalMod = proposalJSON | ||
.replaceAll('STARS', name) | ||
.replaceAll('ibc/987C17B1', `ibc/987C17B1${id}`); | ||
return JSON.parse(proposalMod); | ||
}; | ||
t.context = { | ||
...context, | ||
getCollateralProposal, | ||
}; | ||
t.log('installed', proposal.bundles.length, 'bundles'); | ||
}); | ||
|
||
test.after.always(t => { | ||
// This will fail if a subset of tests are run. It detects that three | ||
// collaterals were added to the auction after ATOM. | ||
t.like(t.context.readLatest(`${auctioneerPath}.book3`), { | ||
currentPriceLevel: null, | ||
}); | ||
return t.context.shutdown && t.context.shutdown(); | ||
}); | ||
|
||
test('addAsset to quiescent auction', async t => { | ||
const { advanceTimeTo, readLatest } = t.context; | ||
|
||
const proposal = t.context.getCollateralProposal('COMETS', 'A'); | ||
const bridgeMessage = { | ||
type: 'CORE_EVAL', | ||
evals: proposal.evals, | ||
}; | ||
|
||
const { EV } = t.context.runUtils; | ||
|
||
const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit'); | ||
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule(); | ||
const { liveAuctionSchedule, nextAuctionSchedule } = schedules; | ||
const nextEndTime = liveAuctionSchedule | ||
? liveAuctionSchedule.endTime | ||
: nextAuctionSchedule.endTime; | ||
const fiveMinutes = harden({ | ||
relValue: 5n * 60n, | ||
timerBrand: nextEndTime.timerBrand, | ||
}); | ||
const nextQuiescentTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes); | ||
await advanceTimeTo(nextQuiescentTime); | ||
|
||
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem( | ||
'coreEvalBridgeHandler', | ||
); | ||
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage); | ||
t.log('proposal executed'); | ||
|
||
t.like(readLatest(`${auctioneerPath}.book1`), { | ||
currentPriceLevel: null, | ||
}); | ||
}); | ||
|
||
test('addAsset to active auction', async t => { | ||
const { advanceTimeTo, readLatest } = t.context; | ||
const { EV } = t.context.runUtils; | ||
|
||
t.like(readLatest(`${auctioneerPath}.book0`), { startPrice: null }); | ||
|
||
const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit'); | ||
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule(); | ||
const { nextAuctionSchedule } = schedules; | ||
t.truthy(nextAuctionSchedule); | ||
const nextStartTime = nextAuctionSchedule.startTime; | ||
const fiveMinutes = harden({ | ||
relValue: 5n * 60n, | ||
timerBrand: nextStartTime.timerBrand, | ||
}); | ||
const futureBusyTime = TimeMath.addAbsRel(nextStartTime, fiveMinutes); | ||
|
||
await advanceTimeTo(futureBusyTime); | ||
|
||
t.log('launching proposal'); | ||
|
||
const proposal = t.context.getCollateralProposal('PLANETS', 'B'); | ||
const bridgeMessage = { | ||
type: 'CORE_EVAL', | ||
evals: proposal.evals, | ||
}; | ||
t.log({ bridgeMessage }); | ||
|
||
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem( | ||
'coreEvalBridgeHandler', | ||
); | ||
EV(coreEvalBridgeHandler).fromBridge(bridgeMessage); | ||
|
||
const nextEndTime = nextAuctionSchedule.endTime; | ||
const afterEndTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes); | ||
await advanceTimeTo(afterEndTime); | ||
t.log('proposal executed'); | ||
|
||
const schedulesAfter = await EV(auctioneerKit.creatorFacet).getSchedule(); | ||
// TimeMath.compareAbs() can't handle brands processed by kmarshall | ||
t.truthy( | ||
schedules.nextAuctionSchedule.endTime.absValue < | ||
schedulesAfter.nextAuctionSchedule.endTime.absValue, | ||
); | ||
|
||
t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null }); | ||
}); | ||
|
||
test('addAsset to auction starting soon', async t => { | ||
const { advanceTimeTo, readLatest } = t.context; | ||
const { EV } = t.context.runUtils; | ||
|
||
const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit'); | ||
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule(); | ||
const { nextAuctionSchedule } = schedules; | ||
t.truthy(nextAuctionSchedule); | ||
const nextStartTime = nextAuctionSchedule.startTime; | ||
const fiveMinutes = harden({ | ||
relValue: 5n * 60n, | ||
timerBrand: nextStartTime.timerBrand, | ||
}); | ||
const tooCloseTime = TimeMath.subtractAbsRel(nextStartTime, fiveMinutes); | ||
|
||
await advanceTimeTo(tooCloseTime); | ||
|
||
const proposal = t.context.getCollateralProposal('MOONS', 'C'); | ||
t.log('launching proposal'); | ||
const bridgeMessage = { | ||
type: 'CORE_EVAL', | ||
evals: proposal.evals, | ||
}; | ||
t.log({ bridgeMessage }); | ||
|
||
const coreEvalBridgeHandler = await EV.vat('bootstrap').consumeItem( | ||
'coreEvalBridgeHandler', | ||
); | ||
EV(coreEvalBridgeHandler).fromBridge(bridgeMessage); | ||
|
||
const nextEndTime = nextAuctionSchedule.endTime; | ||
const afterEndTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes); | ||
await advanceTimeTo(afterEndTime); | ||
|
||
t.log('proposal executed'); | ||
|
||
const schedulesAfter = await EV(auctioneerKit.creatorFacet).getSchedule(); | ||
t.truthy( | ||
schedules.nextAuctionSchedule.endTime.absValue < | ||
schedulesAfter.nextAuctionSchedule.endTime.absValue, | ||
); | ||
t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null }); | ||
}); |
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.
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.
Why do we need this check? Is each test not independent?
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.
Each test now ends by verifying that
readLatest(
${auctioneerPath}.book1)
finds something. What's actually happening is that the tests will sequentially addbook1
,book2
, andbook3
. In order to allow for parallelism, since they take so long, I didn't make them sequential, so I don't know what order they run in.I could have each test check all three potentially-present nodes and verify that one has a matching name. I thought it more straightforward to verify in the
.after
that 3 had been added. Please let me know if you think there's a more legible approach.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.
Actually, now that I moved building the proposal into
.before
, the total time was 38s. When I modified the tests to.serial
that grew to 40s, which is probably not significant.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.
not significant. also probably a smaller difference in CI with fewer cores.