Skip to content

Commit

Permalink
update transactions get get Go tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Jan 31, 2024
1 parent d2b571f commit 58c75f2
Show file tree
Hide file tree
Showing 29 changed files with 376 additions and 750 deletions.
21 changes: 14 additions & 7 deletions contracts/BasicNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ access(all) contract BasicNFT: NonFungibleToken {
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
switch viewType {
case Type<MetadataViews.NFTCollectionData>():
let collectionRef = self.account.storage.borrow<&ExampleNFT.Collection>(
from: /storage/cadenceExampleNFTCollection
let collectionRef = self.account.storage.borrow<&UniversalCollection.Collection>(
from: /storage/flowBasicNFTCollection
) ?? panic("Could not borrow a reference to the stored collection")

return collectionRef.getNFTCollectionDataView()
let collectionData = MetadataViews.NFTCollectionData(
storagePath: collectionRef.storagePath,
publicPath: collectionRef.publicPath,
publicCollection: Type<&UniversalCollection.Collection>(),
publicLinkedType: Type<&UniversalCollection.Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
return <-BasicNFT.createEmptyCollection(nftType: Type<@BasicNFT.NFT>())
})
)
return collectionData
case Type<MetadataViews.NFTCollectionDisplay>():
let media = MetadataViews.Media(
file: MetadataViews.HTTPFile(
Expand Down Expand Up @@ -122,9 +130,8 @@ access(all) contract BasicNFT: NonFungibleToken {
let minter <- create NFTMinter()
self.account.storage.save(<-minter, to: /storage/flowBasicNFTMinterPath)

let collection <- self.createEmptyCollection(nftType: Type<@BasicNFT.NFT>()>)
let dataView = collection.getNFTCollectionDataView()
self.account.storage.save(collection, to: dataView.storagePath)
let collection <- self.createEmptyCollection(nftType: Type<@BasicNFT.NFT>())
self.account.storage.save(<-collection, to: /storage/flowBasicNFTCollection)
}
}

2 changes: 1 addition & 1 deletion contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ access(all) contract ExampleNFT: NonFungibleToken {
publicCollection: Type<&ExampleNFT.Collection>(),
publicLinkedType: Type<&ExampleNFT.Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
return <-collectionRef.createEmptyCollection()
return <-ExampleNFT.createEmptyCollection(nftType: Type<@ExampleNFT.NFT>())
})
)
return collectionData
Expand Down
3 changes: 0 additions & 3 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,6 @@ access(all) contract MetadataViews {
publicLinkedType: Type,
createEmptyCollectionFunction: fun(): @{NonFungibleToken.Collection}
) {
pre {
publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Receiver, ViewResolver.ResolverCollection}>()): "Public type must include NonFungibleToken.Receiver and ViewResolver.ResolverCollection interfaces."
}
self.storagePath=storagePath
self.publicPath=publicPath
self.publicCollection=publicCollection
Expand Down
16 changes: 2 additions & 14 deletions contracts/UniversalCollection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@ access(all) contract UniversalCollection {
/// Dictionary mapping NFT IDs to the stored NFTs
access(contract) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}

access(self) var storagePath: StoragePath
access(self) var publicPath: PublicPath

access(all) fun getNFTCollectionDataView(): AnyStruct {
return MetadataViews.NFTCollectionData(
storagePath: StoragePath(identifier: self.identifier)!,
publicPath: PublicPath(identifier: self.identifier)!,
publicCollection: Type<&UniversalCollection.Collection>(),
publicLinkedType: Type<&UniversalCollection.Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
return <-self.createEmptyCollection()
})
)
}
access(all) var storagePath: StoragePath
access(all) var publicPath: PublicPath

access(all) fun createEmptyCollection(): @{NonFungibleToken.Collection} {
return <- create Collection(identifier: self.identifier, type: self.supportedType)
Expand Down
24 changes: 12 additions & 12 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

78 changes: 39 additions & 39 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions lib/go/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.18

require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/onflow/cadence v1.0.0-preview.2.0.20240120000236-f3397a0efdad
github.com/onflow/flow-emulator v0.59.1-0.20240122200325-58ef35ed4aed
github.com/onflow/flow-go-sdk v0.44.1-0.20240124213231-78d9f08eeae1
github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240120002146-9f1763b66d80
github.com/onflow/flow-nft/lib/go/templates v0.0.0-00010101000000-000000000000
github.com/onflow/cadence v1.0.0-M4
github.com/onflow/flow-emulator v1.0.0-M1
github.com/onflow/flow-go-sdk v1.0.0-M1
github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20240125205553-d2b571fb3fad
github.com/onflow/flow-nft/lib/go/templates v0.0.0-20240125205553-d2b571fb3fad
github.com/rs/zerolog v1.29.0
github.com/stretchr/testify v1.8.4
)
Expand Down Expand Up @@ -113,11 +113,10 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect
github.com/onflow/crypto v0.25.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20240120002724-ff3d1a4bab55 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20240120002724-ff3d1a4bab55 // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240109231227-22564b43846d // indirect
github.com/onflow/flow-go v0.33.2-0.20240122190738-254af677b873 // indirect
github.com/onflow/flow-go/crypto v0.25.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v0.15.1-0.20240125214229-b7a95136dd0d // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.1-0.20240125214229-b7a95136dd0d // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20240125205519-2e80d9b4bd01 // indirect
github.com/onflow/flow-go v0.33.2-0.20240126002816-f0770a716d61 // indirect
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231213135419-ae911cc351a2 // indirect
github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
Expand All @@ -139,7 +138,7 @@ require (
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand Down Expand Up @@ -195,6 +194,6 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)

// replace github.com/onflow/flow-nft/lib/go/contracts => ../contracts
replace github.com/onflow/flow-nft/lib/go/contracts => ../contracts

// replace github.com/onflow/flow-nft/lib/go/templates => ../templates
replace github.com/onflow/flow-nft/lib/go/templates => ../templates
Loading

0 comments on commit 58c75f2

Please sign in to comment.