Skip to content

Commit

Permalink
TestWrappedDepositDoesntWorkDifferentAddress (#32)
Browse files Browse the repository at this point in the history
I think this meets the intent of the test, but not 100% sure: mint to
wrong account

Co-authored-by: ash <[email protected]>
  • Loading branch information
web3ashlee and ash authored Dec 20, 2023
1 parent fdcbbef commit 8cd20e3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/FlowtyWrapped_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions transactions/fail_mint_to_wrong_account.cdc
Original file line number Diff line number Diff line change
@@ -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)

}
}

0 comments on commit 8cd20e3

Please sign in to comment.