Skip to content

Commit

Permalink
chore(zoe): add test of burnInvitation.js (#3126)
Browse files Browse the repository at this point in the history
* chore: add test of burnInvitation.js

* chore: add test that tries to burn multiple invitations at once
  • Loading branch information
katelynsills authored May 20, 2021
1 parent 4c06b25 commit 13ce8a8
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions packages/zoe/test/unitTests/zoe/test-burnInvitation.js
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',
},
);
});

0 comments on commit 13ce8a8

Please sign in to comment.