public-awesome / cw-ics721

CosmWasm IBC NFT Transfers
MIT License
59 stars 31 forks source link

go-based e2e testing for callbacks and cw721 backward compatibility #101

Open taitruong opened 3 months ago

taitruong commented 3 months ago

cw-ics721 supports NFT transfer for cw721 v16 contracts and higher - up to latest version v18. Rn, e2e tests covers only v18: https://github.com/CosmWasm/cw-nfts/releases/tag/v0.18.0

e2e should cover tests for handling different

  1. cw721 contract versions: v16, v17 and latest v18 version
  2. cw721 code ids: when transferring an NFT, on target chain cw-ics721 creates a new collection (and NFT). For this CW721_CODE_ID store is used. Ideally all cw-ics721 contracts are using same version across all chains. But in reality this might not be the case. Like for Stargaze there is a custom sg721-base.

Search in go files where cw721_base_v0.18.0.wasm is used and uploaded.

Check in TestSendBetweenThreeIdenticalChains:

// Builds three identical chains A, B, and C then sends along the path
// A -> B -> C -> A -> C -> B -> A. If this works, likely most other
// things do too. :)
func TestSendBetweenThreeIdenticalChains(t *testing.T) {
...
}

Here it uses always cw721 v18 for transfering to chains A -> B -> C -> A -> C -> B -> A.

In instantiateCw721() and in instantiateBridge() it always uses cw721 v18.

A test case could be changing this:

wasm files are store in ./external-wasm, containing:

please note that for SG we also need sg_ics721.wasm

taitruong commented 3 months ago

There is a callback bug fix in PR #98 - so this issue should work on this PR branch class_id_fix.

The callback is as follows:

So for receive callback there are 3 test cases:

  1. initial nft transfer, where no nft contract is created yet by ics721 on target chain
  2. 2nd NFT transfer, with exsiting nft contract - instantiated and escrowed by ics721
  3. CW721_CODE_ID has changed to another code id in ics721, 3rd NFT transfer should also work

For all 3 test cases, callbacks are ALWAYS executed on the same, escrowed nft contract on target chain!

Receive callback should work on both cases.