Skip to content

Commit

Permalink
add tests for redeeming nfts and fts
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed Jan 9, 2024
1 parent 4602454 commit 252d5fc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
3 changes: 3 additions & 0 deletions contracts/standard/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub contract ExampleNFT: NonFungibleToken, ViewResolver {
pub event ContractInitialized()
pub event Withdraw(id: UInt64, from: Address?)
pub event Deposit(id: UInt64, to: Address?)
pub event Mint(id: UInt64)

pub event CollectionCreated(id: UInt64)
pub event CollectionDestroyed(id: UInt64)
Expand Down Expand Up @@ -50,6 +51,8 @@ pub contract ExampleNFT: NonFungibleToken, ViewResolver {
self.description = description
self.thumbnail = thumbnail
self.royalties = royalties

emit Mint(id: self.id)
}

pub fun setRoyalties(_ royalties: [MetadataViews.Royalty]) {
Expand Down
5 changes: 5 additions & 0 deletions scripts/lost-and-found/get_address.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "LostAndFound"

pub fun main(): Address {
return LostAndFound.getAddress()
}
43 changes: 38 additions & 5 deletions tests/LostAndFound_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,54 @@ pub fun testTrySendFtResource_InvalidCapability() {
Test.assertEqual(exampleTokenIdentifier(), event.type.identifier)
}

pub fun testRedeemAllTickets_ExampleNft() {
let acct = getNewAccount()
let id = trySendNft(acct)

setupExampleNft(acct: acct)
txExecutor("example-nft/redeem_example_nft_all.cdc", [acct], [])

let event = Test.eventsOfType(Type<ExampleNFT.Deposit>()).removeLast() as! ExampleNFT.Deposit
Test.assertEqual(acct.address, event.to!)
Test.assertEqual(id, event.id)
}

pub fun testRedeemAllTickets_ExampleToken() {
let acct = getNewAccount()
let amount = 5.0
trySendFt(acct, amount)

setupExampleToken(acct: acct)
txExecutor("example-token/redeem_example_token_all.cdc", [acct], [])

let event = Test.eventsOfType(Type<ExampleToken.TokensDeposited>()).removeLast() as! ExampleToken.TokensDeposited
Test.assertEqual(acct.address, event.to!)
Test.assertEqual(amount, event.amount)
}

pub fun testGetAddress() {
let addr = scriptExecutor("lost-and-found/get_address.cdc", [])! as! Address
Test.assertEqual(lostAndFoundAccount.address, addr)
}

// TODO: send non nft/ft resource
// TODO: getAddress
// TODO: redeemAll - nft
// TODO: redeemAll - ft
// TODO: borrowAllTickets for address
// TODO: borrowAllTicketsByType - nft
// TODO: borrowAllTicketsByType - ft
// TODO: create depositor
pub fun mintAndSendNft(_ acct: Test.Account) {
pub fun mintAndSendNft(_ acct: Test.Account): UInt64 {
txExecutor("example-nft/mint_and_deposit_example_nft.cdc", [exampleNftAccount], [acct.address])
let event = Test.eventsOfType(Type<ExampleNFT.Mint>()).removeLast() as! ExampleNFT.Mint

return event.id
}

pub fun trySendNft(_ acct: Test.Account) {
pub fun trySendNft(_ acct: Test.Account): UInt64 {
txExecutor("example-nft/try_send_example_nft.cdc", [exampleNftAccount], [acct.address])
let event = Test.eventsOfType(Type<ExampleNFT.Mint>()).removeLast() as! ExampleNFT.Mint

return event.id
}

pub fun trySendFt(_ acct: Test.Account, _ amount: UFix64) {
Expand Down
2 changes: 1 addition & 1 deletion transactions/example-nft/redeem_example_nft_all.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "NonFungibleToken"

import "LostAndFound"

transaction() {
transaction {
let receiver: Capability<&{NonFungibleToken.CollectionPublic}>
let redeemer: Address

Expand Down

0 comments on commit 252d5fc

Please sign in to comment.