-
Notifications
You must be signed in to change notification settings - Fork 229
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
Payments are virtual objects. #2526
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)); | ||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can these two |
||
}, | ||
}); | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how well the
Far(makeFarName(...
stuff is going to get along with the virtual object machinery. The construct is certainly ugly and very hard to parse visually. I would have written this as just:But if this object is going to be used as a presence we need to get that
Far()
wrapper on there somehow.The return value from
paymentVOMaker
is going to get hardened. I don't know howharden
deals with objects with properties that are already hardened. I think that's OK, but this is one of those mysterious edge cases that I always have to either ask @erights about or just try and see what happens.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
harden
is idempotent. That part is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting the
Far...
to be in themakeKind
invocationLI don't like needing the
self:
section. There was a slightly different pattern that didn't require that, but I couldn't lay my hands on that issue yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @dtribble said,
harden()
is idempotent. HoweverFar
is not: it only accepts unhardened objects (it mutates them before hardening them).I have a branch in which
makeKind
asserts that the maker it was given is applyingFar
to theself
that it returns, under the theory that the maker should be doingharden
to the{ init, self }
pair that it returns ("don't let objects out of your sight without hardening them first"), andFar()
cannot be applied to objects that are already hardened, therefore the maker must apply theFar
before it hardens{ init, self }
.(the assertion on that branch isn't very helpful, however, because if you make the most common mistake and don't harden the return value, it emits a particularly weird error message instead of something that would guide you towards the light)
It would certainly be more ergonomic to tell
makeKind
the interface name, and then havemakeKind
apply theFar()
itself, but that would require that the maker not harden its return value, which feels counter to the habit we're trying to teach developers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that integration is the right thing. It should happen within the same module. The
init/self
is the squishy underbelly of constructing useful remote and persistent objects. They don't need to be hardened, given that they should never escape directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Retracted previous comment. I took "escape" out of context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good. To clarify for the future, I just meant that the internal description of what needs to be built --
paymentVOMaker
-- on line 9 gets used on line 18 and the result of that is what gets locked down by the process. ThepaymentVOMaker
should never escape.