Skip to content

Commit

Permalink
refactor: bootstrap and context hold publicFacet vs instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert authored and turadg committed Sep 20, 2023
1 parent 3183025 commit 3d25c53
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 92 deletions.
10 changes: 5 additions & 5 deletions agoric/contract/test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ export const bootstrapContext = async (conf) => {
character: 'KREAdCHARACTER',
item: 'KREAdITEM',
}),
}
};

// Start contract instance
const instance = await E(zoe).startInstance(
const { creatorFacet, instance, publicFacet } = await E(zoe).startInstance(
installation,
{ Money: issuerMockIST },
harden(kreadTerms),
harden(privateArgs),
);
const { creatorFacet } = instance;
const terms = await E(zoe).getTerms(instance.instance);
const terms = await E(zoe).getTerms(instance);
await E(creatorFacet).initializeBaseAssets(defaultCharacters, defaultItems);

const {
Expand All @@ -105,7 +104,8 @@ export const bootstrapContext = async (conf) => {
const result = {
contractAssets,
assets,
instance,
creatorFacet,
publicFacet,
purses,
zoe,
paymentAsset: {
Expand Down
14 changes: 2 additions & 12 deletions agoric/contract/test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ harden(setupZoe);
*/
export const addCharacterToBootstrap = async (bootstrap) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
paymentAsset,
purses,
zoe,
} = bootstrap;
const { publicFacet, paymentAsset, purses, zoe } = bootstrap;

const { offerArgs, give } = flow.mintCharacter.expected;

Expand Down Expand Up @@ -67,12 +62,7 @@ harden(addCharacterToBootstrap);
*/
export const addItemToBootstrap = async (bootstrap, item) => {
/** @type {Bootstrap} */
const {
instance: { creatorFacet },
contractAssets,
purses,
zoe,
} = bootstrap;
const { creatorFacet, contractAssets, purses, zoe } = bootstrap;

const mintItemInvitation = await E(creatorFacet).makeMintItemInvitation();
const itemAmount = AmountMath.make(
Expand Down
22 changes: 11 additions & 11 deletions agoric/contract/test/test-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test.before(async (t) => {
const unequipOffer = async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -82,7 +82,7 @@ const unequipOffer = async (t) => {
test.serial('| INVENTORY - Unequip Item', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
purses,
} = t.context;
const {
Expand Down Expand Up @@ -115,7 +115,7 @@ test.serial('| INVENTORY - Unequip Item', async (t) => {
test.serial('| INVENTORY - Unequip already unequipped item', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -182,7 +182,7 @@ test.serial('| INVENTORY - Unequip already unequipped item', async (t) => {
test.serial('| INVENTORY - Unequip - wrong character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -265,7 +265,7 @@ test.serial('| INVENTORY - Unequip - wrong character', async (t) => {
test.serial('| INVENTORY - Equip Item', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -360,7 +360,7 @@ test.serial('| INVENTORY - Equip Item', async (t) => {
test.serial('| INVENTORY - Equip Item duplicate category', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -466,7 +466,7 @@ test.serial('| INVENTORY - Equip Item duplicate category', async (t) => {
test.serial('| INVENTORY - Swap Items', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -569,7 +569,7 @@ test.serial('| INVENTORY - Swap Items', async (t) => {
test.serial('| INVENTORY - Swap Items - Initially empty', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -663,7 +663,7 @@ test.serial('| INVENTORY - Swap Items - Initially empty', async (t) => {
test.serial('| INVENTORY - Swap Items - Different categories', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -773,7 +773,7 @@ test.serial('| INVENTORY - Swap Items - Different categories', async (t) => {

test.serial('| INVENTORY - Unequip all', async (t) => {
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down Expand Up @@ -847,7 +847,7 @@ test.serial('| INVENTORY - Unequip all', async (t) => {

test.serial('| INVENTORY - UnequipAll empty inventory', async (t) => {
const {
instance: { publicFacet },
publicFacet,
contractAssets,
purses,
zoe,
Expand Down
18 changes: 9 additions & 9 deletions agoric/contract/test/test-market-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { makeKreadUser } from './make-user.js';
async function sellCharacter(context, user, characterName, askingPrice) {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
paymentAsset,
Expand Down Expand Up @@ -48,7 +48,7 @@ async function sellCharacter(context, user, characterName, askingPrice) {
async function buyCharacter(context, user, characterName, seller) {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
} = context;
Expand Down Expand Up @@ -93,7 +93,7 @@ async function buyCharacter(context, user, characterName, seller) {

test.before(async (t) => {
const bootstrap = await bootstrapContext();
const { zoe, contractAssets, assets, purses, instance, paymentAsset } =
const { zoe, contractAssets, assets, purses, publicFacet, paymentAsset } =
bootstrap;

const bob = makeKreadUser('bob', purses);
Expand All @@ -104,7 +104,7 @@ test.before(async (t) => {
bob.depositPayment(payout);

t.context = {
instance,
publicFacet,
contractAssets,
assets,
purses,
Expand All @@ -117,7 +117,7 @@ test.before(async (t) => {
test.serial('---| METRICS - Initialization', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
} = t.context;

const metrics = await E(publicFacet).getMarketMetrics();
Expand All @@ -132,7 +132,7 @@ test.serial('---| METRICS - Initialization', async (t) => {
test.serial('---| METRICS - Collection size', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
paymentAsset,
zoe,
users: { bob },
Expand Down Expand Up @@ -172,7 +172,7 @@ test.serial('---| METRICS - Collection size', async (t) => {
test.serial('---| METRICS - Average levels character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
users: { bob },
} = t.context;

Expand Down Expand Up @@ -202,7 +202,7 @@ test.serial('---| METRICS - Average levels character', async (t) => {
test.serial('---| METRICS - Amount sold character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
users: { bob },
} = t.context;

Expand Down Expand Up @@ -231,7 +231,7 @@ test.serial('---| METRICS - Amount sold character', async (t) => {
test.serial('---| METRICS - Latest sale price character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
users: { bob },
} = t.context;

Expand Down
26 changes: 13 additions & 13 deletions agoric/contract/test/test-market.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test.before(async (t) => {
contractAssets,
assets,
purses,
instance,
publicFacet,
paymentAsset,
royaltyPurse,
platformFeePurse,
Expand All @@ -57,7 +57,7 @@ test.before(async (t) => {
character: contractAssets.character.issuer.makeEmptyPurse(),
item: contractAssets.item.issuer.makeEmptyPurse(),
payment: paymentAsset.issuerMockIST.makeEmptyPurse(),
});
j });

const payout = paymentAsset.mintMockIST.mintPayment(
AmountMath.make(paymentAsset.brandMockIST, harden(100n)),
Expand All @@ -70,7 +70,7 @@ test.before(async (t) => {
// bob.depositPayment(payoutBob);

t.context = {
instance,
publicFacet,
contractAssets,
assets,
purses,
Expand All @@ -87,7 +87,7 @@ test.before(async (t) => {
test.serial('---| MARKET - Sell character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob },
Expand Down Expand Up @@ -150,7 +150,7 @@ test.serial(
async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down Expand Up @@ -212,7 +212,7 @@ test.serial(
test.serial('---| MARKET - Buy character', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down Expand Up @@ -304,7 +304,7 @@ test.serial('---| MARKET - Buy character', async (t) => {
test.serial('---| MARKET - Buy character not on market', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { alice },
Expand Down Expand Up @@ -358,7 +358,7 @@ test.serial('---| MARKET - Buy character not on market', async (t) => {
test.serial('---| MARKET - Sell Item', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob },
Expand Down Expand Up @@ -400,7 +400,7 @@ test.serial(
async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down Expand Up @@ -456,7 +456,7 @@ test.serial(
test.serial('---| MARKET - Buy item', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down Expand Up @@ -509,7 +509,7 @@ test.serial('---| MARKET - Buy item', async (t) => {
test.serial('---| MARKET - Buy item not on market', async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { alice },
Expand Down Expand Up @@ -555,7 +555,7 @@ test.serial(
async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down Expand Up @@ -673,7 +673,7 @@ test.serial(
async (t) => {
/** @type {Bootstrap} */
const {
instance: { publicFacet },
publicFacet,
contractAssets,
zoe,
users: { bob, alice },
Expand Down
Loading

0 comments on commit 3d25c53

Please sign in to comment.