warp-contracts / warp

An implementation of the Arweave SmartWeave smart contracts protocol.
MIT License
159 stars 44 forks source link

bug: Internal writers #326

Closed koonopek closed 1 year ago

koonopek commented 1 year ago

I have a problem when trying to do internal writes. Internal "reads" work correctly.

Code:

await SmartWeave.contracts.write(this.nftContractId,
     { function: 'transfer', tokenId: this.nftId, to: this.owner }
);
// nftContractId - is initialized with existing contractId

Full repo: https://github.com/warp-contracts/teleport To reproduce run npm install npm run test:warp

Error:

FAILED should cancel if stage = PENDING
              duration_ms: 767.67275
              failureType: 'testCodeFailure'
              error: |-
                Cannot create interaction: TypeError: Cannot read properties of undefined (reading 'manifest')
                    at HandlerBasedContract.createExecutionContext (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:372:81)
                    at async HandlerBasedContract.readState (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:120:34)
                    at async CacheableStateEvaluator.doReadState (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/DefaultStateEvaluator.js:104:21)
                    at async CacheableStateEvaluator.eval (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/CacheableStateEvaluator.js:74:16)
                    at async HandlerBasedContract.callContractForTx (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:492:33)
                    at async HandlerBasedContract.dryWriteFromTx (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:160:16)
                    at async swGlobal.contracts.write (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/handler/AbstractContractHandler.js:37:28)
                    at async Offer.cancel (eval at create (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/HandlerExecutorFactory.js:222:42), <anonymous>:100:13)
                    at async JsHandlerApi.handle [as contractFunction] (eval at create (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/HandlerExecutorFactory.js:222:42), <anonymous>:41:43)
                    at async JsHandlerApi.handle (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/handler/JsHandlerApi.js:30:35)
              code: 'ERR_TEST_FAILURE'
              stack: |-
                HandlerBasedContract.createExecutionContext (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:372:81)
                async HandlerBasedContract.readState (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:120:34)
                async CacheableStateEvaluator.doReadState (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/DefaultStateEvaluator.js:104:21)
                async CacheableStateEvaluator.eval (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/CacheableStateEvaluator.js:74:16)
                async HandlerBasedContract.callContractForTx (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:492:33)
                async HandlerBasedContract.dryWriteFromTx (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:160:16)
                async swGlobal.contracts.write (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/handler/AbstractContractHandler.js:37:28)
                async Offer.cancel (eval at create (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/HandlerExecutorFactory.js:222:42), <anonymous>:100:13)
                async JsHandlerApi.handle [as contractFunction] (eval at create (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/HandlerExecutorFactory.js:222:42), <anonymous>:41:43)
                async JsHandlerApi.handle (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/core/modules/impl/handler/JsHandlerApi.js:30:35)
                HandlerBasedContract.createInteraction (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:253:23)
                async HandlerBasedContract.writeInteraction (/Users/michalkonopka/code/github.com/teleport/node_modules/warp-contracts/lib/cjs/contract/HandlerBasedContract.js:195:35)
                async Object.<anonymous> (file:///Users/michalkonopka/code/github.com/teleport/warp-contracts/offer.warp.test.js:242:13)
                async ItTest.run (node:internal/test_runner/test:544:9)
                async Suite.processPendingSubtests (node:internal/test_runner/test:303:7)
ppedziwiatr commented 1 year ago

@koonopek , can you please verify on https://github.com/warp-contracts/warp/pull/311#issuecomment-1385074003 (1.2.48-beta.1 version)?

koonopek commented 1 year ago

Works like a charm! Please close issue, if you find this solution sufficient from you side, for me its perfectly ok to use beta :)

ppedziwiatr commented 1 year ago

cool, the above PR should be 'soon' merged into the main, so I won't put more time into this right now :-)