From 84f5badbc23be4e58da99a0f4a4e0af343fd272f Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Mon, 9 Sep 2024 07:20:19 -0700 Subject: [PATCH 1/2] fix issues causing nft borrowing and data resolution to not work --- contracts/nft/BaseCollection.cdc | 2 +- contracts/nft/BaseNFT.cdc | 4 ++-- contracts/nft/UniversalCollection.cdc | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/contracts/nft/BaseCollection.cdc b/contracts/nft/BaseCollection.cdc index 7a9203f..ef2482f 100644 --- a/contracts/nft/BaseCollection.cdc +++ b/contracts/nft/BaseCollection.cdc @@ -23,7 +23,7 @@ access(all) contract interface BaseCollection: ViewResolver { token.getType() == self.nftType: "unexpected nft type being deposited" } - destroy self.ownedNFTs.insert(key: token.uuid, <-token) + destroy self.ownedNFTs.insert(key: token.id, <-token) } access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? { diff --git a/contracts/nft/BaseNFT.cdc b/contracts/nft/BaseNFT.cdc index bda3e66..aae87aa 100644 --- a/contracts/nft/BaseNFT.cdc +++ b/contracts/nft/BaseNFT.cdc @@ -42,7 +42,7 @@ access(all) contract interface BaseNFT: ViewResolver { access(all) fun resolveView(_ view: Type): AnyStruct? { if view == Type() { - return self.id + return MetadataViews.Serial(self.id) } let rt = self.getType() @@ -75,7 +75,7 @@ access(all) contract interface BaseNFT: ViewResolver { } ) case Type(): - return md.collectionInfo.collectionDisplay + return md.collectionInfo.getDisplay() } if let entry = md.borrowMetadata(id: self.metadataID) { diff --git a/contracts/nft/UniversalCollection.cdc b/contracts/nft/UniversalCollection.cdc index 9f53021..d65b452 100644 --- a/contracts/nft/UniversalCollection.cdc +++ b/contracts/nft/UniversalCollection.cdc @@ -14,6 +14,18 @@ access(all) contract UniversalCollection { return <- create Collection(nftType: self.nftType) } + access(all) fun deposit(token: @{NonFungibleToken.NFT}) { + pre { + token.getType() == self.nftType: "unexpected nft type being deposited" + } + + destroy self.ownedNFTs.insert(key: token.id, <-token) + } + + access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? { + return &self.ownedNFTs[id] + } + init (nftType: Type) { self.ownedNFTs <- {} self.nftType = nftType From 74f835f105d43efd338ae56cdd67e06d721e990c Mon Sep 17 00:00:00 2001 From: Austin Kline Date: Mon, 9 Sep 2024 07:29:49 -0700 Subject: [PATCH 2/2] fix test file --- run-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.sh b/run-tests.sh index a093fec..6b4cdb3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -2,4 +2,4 @@ set -e -flow-c1 test --cover --covercode="contracts" --coverprofile="coverage.lcov" tests/*_tests.cdc +flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" tests/*_tests.cdc