NEAR-DevHub / neardevhub-contract

DevHub Portal Product Contract (Hosted on NEAR Blockchain) – Includes other instances (e.g. Infrastructure, Events)
https://neardevhub.org
19 stars 15 forks source link

Updated near-sdk dependency #26

Closed gautamprikshit1 closed 1 year ago

gautamprikshit1 commented 1 year ago

Updated near-sdk to v4.1.1. Fixes #23

gautamprikshit1 commented 1 year ago

@frol please help me with migrating cross contract calls.

frol commented 1 year ago

@gautamprikshit1 Can you be more specific? What exactly do you need help with?

Here are some good starting points with cross-contract calls implementation:

gautamprikshit1 commented 1 year ago

https://github.com/gautamprikshit1/neardevhub-contract/blob/2f29abc93de4f1de91b9026bd5eb49ed48df17fb/src/notify.rs#L19

This line generates an error post upgrade, cannot find function in ext_scoial_db

frol commented 1 year ago

@ailisp Can you take a look and maybe check it locally? (it is getting late here)

ailisp commented 1 year ago

https://github.com/gautamprikshit1/neardevhub-contract/blob/2f29abc93de4f1de91b9026bd5eb49ed48df17fb/src/notify.rs#L19

This line generates an error post upgrade, cannot find function in ext_scoial_db

this because it tries cross contract call social.near on mainnet. If you're testing on sandbox or testnet it's not exist. You can test by either deploy to mainnet, or deploy a socialdb contract to sandbox/testnet.

frol commented 1 year ago

@gautamprikshit1 Here is the guide on how to set things up on testnet:

Compile the contract to Wasm:

$ sh build.sh

Create testnet account if you don't have one yet: https://wallet.testnet.near.org/

Log into the account from the terminal (install near.cli.rs):

$ near account import-account using-web-wallet network-config testnet

Deploy the res/devgovgigs.wasm file to your account:

$ near contract deploy use-file 'res/devgovgigs.wasm' with-init-call new json-args '{}' prepaid-gas '100.000 TeraGas' attached-deposit '0 NEAR' network-config testnet

Deploy devhub-widgets following this guide.

Go to https://test.near.social/ and sign in there, and open the Feed page of DevHub components deployed on the previous step to your account, and check that it works as expected try creating a new post, comment on it, etc, and report back.

gautamprikshit1 commented 1 year ago

image Everthing works fine except that one rendering error

frol commented 1 year ago

@gautamprikshit1 I had to revert this PR (https://github.com/near/neardevhub-contract/commit/8fc1fdd54237c646d16b25cbf5bbd7d84a7a4a49) as it caused "panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidData, error: ParseAccountIdError }" on any call to the contract.

Please, test the migration path with the following:

  1. Re-create or create a fresh account on testnet
  2. Compile and deploy an old version of the contract (you can use the current main branch)
  3. (if you created a new account) deploy the devhub-widgets there, otherwise skip this step
  4. Create all types of posts (idea, solution) and replies (attestation, sponsorship with "USD" and "NEAR" as inputs)
  5. Deploy the new version of the contract (from your PR)
  6. Try making a view call, e.g.: near contract call-function as-read-only devgovgigs.near 'get_children_ids' json-args '{}' network-config 'mainnet' now (change the account id and network connection name [testnet])

It would be great to have tests suite using workspaces-rs to catch such migration issues.

gautamprikshit1 commented 1 year ago

@frol so I have to deploy the old contract and upgrade it to the newer one

frol commented 1 year ago

@gautamprikshit1 Yes, this is the way to reproduce the issue, and then we will need to solve it. I believe it will require writing a migration: https://github.com/near/neardevhub-contract/blob/main/src/migrations.rs

Given that the error message mentions a ParseAccountIdError, my wild guess is that it is SponsorshipToken that is at blame as previously USD was not parsed and was just passed as address account and AccountId type was not a strictly-validated type, but just a String alias, so it accepted "usd" as address just fine, but now it tries to read it as a valid account id and fails. Thus the migration should go through all the SponsortShip posts and update the SponsorshipToken to either ::USD or proper address in ::NEP141 (FYI, NEP is an abbreviatiation that denotes standards in NEAR ecosystem)