Agoric / dapp-orchestration-basics

Agoric Orchestration Sample dApp
2 stars 3 forks source link

contract test to act like UI client #20

Open dckc opened 2 months ago

dckc commented 2 months ago

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 }:

https://github.com/Agoric/dapp-orchestration-basics/blob/2379c1a3370387b7017b4a5ed9e6e8278e353fe0/contract/test/orca-contract.test.js#L428-L433

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:

https://github.com/Agoric/dapp-orchestration-basics/blob/2379c1a3370387b7017b4a5ed9e6e8278e353fe0/contract/test/orca-contract.test.js#L437

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

So the offer handler doesn't actually run.

cc @Jovonni @turadg

dckc commented 2 months ago

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 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 commented 2 months ago

interesting, good catch.

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

dckc commented 1 month ago

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

https://github.com/Agoric/dapp-orchestration-basics/blob/486f4eb6e0586542661420cc5a1c494a2380cc46/contract/test/orca-contract.test.js#L217-L230