-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ERTP payments as virtual objects
- Loading branch information
1 parent
48d4813
commit e6a0924
Showing
82 changed files
with
425 additions
and
77 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,2 @@ | ||
declare var makeKind: function; | ||
declare var makeWeakStore: function; |
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 |
---|---|---|
|
@@ -73,8 +73,7 @@ | |
"test/**/test-*.js" | ||
], | ||
"require": [ | ||
"esm", | ||
"@agoric/install-ses" | ||
"esm" | ||
] | ||
}, | ||
"eslintConfig": { | ||
|
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,22 @@ | ||
// @ts-check | ||
/* global makeKind */ | ||
|
||
import { Far } from '@agoric/marshal'; | ||
import { makeFarName, ERTPKind } from './interfaces'; | ||
|
||
export const makePaymentMaker = (allegedName, brand) => { | ||
const paymentVOFactory = state => { | ||
return { | ||
init: b => (state.brand = b), | ||
self: Far(makeFarName(allegedName, ERTPKind.PAYMENT), { | ||
getAllegedBrand: () => state.brand, | ||
}), | ||
}; | ||
}; | ||
|
||
const paymentMaker = makeKind(paymentVOFactory); | ||
|
||
const makePayment = () => paymentMaker(brand); | ||
|
||
return makePayment; | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/ERTP/test/swingsetTests/basicFunctionality/bootstrap.js
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,31 @@ | ||
import { E } from '@agoric/eventual-send'; | ||
import { assert, details as X } from '@agoric/assert'; | ||
import { makeIssuerKit } from '../../../src'; | ||
|
||
export function buildRootObject(vatPowers, vatParameters) { | ||
const arg0 = vatParameters.argv[0]; | ||
|
||
function testBasicFunctionality(aliceMaker) { | ||
vatPowers.testLog('start test basic functionality'); | ||
const { mint: moolaMint, issuer, amountMath } = makeIssuerKit('moola'); | ||
const moolaPayment = moolaMint.mintPayment(amountMath.make(1000)); | ||
|
||
const aliceP = E(aliceMaker).make(issuer, amountMath, moolaPayment); | ||
return E(aliceP).testBasicFunctionality(); | ||
} | ||
|
||
const obj0 = { | ||
async bootstrap(vats) { | ||
switch (arg0) { | ||
case 'basicFunctionality': { | ||
const aliceMaker = await E(vats.alice).makeAliceMaker(); | ||
return testBasicFunctionality(aliceMaker); | ||
} | ||
default: { | ||
assert.fail(X`unrecognized argument value ${arg0}`); | ||
} | ||
} | ||
}, | ||
}; | ||
return harden(obj0); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/ERTP/test/swingsetTests/basicFunctionality/test-basicFunctionality.js
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,34 @@ | ||
// @ts-check | ||
/* global __dirname */ | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import '@agoric/swingset-vat/tools/prepare-test-env'; | ||
|
||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import test from 'ava'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { loadBasedir, buildVatController } from '@agoric/swingset-vat'; | ||
import path from 'path'; | ||
|
||
async function main(basedir, argv) { | ||
const dir = path.resolve(`${__dirname}/..`, basedir); | ||
const config = await loadBasedir(dir); | ||
const controller = await buildVatController(config, argv); | ||
await controller.run(); | ||
return controller.dump(); | ||
} | ||
|
||
const expected = [ | ||
'start test basic functionality', | ||
'isLive: true', | ||
'getAmountOf: {"brand":{},"value":1000}', | ||
'newPayment amount: {"brand":{},"value":1000}', | ||
'burned amount: {"brand":{},"value":200}', | ||
'claimedPayment amount: {"brand":{},"value":200}', | ||
'combinedPayment amount: {"brand":{},"value":600}', | ||
]; | ||
|
||
test('test splitPayments', async t => { | ||
const dump = await main('basicFunctionality', ['basicFunctionality']); | ||
t.deepEqual(dump.log, expected); | ||
}); |
69 changes: 69 additions & 0 deletions
69
packages/ERTP/test/swingsetTests/basicFunctionality/vat-alice.js
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,69 @@ | ||
import { E } from '@agoric/eventual-send'; | ||
|
||
function makeAliceMaker(log) { | ||
return harden({ | ||
make(issuer, amountMath, oldPaymentP) { | ||
const alice = harden({ | ||
async testBasicFunctionality() { | ||
// isLive | ||
const alive = await E(issuer).isLive(oldPaymentP); | ||
log('isLive: ', alive); | ||
|
||
// getAmountOf | ||
const amount = await E(issuer).getAmountOf(oldPaymentP); | ||
log('getAmountOf: ', amount); | ||
|
||
// Make Purse | ||
|
||
const purse = E(issuer).makeEmptyPurse(); | ||
|
||
// Deposit Payment | ||
|
||
const payment = await oldPaymentP; | ||
await E(purse).deposit(payment); | ||
|
||
// Withdraw Payment | ||
const newPayment = E(purse).withdraw(amount); | ||
const newAmount = await E(issuer).getAmountOf(newPayment); | ||
log('newPayment amount: ', newAmount); | ||
|
||
// splitMany | ||
const moola200 = await E(amountMath).make(200); | ||
const [paymentToBurn, paymentToClaim, ...payments] = await E( | ||
issuer, | ||
).splitMany( | ||
newPayment, | ||
harden([moola200, moola200, moola200, moola200, moola200]), | ||
); | ||
|
||
// burn | ||
const burnedAmount = await E(issuer).burn(paymentToBurn); | ||
log('burned amount: ', burnedAmount); | ||
|
||
// claim | ||
const claimedPayment = await E(issuer).claim(paymentToClaim); | ||
const claimedPaymentAmount = await E(issuer).getAmountOf( | ||
claimedPayment, | ||
); | ||
log('claimedPayment amount: ', claimedPaymentAmount); | ||
|
||
// combine | ||
const combinedPayment = E(issuer).combine(payments); | ||
const combinedPaymentAmount = await E(issuer).getAmountOf( | ||
combinedPayment, | ||
); | ||
log('combinedPayment amount: ', combinedPaymentAmount); | ||
}, | ||
}); | ||
return alice; | ||
}, | ||
}); | ||
} | ||
|
||
export function buildRootObject(vatPowers) { | ||
return harden({ | ||
makeAliceMaker() { | ||
return harden(makeAliceMaker(vatPowers.testLog)); | ||
}, | ||
}); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/ERTP/test/swingsetTests/splitPayments/test-splitPayments.js
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
3 changes: 3 additions & 0 deletions
3
packages/ERTP/test/unitTests/mathHelpers/test-natMathHelpers.js
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
3 changes: 3 additions & 0 deletions
3
packages/ERTP/test/unitTests/mathHelpers/test-setMathHelpers.js
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
3 changes: 3 additions & 0 deletions
3
packages/ERTP/test/unitTests/mathHelpers/test-strSetMathHelpers.js
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
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
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,2 @@ | ||
declare var makeKind: function; | ||
declare var makeWeakStore: function; |
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
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
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,2 @@ | ||
declare var makeKind: function; | ||
declare var makeWeakStore: function; |
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
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
Oops, something went wrong.