diff --git a/test/FlowtyWrapped_tests.cdc b/test/FlowtyWrapped_tests.cdc index 98742e4..833a228 100644 --- a/test/FlowtyWrapped_tests.cdc +++ b/test/FlowtyWrapped_tests.cdc @@ -57,6 +57,26 @@ pub fun testGetEditions() { scriptExecutor("get_editions_flowty_wrapped.cdc", [acct.address, nftID1]) } +pub fun testDepositToWrongAddressFails() { + let acct = Test.createAccount() + let wrongAccount = Test.createAccount() + + + txExecutor("setup_flowty_wrapped.cdc", [acct], [], nil) + txExecutor("setup_flowty_wrapped.cdc", [wrongAccount], [], nil) + + + let username: String = "user1" + let ticket: Int = 1 + let totalNftsOwned: Int = 1 + let floatCount: Int = 1 + let favoriteCollections: [String] = [""] + let collections: [String] = [""] + + txExecutor("fail_mint_to_wrong_account.cdc", [minterAccount], [acct.address, wrongAccount.address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], "The NFT must be owned by the collection owner") + +} + pub fun setupForMint(acct: Test.Account) { txExecutor("setup_flowty_wrapped.cdc", [acct], [], nil) diff --git a/transactions/fail_mint_to_wrong_account.cdc b/transactions/fail_mint_to_wrong_account.cdc new file mode 100644 index 0000000..810ff68 --- /dev/null +++ b/transactions/fail_mint_to_wrong_account.cdc @@ -0,0 +1,34 @@ +import "FungibleToken" +import "FlowtyWrapped" +import "NonFungibleToken" +import "MetadataViews" +import "WrappedEditions" + +transaction(address: Address, wrongAccount:Address, username: String, ticket: Int, totalNftsOwned: Int, floatCount: Int, favoriteCollections: [String], collections: [String]) { + // local variable for storing the minter reference + let minter: &FlowtyWrapped.Admin + + prepare(acct: AuthAccount) { + //borrow a reference to the NFTMinter resource in storage + self.minter = acct.borrow<&FlowtyWrapped.Admin>(from: FlowtyWrapped.AdminStoragePath) + ?? panic("Could not borrow a reference to the NFT minter") + } + + execute { + let wrapped2023Data = WrappedEditions.Wrapped2023Data( + username, + ticket, + totalNftsOwned, + floatCount, + favoriteCollections, + collections + ) + let data: {String: AnyStruct} = { + "wrapped": wrapped2023Data + } + let receiver = getAccount(wrongAccount).getCapability<&{NonFungibleToken.CollectionPublic}>(FlowtyWrapped.CollectionPublicPath).borrow()! + let nft <- self.minter.mintNFT(editionName: "Flowty Wrapped 2023", address: address, data: data ) + receiver.deposit(token: <-nft) + + } +}