Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract test to act like UI client #20

Open
dckc opened this issue Aug 16, 2024 · 3 comments · May be fixed by #25
Open

contract test to act like UI client #20

dckc opened this issue Aug 16, 2024 · 3 comments · May be fixed by #25

Comments

@dckc
Copy link
Member

dckc commented Aug 16, 2024

It's important to have a test to nail down the interface between the contract and clients such as the UI.

I'm pretty sure the contract requires offerArgs of the form { chainName } and the UI supplies that when it makes offers.

The test code, on the other hand, provides offerArgs of the form { id: offerId }:

const initialUserSeat = await E(zoe).offer(
initialInvitation,
makeAccountOffer,
undefined,
{ id: offerId },
);

I was surprised that this test code works.

Diagnosis: the offer handler in the contract is an async flow, so it returns a vow. The client code in the test doesn't resolve the vow:

const offerResult = await E(initialUserSeat).getOfferResult();

    ℹ offer result: Object @Vow {
        payload: {
          vowV0: Object @Alleged: VowInternalsKit vowV0 {},
        },
      }

So the offer handler doesn't actually run.

cc @Jovonni @turadg

@dckc
Copy link
Member Author

dckc commented Aug 16, 2024

If we resolve the vow, we see that the test fails.

  orchestrate - osmosis makeAccount returns a ContinuingOfferResult
  Rejected promise returned by test. Reason:

  Error {
    message: 'In "getChain" method of (Orchestrator orchestrator): arg 0: undefined "[undefined]" - Must be a string',
  }
change to resolve the vow
diff --git a/contract/package.json b/contract/package.json
index f176af3..79b9fc3 100644
--- a/contract/package.json
+++ b/contract/package.json
@@ -30,7 +30,6 @@
     "@agoric/time": "dev",
     "@agoric/vat-data": "dev",
     "@agoric/xsnap": "dev",
-    "@agoric/zone": "^0.2.2",
     "@cosmjs/amino": "^0.32.3",
     "@cosmjs/proto-signing": "^0.32.3",
     "@endo/eslint-plugin": "^2.2.0",
diff --git a/contract/src/orca.flows.js b/contract/src/orca.flows.js
index e9cccf1..91426fb 100644
--- a/contract/src/orca.flows.js
+++ b/contract/src/orca.flows.js
@@ -21,7 +21,7 @@ const trace = makeTracer('OrchFlows');
  * @param {ZCFSeat} seat
  * @param {{ chainName: string }} offerArgs
  */
-export const makeAccount = async (orch, _ctx, seat, { chainName }) => {
+export const makeAccount = async (orch, _ctx, seat, offerArgs) => {
   const { give } = seat.getProposal();
   trace('version 0.1.36');
   trace('give');
@@ -31,8 +31,9 @@ export const makeAccount = async (orch, _ctx, seat, { chainName }) => {
   trace(orch);
   trace('seat');
   trace(seat);
-  trace(chainName);
+  trace(offerArgs);
   seat.exit();
+  const { chainName } = offerArgs;
   const chain = await orch.getChain(chainName);
   trace('chain object');
   trace(chain);
diff --git a/contract/test/orca-contract.test.js b/contract/test/orca-contract.test.js
index 36d5706..eee1248 100644
--- a/contract/test/orca-contract.test.js
+++ b/contract/test/orca-contract.test.js
@@ -9,6 +9,8 @@ import { E, Far } from '@endo/far';
 import { makeNodeBundleCache } from '@endo/bundle-source/cache.js';
 import { makeZoeKitForTest } from '@agoric/zoe/tools/setup-zoe.js';
 import { AmountMath, makeIssuerKit } from '@agoric/ertp';
+import { makeHeapZone } from '@agoric/zone';
+import { prepareSwingsetVowTools } from '@agoric/vow/vat.js';
 
 import { startOrcaContract } from '../src/orca.proposal.js';
 
@@ -42,6 +44,9 @@ const makeTestContext = async t => {
   const bundle = await bundleCache.load(contractPath, 'orca');
   const tools = await makeMockTools(t, bundleCache);
 
+  const rootZone = makeHeapZone();
+  const vowTools = prepareSwingsetVowTools(rootZone.subZone('vows'));
+
   const makeDummyStorageNode = (nodeName = 'rootNode') => {
     return Far('DummyStorageNode', {
       makeChildNode: async childName => {
@@ -210,6 +215,7 @@ const makeTestContext = async t => {
     agoricNames,
     storageNode: makeDummyStorageNode(),
     marshaller: makeDummyMarshaller(),
+    vowTools,
     ...tools,
   };
 };
@@ -384,6 +390,7 @@ const orchestrationAccountScenario = test.macro({
       agoricNames,
       storageNode,
       marshaller,
+      vowTools: vt,
     } = t.context;
     t.log('installing the contract...');
     const installation = E(zoe).install(bundle);
@@ -434,7 +441,7 @@ const orchestrationAccountScenario = test.macro({
     t.log('initial user seat:', initialUserSeat);
 
     t.log('getting offer result...');
-    const offerResult = await E(initialUserSeat).getOfferResult();
+    const offerResult = await vt.when(E(initialUserSeat).getOfferResult());
     t.log('offer result:', offerResult);
     t.truthy(offerResult, 'Offer result should exist');
 
diff --git a/yarn.lock b/yarn.lock
index 56e39bb..ae19072 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2090,7 +2090,7 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@agoric/zone@npm:0.2.3-dev-7f12e80.0+7f12e80":
+"@agoric/zone@npm:0.2.3-dev-7f12e80.0+7f12e80, @agoric/zone@npm:dev":
   version: 0.2.3-dev-7f12e80.0
   resolution: "@agoric/zone@npm:0.2.3-dev-7f12e80.0"
   dependencies:
@@ -10877,7 +10877,7 @@ __metadata:
     "@agoric/vow": "npm:dev"
     "@agoric/xsnap": "npm:dev"
     "@agoric/zoe": "npm:dev"
-    "@agoric/zone": "npm:^0.2.2"
+    "@agoric/zone": "npm:dev"
     "@cosmjs/amino": "npm:^0.32.3"
     "@cosmjs/proto-signing": "npm:^0.32.3"
     "@endo/bundle-source": "npm:^3.3.0"

@Jovonni
Copy link
Contributor

Jovonni commented Aug 16, 2024

interesting, good catch.

This test wasn't updated when we added the offer arg for chainName 🙏🏽

@dckc
Copy link
Member Author

dckc commented Sep 24, 2024

In the current tests, vstorage queries are mocked in such a way that they're completely disconnected from the operation of the contract:

const makeQueryToolMock = () => {
return {
queryData: async path => {
console.log(`Querying data at path: ${path}`);
if (path.includes('wallet')) {
return {
offerToPublicSubscriberPaths: [['offerId', { account: 'osmo1abc' }]],
status: {
id: 'offerId',
numWantsSatisfied: 1,
result: 'UNPUBLISHED',
error: undefined,
},
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants