Skip to content

Commit

Permalink
TestMint and TestRegisterEdition (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: ash <[email protected]>
  • Loading branch information
web3ashlee and ash authored Dec 19, 2023
1 parent c108b72 commit 69062e4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions contracts/WrappedEditions.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub contract WrappedEditions {
var count = 0
while count < casted.tickets {
entries.append(address)
count = count + 1
}
raffle.addEntries(entries)

Expand Down
38 changes: 37 additions & 1 deletion test/FlowtyWrapped_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "test_helpers.cdc"

import "FlowtyWrapped"


pub fun setup() {
var err = Test.deployContract(name: "FlowtyRaffles", path: "../contracts/raffle/FlowtyRaffles.cdc", arguments: [])
Test.expect(err, Test.beNil())
Expand All @@ -24,7 +23,44 @@ pub fun setup() {
Test.expect(err, Test.beNil())
}

pub let rafflesAcct = Test.getAccount(Address(0x0000000000000007))
pub let minterAccount = Test.getAccount(Address(0x0000000000000007))

pub fun testSetupManager() {
let acct = Test.createAccount()
txExecutor("setup_flowty_wrapped.cdc", [acct], [], nil)
}

pub fun testRegisterEdition() {
let acct = Test.createAccount()

let removeAfterReveal: Bool = true
let start: UInt64 = 0
let end: UInt64 = 100
let baseImageUrl: String = ""
let baseHtmlUrl: String = "https://flowty.io/asset/0x0000000000000007/FlowtyWrapped" //TODO change to dynamic address testnet/mainnet
registerEdition(rafflesAcct: rafflesAcct, removeAfterReveal: removeAfterReveal, start: start, end: end, baseImageUrl: baseImageUrl, baseHtmlUrl: baseHtmlUrl)
}

pub fun testMint(){
let acct = Test.createAccount()

txExecutor("setup_flowty_wrapped.cdc", [acct], [], nil)

let username: String = "user1"
let ticket: Int = 1
let totalNftsOwned: Int = 1
let floatCount: Int = 1
let favoriteCollections: [String] = [""]
let collections: [String] = [""]

mintFlowtyWrapped(minterAccount: minterAccount, address: acct.address, username: username, ticket: ticket, totalNftsOwned: totalNftsOwned, floatCount: floatCount, favoriteCollections: favoriteCollections, collections: collections)
}

pub fun registerEdition(rafflesAcct: Test.Account, removeAfterReveal: Bool, start: UInt64, end: UInt64, baseImageUrl: String, baseHtmlUrl: String) {
txExecutor("register_edition.cdc", [rafflesAcct], [removeAfterReveal, start, end, baseImageUrl, baseHtmlUrl], nil)
}

pub fun mintFlowtyWrapped(minterAccount: Test.Account, address: Address, username: String, ticket: Int, totalNftsOwned: Int, floatCount: Int, favoriteCollections: [String], collections: [String]) {
txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], nil)
}
27 changes: 20 additions & 7 deletions transactions/mint_flowty_wrapped.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@ import "FungibleToken"
import "FlowtyWrapped"
import "NonFungibleToken"
import "MetadataViews"
import "WrappedEditions"


transaction(recipient: Address) {
transaction(address: Address, username: String, ticket: Int, totalNftsOwned: Int, floatCount: Int, favoriteCollections: [String], collections: [String]) {
// local variable for storing the minter reference
let minter: &FlowtyWrapped.NFTMinter
let minter: &FlowtyWrapped.Admin


prepare(acct: AuthAccount) {
// borrow a reference to the NFTMinter resource in storage
self.minter = acct.borrow<&FlowtyWrapped.NFTMinter>(from: /storage/FlowtyWrapped_0xf8d6e0586b0a20c7_Minter)
//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 receiver = getAccount(recipient).getCapability<&{NonFungibleToken.CollectionPublic}>(FlowtyWrapped.CollectionPublicPath).borrow()!
let nft <- self.minter.mintNFT()
let wrapped2023Data = WrappedEditions.Wrapped2023Data(
username,
ticket,
totalNftsOwned,
floatCount,
favoriteCollections,
collections
)
let data: {String: AnyStruct} = {
"wrapped": wrapped2023Data
}
let receiver = getAccount(address).getCapability<&{NonFungibleToken.CollectionPublic}>(FlowtyWrapped.CollectionPublicPath).borrow()!
let nft <- self.minter.mintNFT(editionName: "Flowty Wrapped 2023", address: address, data: data )
receiver.deposit(token: <-nft)

}
Expand Down

0 comments on commit 69062e4

Please sign in to comment.