-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(boot): break out
vtransfer.test.ts
- Loading branch information
1 parent
e3772fd
commit eaa7c5b
Showing
2 changed files
with
115 additions
and
94 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
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,115 @@ | ||
/* eslint-disable @jessie.js/safe-await-separator -- confused by casting 'as' */ | ||
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import type { TestFn } from 'ava'; | ||
|
||
import type { ScopedBridgeManager } from '@agoric/vats'; | ||
import type { | ||
TransferMiddleware, | ||
TransferVat, | ||
} from '@agoric/vats/src/vat-transfer.js'; | ||
import { BridgeId, VTRANSFER_IBC_EVENT } from '@agoric/internal'; | ||
import { makeSwingsetTestKit } from '../../tools/supports.ts'; | ||
|
||
const makeDefaultTestContext = async t => { | ||
const swingsetTestKit = await makeSwingsetTestKit( | ||
t.log, | ||
'bundles/vtransfer', | ||
{ configSpecifier: '@agoric/vm-config/decentral-demo-config.json' }, | ||
); | ||
return swingsetTestKit; | ||
}; | ||
|
||
type DefaultTestContext = Awaited<ReturnType<typeof makeDefaultTestContext>>; | ||
|
||
const test: TestFn<DefaultTestContext> = anyTest; | ||
|
||
test.before(async t => (t.context = await makeDefaultTestContext(t))); | ||
test.after.always(t => t.context.shutdown?.()); | ||
|
||
test('vtransfer', async t => { | ||
const { buildProposal, evalProposal, getOutboundMessages, runUtils } = | ||
t.context; | ||
const { EV } = runUtils; | ||
|
||
// Pull what transfer-proposal produced into local scope | ||
const transferVat = (await EV.vat('bootstrap').consumeItem( | ||
'transferVat', | ||
)) as ERef<TransferVat>; | ||
t.truthy(transferVat); | ||
const transferMiddleware = (await EV.vat('bootstrap').consumeItem( | ||
'transferMiddleware', | ||
)) as TransferMiddleware; | ||
t.truthy(transferMiddleware); | ||
const vtransferBridgeManager = (await EV.vat('bootstrap').consumeItem( | ||
'vtransferBridgeManager', | ||
)) as ScopedBridgeManager<'vtransfer'>; | ||
t.truthy(vtransferBridgeManager); | ||
|
||
// only VTRANSFER_IBC_EVENT is supported by vtransferBridgeManager | ||
await t.throwsAsync( | ||
EV(vtransferBridgeManager).fromBridge({ | ||
type: 'VTRANSFER_OTHER', | ||
}), | ||
{ | ||
message: `Invalid inbound event type "VTRANSFER_OTHER"; expected "${VTRANSFER_IBC_EVENT}"`, | ||
}, | ||
); | ||
|
||
const target = 'agoric1vtransfertest'; | ||
const packet = 'thisIsPacket'; | ||
|
||
// 0 interceptors for target | ||
|
||
// it's an error to target an address before an interceptor is registered | ||
await t.throwsAsync( | ||
EV(vtransferBridgeManager).fromBridge({ | ||
target, | ||
type: VTRANSFER_IBC_EVENT, | ||
event: 'echo', | ||
}), | ||
{ | ||
message: | ||
'key "agoric1vtransfertest" not found in collection "targetToApp"', | ||
}, | ||
); | ||
|
||
// 1 interceptors for target | ||
|
||
// Tap into VTRANSFER_IBC_EVENT messages | ||
const testVtransferProposal = buildProposal( | ||
'@agoric/builders/scripts/vats/test-vtransfer.js', | ||
); | ||
await evalProposal(testVtransferProposal); | ||
|
||
// simulate a Golang upcall with arbitrary payload | ||
// note that property order matters! | ||
const expectedAckData = { | ||
event: 'writeAcknowledgement', | ||
packet, | ||
target, | ||
type: VTRANSFER_IBC_EVENT, | ||
}; | ||
|
||
await EV(vtransferBridgeManager).fromBridge(expectedAckData); | ||
|
||
// verify the ackMethod outbound | ||
const messages = getOutboundMessages(BridgeId.VTRANSFER); | ||
t.deepEqual(messages, [ | ||
{ | ||
target, | ||
type: 'BRIDGE_TARGET_REGISTER', | ||
}, | ||
{ | ||
ack: btoa(JSON.stringify(expectedAckData)), | ||
method: 'receiveExecuted', | ||
packet, | ||
type: 'IBC_METHOD', | ||
}, | ||
]); | ||
|
||
// test adding an interceptor for the same target, which should fail | ||
await t.throwsAsync(() => evalProposal(testVtransferProposal), { | ||
message: /Target.*already registered/, | ||
}); | ||
}); |