Skip to content

Commit

Permalink
Update more cadence code
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Sep 19, 2023
1 parent c3a4757 commit bb3154c
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 114 deletions.
66 changes: 33 additions & 33 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/borrow_nft.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import NonFungibleToken from "NonFungibleToken"
import ExampleNFT from "ExampleNFT"

pub fun main(address: Address, id: UInt64) {
access(all) fun main(address: Address, id: UInt64) {
let account = getAccount(address)

let collectionRef = account
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_collection_ids.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import NonFungibleToken from "NonFungibleToken"
import ExampleNFT from "ExampleNFT"

pub fun main(address: Address, collectionPublicPath: PublicPath): [UInt64] {
access(all) fun main(address: Address, collectionPublicPath: PublicPath): [UInt64] {
let account = getAccount(address)

let collectionRef = account
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_collection_length.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NonFungibleToken from "NonFungibleToken"
import ExampleNFT from "ExampleNFT"

pub fun main(address: Address): Int {
access(all) fun main(address: Address): Int {
let account = getAccount(address)

let collectionRef = account
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_contract_storage_path.cdc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MetadataViews from "MetadataViews"
import ViewResolver from "ViewResolver"

pub fun main(addr: Address, name: String): StoragePath? {
access(all) fun main(addr: Address, name: String): StoragePath? {
let t = Type<MetadataViews.NFTCollectionData>()
let borrowedContract = getAccount(addr).contracts.borrow<&ViewResolver>(name: name)
?? panic("contract could not be borrowed")
Expand Down
52 changes: 26 additions & 26 deletions scripts/get_nft_metadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
import ExampleNFT from "ExampleNFT"
import MetadataViews from "MetadataViews"

pub struct NFT {
pub let name: String
pub let description: String
pub let thumbnail: String
pub let owner: Address
pub let type: String
pub let royalties: [MetadataViews.Royalty]
pub let externalURL: String
pub let serialNumber: UInt64
pub let collectionPublicPath: PublicPath
pub let collectionStoragePath: StoragePath
pub let collectionProviderPath: PrivatePath
pub let collectionPublic: String
pub let collectionPublicLinkedType: String
pub let collectionProviderLinkedType: String
pub let collectionName: String
pub let collectionDescription: String
pub let collectionExternalURL: String
pub let collectionSquareImage: String
pub let collectionBannerImage: String
pub let collectionSocials: {String: String}
pub let edition: MetadataViews.Edition
pub let traits: MetadataViews.Traits
pub let medias: MetadataViews.Medias?
pub let license: MetadataViews.License?
access(all) struct NFT {
access(all) let name: String
access(all) let description: String
access(all) let thumbnail: String
access(all) let owner: Address
access(all) let type: String
access(all) let royalties: [MetadataViews.Royalty]
access(all) let externalURL: String
access(all) let serialNumber: UInt64
access(all) let collectionPublicPath: PublicPath
access(all) let collectionStoragePath: StoragePath
access(all) let collectionProviderPath: PrivatePath
access(all) let collectionPublic: String
access(all) let collectionPublicLinkedType: String
access(all) let collectionProviderLinkedType: String
access(all) let collectionName: String
access(all) let collectionDescription: String
access(all) let collectionExternalURL: String
access(all) let collectionSquareImage: String
access(all) let collectionBannerImage: String
access(all) let collectionSocials: {String: String}
access(all) let edition: MetadataViews.Edition
access(all) let traits: MetadataViews.Traits
access(all) let medias: MetadataViews.Medias?
access(all) let license: MetadataViews.License?

init(
name: String,
Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct NFT {
}
}

pub fun main(address: Address, id: UInt64): NFT {
access(all) fun main(address: Address, id: UInt64): NFT {
let account = getAccount(address)

let collection = account
Expand Down
44 changes: 22 additions & 22 deletions scripts/get_nft_view.cdc
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import ExampleNFT from "ExampleNFT"
import MetadataViews from "MetadataViews"

pub struct NFTView {
pub let id: UInt64
pub let uuid: UInt64
pub let name: String
pub let description: String
pub let thumbnail: String
pub let royalties: [MetadataViews.Royalty]
pub let externalURL: String
pub let collectionPublicPath: PublicPath
pub let collectionStoragePath: StoragePath
pub let collectionProviderPath: PrivatePath
pub let collectionPublic: String
pub let collectionPublicLinkedType: String
pub let collectionProviderLinkedType: String
pub let collectionName: String
pub let collectionDescription: String
pub let collectionExternalURL: String
pub let collectionSquareImage: String
pub let collectionBannerImage: String
pub let collectionSocials: {String: String}
pub let traits: MetadataViews.Traits
access(all) struct NFTView {
access(all) let id: UInt64
access(all) let uuid: UInt64
access(all) let name: String
access(all) let description: String
access(all) let thumbnail: String
access(all) let royalties: [MetadataViews.Royalty]
access(all) let externalURL: String
access(all) let collectionPublicPath: PublicPath
access(all) let collectionStoragePath: StoragePath
access(all) let collectionProviderPath: PrivatePath
access(all) let collectionPublic: String
access(all) let collectionPublicLinkedType: String
access(all) let collectionProviderLinkedType: String
access(all) let collectionName: String
access(all) let collectionDescription: String
access(all) let collectionExternalURL: String
access(all) let collectionSquareImage: String
access(all) let collectionBannerImage: String
access(all) let collectionSocials: {String: String}
access(all) let traits: MetadataViews.Traits

init(
id: UInt64,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub struct NFTView {
}
}

pub fun main(address: Address, id: UInt64): NFTView {
access(all) fun main(address: Address, id: UInt64): NFTView {
let account = getAccount(address)

let collection = account
Expand Down
2 changes: 1 addition & 1 deletion scripts/get_total_supply.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ExampleNFT from "ExampleNFT"

pub fun main(): UInt64 {
access(all) fun main(): UInt64 {
return ExampleNFT.totalSupply
}
46 changes: 23 additions & 23 deletions tests/test_example_nft.cdc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Test

pub let blockchain = Test.newEmulatorBlockchain()
pub let admin = blockchain.createAccount()
pub let recipient = blockchain.createAccount()
access(all) let blockchain = Test.newEmulatorBlockchain()
access(all) let admin = blockchain.createAccount()
access(all) let recipient = blockchain.createAccount()

pub fun setup() {
access(all) fun setup() {
blockchain.useConfiguration(Test.Configuration({
"ExampleNFT": admin.address
}))
Expand All @@ -20,13 +20,13 @@ pub fun setup() {
Test.expect(err, Test.beNil())
}

pub fun testContractInitializedEventEmitted() {
access(all) fun testContractInitializedEventEmitted() {
let typ = CompositeType("A.01cf0e2f2f715450.ExampleNFT.ContractInitialized")!

Test.assertEqual(1, blockchain.eventsOfType(typ).length)
}

pub fun testGetTotalSupply() {
access(all) fun testGetTotalSupply() {
let code = Test.readFile("../scripts/get_total_supply.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -39,7 +39,7 @@ pub fun testGetTotalSupply() {
Test.assertEqual(0 as UInt64, totalSupply)
}

pub fun testSetupAccount() {
access(all) fun testSetupAccount() {
var code = Test.readFile("../transactions/setup_account.cdc")
let tx = Test.Transaction(
code: code,
Expand All @@ -63,7 +63,7 @@ pub fun testSetupAccount() {
Test.assertEqual(0, collectionLength)
}

pub fun testMintNFT() {
access(all) fun testMintNFT() {
var code = Test.readFile("../transactions/setup_account_to_receive_royalty.cdc")
var tx = Test.Transaction(
code: code,
Expand Down Expand Up @@ -112,7 +112,7 @@ pub fun testMintNFT() {
Test.assertEqual([0] as [UInt64], collectionIDs)
}

pub fun testTransferNFT() {
access(all) fun testTransferNFT() {
var code = Test.readFile("../transactions/transfer_nft.cdc")
let tx = Test.Transaction(
code: code,
Expand Down Expand Up @@ -148,7 +148,7 @@ pub fun testTransferNFT() {
Test.assertEqual([0] as [UInt64], collectionIDs)
}

pub fun testTransferMissingNFT() {
access(all) fun testTransferMissingNFT() {
var code = Test.readFile("../transactions/transfer_nft.cdc")
let tx = Test.Transaction(
code: code,
Expand All @@ -168,7 +168,7 @@ pub fun testTransferMissingNFT() {
)
}

pub fun testBorrowNFT() {
access(all) fun testBorrowNFT() {
let code = Test.readFile("../scripts/borrow_nft.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -181,7 +181,7 @@ pub fun testBorrowNFT() {
Test.expect(scriptResult, Test.beSucceeded())
}

pub fun testBorrowMissingNFT() {
access(all) fun testBorrowMissingNFT() {
let code = Test.readFile("../scripts/borrow_nft.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -194,7 +194,7 @@ pub fun testBorrowMissingNFT() {
Test.expect(scriptResult, Test.beFailed())
}

pub fun testGetCollectionIDs() {
access(all) fun testGetCollectionIDs() {
let code = Test.readFile("../scripts/get_collection_ids.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -210,7 +210,7 @@ pub fun testGetCollectionIDs() {
Test.assertEqual([0] as [UInt64], collectionIDs)
}

pub fun testGetCollectionLength() {
access(all) fun testGetCollectionLength() {
let code = Test.readFile("../scripts/get_collection_length.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -223,7 +223,7 @@ pub fun testGetCollectionLength() {
Test.assertEqual(1, collectionLength)
}

pub fun testGetContractStoragePath() {
access(all) fun testGetContractStoragePath() {
let code = Test.readFile("../scripts/get_contract_storage_path.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -239,7 +239,7 @@ pub fun testGetContractStoragePath() {
Test.assertEqual(/storage/exampleNFTCollection, storagePath)
}

pub fun testGetMissingContractStoragePath() {
access(all) fun testGetMissingContractStoragePath() {
let code = Test.readFile("../scripts/get_contract_storage_path.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -252,7 +252,7 @@ pub fun testGetMissingContractStoragePath() {
Test.expect(scriptResult, Test.beFailed())
}

pub fun testGetNFTMetadata() {
access(all) fun testGetNFTMetadata() {
let code = Test.readFile("scripts/get_nft_metadata.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -265,7 +265,7 @@ pub fun testGetNFTMetadata() {
Test.expect(scriptResult, Test.beSucceeded())
}

pub fun testGetMissingNFTMetadata() {
access(all) fun testGetMissingNFTMetadata() {
let code = Test.readFile("scripts/get_nft_metadata.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -278,7 +278,7 @@ pub fun testGetMissingNFTMetadata() {
Test.expect(scriptResult, Test.beFailed())
}

pub fun testGetNFTView() {
access(all) fun testGetNFTView() {
let code = Test.readFile("scripts/get_nft_view.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -291,7 +291,7 @@ pub fun testGetNFTView() {
Test.expect(scriptResult, Test.beSucceeded())
}

pub fun testGetMissingNFTView() {
access(all) fun testGetMissingNFTView() {
let code = Test.readFile("scripts/get_nft_view.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -304,7 +304,7 @@ pub fun testGetMissingNFTView() {
Test.expect(scriptResult, Test.beFailed())
}

pub fun testGetViews() {
access(all) fun testGetViews() {
let code = Test.readFile("scripts/get_views.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -317,7 +317,7 @@ pub fun testGetViews() {
Test.expect(scriptResult, Test.beSucceeded())
}

pub fun testGetExampleNFTViews() {
access(all) fun testGetExampleNFTViews() {
let code = Test.readFile("scripts/get_example_nft_views.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand All @@ -327,7 +327,7 @@ pub fun testGetExampleNFTViews() {
Test.expect(scriptResult, Test.beSucceeded())
}

pub fun testResolveExampleNFTViews() {
access(all) fun testResolveExampleNFTViews() {
let code = Test.readFile("scripts/resolve_nft_views.cdc")
let scriptResult = blockchain.executeScript(
code,
Expand Down
3 changes: 2 additions & 1 deletion transactions/destroy_nft.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ transaction(id: UInt64) {

prepare(signer: auth(BorrowValue) &Account) {
// borrow a reference to the owner's collection
self.collectionRef = signer.storage.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath)
self.collectionRef = signer.storage
.borrow<auth(NonFungibleToken.Withdrawable) &ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath)
?? panic("Account does not store an object at the specified path")
}

Expand Down
4 changes: 2 additions & 2 deletions transactions/setup_account.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MetadataViews from "MetadataViews"

transaction {

prepare(signer: auth(BorrowValue) &Account) {
prepare(signer: auth(BorrowValue, Capabilities) &Account) {
// Return early if the account already has a collection
if signer.storage.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) != nil {
return
Expand All @@ -24,7 +24,7 @@ transaction {
ExampleNFT.CollectionStoragePath
)
signer.capabilities.publish(
collectionCap
collectionCap,
at: ExampleNFT.CollectionPublicPath,
)
}
Expand Down
2 changes: 1 addition & 1 deletion transactions/setup_account_from_nft_reference.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ transaction(address: Address, publicPath: PublicPath, id: UInt64) {
)

signer.capabilities.publish(
collectionCap
collectionCap,
at: nftCollectionView.publicPath,
)
}
Expand Down
2 changes: 1 addition & 1 deletion transactions/setup_account_to_receive_royalty.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MetadataViews from "MetadataViews"

transaction(vaultPath: StoragePath) {

prepare(signer: auth(BorrowValue) &Account) {
prepare(signer: auth(BorrowValue, Capabilities) &Account) {

// Return early if the account doesn't have a FungibleToken Vault
if signer.storage.borrow<&FungibleToken.Vault>(from: vaultPath) == nil {
Expand Down

0 comments on commit bb3154c

Please sign in to comment.