Skip to content

Commit

Permalink
Lost and found tests (#47)
Browse files Browse the repository at this point in the history
* fix all imports

* initial tests, mark test scenarios to add

* add tests for attempting to send nfts and fts

* add tests for redeeming nfts and fts

* tests for borrowing tickets by type

* add tests for depositor send and deposit

* update flow cli version
  • Loading branch information
austinkline authored Jan 10, 2024
1 parent 0d550af commit 384d57c
Show file tree
Hide file tree
Showing 62 changed files with 834 additions and 624 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ jobs:
- name: Install Flow dependencies
run: npm i
- name: Install Flow CLI
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.9.2
run: bash -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.10.0
- name: Run tests
run: sh ./run-tests.sh
run: |
./run-tests.sh
- name: Normalize coverage report filepaths
run : sh ./normalize_coverage_report.sh
- name: Upload coverage reports to Codecov
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
.idea
node_modules
creds.*.json

coverage.lcov
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ items that have been sent to them, and another helper to deposit items to a rede
Deposit an item

```cadence
import ExampleNFT from 0xf8d6e0586b0a20c7
import NonFungibleToken from 0xf8d6e0586b0a20c7
import "ExampleNFT"
import "NonFungibleToken"
import LostAndFound from 0xf669cb8d41ce0c74
import "LostAndFound"
transaction(recipient: Address) {
// local variable for storing the minter reference
Expand Down Expand Up @@ -88,10 +88,10 @@ transaction(recipient: Address) {
Redeem them all

```cadence
import ExampleNFT from 0xf8d6e0586b0a20c7
import NonFungibleToken from 0xf8d6e0586b0a20c7
import "ExampleNFT"
import "NonFungibleToken"
import LostAndFound from 0xf669cb8d41ce0c74
import "LostAndFound"
transaction() {
let receiver: Capability<&{NonFungibleToken.CollectionPublic}>
Expand Down Expand Up @@ -127,10 +127,10 @@ transaction() {
Deposit a vault

```cadence
import FungibleToken from 0xee82856bf20e2aa6
import ExampleToken from 0xf8d6e0586b0a20c7
import "FungibleToken"
import "ExampleToken"
import LostAndFound from 0xf669cb8d41ce0c74
import "LostAndFound"
transaction(redeemer: Address, amount: UFix64) {
let tokenAdmin: &ExampleToken.Administrator
Expand Down Expand Up @@ -169,10 +169,10 @@ transaction(redeemer: Address, amount: UFix64) {
Redeem them

```cadence
import ExampleToken from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import "ExampleToken"
import "FungibleToken"
import LostAndFound from 0xf669cb8d41ce0c74
import "LostAndFound"
transaction() {
let receiver: Capability<&{FungibleToken.Receiver}>
Expand Down Expand Up @@ -219,9 +219,9 @@ check the balance against this value and emit an event when the balance is less

### Initialize the depositor
```cadence
import LostAndFound from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import FlowToken from 0xf8d6e0586b0a20c7
import "LostAndFound"
import "FungibleToken"
import "FlowToken"
transaction {
Expand All @@ -238,9 +238,9 @@ transaction {

### Add Flow tokens to the Depositor
```cadence
import LostAndFound from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import FlowToken from 0xf8d6e0586b0a20c7
import "LostAndFound"
import "FungibleToken"
import "FlowToken"
transaction(amount: UFix64) {
prepare(acct: AuthAccount) {
Expand All @@ -257,13 +257,13 @@ transaction(amount: UFix64) {
### Deposit through the Depositor
```cadence
import FlowToken from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import ExampleNFT from 0xf8d6e0586b0a20c7
import NonFungibleToken from 0xf8d6e0586b0a20c7
import MetadataViews from 0xf8d6e0586b0a20c7
import "FlowToken"
import "FungibleToken"
import "ExampleNFT"
import "NonFungibleToken"
import "MetadataViews"
import LostAndFound from 0xf8d6e0586b0a20c7
import "LostAndFound"
transaction(recipient: Address) {
// local variable for storing the minter reference
Expand Down Expand Up @@ -308,7 +308,7 @@ LostAndFound has a few helper functions to make it easier for you to discover wh

### Get all types deposited to an address
```cadence
import LostAndFound from 0xf8d6e0586b0a20c7
import "LostAndFound"
pub fun main(addr: Address): [Type] {
let shelfManager = LostAndFound.borrowShelfManager()
Expand All @@ -324,7 +324,7 @@ pub fun main(addr: Address): [Type] {
### Borrow all tickets of all types

```cadence
import LostAndFound from 0xf8d6e0586b0a20c7
import "LostAndFound"
pub fun main(addr: Address): [&LostAndFound.Ticket] {
return LostAndFound.borrowAllTickets(addr: addr)
Expand All @@ -334,8 +334,8 @@ pub fun main(addr: Address): [&LostAndFound.Ticket] {
### Borrow all tickets of a type
```cadence
import LostAndFound from 0xf8d6e0586b0a20c7
import ExampleNFT from 0xf8d6e0586b0a20c7
import "LostAndFound"
import "ExampleNFT"
pub fun main(addr: Address): [&LostAndFound.Ticket] {
return LostAndFound.borrowAllTicketsByType(addr: addr, type: Type<@ExampleNFT.NFT>())
Expand Down
2 changes: 1 addition & 1 deletion contracts/LostAndFoundHelper.cdc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LostAndFound from "./LostAndFound.cdc"
import "LostAndFound"

pub contract LostAndFoundHelper {

Expand Down
20 changes: 20 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 Expand Up @@ -240,6 +243,23 @@ pub contract ExampleNFT: NonFungibleToken, ViewResolver {
self.mintNFTWithId(recipient: recipient, name: name, description: description, thumbnail: thumbnail, royaltyReceipient: royaltyReceipient, id: ExampleNFT.totalSupply)
}

pub fun mint(
name: String,
description: String,
thumbnail: String,
): @NFT {
ExampleNFT.totalSupply = ExampleNFT.totalSupply + 1
let newNFT <- create NFT(
id: ExampleNFT.totalSupply,
name: name,
description: description,
thumbnail: thumbnail,
royalties: []
)

return <- newNFT
}

pub fun mintNFTWithId(
recipient: &{NonFungibleToken.CollectionPublic},
name: String,
Expand Down
Loading

0 comments on commit 384d57c

Please sign in to comment.