Skip to content

Commit

Permalink
lint: inline snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
mujahidkay committed Sep 30, 2024
1 parent e8cb88e commit fcb738e
Show file tree
Hide file tree
Showing 55 changed files with 852 additions and 842 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = {
themeConfig: {
sidebar: 'auto'
}
}
};
```

Or, add a config entry, either as part of a group or as an individual page.
Expand All @@ -133,7 +133,7 @@ module.exports = {
}
]
}
}
};
```

## Writing Links
Expand Down Expand Up @@ -564,8 +564,8 @@ export default ({ router }) => {
path: '/getting-started/agoric-cli-guide.html',
redirect: '/guides/agoric-cli/'
}
])
}
]);
};
```

The general format should be self-explanatory. However, there are two things you need to know that aren't apparent
Expand Down
30 changes: 15 additions & 15 deletions main/e2e-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ Before you start writing your E2E tests, you'll need to create a configuration f
Inside `synpress.config.js`, you'll set the `baseUrl` property within the e2e configuration. This tells Cypress where to find your DApp during testing. Here's an example configuration:

```js
const baseConfig = require('@agoric/synpress/synpress.config')
const { defineConfig } = require('cypress')
const baseConfig = require('@agoric/synpress/synpress.config');
const { defineConfig } = require('cypress');

module.exports = defineConfig({
...baseConfig,
e2e: {
...baseConfig.e2e,
baseUrl: 'http://localhost:5173'
}
})
});
```

In this example, `baseUrl` is set to `http://localhost:5173`. Make sure to replace this with the actual URL where your DApp is running.
Expand All @@ -69,7 +69,7 @@ Navigate to your project's `tests/e2e` directory and create a new file named `su
After creating your `support.js` file, make sure to include the following import statement:

```js
import '@agoric/synpress/support/index'
import '@agoric/synpress/support/index';
```

This import is essential because it brings in the necessary functionalities from `@agoric/synpress` to interact with the Keplr wallet within your e2e tests. Without it, your tests won't be able to leverage the features provided by `@agoric/synpress` for Keplr integration.
Expand All @@ -86,8 +86,8 @@ You use `describe` blocks to group related tests together, and `it` blocks to de
describe('User Login', () => {
it('should login with valid credentials', () => {
// Test steps for login functionality
})
})
});
});
```

### Test 1: Setting Up Keplr Wallet
Expand All @@ -96,9 +96,9 @@ describe('User Login', () => {
it('should setup a Keplr wallet', () => {
cy.setupWallet({
secretWords: 'KEPLR_MNEMONIC'
})
cy.visit('/')
})
});
cy.visit('/');
});
```

This test case simulates setting up a Keplr wallet for your tests, using the `cy.setupWallet` method. Make sure to replace `KEPLR_MNEMONIC` with a 24-word mnemonic phrase. The `setupWallet` method creates a wallet based on the provided mnemonic phrase, which can then be used throughout your test suite.
Expand All @@ -109,9 +109,9 @@ After setting up the wallet, we visit the root path (`/`) of the DApp using `cy.

```js
it('should accept connection with wallet', () => {
cy.contains('Connect Wallet').click()
cy.acceptAccess()
})
cy.contains('Connect Wallet').click();
cy.acceptAccess();
});
```

This test simulates a user connecting their Keplr wallet to your DApp. `cy.contains('Connect Wallet')` searches for an element containing the text `Connect Wallet` on the webpage and triggers a click event. `cy.acceptAccess` simulates accepting Keplr wallet access for your DApp.
Expand All @@ -120,9 +120,9 @@ This test simulates a user connecting their Keplr wallet to your DApp. `cy.conta

```js
it('should confirm make an offer transaction', () => {
cy.contains('Make an Offer').click()
cy.confirmTransaction()
})
cy.contains('Make an Offer').click();
cy.confirmTransaction();
});
```

This test simulates transaction Signing on your DApp. `cy.contains('Make an Offer')` searches for an element containing the text `Make an Offer` and triggers a click event. `cy.confirmTransaction` simulates confirming a transaction.
Expand Down
12 changes: 6 additions & 6 deletions main/glossary/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ and the [ERTP API's Brand section](/reference/ertp-api/brand).
Before a contract can be installed on Zoe, its source code must be bundled. This is done by:

```js
import bundleSource from '@endo/bundle-source'
import bundleSource from '@endo/bundle-source';
const atomicSwapBundle = await bundleSource(
require.resolve('@agoric/zoe/src/contracts/atomicSwap')
)
);
```

The installation operation returns an `installation`, which is an object with a single
Expand All @@ -153,7 +153,7 @@ In most cases, the bundle contains a base64-encoded zip file that you can
extract for review.

```js
const { endoZipBase64 } = await E(installation).getBundle()
const { endoZipBase64 } = await E(installation).getBundle();
```

```sh
Expand Down Expand Up @@ -296,10 +296,10 @@ A _facet_ is an object that exposes an API or particular view of some larger ent
You can make any number of facets of an entity. In JavaScript, you often make a facet that forwards method calls:

```js
import { Far } from '@endo/far'
import { Far } from '@endo/far';
const facet = Far('FacetName', {
myMethod: (...args) => oldObject.method(...args)
})
});
```

Two Agoric uses are:
Expand Down Expand Up @@ -550,7 +550,7 @@ const myProposal = harden({
give: { Asset: AmountMath.make(quatloosBrand, 4n) },
want: { Price: AmountMath.make(moolaBrand, 15n) },
exit: { onDemand: null }
})
});
```

`give` and `want` each associate [Keywords](#keyword) defined by the contract with corresponding [Amounts](#amount) describing respectively what will be given and what is being requested in exchange.
Expand Down
4 changes: 2 additions & 2 deletions main/guides/coreeval/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const permit = harden({
instance: { produce: { [contractName]: true } },
issuer: { consume: { IST: true }, produce: { Ticket: true } },
brand: { consume: { IST: true }, produce: { Ticket: true } }
})
});

export const main = startSellConcertTicketsContract
export const main = startSellConcertTicketsContract;
```

## Selected BootstrapPowers
Expand Down
46 changes: 23 additions & 23 deletions main/guides/coreeval/proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ After some preliminaries, ...

```js
// @ts-check
import { allValues } from './objectTools.js'
import { allValues } from './objectTools.js';
import {
AmountMath,
installContract,
startContract
} from './platform-goals/start-contract.js'
} from './platform-goals/start-contract.js';

const { Fail } = assert
const IST_UNIT = 1_000_000n
const { Fail } = assert;
const IST_UNIT = 1_000_000n;

export const makeInventory = (brand, baseUnit) => {
return {
Expand All @@ -43,14 +43,14 @@ export const makeInventory = (brand, baseUnit) => {
tradePrice: AmountMath.make(brand, baseUnit * 1n),
maxTickets: 3n
}
}
}
};
};

export const makeTerms = (brand, baseUnit) => {
return {
inventory: makeInventory(brand, baseUnit)
}
}
};
};

/**
* @typedef {{
Expand All @@ -66,7 +66,7 @@ export const makeTerms = (brand, baseUnit) => {
... the function for deploying the contract is `startSellConcertTicketsContract`:

```js
const contractName = 'sellConcertTickets'
const contractName = 'sellConcertTickets';

/**
* Core eval script to start contract
Expand All @@ -75,23 +75,23 @@ const contractName = 'sellConcertTickets'
* @param {*} config
*/
export const startSellConcertTicketsContract = async (powers, config) => {
console.log('core eval for', contractName)
console.log('core eval for', contractName);
const {
// must be supplied by caller or template-replaced
bundleID = Fail`no bundleID`
} = config?.options?.[contractName] ?? {}
} = config?.options?.[contractName] ?? {};

const installation = await installContract(powers, {
name: contractName,
bundleID
})
});

const ist = await allValues({
brand: powers.brand.consume.IST,
issuer: powers.issuer.consume.IST
})
});

const terms = makeTerms(ist.brand, 1n * IST_UNIT)
const terms = makeTerms(ist.brand, 1n * IST_UNIT);

await startContract(powers, {
name: contractName,
Expand All @@ -101,10 +101,10 @@ export const startSellConcertTicketsContract = async (powers, config) => {
terms
},
issuerNames: ['Ticket']
})
});

console.log(contractName, '(re)started')
}
console.log(contractName, '(re)started');
};
```
A `BootstrapPowers` object is composed of several _promise spaces_.
Expand Down Expand Up @@ -137,12 +137,12 @@ export const installContract = async (
{ consume: { zoe }, installation: { produce: produceInstallation } },
{ name, bundleID }
) => {
const installation = await E(zoe).installBundleID(bundleID)
produceInstallation[name].reset()
produceInstallation[name].resolve(installation)
console.log(name, 'installed as', bundleID.slice(0, 8))
return installation
}
const installation = await E(zoe).installBundleID(bundleID);
produceInstallation[name].reset();
produceInstallation[name].resolve(installation);
console.log(name, 'installed as', bundleID.slice(0, 8));
return installation;
};
```
This `installation` promise space is linked to the `E(agoricNames).lookup('installation')` NameHub: when you call `produce[name].resolve(value)` on the installation promise space, it triggers an update in the NameHub. The update associates the provided name with the provided value so that `E(agoricNames).lookup('installation', name)` is a promise for `value`.
Expand Down
2 changes: 1 addition & 1 deletion main/guides/getting-started/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ file `ui/public/conf/installationConstants.js` with contents like:
export default {
CONTRACT_NAME: 'fungibleFaucet',
INSTALLATION_BOARD_ID: '1456154132'
}
};
```

The board provides a unique ID per object, in this case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const inventory = {
tradePrice: AmountMath.make(istBrand, n),
maxTickets: n
}
}
};
```

Our contract takes the provided `inventory` object as a parameter to initiate the process.
Expand All @@ -49,8 +49,8 @@ In our example, tickets are non-fungible and can have duplicates, meaning there
</details>

```js
const ticketMint = await zcf.makeZCFMint('Ticket', AssetKind.COPY_BAG)
const { brand: ticketBrand } = ticketMint.getIssuerRecord()
const ticketMint = await zcf.makeZCFMint('Ticket', AssetKind.COPY_BAG);
const { brand: ticketBrand } = ticketMint.getIssuerRecord();
```

Once our asset is defined, we will mint our inventory at the start of our the smart contract and allocate it to our `inventorySeat` object.
Expand All @@ -69,14 +69,14 @@ const inventoryBag = makeCopyBag(
ticket,
maxTickets
])
)
);
const toMint = {
Tickets: {
brand: ticketBrand,
value: inventoryBag
}
}
const inventorySeat = ticketMint.mintGains(toMint)
};
const inventorySeat = ticketMint.mintGains(toMint);
```

## Trading Tickets
Expand All @@ -85,7 +85,7 @@ Customers who wish to purchase event tickets first [make an invitation](https://

```js
const makeTradeInvitation = () =>
zcf.makeInvitation(tradeHandler, 'buy tickets', undefined, proposalShape)
zcf.makeInvitation(tradeHandler, 'buy tickets', undefined, proposalShape);
```

Here you can see two important parameters:
Expand All @@ -94,9 +94,9 @@ Here you can see two important parameters:

```js
const tradeHandler = buyerSeat => {
const { give, want } = buyerSeat.getProposal()
const { give, want } = buyerSeat.getProposal();
// ... checks and transfers
}
};
```

- **proposalShape** (Optional): This object outlines the necessary and permissible elements of each [proposal](https://docs.agoric.com/reference/zoe-api/zoe-contract-facet.html#proposal-shapes). Here is the proposal shape for this contract.
Expand All @@ -106,7 +106,7 @@ const proposalShape = harden({
give: { Price: AmountShape },
want: { Tickets: { brand: ticketBrand, value: M.bag() } },
exit: M.any()
})
});
```

## Trade Handler
Expand All @@ -115,20 +115,20 @@ The `tradeHandler` function begins by checking to see if there are enough ticket

```js
AmountMath.isGTE(inventorySeat.getCurrentAllocation().Tickets, want.Tickets) ||
Fail`Not enough inventory, ${q(want.Tickets)} wanted`
Fail`Not enough inventory, ${q(want.Tickets)} wanted`;
```

Next, the total price is calcualted using `bagPrice`:

```js
const totalPrice = bagPrice(want.Tickets.value, inventory)
const totalPrice = bagPrice(want.Tickets.value, inventory);
```

After that, a check is made to ensure the offered price is sufficient:

```js
AmountMath.isGTE(give.Price, totalPrice) ||
Fail`Total price is ${q(totalPrice)}, but ${q(give.Price)} was given`
Fail`Total price is ${q(totalPrice)}, but ${q(give.Price)} was given`;
```

Finally, `atomicRearrange` can be called to exchange the requested tickets for the required payment:
Expand All @@ -142,7 +142,7 @@ atomicRearrange(
// tickets from inventory to buyer
[inventorySeat, buyerSeat, want]
])
)
);
```

Take a complete look at this example code in our [Github repository](https://github.com/Agoric/dapp-agoric-basics/blob/main/contract/src/sell-concert-tickets.contract.js).
Expand Down
Loading

0 comments on commit fcb738e

Please sign in to comment.