-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(zoe): add test of burnInvitation.js (#3126)
* chore: add test of burnInvitation.js * chore: add test that tries to burn multiple invitations at once
- Loading branch information
1 parent
4c06b25
commit 13ce8a8
Showing
1 changed file
with
85 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// @ts-check | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava'; | ||
import { Far } from '@agoric/marshal'; | ||
|
||
import { makeIssuerKit, AssetKind, AmountMath } from '@agoric/ertp'; | ||
|
||
import { burnInvitation } from '../../../src/zoeService/offer/burnInvitation'; | ||
|
||
test('burnInvitation', async t => { | ||
const mockInvitationKit = makeIssuerKit('mockInvitation', AssetKind.SET); | ||
|
||
const instanceHandle = Far('handle', {}); | ||
const invitationHandle = Far('handle', {}); | ||
|
||
const invitation = mockInvitationKit.mint.mintPayment( | ||
AmountMath.make(mockInvitationKit.brand, [ | ||
{ instance: instanceHandle, handle: invitationHandle }, | ||
]), | ||
); | ||
|
||
t.deepEqual(await burnInvitation(mockInvitationKit.issuer, invitation), { | ||
instanceHandle, | ||
invitationHandle, | ||
}); | ||
}); | ||
|
||
test('burnInvitation - not an invitation', async t => { | ||
const mockInvitationKit = makeIssuerKit('mockInvitation', AssetKind.SET); | ||
|
||
await t.throwsAsync( | ||
// @ts-ignore invalid payment for the purposes of testing | ||
() => burnInvitation(mockInvitationKit.issuer, undefined), | ||
{ message: 'A Zoe invitation is required, not "[undefined]"' }, | ||
); | ||
}); | ||
|
||
test('burnInvitation - invitation already used', async t => { | ||
const mockInvitationKit = makeIssuerKit('mockInvitation', AssetKind.SET); | ||
|
||
const instanceHandle = Far('handle', {}); | ||
const invitationHandle = Far('handle', {}); | ||
|
||
const invitation = mockInvitationKit.mint.mintPayment( | ||
AmountMath.make(mockInvitationKit.brand, [ | ||
{ instance: instanceHandle, handle: invitationHandle }, | ||
]), | ||
); | ||
|
||
t.deepEqual(await burnInvitation(mockInvitationKit.issuer, invitation), { | ||
instanceHandle, | ||
invitationHandle, | ||
}); | ||
|
||
await t.throwsAsync( | ||
() => burnInvitation(mockInvitationKit.issuer, invitation), | ||
{ | ||
message: | ||
'A Zoe invitation is required, not "[Alleged: mockInvitation payment]"', | ||
}, | ||
); | ||
}); | ||
|
||
test('burnInvitation - multiple invitations', async t => { | ||
const mockInvitationKit = makeIssuerKit('mockInvitation', AssetKind.SET); | ||
|
||
const instanceHandle = Far('handle', {}); | ||
const invitationHandle1 = Far('handle', {}); | ||
const invitationHandle2 = Far('handle', {}); | ||
|
||
const invitations = mockInvitationKit.mint.mintPayment( | ||
AmountMath.make(mockInvitationKit.brand, [ | ||
{ instance: instanceHandle, handle: invitationHandle1 }, | ||
{ instance: instanceHandle, handle: invitationHandle2 }, | ||
]), | ||
); | ||
|
||
await t.throwsAsync( | ||
() => burnInvitation(mockInvitationKit.issuer, invitations), | ||
{ | ||
message: 'Only one invitation can be redeemed at a time', | ||
}, | ||
); | ||
}); |