Skip to content

Commit

Permalink
chore: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed May 18, 2020
1 parent 401e86a commit a376876
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 25 deletions.
26 changes: 26 additions & 0 deletions packages/swingset-runner/demo/resolveCircular/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import harden from '@agoric/harden';

console.log(`=> loading bootstrap.js`);

function build(E, log) {
return {
bootstrap(argv, vats) {
const pa = E(vats.bob).genPromise1();
const pb = E(vats.bob).genPromise2();
const pc = E(vats.bob).usePromises([pa], [pb]);
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}
41 changes: 41 additions & 0 deletions packages/swingset-runner/demo/resolveCircular/vat-bob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import harden from '@agoric/harden';

function makePR() {
let r;
const p = new Promise((resolve, _reject) => {
r = resolve;
});
return [p, r];
}

function build(E, log) {
let p1, r1;
let p2, r2;
return {
genPromise1() {
[p1, r1] = makePR();
return p1;
},
genPromise2() {
[p2, r2] = makePR();
return p2;
},
usePromises(pa, pb) {
r1(pb);
r2(pa);
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}
47 changes: 25 additions & 22 deletions packages/swingset-runner/demo/resolvePassResultPromise/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import harden from '@agoric/harden';

console.log(`=> loading bootstrap.js`);

function build(E, log) {
return {
bootstrap(argv, vats) {
console.log('=> Alice: bootstrap() called');

log('Alice: sending first to Bob');
const p1 = E(vats.bob).first();
log('Alice: sending second to Bob');
const p2 = E(vats.bob).second(p1);
log(`Alice: awaiting Bob's responses`);
p1.then(
r => log(`=> Alice: Bob's response to first resolved to '${r}'`),
e => log(`=> Alice: Bobs' response to first rejected as '${e}'`),
);
p2.then(
r => log(`=> Alice: Bob's response to second resolved to '${r}'`),
e => log(`=> Alice: Bobs' response to second rejected as '${e}'`),
);
log('=> Alice: bootstrap() done');
return 'Alice started';
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
Expand All @@ -11,28 +35,7 @@ export default function setup(syscall, state, helpers) {
return helpers.makeLiveSlots(
syscall,
state,
E =>
harden({
bootstrap(argv, vats) {
console.log('=> Alice: bootstrap() called');

log('Alice: sending first to Bob');
const p1 = E(vats.bob).first();
log('Alice: sending second to Bob');
const p2 = E(vats.bob).second(p1);
log(`Alice: awaiting Bob's responses`);
p1.then(
r => log(`=> Alice: Bob's response to first resolved to '${r}'`),
e => log(`=> Alice: Bobs' response to first rejected as '${e}'`),
);
p2.then(
r => log(`=> Alice: Bob's response to second resolved to '${r}'`),
e => log(`=> Alice: Bobs' response to second rejected as '${e}'`),
);
log('=> Alice: bootstrap() done');
return 'Alice started';
},
}),
E => harden(build(E, log)),
helpers.vatID,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import harden from '@agoric/harden';

function build(_E, log) {
let resolver;
return harden({
return {
first() {
log('=> Bob: in first');
const answer = new Promise((theResolver, _theRejector) => {
Expand All @@ -20,7 +20,7 @@ function build(_E, log) {
log('=> Bob: second done');
return `Bob's second answer`;
},
});
};
}

export default function setup(syscall, state, helpers) {
Expand All @@ -31,7 +31,7 @@ export default function setup(syscall, state, helpers) {
return helpers.makeLiveSlots(
syscall,
state,
E => build(E, log),
E => harden(build(E, log)),
helpers.vatID,
);
}
25 changes: 25 additions & 0 deletions packages/swingset-runner/demo/resolveSimpleCicular/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import harden from '@agoric/harden';

console.log(`=> loading bootstrap.js`);

function build(E, log) {
return {
bootstrap(argv, vats) {
const pa = E(vats.bob).genPromise();
const pb = E(vats.bob).usePromise([pa]);
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}
35 changes: 35 additions & 0 deletions packages/swingset-runner/demo/resolveSimpleCicular/vat-bob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import harden from '@agoric/harden';

function makePR() {
let r;
const p = new Promise((resolve, _reject) => {
r = resolve;
});
return [p, r];
}

function build(E, log) {
let p, r;
return {
genPromise() {
[p, r] = makePR();
return p;
},
usePromise(pa) {
r(pa);
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import harden from '@agoric/harden';

console.log(`=> loading bootstrap.js`);

function build(E, log) {
return {
bootstrap(argv, vats) {
console.log('=> Alice: bootstrap() called');

const p1 = E(vats.bob).first();
const p2 = E(vats.bob).second(p1);
const p3 = E(vats.bob).third();
p1.then(
r => {
log(`=> Alice: Bob.first resolved to '${r}' (should be a promise in an array)`);
r[0].then(
rr => log(`=> Alice: Bob.first result resolved to '${rr}'`),
ee => log(`=> Alice: Bob.first result rejected as '${ee}'`),
);
},
e => log(`=> Alice: Bob.first rejected as '${e}'`),
);
p2.then(
r => log(`=> Alice: Bob.second resolved to '${r}'`),
e => log(`=> Alice: Bob.second rejected as '${e}'`),
);
p3.then(
r => log(`=> Alice: Bob.third resolved to '${r}'`),
e => log(`=> Alice: Bob.third rejected as '${e}'`),
);
log('=> Alice: bootstrap() done');
return 'Alice started';
},
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
log(`=> setup called`);
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import harden from '@agoric/harden';

function makePR() {
let r;
const p = new Promise((resolve, _reject) => {
r = resolve;
});
return [p, r];
}

function build(_E, log) {
let r1;
let r2;
return {
first() {
log('=> Bob: first begins');
let p1;
[p1, r1] = makePR();
return p1;
},
second(p) {
log('=> Bob: second begins');
let p2;
[p2, r2] = makePR();
r1([p2]);
p.then(
r => log(`=> Bob: second(p) resolved to '${r}'`),
e => log(`=> Bob: second(p) rejected as '${e}'`),
);
log('=> Bob: second done');
return p2;
},
third(p) {
log('=> Bob: third begins');
r2(`Bob's resolution to p2`);
return `Bob's answer to third`;
}
};
}

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
}
return helpers.makeLiveSlots(
syscall,
state,
E => harden(build(E, log)),
helpers.vatID,
);
}

0 comments on commit a376876

Please sign in to comment.