From 76f37d0ca5e966de55a7645b5698e4af5c128643 Mon Sep 17 00:00:00 2001
From: amessbee <53943791+amessbee@users.noreply.github.com>
Date: Fri, 10 May 2024 11:46:11 +0500
Subject: [PATCH 01/22] docs: Updates to the description of dapp-agoric-basics
in ReadMe.md
---
README.md | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 777c5841..1960c98f 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,6 @@
# Agoric Dapp Starter: Agoric Basics
-This is a simple app for the [Agoric smart contract platform](https://docs.agoric.com/).
-
-
-
-The contract lets you make an offer to give a small amount of [IST](https://inter.trade/) in exchange for
-a few NFTs.
+This is a basic Agoric Dapp that contains three smart contracts `postal-service`, `sell-concert-tickets`, and `swaparoo` demonstrating different scenarios which can be implemented easily using Agoric SDK. There is also a UI for `sell-concert-tickets` contract that a user can use to buy three different types of concert tickets and pay through a wallet extension in the browser.
## Getting started
From 14050a5ae17083a3b4f719ea5756e40a5c914fe7 Mon Sep 17 00:00:00 2001
From: amessbee <53943791+amessbee@users.noreply.github.com>
Date: Fri, 10 May 2024 12:03:42 +0500
Subject: [PATCH 02/22] docs: added detailed instruction to start contracts and
UI.
---
README.md | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1960c98f..4c49efb8 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,23 @@ This is a basic Agoric Dapp that contains three smart contracts `postal-service`
## Getting started
-See [Your First Agoric Dapp](https://docs.agoric.com/guides/getting-started/) tutorial.
+Assuming all the required dependecies are already installed (including node, nvm, docker, Keplr - See [here](https://docs.agoric.com/guides/getting-started/) tutorial on how to install these dependecies.), here are the steps to run `dapp-agoric-basics`:
+- run `yarn install` in the `agoric-basics` directory, to install dependencies of the Dapp.
+- run `yarn start:docker` to start Agoric blockchain from the container.
+- run `yarn docker:logs` to to make sure blocks are being produced by viewing the Docker logs; once your logs ressemeble the following, stop the logs by pressing `ctrl+c`.
+```
+demo-agd-1 | 2023-12-27T04:08:06.384Z block-manager: block 1003 begin
+demo-agd-1 | 2023-12-27T04:08:06.386Z block-manager: block 1003 commit
+demo-agd-1 | 2023-12-27T04:08:07.396Z block-manager: block 1004 begin
+demo-agd-1 | 2023-12-27T04:08:07.398Z block-manager: block 1004 commit
+demo-agd-1 | 2023-12-27T04:08:08.405Z block-manager: block 1005 begin
+demo-agd-1 | 2023-12-27T04:08:08.407Z block-manager: block 1005 commit
+```
+- run `yarn start:contract` to start the contracts.
+- run `yarn start:ui` to start `sell-concert-tickets` contract UI.
+- open a browser and navigate to `localhost:5173` to interact with the contract via UI.
+
+To follow more detailed tutorial, go [here](https://docs.agoric.com/guides/getting-started/tutorial-dapp-agoric-basics.html).
## Contributing: Development, Testing
From 28355272940377fcd8e0d28268a78750dd8b0a84 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Fri, 10 May 2024 12:12:55 +0500
Subject: [PATCH 03/22] docs: added a separate subsection for Testing with
instructions
---
README.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/README.md b/README.md
index 4c49efb8..2af3c70a 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,13 @@ demo-agd-1 | 2023-12-27T04:08:08.407Z block-manager: block 1005 commit
To follow more detailed tutorial, go [here](https://docs.agoric.com/guides/getting-started/tutorial-dapp-agoric-basics.html).
+## Testing
+
+To perform unit tests:
+-run the command `yarn test` in the root directory.
+To perform end to end test
+-run the command `yarn test:e2e` in the root directory.
+
## Contributing: Development, Testing
The UI is a React app started with the [vite](https://vitejs.dev/) `react-ts` template.
From 81f1f40c605f731634e6e35dbf4ce2ede481314a Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Fri, 10 May 2024 12:16:25 +0500
Subject: [PATCH 04/22] docs: Cleaned Contributing subsection and removed
confusing links.
---
README.md | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
index 2af3c70a..958f24ed 100644
--- a/README.md
+++ b/README.md
@@ -29,12 +29,5 @@ To perform unit tests:
To perform end to end test
-run the command `yarn test:e2e` in the root directory.
-## Contributing: Development, Testing
-
-The UI is a React app started with the [vite](https://vitejs.dev/) `react-ts` template.
-On top of that, we add
-
-- Watching [blockchain state queries](https://docs.agoric.com/guides/getting-started/contract-rpc.html#querying-vstorage)
-- [Signing and sending offers](https://docs.agoric.com/guides/getting-started/contract-rpc.html#signing-and-broadcasting-offers)
-
-See [CONTRIBUTING](./CONTRIBUTING.md) for more on testing.
+## Contributing
+See [CONTRIBUTING](./CONTRIBUTING.md) for more on contributions.
From c882a79982bcf8efc72984a9a1a32990464afea4 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Mon, 13 May 2024 05:59:55 +0500
Subject: [PATCH 05/22] docs: Added text related to dependencies on node
version and vite
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 958f24ed..a3bcce06 100644
--- a/README.md
+++ b/README.md
@@ -4,10 +4,10 @@ This is a basic Agoric Dapp that contains three smart contracts `postal-service`
## Getting started
-Assuming all the required dependecies are already installed (including node, nvm, docker, Keplr - See [here](https://docs.agoric.com/guides/getting-started/) tutorial on how to install these dependecies.), here are the steps to run `dapp-agoric-basics`:
+Make sure all the required dependecies are already installed (including node, nvm, docker, Keplr, and that your node version is set to `18.x.x` by running `nvm use 18.20.2`. See [a tutorial here](https://docs.agoric.com/guides/getting-started/) on how to install these dependecies.). Here are the steps to run `dapp-agoric-basics`:
- run `yarn install` in the `agoric-basics` directory, to install dependencies of the Dapp.
- run `yarn start:docker` to start Agoric blockchain from the container.
-- run `yarn docker:logs` to to make sure blocks are being produced by viewing the Docker logs; once your logs ressemeble the following, stop the logs by pressing `ctrl+c`.
+- run `yarn docker:logs` to to make sure blocks are being produced by viewing the Docker logs; once your logs resemble the following, stop the logs by pressing `ctrl+c`.
```
demo-agd-1 | 2023-12-27T04:08:06.384Z block-manager: block 1003 begin
demo-agd-1 | 2023-12-27T04:08:06.386Z block-manager: block 1003 commit
@@ -17,7 +17,7 @@ demo-agd-1 | 2023-12-27T04:08:08.405Z block-manager: block 1005 begin
demo-agd-1 | 2023-12-27T04:08:08.407Z block-manager: block 1005 commit
```
- run `yarn start:contract` to start the contracts.
-- run `yarn start:ui` to start `sell-concert-tickets` contract UI.
+- run `yarn start:ui` to start `sell-concert-tickets` contract UI. You will need `vite` for UI to start properly. You can install `vite` by running `yarn add vite`.
- open a browser and navigate to `localhost:5173` to interact with the contract via UI.
To follow more detailed tutorial, go [here](https://docs.agoric.com/guides/getting-started/tutorial-dapp-agoric-basics.html).
From 346f0215e9a65bc7342aa2b023ab1ebdcee0a1fd Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Mon, 13 May 2024 08:11:24 +0500
Subject: [PATCH 06/22] docs: Remove vite dependency comment
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index a3bcce06..4db5ef53 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ demo-agd-1 | 2023-12-27T04:08:08.405Z block-manager: block 1005 begin
demo-agd-1 | 2023-12-27T04:08:08.407Z block-manager: block 1005 commit
```
- run `yarn start:contract` to start the contracts.
-- run `yarn start:ui` to start `sell-concert-tickets` contract UI. You will need `vite` for UI to start properly. You can install `vite` by running `yarn add vite`.
+- run `yarn start:ui` to start `sell-concert-tickets` contract UI.
- open a browser and navigate to `localhost:5173` to interact with the contract via UI.
To follow more detailed tutorial, go [here](https://docs.agoric.com/guides/getting-started/tutorial-dapp-agoric-basics.html).
From d192f04302ae9000a0da535fc72a9d117bbdc9bf Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Mon, 13 May 2024 17:48:15 +0500
Subject: [PATCH 07/22] WIP: toy code for cate token
---
contract/Makefile | 7 +-
contract/rollup.config.mjs | 6 +-
contract/src/cateCoin.contract.js | 119 ++++++++++++++++++
contract/src/cateCoin.proposal.js | 64 ++++++++++
contract/test/test-cateCoin.js | 201 ++++++++++++++++++++++++++++++
5 files changed, 395 insertions(+), 2 deletions(-)
create mode 100644 contract/src/cateCoin.contract.js
create mode 100644 contract/src/cateCoin.proposal.js
create mode 100644 contract/test/test-cateCoin.js
diff --git a/contract/Makefile b/contract/Makefile
index 3bd65b81..fe726b6f 100644
--- a/contract/Makefile
+++ b/contract/Makefile
@@ -60,7 +60,12 @@ vote:
instance-q:
agd query vstorage data published.agoricNames.instance -o json
-start-contract: start-contract-mint start-contract-swap start-contract-pay
+start-contract: start-contract-mint start-contract-swap start-contract-pay start-contract-cate
+
+start-contract-cate:
+ yarn node scripts/deploy-contract.js \
+ --install src/cateCoin.contract.js \
+ --eval src/cateCoin.proposal.js
start-contract-mint:
yarn node scripts/deploy-contract.js \
diff --git a/contract/rollup.config.mjs b/contract/rollup.config.mjs
index b5617069..53d42bee 100644
--- a/contract/rollup.config.mjs
+++ b/contract/rollup.config.mjs
@@ -22,7 +22,7 @@ import { permit as postalServicePermit } from './src/postal-service.proposal.js'
import { permit as swapPermit } from './src/swaparoo.proposal.js';
import { permit as sellPermit } from './src/sell-concert-tickets.proposal.js';
import { permit as boardAuxPermit } from './src/platform-goals/board-aux.core.js';
-
+import { permit as catePermit} from './src/cateCoin.proposal.js'
/**
* @param {*} opts
* @returns {import('rollup').RollupOptions}
@@ -89,5 +89,9 @@ const config = [
name: 'postal-service',
permit: postalServicePermit,
}),
+ config1({
+ name: 'cateCoin',
+ permit: catePermit,
+ }),
];
export default config;
diff --git a/contract/src/cateCoin.contract.js b/contract/src/cateCoin.contract.js
new file mode 100644
index 00000000..bc591b94
--- /dev/null
+++ b/contract/src/cateCoin.contract.js
@@ -0,0 +1,119 @@
+
+import { AmountMath, AmountShape, makeIssuerKit, AssetKind } from '@agoric/ertp';
+import { Far } from '@endo/far';
+import { M, getCopyBagEntries, makeCopyBag } from '@endo/patterns';
+//import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
+import '@agoric/zoe/exported.js';
+
+
+
+export const start = async (zcf) => {
+
+ // Step 0: get an issuer kit
+ const {
+ issuer: cateIssuer,
+ mint: cateMint,
+ brand: cateBrand,
+ } = makeIssuerKit('cateCoin');
+ let currSupply = AmountMath.make(cateBrand, 0n);;
+ const maxSupply = AmountMath.make(cateBrand, 1000_000n);;
+ let creatorPurse;
+ let isInitialized = 0;
+
+ const getIssuer = () => cateIssuer;
+
+ const createInitialCoins = ( myPurse, amount) => {
+
+ if(isInitialized === 1)
+ return 'Fail - already initialized';
+
+ console.log('creating first coins');
+ isInitialized = 1;
+ creatorPurse = myPurse;
+
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ if (AmountMath.isGTE(cateAmount, maxSupply ) )
+ return 'fail - amount exceeds maxSupply';
+ const catePayment = cateMint.mintPayment( cateAmount );
+
+ creatorPurse.deposit(catePayment);
+ currSupply = amount;
+
+ const currentAmount = creatorPurse.getCurrentAmount();
+ console.log("Current Amount in my purse after deposit is : ", currentAmount);
+ return 'success';
+ };
+ const mintCateCoins = ( myPurse, amount) => {
+ if(creatorPurse !== myPurse)
+ return 'Fail - Only creator can mint new tokens';
+ if( currSupply+amount > maxSupply )
+ return 'Fail - reached max supply';
+
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ const catePayment = cateMint.mintPayment( cateAmount );
+ creatorPurse.deposit(catePayment);
+ currSupply += amount;
+
+ return 'success';
+ };
+ const transferCateCoins = ( fromPurse, toPurse, amount) => {
+
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ if (AmountMath.isGTE(fromPurse.getCurrentAmount(), cateAmount)){
+ const catePayment = fromPurse.withdraw(cateAmount);
+ toPurse.deposit(catePayment);
+ return 'success';
+ }
+ return 'fail - not enough funds in sender account';
+ };
+
+ return {
+ creatorFacet: Far('Creator Facet', { mintCateCoins, transferCateCoins, getIssuer, createInitialCoins }),
+ publicFacet: Far('Public Facet', { transferCateCoins }),
+ };
+
+
+
+ // // Step 1: Get the address of the inviter
+ // //Check if this is the first call to this instance of the contract
+ // //Get the address of the party.
+ // const inviterAddress = zcf.state.get('inviterAddress');
+ // if (inviterAddress === undefined) {
+ // zcf.state.inviterAddress = zcf.getAddress();
+ // inviterAddress = zcf.state.get('inviterAddress');
+
+
+ // }
+
+
+ // console.log("The address of zoe I got is : ${inviterAddress}");
+ // return ;
+
+ // const { inventory } = zcf.getTerms();
+
+ // const inventoryValues = Object.values(inventory);
+
+
+ // const paymentAmount = cateIssuer.getAmountOf(catePayment);
+
+ // //TODO: check - Not sure if we can burn partial amount from a payment
+ // const amountToBurn = AmountMath.make(cateBrand, 5n);
+ // const burntAmount = cateIssuer.burn(catePayment, amountToBurn);
+ // console.log(burntAmount);
+
+
+ // const catePurse = cateIssuer.makeEmptyPurse();
+ // const currentAmount = catePurse.getCurrentAmount();
+ // console.log("Current Amount in my purse is : ",currentAmount);
+ // catePurse.deposit(catePayment);
+ // currentAmount = catePurse.getCurrentAmount();
+ // console.log("Current Amount in my purse after deposit is : ",currentAmount);
+
+
+ // const cate3 = AmountMath.make(brand, 30n);
+ // const withdrawalPayment = purse.withdraw(cate3);
+
+
+};
+
+harden(start);
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
new file mode 100644
index 00000000..fba0d2a2
--- /dev/null
+++ b/contract/src/cateCoin.proposal.js
@@ -0,0 +1,64 @@
+const contractName = 'cateCoin';
+
+/**
+ * Core eval script to start contract
+ *
+ * @param {BootstrapPowers} permittedPowers
+ * @param {*} config
+ */
+export const startCateCoin = async (powers, config) => {
+ console.log('core eval for', contractName);
+ const {
+ // must be supplied by caller or template-replaced
+ bundleID = Fail`no bundleID`,
+ } = 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);
+
+ await startContract(powers, {
+ name: contractName,
+ startArgs: {
+ installation,
+ issuerKeywordRecord: { Price: ist.issuer },
+ terms,
+ },
+ issuerNames: ['Ticket'],
+ });
+
+ console.log(contractName, '(re)started');
+};
+
+// Define a manifest object describing the contract's capabilities and permissions
+export const manifest = /** @type {const} */ ({
+ [startCateCoin.name]: { // Define entry for the postalService contract
+ consume: { // Resources consumed by the contract
+ agoricNames: true, // Needs access to the agoricNames registry
+ namesByAddress: true, // Needs access to the namesByAddress registry
+ namesByAddressAdmin: true, // Needs administrative access to the namesByAddress registry
+ startUpgradable: true, // Allows upgrades to the contract
+ zoe: true, // Needs access to the Zoe service for contract execution
+ },
+ installation: { // Capabilities provided by the contract during installation
+ consume: { [contractName]: true },
+ produce: { [contractName]: true },
+ },
+ instance: { // Capabilities provided by the contract instance
+ produce: { [contractName]: true }, // Produces a "postalService" instance
+ },
+ },
+});
+
+// Define the permit object based on the manifest
+export const permit = Object.values(manifest)[0];
+
+export const main = startCateCoin;
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
new file mode 100644
index 00000000..7f39db34
--- /dev/null
+++ b/contract/test/test-cateCoin.js
@@ -0,0 +1,201 @@
+
+import { test as anyTest } from './prepare-test-env-ava.js';
+// Imports the 'test' function from a local file './prepare-test-env-ava.js'.
+
+import { createRequire } from 'module';
+import { E } from '@endo/far';
+import { makeCopyBag, M } from '@endo/patterns';
+import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
+import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
+import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp';
+// Imports various modules needed for the tests.
+
+import { makeStableFaucet } from './mintStable.js';
+// import {
+// startSellConcertTicketsContract,
+// makeInventory,
+// makeTerms,
+// permit,
+// } from '../src/sell-concert-tickets.proposal.js';
+import { start } from '../src/cateCoin.contract.js';
+import { getBundleId } from '../tools/bundle-tools.js';
+import { mockBootstrapPowers } from './boot-tools.js';
+import {
+ produceBoardAuxManager,
+ permit as boardAuxPermit,
+} from '../src/platform-goals/board-aux.core.js';
+import { extract } from '@agoric/vats/src/core/utils.js';
+// Imports modules and functions for specific test scenarios.
+
+/** @typedef {typeof import('../src/sell-concert-tickets.contract.js').start} AssetContractFn */
+// Defines the type of 'AssetContractFn'.
+
+const myRequire = createRequire(import.meta.url);
+const contractPath = myRequire.resolve(
+ `../src/cateCoin.contract.js`,
+);
+
+const test = anyTest;
+// Renames the imported 'test' function for use in the file.
+
+const UNIT6 = 1_000_000n;
+const CENT = UNIT6 / 100n;
+// Defines constants for unit values.
+
+/**
+ * Tests assume access to the zoe service and that contracts are bundled.
+ *
+ * See test-bundle-source.js for basic use of bundleSource().
+ * Here we use a bundle cache to optimize running tests multiple times.
+ *
+ * @param {unknown} _t
+ */
+// Provides an overview of test assumptions and setup context.
+
+
+const makeTestContext = async _t => {
+ // Defines a function to create test context.
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ // Creates a Zoe service kit for testing.
+
+ const bundleCache = await makeNodeBundleCache('bundles/', {}, nodeModuleSpecifier => import(nodeModuleSpecifier));
+ // Creates a node bundle cache instance with the specified options and import function.
+ const bundle = await bundleCache.load(contractPath, 'assetContract');
+
+ const installation = E(zoe).install(bundle);
+ // Installs the contract bundle on Zoe.
+ //const { instance } = await E(zoe).startInstance(installation);
+ return { zoe, bundle, bundleCache, feeMintAccess };
+ // Returns the test context containing Zoe service, contract bundle, bundle cache, and fee mint access.
+ };
+
+ test.before(async t => (t.context = await makeTestContext(t)));
+ // Executes setup function before tests and assigns the context to 't'.
+
+test('Install CateCoin contract', async t => {
+ // Defines a test case to install the sell concert tickets contract.
+ const { zoe, bundle } = t.context;
+ // Destructures Zoe service and contract bundle from test context.
+
+ const installation = await E(zoe).install(bundle);
+ // Installs the contract bundle on Zoe.
+ t.log(installation);
+ // Logs the installation details.
+ t.is(typeof installation, 'object');
+ // Asserts that the installation is an object.
+});
+
+test('Start CateCoin contract', async t => {
+ // Defines a test case to start contract.
+ const { zoe, bundle } = t.context;
+ // Destructures Zoe service and contract bundle from test context.
+
+ const installation = E(zoe).install(bundle);
+ // Installs the contract bundle on Zoe.
+ const { instance } = await E(zoe).startInstance(installation);
+ // Starts a new contract instance on Zoe.
+ t.log(instance);
+ // Logs the contract instance.
+ t.is(typeof instance, 'object');
+ // Asserts that the contract instance is an object.
+});
+
+test('createInitialCoins creates a fixed amount of initial CateCoin', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
+
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
+
+ const coins = await E(creatorFacet).createInitialCoins(myPurse,100n);
+
+ // Creates a bag of tickets with different rows and quantities.
+ const amnt = await myPurse.getCurrentAmount();
+ const amnt2 = AmountMath.make(cateBrand, 100n);
+ t.true(
+ AmountMath.isEqual(
+ amnt,
+ amnt2
+ )
+ );
+ // Asserts that the calculated bag price matches the expected total price.
+ });
+
+ test('createInitialCoins CateCoin more than maxSupply', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
+
+ const coins = await E(creatorFacet).createInitialCoins(myPurse,1000_001n);
+
+ // Creates a bag of tickets with different rows and quantities.
+ const amnt = await myPurse.getCurrentAmount()
+ const amnt2 = AmountMath.make(cateBrand, 0n)
+ t.true(
+ AmountMath.isEqual(
+ amnt,
+ amnt2
+ )
+ );
+ // Asserts that the calculated bag price matches the expected total price.
+ });
+
+ test('transferCateCoins two purses', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse,1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+ // Creates a bag of tickets with different rows and quantities.
+ const fromAmnt = await fromPurse.getCurrentAmount()
+ const toAmnt = await toPurse.getCurrentAmount()
+ t.true(
+ AmountMath.isEqual(
+ fromAmnt,
+ toAmnt
+ )
+ );
+ });
+ test('transferCateCoins more than sender has', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse,1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 501n);
+ // Creates a bag of tickets with different rows and quantities.
+ const fromAmnt = await fromPurse.getCurrentAmount()
+ const toAmnt = await toPurse.getCurrentAmount()
+ t.true(
+ AmountMath.isEqual(
+ fromAmnt,
+ toAmnt
+ )
+ );
+ });
+
\ No newline at end of file
From e81b0ea49b7b8347bccee46e4caa5a9843802b56 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Mon, 13 May 2024 18:07:37 +0500
Subject: [PATCH 08/22] WIP: toy code for cate token
---
contract/src/cateCoin.contract.js | 5 ++---
contract/src/cateCoin.proposal.js | 9 +++++++++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/contract/src/cateCoin.contract.js b/contract/src/cateCoin.contract.js
index bc591b94..fd6300fb 100644
--- a/contract/src/cateCoin.contract.js
+++ b/contract/src/cateCoin.contract.js
@@ -1,8 +1,7 @@
-import { AmountMath, AmountShape, makeIssuerKit, AssetKind } from '@agoric/ertp';
+import { AmountMath, makeIssuerKit } from '@agoric/ertp';
import { Far } from '@endo/far';
-import { M, getCopyBagEntries, makeCopyBag } from '@endo/patterns';
-//import { atomicRearrange } from '@agoric/zoe/src/contractSupport/atomicTransfer.js';
+
import '@agoric/zoe/exported.js';
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index fba0d2a2..3ac73139 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -6,6 +6,15 @@ const contractName = 'cateCoin';
* @param {BootstrapPowers} permittedPowers
* @param {*} config
*/
+
+
+import {
+ installContract,
+} from './platform-goals/start-contract.js';
+import { allValues } from './objectTools.js';
+
+const { Fail } = assert;
+
export const startCateCoin = async (powers, config) => {
console.log('core eval for', contractName);
const {
From 1f80e7c64653110c32ecb8612e58b12400fec69e Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Mon, 13 May 2024 21:26:24 +0500
Subject: [PATCH 09/22] WIP: toy code for cate token
---
contract/src/cateCoin.proposal.js | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index 3ac73139..3dacd165 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -1,11 +1,4 @@
-const contractName = 'cateCoin';
-/**
- * Core eval script to start contract
- *
- * @param {BootstrapPowers} permittedPowers
- * @param {*} config
- */
import {
@@ -15,6 +8,15 @@ import { allValues } from './objectTools.js';
const { Fail } = assert;
+const contractName = 'cateCoin';
+
+/**
+ * Core eval script to start contract
+ *
+ * @param {BootstrapPowers} permittedPowers
+ * @param {*} config
+ */
+
export const startCateCoin = async (powers, config) => {
console.log('core eval for', contractName);
const {
From 58321eb29194eb4d79ed7d53f373d1cca80a3dad Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:08:41 +0500
Subject: [PATCH 10/22] fix: zcf is being used now
---
contract/src/cateCoin.contract.js | 71 ++++++++++++++-----------------
1 file changed, 32 insertions(+), 39 deletions(-)
diff --git a/contract/src/cateCoin.contract.js b/contract/src/cateCoin.contract.js
index fd6300fb..39611f6c 100644
--- a/contract/src/cateCoin.contract.js
+++ b/contract/src/cateCoin.contract.js
@@ -1,78 +1,78 @@
-
import { AmountMath, makeIssuerKit } from '@agoric/ertp';
import { Far } from '@endo/far';
import '@agoric/zoe/exported.js';
-
-
-export const start = async (zcf) => {
-
+export const start = async zcf => {
// Step 0: get an issuer kit
const {
issuer: cateIssuer,
mint: cateMint,
brand: cateBrand,
} = makeIssuerKit('cateCoin');
- let currSupply = AmountMath.make(cateBrand, 0n);;
- const maxSupply = AmountMath.make(cateBrand, 1000_000n);;
+ let currSupply = AmountMath.make(cateBrand, 0n);
+ const maxSupply = AmountMath.make(cateBrand, 1000_000n);
let creatorPurse;
let isInitialized = 0;
const getIssuer = () => cateIssuer;
+ const cateAssetKind = zcf.getAssetKind(cateBrand);
+ console.log('AssetKind for Cate Coin is : ', cateAssetKind);
- const createInitialCoins = ( myPurse, amount) => {
-
- if(isInitialized === 1)
- return 'Fail - already initialized';
+ const createInitialCoins = (myPurse, amount) => {
+ if (isInitialized === 1) return 'Fail - already initialized';
console.log('creating first coins');
isInitialized = 1;
creatorPurse = myPurse;
-
+
const cateAmount = AmountMath.make(cateBrand, amount);
- if (AmountMath.isGTE(cateAmount, maxSupply ) )
+ if (AmountMath.isGTE(cateAmount, maxSupply))
return 'fail - amount exceeds maxSupply';
- const catePayment = cateMint.mintPayment( cateAmount );
-
+ const catePayment = cateMint.mintPayment(cateAmount);
+
creatorPurse.deposit(catePayment);
currSupply = amount;
-
+
const currentAmount = creatorPurse.getCurrentAmount();
- console.log("Current Amount in my purse after deposit is : ", currentAmount);
+ console.log(
+ 'Current Amount in my purse after deposit is : ',
+ currentAmount,
+ );
return 'success';
};
- const mintCateCoins = ( myPurse, amount) => {
- if(creatorPurse !== myPurse)
+ const mintCateCoins = (myPurse, amount) => {
+ if (creatorPurse !== myPurse)
return 'Fail - Only creator can mint new tokens';
- if( currSupply+amount > maxSupply )
- return 'Fail - reached max supply';
-
+ if (currSupply + amount > maxSupply) return 'Fail - reached max supply';
+
const cateAmount = AmountMath.make(cateBrand, amount);
- const catePayment = cateMint.mintPayment( cateAmount );
+ const catePayment = cateMint.mintPayment(cateAmount);
creatorPurse.deposit(catePayment);
currSupply += amount;
-
+
return 'success';
};
- const transferCateCoins = ( fromPurse, toPurse, amount) => {
-
+ const transferCateCoins = (fromPurse, toPurse, amount) => {
const cateAmount = AmountMath.make(cateBrand, amount);
- if (AmountMath.isGTE(fromPurse.getCurrentAmount(), cateAmount)){
+ if (AmountMath.isGTE(fromPurse.getCurrentAmount(), cateAmount)) {
const catePayment = fromPurse.withdraw(cateAmount);
toPurse.deposit(catePayment);
- return 'success';
+ return 'success';
}
return 'fail - not enough funds in sender account';
};
return {
- creatorFacet: Far('Creator Facet', { mintCateCoins, transferCateCoins, getIssuer, createInitialCoins }),
- publicFacet: Far('Public Facet', { transferCateCoins }),
+ creatorFacet: Far('Creator Facet', {
+ mintCateCoins,
+ transferCateCoins,
+ getIssuer,
+ createInitialCoins,
+ }),
+ publicFacet: Far('Public Facet', { transferCateCoins }),
};
-
-
// // Step 1: Get the address of the inviter
// //Check if this is the first call to this instance of the contract
// //Get the address of the party.
@@ -80,11 +80,9 @@ export const start = async (zcf) => {
// if (inviterAddress === undefined) {
// zcf.state.inviterAddress = zcf.getAddress();
// inviterAddress = zcf.state.get('inviterAddress');
-
// }
-
// console.log("The address of zoe I got is : ${inviterAddress}");
// return ;
@@ -92,14 +90,12 @@ export const start = async (zcf) => {
// const inventoryValues = Object.values(inventory);
-
// const paymentAmount = cateIssuer.getAmountOf(catePayment);
// //TODO: check - Not sure if we can burn partial amount from a payment
// const amountToBurn = AmountMath.make(cateBrand, 5n);
// const burntAmount = cateIssuer.burn(catePayment, amountToBurn);
// console.log(burntAmount);
-
// const catePurse = cateIssuer.makeEmptyPurse();
// const currentAmount = catePurse.getCurrentAmount();
@@ -108,11 +104,8 @@ export const start = async (zcf) => {
// currentAmount = catePurse.getCurrentAmount();
// console.log("Current Amount in my purse after deposit is : ",currentAmount);
-
// const cate3 = AmountMath.make(brand, 30n);
// const withdrawalPayment = purse.withdraw(cate3);
-
-
};
harden(start);
From 174144667a56d55312e8180cd9d061dadb85ca63 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:21:44 +0500
Subject: [PATCH 11/22] fix: startContract is now accessible in proposal
---
contract/src/cateCoin.proposal.js | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index 3dacd165..1dcbeb67 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -1,8 +1,6 @@
-
-
-
import {
installContract,
+ startContract,
} from './platform-goals/start-contract.js';
import { allValues } from './objectTools.js';
@@ -34,7 +32,7 @@ export const startCateCoin = async (powers, config) => {
issuer: powers.issuer.consume.IST,
});
- const terms = makeTerms(ist.brand, 1n * IST_UNIT);
+ const terms = undefined;
await startContract(powers, {
name: contractName,
@@ -51,19 +49,23 @@ export const startCateCoin = async (powers, config) => {
// Define a manifest object describing the contract's capabilities and permissions
export const manifest = /** @type {const} */ ({
- [startCateCoin.name]: { // Define entry for the postalService contract
- consume: { // Resources consumed by the contract
+ [startCateCoin.name]: {
+ // Define entry for the postalService contract
+ consume: {
+ // Resources consumed by the contract
agoricNames: true, // Needs access to the agoricNames registry
namesByAddress: true, // Needs access to the namesByAddress registry
namesByAddressAdmin: true, // Needs administrative access to the namesByAddress registry
startUpgradable: true, // Allows upgrades to the contract
zoe: true, // Needs access to the Zoe service for contract execution
},
- installation: { // Capabilities provided by the contract during installation
- consume: { [contractName]: true },
- produce: { [contractName]: true },
+ installation: {
+ // Capabilities provided by the contract during installation
+ consume: { [contractName]: true },
+ produce: { [contractName]: true },
},
- instance: { // Capabilities provided by the contract instance
+ instance: {
+ // Capabilities provided by the contract instance
produce: { [contractName]: true }, // Produces a "postalService" instance
},
},
From 022209e18cd38bd59da9c054dc31a5206b45bd63 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:26:59 +0500
Subject: [PATCH 12/22] fix: removed unused from test-cateCoin.js
---
contract/test/test-cateCoin.js | 262 ++++++++++++++-------------------
1 file changed, 111 insertions(+), 151 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index 7f39db34..8d847620 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -1,76 +1,57 @@
-
-import { test as anyTest } from './prepare-test-env-ava.js';
-// Imports the 'test' function from a local file './prepare-test-env-ava.js'.
-
import { createRequire } from 'module';
import { E } from '@endo/far';
-import { makeCopyBag, M } from '@endo/patterns';
+
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
-import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp';
+import { AmountMath } from '@agoric/ertp';
// Imports various modules needed for the tests.
-import { makeStableFaucet } from './mintStable.js';
+// import { makeStableFaucet } from './mintStable.js';
// import {
// startSellConcertTicketsContract,
// makeInventory,
// makeTerms,
// permit,
// } from '../src/sell-concert-tickets.proposal.js';
-import { start } from '../src/cateCoin.contract.js';
-import { getBundleId } from '../tools/bundle-tools.js';
-import { mockBootstrapPowers } from './boot-tools.js';
-import {
- produceBoardAuxManager,
- permit as boardAuxPermit,
-} from '../src/platform-goals/board-aux.core.js';
-import { extract } from '@agoric/vats/src/core/utils.js';
+// import { start } from '../src/cateCoin.contract.js';
+// import { getBundleId } from '../tools/bundle-tools.js';
+// import { mockBootstrapPowers } from './boot-tools.js';
+// import {
+// produceBoardAuxManager,
+// permit as boardAuxPermit,
+// } from '../src/platform-goals/board-aux.core.js';
+// import { extract } from '@agoric/vats/src/core/utils.js';
// Imports modules and functions for specific test scenarios.
-
-/** @typedef {typeof import('../src/sell-concert-tickets.contract.js').start} AssetContractFn */
-// Defines the type of 'AssetContractFn'.
+import { test as anyTest } from './prepare-test-env-ava.js';
const myRequire = createRequire(import.meta.url);
-const contractPath = myRequire.resolve(
- `../src/cateCoin.contract.js`,
-);
+const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
// Renames the imported 'test' function for use in the file.
-const UNIT6 = 1_000_000n;
-const CENT = UNIT6 / 100n;
-// Defines constants for unit values.
-
-/**
- * Tests assume access to the zoe service and that contracts are bundled.
- *
- * See test-bundle-source.js for basic use of bundleSource().
- * Here we use a bundle cache to optimize running tests multiple times.
- *
- * @param {unknown} _t
- */
-// Provides an overview of test assumptions and setup context.
-
-
const makeTestContext = async _t => {
- // Defines a function to create test context.
- const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
- // Creates a Zoe service kit for testing.
-
- const bundleCache = await makeNodeBundleCache('bundles/', {}, nodeModuleSpecifier => import(nodeModuleSpecifier));
- // Creates a node bundle cache instance with the specified options and import function.
- const bundle = await bundleCache.load(contractPath, 'assetContract');
-
- const installation = E(zoe).install(bundle);
+ // Defines a function to create test context.
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ // Creates a Zoe service kit for testing.
+
+ const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+ );
+ // Creates a node bundle cache instance with the specified options and import function.
+ const bundle = await bundleCache.load(contractPath, 'assetContract');
+
+ E(zoe).install(bundle);
// Installs the contract bundle on Zoe.
- //const { instance } = await E(zoe).startInstance(installation);
- return { zoe, bundle, bundleCache, feeMintAccess };
- // Returns the test context containing Zoe service, contract bundle, bundle cache, and fee mint access.
- };
-
- test.before(async t => (t.context = await makeTestContext(t)));
- // Executes setup function before tests and assigns the context to 't'.
+ //const { instance } = await E(zoe).startInstance(installation);
+ return { zoe, bundle, bundleCache, feeMintAccess };
+ // Returns the test context containing Zoe service, contract bundle, bundle cache, and fee mint access.
+};
+
+test.before(async t => (t.context = await makeTestContext(t)));
+// Executes setup function before tests and assigns the context to 't'.
test('Install CateCoin contract', async t => {
// Defines a test case to install the sell concert tickets contract.
@@ -89,7 +70,7 @@ test('Start CateCoin contract', async t => {
// Defines a test case to start contract.
const { zoe, bundle } = t.context;
// Destructures Zoe service and contract bundle from test context.
-
+
const installation = E(zoe).install(bundle);
// Installs the contract bundle on Zoe.
const { instance } = await E(zoe).startInstance(installation);
@@ -101,101 +82,80 @@ test('Start CateCoin contract', async t => {
});
test('createInitialCoins creates a fixed amount of initial CateCoin', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
-
- //Does not work here -
- const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const cateBrand = await E(cateIssuer).getBrand();
-
- const myPurse = await E(cateIssuer).makeEmptyPurse();
-
- const coins = await E(creatorFacet).createInitialCoins(myPurse,100n);
-
- // Creates a bag of tickets with different rows and quantities.
- const amnt = await myPurse.getCurrentAmount();
- const amnt2 = AmountMath.make(cateBrand, 100n);
- t.true(
- AmountMath.isEqual(
- amnt,
- amnt2
- )
- );
- // Asserts that the calculated bag price matches the expected total price.
- });
-
- test('createInitialCoins CateCoin more than maxSupply', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
- const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const cateBrand = await E(cateIssuer).getBrand();
- const myPurse = await E(cateIssuer).makeEmptyPurse();
-
- const coins = await E(creatorFacet).createInitialCoins(myPurse,1000_001n);
-
- // Creates a bag of tickets with different rows and quantities.
- const amnt = await myPurse.getCurrentAmount()
- const amnt2 = AmountMath.make(cateBrand, 0n)
- t.true(
- AmountMath.isEqual(
- amnt,
- amnt2
- )
- );
- // Asserts that the calculated bag price matches the expected total price.
- });
-
- test('transferCateCoins two purses', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
-
- //Does not work here -
- const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const fromPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).createInitialCoins(fromPurse,1000n);
- const toPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
- // Creates a bag of tickets with different rows and quantities.
- const fromAmnt = await fromPurse.getCurrentAmount()
- const toAmnt = await toPurse.getCurrentAmount()
- t.true(
- AmountMath.isEqual(
- fromAmnt,
- toAmnt
- )
- );
- });
- test('transferCateCoins more than sender has', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
-
- //Does not work here -
- const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const fromPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).createInitialCoins(fromPurse,1000n);
- const toPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 501n);
- // Creates a bag of tickets with different rows and quantities.
- const fromAmnt = await fromPurse.getCurrentAmount()
- const toAmnt = await toPurse.getCurrentAmount()
- t.true(
- AmountMath.isEqual(
- fromAmnt,
- toAmnt
- )
- );
- });
-
\ No newline at end of file
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
+
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
+
+ const coins = await E(creatorFacet).createInitialCoins(myPurse, 100n);
+
+ // Creates a bag of tickets with different rows and quantities.
+ const amnt = await myPurse.getCurrentAmount();
+ const amnt2 = AmountMath.make(cateBrand, 100n);
+ t.true(AmountMath.isEqual(amnt, amnt2));
+ // Asserts that the calculated bag price matches the expected total price.
+});
+
+test('createInitialCoins CateCoin more than maxSupply', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
+
+ const coins = await E(creatorFacet).createInitialCoins(myPurse, 1000_001n);
+
+ // Creates a bag of tickets with different rows and quantities.
+ const amnt = await myPurse.getCurrentAmount();
+ const amnt2 = AmountMath.make(cateBrand, 0n);
+ t.true(AmountMath.isEqual(amnt, amnt2));
+ // Asserts that the calculated bag price matches the expected total price.
+});
+
+test('transferCateCoins two purses', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+ // Creates a bag of tickets with different rows and quantities.
+ const fromAmnt = await fromPurse.getCurrentAmount();
+ const toAmnt = await toPurse.getCurrentAmount();
+ t.true(AmountMath.isEqual(fromAmnt, toAmnt));
+});
+test('transferCateCoins more than sender has', async t => {
+ // Defines a test case to calculate the total price for a bag of tickets.
+ const { zoe, bundle } = t.context;
+
+ //Does not work here -
+ const installation = E(zoe).install(bundle);
+ const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 501n);
+ // Creates a bag of tickets with different rows and quantities.
+ const fromAmnt = await fromPurse.getCurrentAmount();
+ const toAmnt = await toPurse.getCurrentAmount();
+ t.true(AmountMath.isEqual(fromAmnt, toAmnt));
+});
From a0ecc68a5fbd0bfa037552e62a42db46dafdf603 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:33:25 +0500
Subject: [PATCH 13/22] fix: removed unused from test-cateCoin.js
---
contract/test/test-cateCoin.js | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index 8d847620..ae8bfdf1 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -45,7 +45,7 @@ const makeTestContext = async _t => {
E(zoe).install(bundle);
// Installs the contract bundle on Zoe.
- //const { instance } = await E(zoe).startInstance(installation);
+ // const { instance } = await E(zoe).startInstance(installation);
return { zoe, bundle, bundleCache, feeMintAccess };
// Returns the test context containing Zoe service, contract bundle, bundle cache, and fee mint access.
};
@@ -85,16 +85,17 @@ test('createInitialCoins creates a fixed amount of initial CateCoin', async t =>
// Defines a test case to calculate the total price for a bag of tickets.
const { zoe, bundle } = t.context;
- //Does not work here -
+ // Does not work here -
const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+ // I am removing instance from below
+ const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = await E(cateIssuer).getBrand();
const myPurse = await E(cateIssuer).makeEmptyPurse();
- const coins = await E(creatorFacet).createInitialCoins(myPurse, 100n);
+ await E(creatorFacet).createInitialCoins(myPurse, 100n);
// Creates a bag of tickets with different rows and quantities.
const amnt = await myPurse.getCurrentAmount();
@@ -107,13 +108,14 @@ test('createInitialCoins CateCoin more than maxSupply', async t => {
// Defines a test case to calculate the total price for a bag of tickets.
const { zoe, bundle } = t.context;
const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+ // I am removing instance from below
+ const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = await E(cateIssuer).getBrand();
const myPurse = await E(cateIssuer).makeEmptyPurse();
- const coins = await E(creatorFacet).createInitialCoins(myPurse, 1000_001n);
+ await E(creatorFacet).createInitialCoins(myPurse, 1000_001n);
// Creates a bag of tickets with different rows and quantities.
const amnt = await myPurse.getCurrentAmount();
@@ -126,9 +128,10 @@ test('transferCateCoins two purses', async t => {
// Defines a test case to calculate the total price for a bag of tickets.
const { zoe, bundle } = t.context;
- //Does not work here -
+ // Does not work here -
const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+ // I am removing instance from below
+ const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
const fromPurse = await E(cateIssuer).makeEmptyPurse();
@@ -144,9 +147,10 @@ test('transferCateCoins more than sender has', async t => {
// Defines a test case to calculate the total price for a bag of tickets.
const { zoe, bundle } = t.context;
- //Does not work here -
+ // Does not work here -
const installation = E(zoe).install(bundle);
- const { instance, creatorFacet } = await E(zoe).startInstance(installation);
+ // I am removing instance from below
+ const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
const fromPurse = await E(cateIssuer).makeEmptyPurse();
From b2b173f887086eadf75ef652cfc10e9cb795f8f6 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:43:40 +0500
Subject: [PATCH 14/22] fix: added error handling
---
contract/src/cateCoin.contract.js | 122 ++++++++++++++----------------
1 file changed, 56 insertions(+), 66 deletions(-)
diff --git a/contract/src/cateCoin.contract.js b/contract/src/cateCoin.contract.js
index 39611f6c..439a2049 100644
--- a/contract/src/cateCoin.contract.js
+++ b/contract/src/cateCoin.contract.js
@@ -20,47 +20,71 @@ export const start = async zcf => {
console.log('AssetKind for Cate Coin is : ', cateAssetKind);
const createInitialCoins = (myPurse, amount) => {
- if (isInitialized === 1) return 'Fail - already initialized';
-
- console.log('creating first coins');
- isInitialized = 1;
- creatorPurse = myPurse;
-
- const cateAmount = AmountMath.make(cateBrand, amount);
- if (AmountMath.isGTE(cateAmount, maxSupply))
- return 'fail - amount exceeds maxSupply';
- const catePayment = cateMint.mintPayment(cateAmount);
-
- creatorPurse.deposit(catePayment);
- currSupply = amount;
-
- const currentAmount = creatorPurse.getCurrentAmount();
- console.log(
- 'Current Amount in my purse after deposit is : ',
- currentAmount,
- );
- return 'success';
+ try {
+ if (isInitialized === 1) {
+ throw new Error('Fail - already initialized');
+ }
+
+ console.log('creating first coins');
+ isInitialized = 1;
+ creatorPurse = myPurse;
+
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ if (AmountMath.isGTE(cateAmount, maxSupply)) {
+ throw new Error('Fail - amount exceeds maxSupply');
+ }
+
+ const catePayment = cateMint.mintPayment(cateAmount);
+ creatorPurse.deposit(catePayment);
+ currSupply = amount;
+
+ const currentAmount = creatorPurse.getCurrentAmount();
+ console.log(
+ 'Current Amount in my purse after deposit is : ',
+ currentAmount,
+ );
+ return 'success';
+ } catch (error) {
+ console.error('Error in createInitialCoins:', error);
+ return error.message;
+ }
};
- const mintCateCoins = (myPurse, amount) => {
- if (creatorPurse !== myPurse)
- return 'Fail - Only creator can mint new tokens';
- if (currSupply + amount > maxSupply) return 'Fail - reached max supply';
- const cateAmount = AmountMath.make(cateBrand, amount);
- const catePayment = cateMint.mintPayment(cateAmount);
- creatorPurse.deposit(catePayment);
- currSupply += amount;
+ const mintCateCoins = (myPurse, amount) => {
+ try {
+ if (creatorPurse !== myPurse) {
+ throw new Error('Fail - Only creator can mint new tokens');
+ }
+ if (currSupply + amount > maxSupply) {
+ throw new Error('Fail - reached max supply');
+ }
+
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ const catePayment = cateMint.mintPayment(cateAmount);
+ creatorPurse.deposit(catePayment);
+ currSupply += amount;
- return 'success';
+ return 'success';
+ } catch (error) {
+ console.error('Error in mintCateCoins:', error);
+ return error.message;
+ }
};
+
const transferCateCoins = (fromPurse, toPurse, amount) => {
- const cateAmount = AmountMath.make(cateBrand, amount);
- if (AmountMath.isGTE(fromPurse.getCurrentAmount(), cateAmount)) {
+ try {
+ const cateAmount = AmountMath.make(cateBrand, amount);
+ if (!AmountMath.isGTE(fromPurse.getCurrentAmount(), cateAmount)) {
+ throw new Error('Fail - not enough funds in sender account');
+ }
+
const catePayment = fromPurse.withdraw(cateAmount);
toPurse.deposit(catePayment);
return 'success';
+ } catch (error) {
+ console.error('Error in transferCateCoins:', error);
+ return error.message;
}
- return 'fail - not enough funds in sender account';
};
return {
@@ -72,40 +96,6 @@ export const start = async zcf => {
}),
publicFacet: Far('Public Facet', { transferCateCoins }),
};
-
- // // Step 1: Get the address of the inviter
- // //Check if this is the first call to this instance of the contract
- // //Get the address of the party.
- // const inviterAddress = zcf.state.get('inviterAddress');
- // if (inviterAddress === undefined) {
- // zcf.state.inviterAddress = zcf.getAddress();
- // inviterAddress = zcf.state.get('inviterAddress');
-
- // }
-
- // console.log("The address of zoe I got is : ${inviterAddress}");
- // return ;
-
- // const { inventory } = zcf.getTerms();
-
- // const inventoryValues = Object.values(inventory);
-
- // const paymentAmount = cateIssuer.getAmountOf(catePayment);
-
- // //TODO: check - Not sure if we can burn partial amount from a payment
- // const amountToBurn = AmountMath.make(cateBrand, 5n);
- // const burntAmount = cateIssuer.burn(catePayment, amountToBurn);
- // console.log(burntAmount);
-
- // const catePurse = cateIssuer.makeEmptyPurse();
- // const currentAmount = catePurse.getCurrentAmount();
- // console.log("Current Amount in my purse is : ",currentAmount);
- // catePurse.deposit(catePayment);
- // currentAmount = catePurse.getCurrentAmount();
- // console.log("Current Amount in my purse after deposit is : ",currentAmount);
-
- // const cate3 = AmountMath.make(brand, 30n);
- // const withdrawalPayment = purse.withdraw(cate3);
};
harden(start);
From ea1a300b8db92dd8531acefcc380b5892ec41ab8 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:46:24 +0500
Subject: [PATCH 15/22] fix: added error handling
---
contract/src/cateCoin.proposal.js | 43 +++++++++++++++++--------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index 1dcbeb67..3ad4b395 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -22,29 +22,34 @@ export const startCateCoin = async (powers, config) => {
bundleID = Fail`no bundleID`,
} = config?.options?.[contractName] ?? {};
- const installation = await installContract(powers, {
- name: contractName,
- bundleID,
- });
+ try {
+ const installation = await installContract(powers, {
+ name: contractName,
+ bundleID,
+ });
- const ist = await allValues({
- brand: powers.brand.consume.IST,
- issuer: powers.issuer.consume.IST,
- });
+ const ist = await allValues({
+ brand: powers.brand.consume.IST,
+ issuer: powers.issuer.consume.IST,
+ });
- const terms = undefined;
+ const terms = undefined;
- await startContract(powers, {
- name: contractName,
- startArgs: {
- installation,
- issuerKeywordRecord: { Price: ist.issuer },
- terms,
- },
- issuerNames: ['Ticket'],
- });
+ await startContract(powers, {
+ name: contractName,
+ startArgs: {
+ installation,
+ issuerKeywordRecord: { Price: ist.issuer },
+ terms,
+ },
+ issuerNames: ['Ticket'],
+ });
- console.log(contractName, '(re)started');
+ console.log(contractName, '(re)started');
+ } catch (error) {
+ console.error(`Error starting ${contractName} contract:`, error);
+ throw error; // Rethrow the error after logging it
+ }
};
// Define a manifest object describing the contract's capabilities and permissions
From 16f9331fe2865c16e34fac949868fb6cd8f95afd Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 17:58:45 +0500
Subject: [PATCH 16/22] fix: added error handling
---
contract/test/test-cateCoin.js | 260 +++++++++++++++++----------------
1 file changed, 133 insertions(+), 127 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index ae8bfdf1..a090b453 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -4,162 +4,168 @@ import { E } from '@endo/far';
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { AmountMath } from '@agoric/ertp';
-// Imports various modules needed for the tests.
-
-// import { makeStableFaucet } from './mintStable.js';
-// import {
-// startSellConcertTicketsContract,
-// makeInventory,
-// makeTerms,
-// permit,
-// } from '../src/sell-concert-tickets.proposal.js';
-// import { start } from '../src/cateCoin.contract.js';
-// import { getBundleId } from '../tools/bundle-tools.js';
-// import { mockBootstrapPowers } from './boot-tools.js';
-// import {
-// produceBoardAuxManager,
-// permit as boardAuxPermit,
-// } from '../src/platform-goals/board-aux.core.js';
-// import { extract } from '@agoric/vats/src/core/utils.js';
-// Imports modules and functions for specific test scenarios.
import { test as anyTest } from './prepare-test-env-ava.js';
const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
-// Renames the imported 'test' function for use in the file.
const makeTestContext = async _t => {
- // Defines a function to create test context.
- const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
- // Creates a Zoe service kit for testing.
-
- const bundleCache = await makeNodeBundleCache(
- 'bundles/',
- {},
- nodeModuleSpecifier => import(nodeModuleSpecifier),
- );
- // Creates a node bundle cache instance with the specified options and import function.
- const bundle = await bundleCache.load(contractPath, 'assetContract');
-
- E(zoe).install(bundle);
- // Installs the contract bundle on Zoe.
- // const { instance } = await E(zoe).startInstance(installation);
- return { zoe, bundle, bundleCache, feeMintAccess };
- // Returns the test context containing Zoe service, contract bundle, bundle cache, and fee mint access.
+ try {
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+ );
+ const bundle = await bundleCache.load(contractPath, 'assetContract');
+
+ await E(zoe).install(bundle);
+
+ return { zoe, bundle, bundleCache, feeMintAccess };
+ } catch (error) {
+ console.error('Error in makeTestContext:', error);
+ throw error;
+ }
};
-test.before(async t => (t.context = await makeTestContext(t)));
-// Executes setup function before tests and assigns the context to 't'.
+test.before(async t => {
+ try {
+ t.context = await makeTestContext(t);
+ } catch (error) {
+ console.error('Error in test.before:', error);
+ throw error;
+ }
+});
test('Install CateCoin contract', async t => {
- // Defines a test case to install the sell concert tickets contract.
- const { zoe, bundle } = t.context;
- // Destructures Zoe service and contract bundle from test context.
-
- const installation = await E(zoe).install(bundle);
- // Installs the contract bundle on Zoe.
- t.log(installation);
- // Logs the installation details.
- t.is(typeof installation, 'object');
- // Asserts that the installation is an object.
+ try {
+ const { zoe, bundle } = t.context;
+
+ const installation = await E(zoe).install(bundle);
+ t.log(installation);
+ t.is(typeof installation, 'object');
+ } catch (error) {
+ console.error('Error in Install CateCoin contract test:', error);
+ t.fail(error.message);
+ }
});
test('Start CateCoin contract', async t => {
- // Defines a test case to start contract.
- const { zoe, bundle } = t.context;
- // Destructures Zoe service and contract bundle from test context.
-
- const installation = E(zoe).install(bundle);
- // Installs the contract bundle on Zoe.
- const { instance } = await E(zoe).startInstance(installation);
- // Starts a new contract instance on Zoe.
- t.log(instance);
- // Logs the contract instance.
- t.is(typeof instance, 'object');
- // Asserts that the contract instance is an object.
+ try {
+ const { zoe, bundle } = t.context;
+
+ const installation = await E(zoe).install(bundle);
+ const { instance } = await E(zoe).startInstance(installation);
+ t.log(instance);
+ t.is(typeof instance, 'object');
+ } catch (error) {
+ console.error('Error in Start CateCoin contract test:', error);
+ t.fail(error.message);
+ }
});
test('createInitialCoins creates a fixed amount of initial CateCoin', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
+ try {
+ const { zoe, bundle } = t.context;
- // Does not work here -
- const installation = E(zoe).install(bundle);
- // I am removing instance from below
- const { creatorFacet } = await E(zoe).startInstance(installation);
+ const installation = await E(zoe).install(bundle);
+ const { creatorFacet } = await E(zoe).startInstance(installation);
- const cateIssuer = await E(creatorFacet).getIssuer();
- const cateBrand = await E(cateIssuer).getBrand();
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
- const myPurse = await E(cateIssuer).makeEmptyPurse();
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).createInitialCoins(myPurse, 100n);
+ await E(creatorFacet).createInitialCoins(myPurse, 100n);
- // Creates a bag of tickets with different rows and quantities.
- const amnt = await myPurse.getCurrentAmount();
- const amnt2 = AmountMath.make(cateBrand, 100n);
- t.true(AmountMath.isEqual(amnt, amnt2));
- // Asserts that the calculated bag price matches the expected total price.
+ const amnt = await myPurse.getCurrentAmount();
+ const amnt2 = AmountMath.make(cateBrand, 100n);
+ t.true(AmountMath.isEqual(amnt, amnt2));
+ } catch (error) {
+ console.error('Error in createInitialCoins test:', error);
+ t.fail(error.message);
+ }
});
test('createInitialCoins CateCoin more than maxSupply', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
- const installation = E(zoe).install(bundle);
- // I am removing instance from below
- const { creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const cateBrand = await E(cateIssuer).getBrand();
- const myPurse = await E(cateIssuer).makeEmptyPurse();
-
- await E(creatorFacet).createInitialCoins(myPurse, 1000_001n);
-
- // Creates a bag of tickets with different rows and quantities.
- const amnt = await myPurse.getCurrentAmount();
- const amnt2 = AmountMath.make(cateBrand, 0n);
- t.true(AmountMath.isEqual(amnt, amnt2));
- // Asserts that the calculated bag price matches the expected total price.
+ try {
+ const { zoe, bundle } = t.context;
+
+ const installation = await E(zoe).install(bundle);
+ const { creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = await E(cateIssuer).getBrand();
+ const myPurse = await E(cateIssuer).makeEmptyPurse();
+
+ await E(creatorFacet).createInitialCoins(myPurse, 1000_001n);
+
+ const amnt = await myPurse.getCurrentAmount();
+ const amnt2 = AmountMath.make(cateBrand, 0n);
+ t.true(AmountMath.isEqual(amnt, amnt2));
+ } catch (error) {
+ console.error(
+ 'Error in createInitialCoins more than maxSupply test:',
+ error,
+ );
+ t.fail(error.message);
+ }
});
test('transferCateCoins two purses', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
-
- // Does not work here -
- const installation = E(zoe).install(bundle);
- // I am removing instance from below
- const { creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const fromPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
- const toPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
- // Creates a bag of tickets with different rows and quantities.
- const fromAmnt = await fromPurse.getCurrentAmount();
- const toAmnt = await toPurse.getCurrentAmount();
- t.true(AmountMath.isEqual(fromAmnt, toAmnt));
+ try {
+ const { zoe, bundle } = t.context;
+
+ const installation = await E(zoe).install(bundle);
+ const { creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+
+ const fromAmnt = await fromPurse.getCurrentAmount();
+ const toAmnt = await toPurse.getCurrentAmount();
+ t.true(AmountMath.isEqual(fromAmnt, AmountMath.make(cateBrand, 500n)));
+ t.true(AmountMath.isEqual(toAmnt, AmountMath.make(cateBrand, 500n)));
+ } catch (error) {
+ console.error('Error in transferCateCoins two purses test:', error);
+ t.fail(error.message);
+ }
});
+
test('transferCateCoins more than sender has', async t => {
- // Defines a test case to calculate the total price for a bag of tickets.
- const { zoe, bundle } = t.context;
-
- // Does not work here -
- const installation = E(zoe).install(bundle);
- // I am removing instance from below
- const { creatorFacet } = await E(zoe).startInstance(installation);
-
- const cateIssuer = await E(creatorFacet).getIssuer();
- const fromPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
- const toPurse = await E(cateIssuer).makeEmptyPurse();
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
- await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 501n);
- // Creates a bag of tickets with different rows and quantities.
- const fromAmnt = await fromPurse.getCurrentAmount();
- const toAmnt = await toPurse.getCurrentAmount();
- t.true(AmountMath.isEqual(fromAmnt, toAmnt));
+ try {
+ const { zoe, bundle } = t.context;
+
+ const installation = await E(zoe).install(bundle);
+ const { creatorFacet } = await E(zoe).startInstance(installation);
+
+ const cateIssuer = await E(creatorFacet).getIssuer();
+ const fromPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
+ const toPurse = await E(cateIssuer).makeEmptyPurse();
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
+ const transferResult = await E(creatorFacet).transferCateCoins(
+ fromPurse,
+ toPurse,
+ 501n,
+ );
+
+ t.is(transferResult, 'fail - not enough funds in sender account');
+
+ const fromAmnt = await fromPurse.getCurrentAmount();
+ const toAmnt = await toPurse.getCurrentAmount();
+ t.true(AmountMath.isEqual(fromAmnt, AmountMath.make(cateBrand, 500n)));
+ t.true(AmountMath.isEqual(toAmnt, AmountMath.make(cateBrand, 500n)));
+ } catch (error) {
+ console.error(
+ 'Error in transferCateCoins more than sender has test:',
+ error,
+ );
+ t.fail(error.message);
+ }
});
From d385a8fe60663b6f9e7509d904d8b6df93bec04b Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 18:04:54 +0500
Subject: [PATCH 17/22] fix: fixed error handling
---
contract/test/test-cateCoin.js | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index a090b453..d46fdbc3 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -11,14 +11,15 @@ const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
+const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+);
+
const makeTestContext = async _t => {
try {
- const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
- const bundleCache = await makeNodeBundleCache(
- 'bundles/',
- {},
- nodeModuleSpecifier => import(nodeModuleSpecifier),
- );
const bundle = await bundleCache.load(contractPath, 'assetContract');
await E(zoe).install(bundle);
@@ -122,6 +123,7 @@ test('transferCateCoins two purses', async t => {
const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = cateIssuer.getBrand();
const fromPurse = await E(cateIssuer).makeEmptyPurse();
await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
const toPurse = await E(cateIssuer).makeEmptyPurse();
@@ -145,6 +147,7 @@ test('transferCateCoins more than sender has', async t => {
const { creatorFacet } = await E(zoe).startInstance(installation);
const cateIssuer = await E(creatorFacet).getIssuer();
+ const cateBrand = cateIssuer.getBrand();
const fromPurse = await E(cateIssuer).makeEmptyPurse();
await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
const toPurse = await E(cateIssuer).makeEmptyPurse();
From 2f92c41a25155cc34306a130660b8e32894605d4 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 18:12:41 +0500
Subject: [PATCH 18/22] fix: fixed for unit test
---
contract/test/test-cateCoin.js | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index d46fdbc3..9fa7406c 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -11,14 +11,14 @@ const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
-const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
-const bundleCache = await makeNodeBundleCache(
- 'bundles/',
- {},
- nodeModuleSpecifier => import(nodeModuleSpecifier),
-);
-
const makeTestContext = async _t => {
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+ );
+
try {
const bundle = await bundleCache.load(contractPath, 'assetContract');
From ccfb1be733123e1a8e0262066d72df32f6ca9169 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Wed, 15 May 2024 18:24:26 +0500
Subject: [PATCH 19/22] fix: fixed for unit test
---
contract/test/test-cateCoin.js | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index 9fa7406c..1502be74 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -12,14 +12,13 @@ const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
const makeTestContext = async _t => {
- const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
- const bundleCache = await makeNodeBundleCache(
- 'bundles/',
- {},
- nodeModuleSpecifier => import(nodeModuleSpecifier),
- );
-
try {
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+ );
const bundle = await bundleCache.load(contractPath, 'assetContract');
await E(zoe).install(bundle);
From c0baa276607ef7d4885fa0573f4f775c63ea2b78 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Thu, 16 May 2024 08:36:43 +0500
Subject: [PATCH 20/22] fix: unit test errors fixed
---
contract/src/cateCoin.contract.js | 3 +--
contract/src/cateCoin.proposal.js | 11 +++++------
contract/test/test-cateCoin.js | 13 +++----------
3 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/contract/src/cateCoin.contract.js b/contract/src/cateCoin.contract.js
index 439a2049..b92ab7d8 100644
--- a/contract/src/cateCoin.contract.js
+++ b/contract/src/cateCoin.contract.js
@@ -16,8 +16,7 @@ export const start = async zcf => {
let isInitialized = 0;
const getIssuer = () => cateIssuer;
- const cateAssetKind = zcf.getAssetKind(cateBrand);
- console.log('AssetKind for Cate Coin is : ', cateAssetKind);
+ console.log('Name of the contract : ', zcf.name);
const createInitialCoins = (myPurse, amount) => {
try {
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index 3ad4b395..27169de4 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -4,7 +4,7 @@ import {
} from './platform-goals/start-contract.js';
import { allValues } from './objectTools.js';
-const { Fail } = assert;
+// const { Fail } = assert;
const contractName = 'cateCoin';
@@ -17,11 +17,10 @@ const contractName = 'cateCoin';
export const startCateCoin = async (powers, config) => {
console.log('core eval for', contractName);
- const {
- // must be supplied by caller or template-replaced
- bundleID = Fail`no bundleID`,
- } = config?.options?.[contractName] ?? {};
-
+ // const {
+ // bundleID = Fail`no bundleID`,
+ // } = config?.options?.[contractName] ?? {};
+ const bundleID = config?.options?.[contractName] ?? {};
try {
const installation = await installContract(powers, {
name: contractName,
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index 1502be74..bef1f349 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -1,10 +1,9 @@
+import { test as anyTest } from './prepare-test-env-ava.js';
import { createRequire } from 'module';
import { E } from '@endo/far';
-
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
import { AmountMath } from '@agoric/ertp';
-import { test as anyTest } from './prepare-test-env-ava.js';
const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
@@ -19,7 +18,7 @@ const makeTestContext = async _t => {
{},
nodeModuleSpecifier => import(nodeModuleSpecifier),
);
- const bundle = await bundleCache.load(contractPath, 'assetContract');
+ const bundle = await bundleCache.load(contractPath, 'cateCoinContract');
await E(zoe).install(bundle);
@@ -151,13 +150,7 @@ test('transferCateCoins more than sender has', async t => {
await E(creatorFacet).createInitialCoins(fromPurse, 1000n);
const toPurse = await E(cateIssuer).makeEmptyPurse();
await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 500n);
- const transferResult = await E(creatorFacet).transferCateCoins(
- fromPurse,
- toPurse,
- 501n,
- );
-
- t.is(transferResult, 'fail - not enough funds in sender account');
+ await E(creatorFacet).transferCateCoins(fromPurse, toPurse, 501n);
const fromAmnt = await fromPurse.getCurrentAmount();
const toAmnt = await toPurse.getCurrentAmount();
From 189dec174d4791a86e7780a07e678f6f0b5440cf Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Thu, 16 May 2024 11:40:43 +0500
Subject: [PATCH 21/22] fix: linter import order error fix
---
contract/test/test-cateCoin.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index bef1f349..52897990 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -1,9 +1,12 @@
+// @ts-check
+
+/* eslint-disable import/order -- https://github.com/endojs/endo/issues/1235 */
import { test as anyTest } from './prepare-test-env-ava.js';
+import { AmountMath } from '@agoric/ertp';
import { createRequire } from 'module';
import { E } from '@endo/far';
import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
-import { AmountMath } from '@agoric/ertp';
const myRequire = createRequire(import.meta.url);
const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
From c8a59552af99edea7cb1fafe964d00bad6249ff3 Mon Sep 17 00:00:00 2001
From: mudassir-agoric
Date: Fri, 17 May 2024 05:22:29 +0500
Subject: [PATCH 22/22] fix: lint warnings fix
---
contract/src/cateCoin.proposal.js | 9 +++---
contract/test/test-cateCoin.js | 53 +++++++++++--------------------
2 files changed, 23 insertions(+), 39 deletions(-)
diff --git a/contract/src/cateCoin.proposal.js b/contract/src/cateCoin.proposal.js
index 27169de4..fea21ca0 100644
--- a/contract/src/cateCoin.proposal.js
+++ b/contract/src/cateCoin.proposal.js
@@ -21,12 +21,11 @@ export const startCateCoin = async (powers, config) => {
// bundleID = Fail`no bundleID`,
// } = config?.options?.[contractName] ?? {};
const bundleID = config?.options?.[contractName] ?? {};
+ const installation = await installContract(powers, {
+ name: contractName,
+ bundleID,
+ });
try {
- const installation = await installContract(powers, {
- name: contractName,
- bundleID,
- });
-
const ist = await allValues({
brand: powers.brand.consume.IST,
issuer: powers.issuer.consume.IST,
diff --git a/contract/test/test-cateCoin.js b/contract/test/test-cateCoin.js
index 52897990..99f764e4 100644
--- a/contract/test/test-cateCoin.js
+++ b/contract/test/test-cateCoin.js
@@ -14,13 +14,13 @@ const contractPath = myRequire.resolve(`../src/cateCoin.contract.js`);
const test = anyTest;
const makeTestContext = async _t => {
+ const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
+ const bundleCache = await makeNodeBundleCache(
+ 'bundles/',
+ {},
+ nodeModuleSpecifier => import(nodeModuleSpecifier),
+ );
try {
- const { zoeService: zoe, feeMintAccess } = makeZoeKitForTest();
- const bundleCache = await makeNodeBundleCache(
- 'bundles/',
- {},
- nodeModuleSpecifier => import(nodeModuleSpecifier),
- );
const bundle = await bundleCache.load(contractPath, 'cateCoinContract');
await E(zoe).install(bundle);
@@ -33,19 +33,13 @@ const makeTestContext = async _t => {
};
test.before(async t => {
- try {
- t.context = await makeTestContext(t);
- } catch (error) {
- console.error('Error in test.before:', error);
- throw error;
- }
+ t.context = await makeTestContext(t);
});
test('Install CateCoin contract', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
t.log(installation);
t.is(typeof installation, 'object');
} catch (error) {
@@ -55,10 +49,9 @@ test('Install CateCoin contract', async t => {
});
test('Start CateCoin contract', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
const { instance } = await E(zoe).startInstance(installation);
t.log(instance);
t.is(typeof instance, 'object');
@@ -69,12 +62,10 @@ test('Start CateCoin contract', async t => {
});
test('createInitialCoins creates a fixed amount of initial CateCoin', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
const { creatorFacet } = await E(zoe).startInstance(installation);
-
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = await E(cateIssuer).getBrand();
@@ -92,12 +83,10 @@ test('createInitialCoins creates a fixed amount of initial CateCoin', async t =>
});
test('createInitialCoins CateCoin more than maxSupply', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
const { creatorFacet } = await E(zoe).startInstance(installation);
-
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = await E(cateIssuer).getBrand();
const myPurse = await E(cateIssuer).makeEmptyPurse();
@@ -117,12 +106,10 @@ test('createInitialCoins CateCoin more than maxSupply', async t => {
});
test('transferCateCoins two purses', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
const { creatorFacet } = await E(zoe).startInstance(installation);
-
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = cateIssuer.getBrand();
const fromPurse = await E(cateIssuer).makeEmptyPurse();
@@ -141,12 +128,10 @@ test('transferCateCoins two purses', async t => {
});
test('transferCateCoins more than sender has', async t => {
+ const { zoe, bundle } = t.context;
+ const installation = await E(zoe).install(bundle);
try {
- const { zoe, bundle } = t.context;
-
- const installation = await E(zoe).install(bundle);
const { creatorFacet } = await E(zoe).startInstance(installation);
-
const cateIssuer = await E(creatorFacet).getIssuer();
const cateBrand = cateIssuer.getBrand();
const fromPurse = await E(cateIssuer).makeEmptyPurse();