warp-contracts / warp

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

Internal write not working once a new warp connection is made #221

Closed arcj0 closed 2 years ago

arcj0 commented 2 years ago

To see the issue, here's a test app

After the internal write is made, you can see the state change, but if you read the contract using another WarpFactory connection, the claims aren't processed.

ppedziwiatr commented 2 years ago

Ok, I'm rewriting this to a jest test-case, cause testing and clicking in a browser is really counter productive.

ppedziwiatr commented 2 years ago

Reproduced in https://github.com/warp-contracts/warp/blob/ppe/aftr-joe-iw-issue/src/__tests__/integration/internal-writes/internal-write-aftr.test.ts#L91

ppedziwiatr commented 2 years ago

From further analysis - for some reason the interaction with IW does not show on a call stack

image

As a result, a tag 'Interact-Write' is not being generated.

ppedziwiatr commented 2 years ago

ok, I've found the root cause. I'll describe it in more details on Monday, but the fixes and some explanation are in this PR https://github.com/warp-contracts/warp/pull/223

Most important stuff: https://github.com/warp-contracts/warp/pull/223#pullrequestreview-1110971331 (see the comments in the contract code) https://github.com/warp-contracts/warp/pull/223#discussion_r973219409

Also - I've rewritten your vue example to a jest testcase - https://github.com/warp-contracts/warp/pull/223#discussion_r973222958

ppedziwiatr commented 2 years ago

To sum-up: Do not make SmartWeave.contracts.write and SmartWeave.contracts.readContractState in a same parent transaction on the same contract. The latest state of the callee contract (after making an internal write) is in the result returned by the SmartWeave.contracts.write.

ppedziwiatr commented 2 years ago

added protection in https://github.com/warp-contracts/warp/pull/223#issue-1376187865

ppedziwiatr commented 2 years ago

released in 1.2.7