Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ash committed Dec 20, 2023
1 parent ec46a37 commit 7b7b2df
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
21 changes: 17 additions & 4 deletions CLI_SCRIPTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Flow CLI ready to paste scripts for Flowty Wrapper transactions and scripts


1 - Create new emulator account
(if you already made this step before but restarted emulator, remove emulator-1 object from flow.json)
`flow accounts create`
Expand All @@ -10,10 +9,24 @@ On account name you can add: `emulator-1`
2 - Setup FlowtyWrapped Collection
`flow transactions send --signer=emulator-1 transactions/setup_flowty_wrapped.cdc`

3 - Mint FlowtyWrapped
3 - Register Edition

`flow transactions send --signer=emulator-account transactions/register_edition.cdc 'true' '0' '100' '""' '""'`

`flow transactions send --signer=emulator-account transactions/mint_flowty_wrapped.cdc '0x01cf0e2f2f715450'`
4 - Mint FlowtyWrapped

`flow transactions send --signer=emulator-account transactions/mint_flowty_wrapped.cdc '0x01cf0e2f2f715450' 'testSingleMint' '1' '1' '1' '[""]' '[""]'`

4 - Check NFT Edition

`flow scripts execute scripts/get_editions_flowty_wrapped.cdc '0x01cf0e2f2f715450' '2'`
`flow scripts execute scripts/get_editions_flowty_wrapped.cdc '0x01cf0e2f2f715450' '1'`

Optional

Borrow NFT

`flow scripts execute scripts/borrow_nft.cdc '0x01cf0e2f2f715450' '1'`

Get nftIDs

`flow scripts execute scripts/get_nft_ids.cdc '0x01cf0e2f2f715450'`
17 changes: 17 additions & 0 deletions scripts/borrow_nft.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "NonFungibleToken"
import "MetadataViews"

import "FlowtyWrapped"

pub fun main(addr: Address, nftID: UInt64): Bool{
let cp = getAccount(addr).getCapability<&{NonFungibleToken.CollectionPublic}>(FlowtyWrapped.CollectionPublicPath).borrow()
?? panic("collection not found")

let nft = cp.borrowNFT(id: nftID)

if (nft != nil) {
return true
} else {
return false
}
}
47 changes: 37 additions & 10 deletions test/FlowtyWrapped_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,68 @@ pub fun testGetEditions() {
let castedResult = result! as! [UInt64]
var nftID1 = castedResult[0]

scriptExecutor("get_editions_flowty_wrapped.cdc", [acct.address, nftID1])
let test: AnyStruct? = scriptExecutor("get_editions_flowty_wrapped.cdc", [acct.address, nftID1])
let castedTest = test! as! MetadataViews.Editions

let editionName = "Flowty Wrapped 2023"
let editionNumber: UInt64 = 2 // TODO get real serial
let editionMax = nil

let Edition = castedTest.infoList[0]

let name = Edition.name!
let number = Edition.number
let max = Edition.max

assert(name == editionName, message: "Edition name is not expected result")
assert(number == editionNumber, message: "NFT serial is not expected result")
assert(max == editionMax, message: "max should be nil")
}

pub fun setupForMint(acct: Test.Account) {
pub fun testBorrowNFT() {
let acct = Test.createAccount()
setupForMint(acct: acct)

let result = scriptExecutor("get_nft_ids.cdc", [acct.address])

let castedResult = result! as! [UInt64]
var nftID1 = castedResult[0]

scriptExecutor("borrow_nft.cdc", [acct.address, nftID1])
}

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

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

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

txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [acct.address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], nil)

// now try to mint again, this should fail
txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [acct.address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], "address has already been minted")
}

pub fun testSingleMint() {
let acct = Test.createAccount()
pub fun setupForMint(acct: Test.Account) {

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

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

txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [acct.address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], nil)

// now try to mint again, this should fail
txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [acct.address, username, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], "address has already been minted")
}

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)
}
}

0 comments on commit 7b7b2df

Please sign in to comment.