Skip to content
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

Non fungible token ertp tests #558

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions packages/ERTP/test/unitTests/test-mintObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,63 @@ test('mint.mintPayment setMathHelpers with invites', t => {
t.end();
}
});


// Tests related to non-fungible tokens
// This test models ballet tickets
test('non-fungible tokens example', t => {
try {
const { mint: balletTicketMint, issuer: balletTicketIssuer, amountMath } = produceIssuer('Agoric Ballet Opera tickets', 'set');

const startDateString = (new Date(2020, 1, 17, 20, 30)).toISOString();

const ticketDescriptionObjects = Array(5).fill().map((_, i) => ({
seat: i+1,
show: 'The Sofa',
start: startDateString,
}))
DavidBruant marked this conversation as resolved.
Show resolved Hide resolved

const balletTicketPayments = ticketDescriptionObjects.map(ticketDescription => {
return balletTicketMint.mintPayment( amountMath.make(harden([ticketDescription])) )
})

// Alice will buy ticket 1
const paymentForAlice = balletTicketPayments[0];
// Bob will buy tickets 3 and 4
const paymentForBob = balletTicketIssuer.combine([balletTicketPayments[2], balletTicketPayments[3]])


// ALICE SIDE
// Alice bought ticket 1 and has access to the balletTicketIssuer, because it's public
const myTicketPayment_Alice = balletTicketIssuer.claim(paymentForAlice)
// the call to claim hasn't thrown, so Alice knows myTicketPayment_Alice
// is a genuine 'Agoric Ballet Opera tickets' payment and she has exclusive access
// to its handle
const paymentAmount_Alice = balletTicketIssuer.getBalance(myTicketPayment_Alice)

t.equals(paymentAmount_Alice.extent.length, 1);
t.equals(paymentAmount_Alice.extent[0].seat, 1)
t.equals(paymentAmount_Alice.extent[0].show, 'The Sofa')
t.equals(paymentAmount_Alice.extent[0].start, startDateString)


// BOB SIDE
// Bob bought ticket 3 and 4 and has access to the balletTicketIssuer, because it's public
const myTicketPayment_Bob = balletTicketIssuer.claim(paymentForBob)
const paymentAmount_Bob = balletTicketIssuer.getBalance(myTicketPayment_Bob)

t.equals(paymentAmount_Bob.extent.length, 2);
t.equals(paymentAmount_Bob.extent[0].seat, 3);
t.equals(paymentAmount_Bob.extent[1].seat, 4);
t.equals(paymentAmount_Bob.extent[0].show, 'The Sofa')
t.equals(paymentAmount_Bob.extent[1].show, 'The Sofa')
t.equals(paymentAmount_Bob.extent[0].start, startDateString)
t.equals(paymentAmount_Bob.extent[1].start, startDateString)


} catch (e) {
t.assert(false, e);
} finally {
t.end();
}
});