Skip to content

Commit f5d8a0a

Browse files
committed
chore: add Swingset tests of basic functionality to ERTP. Mostly covered in unit tests and in Zoe, but not all.
1 parent 6f6498d commit f5d8a0a

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { E } from '@agoric/eventual-send';
2+
import { assert, details as X } from '@agoric/assert';
3+
import { makeIssuerKit } from '../../../src';
4+
5+
export function buildRootObject(vatPowers, vatParameters) {
6+
const arg0 = vatParameters.argv[0];
7+
8+
function testBasicFunctionality(aliceMaker) {
9+
vatPowers.testLog('start test basic functionality');
10+
const { mint: moolaMint, issuer, amountMath } = makeIssuerKit('moola');
11+
const moolaPayment = moolaMint.mintPayment(amountMath.make(1000));
12+
13+
const aliceP = E(aliceMaker).make(issuer, amountMath, moolaPayment);
14+
return E(aliceP).testBasicFunctionality();
15+
}
16+
17+
const obj0 = {
18+
async bootstrap(vats) {
19+
switch (arg0) {
20+
case 'basicFunctionality': {
21+
const aliceMaker = await E(vats.alice).makeAliceMaker();
22+
return testBasicFunctionality(aliceMaker);
23+
}
24+
default: {
25+
assert.fail(X`unrecognized argument value ${arg0}`);
26+
}
27+
}
28+
},
29+
};
30+
return harden(obj0);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import test from 'ava';
2+
import { loadBasedir, buildVatController } from '@agoric/swingset-vat';
3+
import path from 'path';
4+
5+
async function main(basedir, argv) {
6+
const dir = path.resolve(`${__dirname}/..`, basedir);
7+
const config = await loadBasedir(dir);
8+
const controller = await buildVatController(config, argv);
9+
await controller.run();
10+
return controller.dump();
11+
}
12+
13+
const expected = [
14+
'start test basic functionality',
15+
'isLive: true',
16+
'getAmountOf: {"brand":{},"value":1000}',
17+
'newPayment amount: {"brand":{},"value":1000}',
18+
'burned amount: {"brand":{},"value":200}',
19+
'claimedPayment amount: {"brand":{},"value":200}',
20+
'combinedPayment amount: {"brand":{},"value":600}',
21+
];
22+
23+
test('test splitPayments', async t => {
24+
const dump = await main('basicFunctionality', ['basicFunctionality']);
25+
t.deepEqual(dump.log, expected);
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { E } from '@agoric/eventual-send';
2+
3+
function makeAliceMaker(log) {
4+
return harden({
5+
make(issuer, amountMath, oldPaymentP) {
6+
const alice = harden({
7+
async testBasicFunctionality() {
8+
// isLive
9+
const alive = await E(issuer).isLive(oldPaymentP);
10+
log('isLive: ', alive);
11+
12+
// getAmountOf
13+
const amount = await E(issuer).getAmountOf(oldPaymentP);
14+
log('getAmountOf: ', amount);
15+
16+
// Make Purse
17+
18+
const purse = E(issuer).makeEmptyPurse();
19+
20+
// Deposit Payment
21+
22+
const payment = await oldPaymentP;
23+
await E(purse).deposit(payment);
24+
25+
// Withdraw Payment
26+
const newPayment = E(purse).withdraw(amount);
27+
const newAmount = await E(issuer).getAmountOf(newPayment);
28+
log('newPayment amount: ', newAmount);
29+
30+
// splitMany
31+
const moola200 = await E(amountMath).make(200);
32+
const [paymentToBurn, paymentToClaim, ...payments] = await E(
33+
issuer,
34+
).splitMany(
35+
newPayment,
36+
harden([moola200, moola200, moola200, moola200, moola200]),
37+
);
38+
39+
// burn
40+
const burnedAmount = await E(issuer).burn(paymentToBurn);
41+
log('burned amount: ', burnedAmount);
42+
43+
// claim
44+
const claimedPayment = await E(issuer).claim(paymentToClaim);
45+
const claimedPaymentAmount = await E(issuer).getAmountOf(
46+
claimedPayment,
47+
);
48+
log('claimedPayment amount: ', claimedPaymentAmount);
49+
50+
// combine
51+
const combinedPayment = E(issuer).combine(payments);
52+
const combinedPaymentAmount = await E(issuer).getAmountOf(
53+
combinedPayment,
54+
);
55+
log('combinedPayment amount: ', combinedPaymentAmount);
56+
},
57+
});
58+
return alice;
59+
},
60+
});
61+
}
62+
63+
export function buildRootObject(vatPowers) {
64+
return harden({
65+
makeAliceMaker() {
66+
return harden(makeAliceMaker(vatPowers.testLog));
67+
},
68+
});
69+
}

0 commit comments

Comments
 (0)