Skip to content

Commit

Permalink
Added ICS721 incoming proxy in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Jun 23, 2024
1 parent 6590d4f commit d8d89f4
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ release/
*.ign

cw-ics721/
cw-ics721-proxy/
cw-nfts/
astral/

Expand Down
78 changes: 76 additions & 2 deletions interslothtest/ics721/ics721_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,83 @@ func (s *ICS721TestSuite) TestICS721() {
sgUser,
slothUser,
"1")
_ = classID
_ = classID // wasm.lazy1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtq8xhtac/channel-2/stars14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9srsl6sm
// wasm.lazyics721/slothchannel/starscontract

tokens := s.AllNFTs(slothChainCW721)
s.AssertPacketRelayed(s.Stargaze, nftSetup.SlothPort, nftSetup.SlothChainChannel, 1)

tokens := s.AllNFTs(s.Slothchain, slothChainCW721)
s.Len(tokens, 1)
s.Equal("1", tokens[0]) // 🦥🚀

s.TransferSlothToStargaze(nftSetup, slothUser, sgUser, "1", slothChainCW721)
}

func (s *ICS721TestSuite) TestIncomingProxy() {
users := interchaintest.GetAndFundTestUsers(s.T(), s.Ctx, s.T().Name(), math.NewInt(10_000_000_000), s.Stargaze, s.Slothchain)
sgUser, slothUser := users[0], users[1]

nftSetup := s.DeployNFTSetup(sgUser, slothUser, "../test-artifacts")
nonSlothCW721CodeID := s.StoreCW721(s.Stargaze, sgUser.KeyName(), "../test-artifacts")
nonSlothContractAddress := s.InstantiateCW721(nonSlothCW721CodeID, sgUser.KeyName(), "NOT A SLOTH", "NAS", sgUser.FormattedAddress())

s.MintNFTs(nonSlothContractAddress, sgUser.KeyName(), sgUser.FormattedAddress(), []string{"1", "2", "3"})

s.NoError(s.Relayer.StartRelayer(s.Ctx, s.RelayerExecRep, s.StargazeSlothPath))
s.NoError(testutil.WaitForBlocks(s.Ctx, 5, s.Stargaze, s.Slothchain))

err := s.TransferNFT(s.Stargaze, sgUser, slothUser, "1", nonSlothContractAddress, nftSetup.SGICS721Contract, nftSetup.SGChannel)
s.NoError(err) // The transfer message itself on stargaze should succeed

s.NoError(testutil.WaitForBlocks(s.Ctx, 10, s.Stargaze, s.Slothchain, s.Celestia))

// Check that the token fails to actually transfer
s.AssertPacketRelayed(s.Stargaze, nftSetup.SlothPort, nftSetup.SlothChainChannel, 1)

cmd := "message.action='/ibc.core.channel.v1.MsgRecvPacket'"
// cmd := "message.action=/ibc.core.channel.v1.MsgRecvPacket"
txSearchRes, err := s.QueryTxsByEvents(s.Slothchain, 1, 10, cmd, "")
s.Require().NoError(err)
s.Require().Len(txSearchRes.Txs, 1)

errorMessage, isFound := s.ExtractValueFromEvents(
txSearchRes.Txs[0].Events,
"write_acknowledgement",
"packet_ack",
)

s.Require().True(isFound)
s.Require().Equal(errorMessage, "{\"error\":\"codespace: wasm, code: 5\"}")

type Response struct {
Data [][]string `json:"data"`
}
var resp Response
s.NoError(s.Slothchain.QueryContract(s.Ctx, nftSetup.SlothChainICS721Contract, "{\"nft_contracts\": {}}", &resp))
s.Len(resp.Data, 0)
// Update the incoming proxy with the non-sloth contract address to verify it works after the update
s.MigrateICS721IncomingProxy(
s.Slothchain,
slothUser.KeyName(),
"../test-artifacts",
nftSetup.SlothChainICS721IncomingProxyContract,
nonSlothContractAddress,
nftSetup.SlothChainICS721Contract,
nftSetup.SlothChainChannel,
)

err = s.TransferNFT(s.Stargaze, sgUser, slothUser, "1", nonSlothContractAddress, nftSetup.SGICS721Contract, nftSetup.SGChannel)
s.NoError(err)

s.NoError(testutil.WaitForBlocks(s.Ctx, 10, s.Stargaze, s.Slothchain, s.Celestia))

// Check that the token fails to actually transfer
s.AssertPacketRelayed(s.Stargaze, nftSetup.SlothPort, nftSetup.SlothChainChannel, 1)

s.NoError(s.Slothchain.QueryContract(s.Ctx, nftSetup.SlothChainICS721Contract, "{\"nft_contracts\": {}}", &resp))
s.Len(resp.Data, 1)

tokens := s.AllNFTs(s.Slothchain, resp.Data[0][1])
s.Len(tokens, 1)
s.Equal("1", tokens[0]) // 🦥🚀
}
Binary file not shown.
Loading

0 comments on commit d8d89f4

Please sign in to comment.