forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScopedBridgeManager utils (Agoric#9396)
refs: Agoric#9063 refs: Agoric#9207 ## Description As part of Agoric#9063 I'm trying to improve the testing situation. One challenge is faking the bridges. This PR factors out some test utils, with the eventual goal of providing fixtures in each test for the bridge comms. Along the way I realized that one of the tests had the wrong bridge, and that we could have avoided that if the scoped bridges were typed by their bridgeId. So this also does that. @michaelfig I'd like your take on this. ### Security Considerations <!-- Does this change introduce new assumptions or dependencies that, if violated, could introduce security vulnerabilities? How does this PR change the boundaries between mutually-suspicious components? What new authorities are introduced by this change, perhaps by new API calls? --> ### Scaling Considerations <!-- Does this change require or encourage significant increase in consumption of CPU cycles, RAM, on-chain storage, message exchanges, or other scarce resources? If so, can that be prevented or mitigated? --> ### Documentation Considerations <!-- Give our docs folks some hints about what needs to be described to downstream users. Backwards compatibility: what happens to existing data or deployments when this code is shipped? Do we need to instruct users to do something to upgrade their saved data? If there is no upgrade path possible, how bad will that be for users? --> ### Testing Considerations <!-- Every PR should of course come with tests of its own functionality. What additional tests are still needed beyond those unit tests? How does this affect CI, other test automation, or the testnet? --> ### Upgrade Considerations <!-- What aspects of this PR are relevant to upgrading live production systems, and how should they be addressed? -->
- Loading branch information
Showing
27 changed files
with
191 additions
and
249 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,66 +1 @@ | ||
import { Fail } from '@agoric/assert'; | ||
import type { ScopedBridgeManager } from '@agoric/vats'; | ||
|
||
import { | ||
makePinnedHistoryTopic, | ||
prepareDurablePublishKit, | ||
subscribeEach, | ||
} from '@agoric/notifier'; | ||
import type { Baggage } from '@agoric/swingset-liveslots'; | ||
import { M, makeScalarBigMapStore } from '@agoric/vat-data'; | ||
import { makeDurableZone } from '@agoric/zone/durable.js'; | ||
import type { ExecutionContext } from 'ava'; | ||
|
||
// TODO DRY with ibcBridgeMock.js in package boot | ||
export const makeBridge = ( | ||
t: ExecutionContext, | ||
baggage = makeScalarBigMapStore('baggage', { | ||
keyShape: M.string(), | ||
durable: true, | ||
}) as Baggage, | ||
zone = makeDurableZone(baggage), | ||
) => { | ||
const makeDurablePublishKit = prepareDurablePublishKit( | ||
baggage, | ||
'DurablePublishKit', | ||
); | ||
|
||
const { subscriber, publisher } = makeDurablePublishKit(); | ||
|
||
const pinnedHistoryTopic = makePinnedHistoryTopic(subscriber); | ||
const events = subscribeEach(pinnedHistoryTopic)[Symbol.asyncIterator](); | ||
|
||
let hndlr; | ||
|
||
const bridgeHandler: ScopedBridgeManager = zone.exo( | ||
'IBC Bridge Manager', | ||
undefined, | ||
{ | ||
toBridge: async obj => { | ||
const { method, type, ...params } = obj; | ||
publisher.publish([method, params]); | ||
console.info('toBridge', type, method, params); | ||
switch (type) { | ||
case 'VLOCALCHAIN_ALLOCATE_ADDRESS': | ||
return 'agoric1fixme'; | ||
default: | ||
Fail`unknown type ${type}`; | ||
} | ||
return undefined; | ||
}, | ||
fromBridge: async obj => { | ||
console.info('fromBridge', obj); | ||
}, | ||
initHandler: h => { | ||
if (hndlr) throw Error('already init'); | ||
hndlr = h; | ||
}, | ||
setHandler: h => { | ||
if (!hndlr) throw Error('must init first'); | ||
hndlr = h; | ||
}, | ||
}, | ||
); | ||
|
||
return { bridgeHandler, events }; | ||
}; | ||
export { makeFakeLocalchainBridge } from '@agoric/vats/tools/fake-bridge.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
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
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
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.