diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 1f424f6..4fc7f24 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 diff --git a/.gitignore b/.gitignore index e44a5d8..4bb8116 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ .idea node_modules creds.*.json + +coverage.lcov \ No newline at end of file diff --git a/README.md b/README.md index 92500ff..bea9563 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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}> @@ -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 @@ -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}> @@ -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 { @@ -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) { @@ -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 @@ -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() @@ -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) @@ -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>()) diff --git a/contracts/LostAndFoundHelper.cdc b/contracts/LostAndFoundHelper.cdc index 1968b3d..4148337 100644 --- a/contracts/LostAndFoundHelper.cdc +++ b/contracts/LostAndFoundHelper.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "./LostAndFound.cdc" +import "LostAndFound" pub contract LostAndFoundHelper { diff --git a/contracts/standard/ExampleNFT.cdc b/contracts/standard/ExampleNFT.cdc index f42334e..8665095 100644 --- a/contracts/standard/ExampleNFT.cdc +++ b/contracts/standard/ExampleNFT.cdc @@ -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) @@ -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]) { @@ -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, diff --git a/coverage.lcov b/coverage.lcov deleted file mode 100644 index 8f6338e..0000000 --- a/coverage.lcov +++ /dev/null @@ -1,444 +0,0 @@ -TN: -SF:A.0000000000000005.LostAndFound -DA:58,0 -DA:59,0 -DA:63,0 -DA:64,0 -DA:69,0 -DA:72,0 -DA:99,0 -DA:100,0 -DA:101,0 -DA:102,0 -DA:103,0 -DA:104,0 -DA:106,0 -DA:110,0 -DA:114,0 -DA:119,0 -DA:124,0 -DA:125,0 -DA:126,0 -DA:127,0 -DA:129,0 -DA:134,0 -DA:135,0 -DA:136,0 -DA:137,0 -DA:139,0 -DA:144,0 -DA:145,0 -DA:148,0 -DA:149,0 -DA:151,0 -DA:152,0 -DA:153,0 -DA:154,0 -DA:155,0 -DA:156,0 -DA:157,0 -DA:158,0 -DA:159,0 -DA:160,0 -DA:161,0 -DA:162,0 -DA:163,0 -DA:164,0 -DA:165,0 -DA:166,0 -DA:167,0 -DA:168,0 -DA:169,0 -DA:170,0 -DA:172,0 -DA:179,0 -DA:180,0 -DA:181,0 -DA:187,0 -DA:188,0 -DA:191,0 -DA:192,0 -DA:207,0 -DA:208,0 -DA:209,0 -DA:213,0 -DA:217,0 -DA:218,0 -DA:219,0 -DA:220,0 -DA:223,0 -DA:231,0 -DA:232,0 -DA:235,0 -DA:236,0 -DA:237,0 -DA:239,0 -DA:240,0 -DA:241,0 -DA:243,0 -DA:244,0 -DA:248,0 -DA:252,0 -DA:253,0 -DA:257,0 -DA:258,0 -DA:272,0 -DA:273,0 -DA:274,0 -DA:275,0 -DA:279,0 -DA:283,0 -DA:284,0 -DA:285,0 -DA:286,0 -DA:287,0 -DA:290,0 -DA:294,0 -DA:298,0 -DA:302,0 -DA:303,0 -DA:304,0 -DA:305,0 -DA:306,0 -DA:307,0 -DA:308,0 -DA:309,0 -DA:312,0 -DA:317,0 -DA:318,0 -DA:319,0 -DA:330,0 -DA:331,0 -DA:334,0 -DA:335,0 -DA:336,0 -DA:337,0 -DA:338,0 -DA:341,0 -DA:342,0 -DA:349,0 -DA:350,0 -DA:353,0 -DA:354,0 -DA:355,0 -DA:356,0 -DA:357,0 -DA:359,0 -DA:360,0 -DA:361,0 -DA:362,0 -DA:364,0 -DA:366,0 -DA:367,0 -DA:368,0 -DA:370,0 -DA:371,0 -DA:372,0 -DA:374,0 -DA:375,0 -DA:376,0 -DA:378,0 -DA:383,0 -DA:384,0 -DA:389,0 -DA:397,1 -DA:401,0 -DA:402,0 -DA:403,0 -DA:404,0 -DA:405,0 -DA:407,0 -DA:408,0 -DA:411,0 -DA:423,0 -DA:424,0 -DA:426,0 -DA:431,0 -DA:432,0 -DA:433,0 -DA:434,0 -DA:437,0 -DA:438,0 -DA:439,0 -DA:440,0 -DA:443,0 -DA:444,0 -DA:445,0 -DA:446,0 -DA:447,0 -DA:448,0 -DA:449,0 -DA:450,0 -DA:452,0 -DA:453,0 -DA:454,0 -DA:458,0 -DA:465,0 -DA:466,0 -DA:467,0 -DA:468,0 -DA:470,0 -DA:471,0 -DA:472,0 -DA:473,0 -DA:474,0 -DA:475,0 -DA:476,0 -DA:478,0 -DA:479,0 -DA:483,0 -DA:498,0 -DA:499,0 -DA:500,0 -DA:503,0 -DA:507,0 -DA:511,0 -DA:520,0 -DA:524,0 -DA:525,0 -DA:526,0 -DA:527,0 -DA:528,0 -DA:531,0 -DA:532,0 -DA:533,0 -DA:534,0 -DA:537,0 -DA:538,0 -DA:540,0 -DA:541,0 -DA:542,0 -DA:544,0 -DA:545,0 -DA:547,0 -DA:549,0 -DA:550,0 -DA:560,0 -DA:561,0 -DA:562,0 -DA:563,0 -DA:564,0 -DA:565,0 -DA:566,0 -DA:567,0 -DA:568,0 -DA:570,0 -DA:575,0 -DA:576,0 -DA:577,0 -DA:578,0 -DA:582,0 -DA:583,0 -DA:584,0 -DA:585,0 -DA:589,0 -DA:593,0 -DA:595,0 -DA:596,0 -DA:597,0 -DA:601,0 -DA:606,0 -DA:607,0 -DA:608,0 -DA:612,0 -DA:616,0 -DA:617,0 -DA:618,0 -DA:619,0 -DA:622,0 -DA:623,0 -DA:624,0 -DA:627,0 -DA:631,0 -DA:632,0 -DA:633,0 -DA:634,0 -DA:637,0 -DA:638,0 -DA:640,0 -DA:641,0 -DA:642,0 -DA:645,0 -DA:649,0 -DA:650,0 -DA:651,0 -DA:653,0 -DA:654,0 -DA:655,0 -DA:656,0 -DA:667,0 -DA:668,0 -DA:669,0 -DA:670,0 -DA:671,0 -DA:672,0 -DA:673,0 -DA:675,0 -DA:676,0 -DA:677,0 -DA:681,0 -DA:682,0 -DA:683,0 -DA:684,0 -DA:685,0 -DA:686,0 -DA:688,0 -DA:689,0 -DA:690,0 -DA:694,0 -DA:695,0 -DA:696,0 -DA:697,0 -DA:700,0 -DA:712,0 -DA:713,0 -DA:716,0 -DA:717,0 -DA:728,0 -DA:729,0 -DA:730,0 -DA:731,0 -DA:732,0 -DA:733,0 -DA:734,0 -DA:735,0 -DA:736,0 -DA:738,0 -DA:743,0 -DA:747,1 -DA:749,1 -DA:750,1 -DA:751,1 -DA:752,1 -DA:754,1 -DA:755,1 -DA:756,1 -LF:313 -LH:9 -end_of_record -TN: -SF:A.0000000000000006.ExampleNFT -DA:48,0 -DA:49,0 -DA:50,0 -DA:51,0 -DA:52,0 -DA:56,0 -DA:60,0 -DA:73,0 -DA:75,0 -DA:85,0 -DA:86,0 -DA:87,0 -DA:88,0 -DA:92,0 -DA:96,0 -DA:100,0 -DA:102,0 -DA:110,0 -DA:114,0 -DA:120,0 -DA:131,0 -DA:136,0 -DA:138,0 -DA:148,0 -DA:160,1 -DA:161,1 -DA:166,0 -DA:168,0 -DA:170,0 -DA:176,0 -DA:178,0 -DA:181,0 -DA:183,0 -DA:185,0 -DA:190,0 -DA:196,0 -DA:200,0 -DA:202,0 -DA:203,0 -DA:206,0 -DA:210,0 -DA:211,0 -DA:212,0 -DA:216,0 -DA:217,0 -DA:223,0 -DA:239,0 -DA:240,0 -DA:251,0 -DA:252,0 -DA:254,0 -DA:263,0 -DA:276,0 -DA:277,0 -DA:279,0 -DA:280,0 -DA:281,0 -DA:282,0 -DA:283,0 -DA:284,0 -DA:287,0 -DA:290,0 -DA:299,0 -DA:309,0 -DA:311,0 -DA:319,0 -DA:323,0 -DA:329,0 -DA:340,0 -DA:349,0 -DA:357,1 -DA:360,1 -DA:361,1 -DA:362,1 -DA:363,1 -DA:366,1 -DA:367,1 -DA:370,1 -DA:376,1 -DA:377,1 -DA:378,1 -DA:380,1 -LF:82 -LH:14 -end_of_record -TN: -SF:A.0000000000000007.ExampleToken -DA:62,1 -DA:76,0 -DA:77,0 -DA:78,0 -DA:91,0 -DA:92,0 -DA:93,0 -DA:94,0 -DA:95,0 -DA:99,0 -DA:111,0 -DA:121,0 -DA:122,0 -DA:130,0 -DA:131,0 -DA:151,0 -DA:152,0 -DA:154,0 -DA:155,0 -DA:156,0 -DA:157,0 -DA:161,0 -DA:179,0 -DA:180,0 -DA:181,0 -DA:182,0 -DA:187,1 -DA:191,1 -DA:192,1 -DA:197,1 -DA:205,1 -DA:210,1 -DA:211,1 -DA:215,1 -LF:34 -LH:9 -end_of_record diff --git a/scripts/Depositor/get_balance.cdc b/scripts/Depositor/get_balance.cdc index 92dcbe8..fd94350 100644 --- a/scripts/Depositor/get_balance.cdc +++ b/scripts/Depositor/get_balance.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" pub fun main(addr: Address): UFix64 { let depositorPublic = getAccount(addr).getCapability<&LostAndFound.Depositor{LostAndFound.DepositorPublic}>(LostAndFound.DepositorPublicPath).borrow()! diff --git a/scripts/ExampleNFT/borrow_all_tickets.cdc b/scripts/ExampleNFT/borrow_all_tickets.cdc deleted file mode 100644 index 88329db..0000000 --- a/scripts/ExampleNFT/borrow_all_tickets.cdc +++ /dev/null @@ -1,5 +0,0 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" - -pub fun main(addr: Address): [&LostAndFound.Ticket] { - return LostAndFound.borrowAllTickets(addr: addr) -} \ No newline at end of file diff --git a/scripts/example-nft/borrow_all_tickets.cdc b/scripts/example-nft/borrow_all_tickets.cdc new file mode 100644 index 0000000..6ec4b6c --- /dev/null +++ b/scripts/example-nft/borrow_all_tickets.cdc @@ -0,0 +1,12 @@ +import "LostAndFound" +import "LostAndFoundHelper" +import "ExampleNFT" + +pub fun main(addr: Address): [LostAndFoundHelper.Ticket] { + let tickets: [LostAndFoundHelper.Ticket] = [] + for ticket in LostAndFound.borrowAllTicketsByType(addr: addr, type: Type<@ExampleNFT.NFT>()) { + tickets.append(LostAndFoundHelper.constructResult(ticket, id: ticket.getNonFungibleTokenID())!) + } + + return tickets +} \ No newline at end of file diff --git a/scripts/ExampleNFT/borrow_all_tickets_as_struct.cdc b/scripts/example-nft/borrow_all_tickets_as_struct.cdc similarity index 86% rename from scripts/ExampleNFT/borrow_all_tickets_as_struct.cdc rename to scripts/example-nft/borrow_all_tickets_as_struct.cdc index 8cdad18..6e01195 100644 --- a/scripts/ExampleNFT/borrow_all_tickets_as_struct.cdc +++ b/scripts/example-nft/borrow_all_tickets_as_struct.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" import LostAndFoundHelper from "../../contracts/LostAndFoundHelper.cdc" pub fun main(addr: Address): [LostAndFoundHelper.Ticket] { diff --git a/scripts/ExampleNFT/get_account_ids.cdc b/scripts/example-nft/get_account_ids.cdc similarity index 63% rename from scripts/ExampleNFT/get_account_ids.cdc rename to scripts/example-nft/get_account_ids.cdc index c881d08..2821f67 100644 --- a/scripts/ExampleNFT/get_account_ids.cdc +++ b/scripts/example-nft/get_account_ids.cdc @@ -1,5 +1,5 @@ -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" +import "ExampleNFT" +import "NonFungibleToken" pub fun main(addr: Address): [UInt64] { let account = getAccount(addr) diff --git a/scripts/ExampleNFT/get_bin_nft_id.cdc b/scripts/example-nft/get_bin_nft_id.cdc similarity index 73% rename from scripts/ExampleNFT/get_bin_nft_id.cdc rename to scripts/example-nft/get_bin_nft_id.cdc index ccdb0ab..612e1e5 100644 --- a/scripts/ExampleNFT/get_bin_nft_id.cdc +++ b/scripts/example-nft/get_bin_nft_id.cdc @@ -1,5 +1,5 @@ -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "ExampleNFT" +import "LostAndFound" pub fun main(addr: Address, type: String): [UInt64] { let tickets = LostAndFound.borrowAllTicketsByType(addr: addr, type: CompositeType(type)!) diff --git a/scripts/example-token/borrow_all_tickets.cdc b/scripts/example-token/borrow_all_tickets.cdc new file mode 100644 index 0000000..6c5e7ce --- /dev/null +++ b/scripts/example-token/borrow_all_tickets.cdc @@ -0,0 +1,12 @@ +import "LostAndFound" +import "LostAndFoundHelper" +import "ExampleToken" + +pub fun main(addr: Address): [LostAndFoundHelper.Ticket] { + let tickets: [LostAndFoundHelper.Ticket] = [] + for ticket in LostAndFound.borrowAllTicketsByType(addr: addr, type: Type<@ExampleToken.Vault>()) { + tickets.append(LostAndFoundHelper.constructResult(ticket, id: ticket.getNonFungibleTokenID())!) + } + + return tickets +} \ No newline at end of file diff --git a/scripts/ExampleToken/borrow_ticket.cdc b/scripts/example-token/borrow_ticket.cdc similarity index 62% rename from scripts/ExampleToken/borrow_ticket.cdc rename to scripts/example-token/borrow_ticket.cdc index ec3e9eb..3ba268a 100644 --- a/scripts/ExampleToken/borrow_ticket.cdc +++ b/scripts/example-token/borrow_ticket.cdc @@ -1,7 +1,7 @@ -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" pub fun main(addr: Address, ticketID: UInt64): &LostAndFound.Ticket? { let shelfManager = LostAndFound.borrowShelfManager() diff --git a/scripts/ExampleToken/borrow_ticket_as_struct.cdc b/scripts/example-token/borrow_ticket_as_struct.cdc similarity index 71% rename from scripts/ExampleToken/borrow_ticket_as_struct.cdc rename to scripts/example-token/borrow_ticket_as_struct.cdc index 81c4ee0..da8fa80 100644 --- a/scripts/ExampleToken/borrow_ticket_as_struct.cdc +++ b/scripts/example-token/borrow_ticket_as_struct.cdc @@ -1,7 +1,7 @@ -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" import LostAndFoundHelper from "../../contracts/LostAndFoundHelper.cdc" pub fun main(addr: Address, ticketID: UInt64): LostAndFoundHelper.Ticket? { diff --git a/scripts/ExampleToken/get_bin_vault_balance.cdc b/scripts/example-token/get_bin_vault_balance.cdc similarity index 73% rename from scripts/ExampleToken/get_bin_vault_balance.cdc rename to scripts/example-token/get_bin_vault_balance.cdc index 5cdc61f..81a0318 100644 --- a/scripts/ExampleToken/get_bin_vault_balance.cdc +++ b/scripts/example-token/get_bin_vault_balance.cdc @@ -1,5 +1,5 @@ -import FungibleToken from "../../contracts/FungibleToken.cdc" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "FungibleToken" +import "LostAndFound" pub fun main(addr: Address, type: String): UFix64 { let tickets = LostAndFound.borrowAllTicketsByType(addr: addr, type: CompositeType(type)!) diff --git a/scripts/ExampleToken/get_example_token_balance.cdc b/scripts/example-token/get_example_token_balance.cdc similarity index 58% rename from scripts/ExampleToken/get_example_token_balance.cdc rename to scripts/example-token/get_example_token_balance.cdc index 5b5a98f..51bfe25 100644 --- a/scripts/ExampleToken/get_example_token_balance.cdc +++ b/scripts/example-token/get_example_token_balance.cdc @@ -1,5 +1,5 @@ -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FungibleToken" +import "ExampleToken" pub fun main(addr: Address): UFix64 { let acct = getAccount(addr) diff --git a/scripts/FlowToken/get_available_flow_balance.cdc b/scripts/flow-token/get_available_flow_balance.cdc similarity index 100% rename from scripts/FlowToken/get_available_flow_balance.cdc rename to scripts/flow-token/get_available_flow_balance.cdc diff --git a/scripts/FlowToken/get_flow_token_balance.cdc b/scripts/flow-token/get_flow_token_balance.cdc similarity index 76% rename from scripts/FlowToken/get_flow_token_balance.cdc rename to scripts/flow-token/get_flow_token_balance.cdc index 018b211..1512c71 100644 --- a/scripts/FlowToken/get_flow_token_balance.cdc +++ b/scripts/flow-token/get_flow_token_balance.cdc @@ -1,4 +1,4 @@ -import FungibleToken from "../../contracts/FungibleToken.cdc" +import "FungibleToken" pub fun main(addr: Address): UFix64 { let cap = getAccount(addr).getCapability<&{FungibleToken.Balance}>(/public/flowTokenBalance) diff --git a/scripts/FlowToken/storage_used_in_flow.cdc b/scripts/flow-token/storage_used_in_flow.cdc similarity index 100% rename from scripts/FlowToken/storage_used_in_flow.cdc rename to scripts/flow-token/storage_used_in_flow.cdc diff --git a/scripts/get_cap_type.cdc b/scripts/get_cap_type.cdc index 59550c5..a65c48c 100644 --- a/scripts/get_cap_type.cdc +++ b/scripts/get_cap_type.cdc @@ -1,7 +1,7 @@ -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" +import "ExampleNFT" +import "NonFungibleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" pub fun main(addr: Address): Bool { let acct = getAccount(addr) diff --git a/scripts/get_flowRepayment_address.cdc b/scripts/get_flowRepayment_address.cdc index 3b67c5a..b1d6ad7 100644 --- a/scripts/get_flowRepayment_address.cdc +++ b/scripts/get_flowRepayment_address.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "../contracts/LostAndFound.cdc" +import "LostAndFound" pub fun main(addr: Address, type: String, ticketID: UInt64): Address? { let shelfManager = LostAndFound.borrowShelfManager() diff --git a/scripts/get_redeemable_types_for_addr.cdc b/scripts/get_redeemable_types_for_addr.cdc index c5bc28b..633cf18 100644 --- a/scripts/get_redeemable_types_for_addr.cdc +++ b/scripts/get_redeemable_types_for_addr.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "../contracts/LostAndFound.cdc" +import "LostAndFound" pub fun main(addr: Address): [Type] { let shelfManager = LostAndFound.borrowShelfManager() diff --git a/scripts/lost-and-found/borrow_all_tickets.cdc b/scripts/lost-and-found/borrow_all_tickets.cdc new file mode 100644 index 0000000..66dc337 --- /dev/null +++ b/scripts/lost-and-found/borrow_all_tickets.cdc @@ -0,0 +1,11 @@ +import "LostAndFound" +import "LostAndFoundHelper" + +pub fun main(addr: Address): [LostAndFoundHelper.Ticket] { + let tickets: [LostAndFoundHelper.Ticket] = [] + for ticket in LostAndFound.borrowAllTickets(addr: addr) { + tickets.append(LostAndFoundHelper.constructResult(ticket, id: ticket.getNonFungibleTokenID())!) + } + + return tickets +} \ No newline at end of file diff --git a/scripts/lost-and-found/check_ticket_item.cdc b/scripts/lost-and-found/check_ticket_item.cdc new file mode 100644 index 0000000..5677712 --- /dev/null +++ b/scripts/lost-and-found/check_ticket_item.cdc @@ -0,0 +1,11 @@ +import "LostAndFound" + +pub fun main(addr: Address, ticketID: UInt64, ticketTypeIdentifier: String): Bool { + let composite = CompositeType(ticketTypeIdentifier)! + + let manager = LostAndFound.borrowShelfManager() + let shelf = manager.borrowShelf(redeemer: addr) ?? panic("no shelf found for given address") + let bin = shelf.borrowBin(type: composite) ?? panic("bin not found") + let ticket = bin.borrowTicket(id: ticketID) ?? panic("ticket not found") + return ticket.checkItem() +} \ No newline at end of file diff --git a/scripts/lost-and-found/estimate_deposit_nft.cdc b/scripts/lost-and-found/estimate_deposit_nft.cdc new file mode 100644 index 0000000..39b98de --- /dev/null +++ b/scripts/lost-and-found/estimate_deposit_nft.cdc @@ -0,0 +1,18 @@ +import "LostAndFound" +import "NonFungibleToken" + +pub fun main(addr: Address, nftID: UInt64, nftStoragePath: StoragePath): UFix64 { + let acct = getAuthAccount(addr) + let c = acct.borrow<&{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}>(from: nftStoragePath) + ?? panic("collection not found") + let nft <- c.withdraw(withdrawID: nftID) + let estimate <- LostAndFound.estimateDeposit(redeemer: addr, item: <-nft, memo: nil, display: nil) + + let item <- estimate.withdraw() + c.deposit(token: <- (item as! @NonFungibleToken.NFT)) + + let fee = estimate.storageFee + destroy estimate + + return fee +} \ No newline at end of file diff --git a/scripts/lost-and-found/get_address.cdc b/scripts/lost-and-found/get_address.cdc new file mode 100644 index 0000000..fb6775d --- /dev/null +++ b/scripts/lost-and-found/get_address.cdc @@ -0,0 +1,5 @@ +import "LostAndFound" + +pub fun main(): Address { + return LostAndFound.getAddress() +} \ No newline at end of file diff --git a/scripts/lost-and-found/get_redeemable_types.cdc b/scripts/lost-and-found/get_redeemable_types.cdc new file mode 100644 index 0000000..58b7170 --- /dev/null +++ b/scripts/lost-and-found/get_redeemable_types.cdc @@ -0,0 +1,5 @@ +import "LostAndFound" + +pub fun main(addr: Address): [Type] { + return LostAndFound.getRedeemableTypes(addr) +} \ No newline at end of file diff --git a/scripts/lost-and-found/get_shelf_owner.cdc b/scripts/lost-and-found/get_shelf_owner.cdc new file mode 100644 index 0000000..73de98f --- /dev/null +++ b/scripts/lost-and-found/get_shelf_owner.cdc @@ -0,0 +1,7 @@ +import "LostAndFound" + +pub fun main(addr: Address): Address { + let m = LostAndFound.borrowShelfManager() + let shelf = m.borrowShelf(redeemer: addr)! + return shelf.getOwner() +} \ No newline at end of file diff --git a/scripts/lost-and-found/get_ticket_ft_balance.cdc b/scripts/lost-and-found/get_ticket_ft_balance.cdc new file mode 100644 index 0000000..1069b30 --- /dev/null +++ b/scripts/lost-and-found/get_ticket_ft_balance.cdc @@ -0,0 +1,11 @@ +import "LostAndFound" + +pub fun main(addr: Address, ticketID: UInt64, ticketTypeIdentifier: String): UFix64? { + let composite = CompositeType(ticketTypeIdentifier)! + + let manager = LostAndFound.borrowShelfManager() + let shelf = manager.borrowShelf(redeemer: addr) ?? panic("no shelf found for given address") + let bin = shelf.borrowBin(type: composite) ?? panic("bin not found") + let ticket = bin.borrowTicket(id: ticketID) ?? panic("ticket not found") + return ticket.getFungibleTokenBalance() +} \ No newline at end of file diff --git a/scripts/lost-and-found/shelf_has_type.cdc b/scripts/lost-and-found/shelf_has_type.cdc new file mode 100644 index 0000000..2523883 --- /dev/null +++ b/scripts/lost-and-found/shelf_has_type.cdc @@ -0,0 +1,8 @@ +import "LostAndFound" + +pub fun main(addr: Address, identifier: String): Bool { + let c = CompositeType(identifier)! + let m = LostAndFound.borrowShelfManager() + let shelf = m.borrowShelf(redeemer: addr) ?? panic("shelf not found for address") + return shelf.hasType(type: c) +} \ No newline at end of file diff --git a/tests/LostAndFound_tests.cdc b/tests/LostAndFound_tests.cdc index bd6b3af..68d481e 100644 --- a/tests/LostAndFound_tests.cdc +++ b/tests/LostAndFound_tests.cdc @@ -1,10 +1,316 @@ import Test import "test_helpers.cdc" +import "LostAndFound" +import "LostAndFoundHelper" +import "ExampleNFT" +import "ExampleToken" + pub fun setup() { deployAll() + + mintFlow(exampleNftAccount, 10.0) + mintFlow(exampleTokenAccount, 10.0) + + txExecutor("depositor/setup_depositor.cdc", [exampleNftAccount], [lowBalanceThreshold]) + txExecutor("depositor/add_flow_tokens.cdc", [exampleNftAccount], [lowBalanceThreshold]) + + txExecutor("depositor/setup_depositor.cdc", [exampleTokenAccount], [lowBalanceThreshold]) + txExecutor("depositor/add_flow_tokens.cdc", [exampleTokenAccount], [lowBalanceThreshold]) } pub fun testImport() { scriptExecutor("import_contracts.cdc", []) +} + +pub fun testEstimateDeposit() { + let acct = getNewAccount() + setupExampleNft(acct: acct) + + let id = mintExampleNfts(acct, 1)[0] + let estimate = scriptExecutor("lost-and-found/estimate_deposit_nft.cdc", [acct.address, id, exampleNftStoragePath])! as! UFix64 + + Test.assert(estimate >= 0.00002, message: "fee is lower than expected") +} + +pub fun testDepositNft() { + let acct = getNewAccount() + mintAndSendNft(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(event.redeemer, acct.address) + Test.assertEqual(exampleNftIdentifier(), event.type.identifier) + + // estimate depositing another to see that the fee is reduced (we have initialized the shelf and bin for this user and resource type pairing) + setupExampleNft(acct: acct) + let id = mintExampleNfts(acct, 1)[0] + let estimate = scriptExecutor("lost-and-found/estimate_deposit_nft.cdc", [acct.address, id, exampleNftStoragePath])! as! UFix64 + Test.assert(estimate == 0.0, message: "fee is higher than expected") +} + +pub fun testGetRedeemableTypes() { + let acct = getNewAccount() + mintAndSendNft(acct) + + let types = scriptExecutor("lost-and-found/get_redeemable_types.cdc", [acct.address])! as! [Type] + let identifiers: [String] = [] + for t in types { + identifiers.append(t.identifier) + } + + Test.assert(identifiers.contains(exampleNftIdentifier()), message: "example nft type not found") +} + +pub fun testTrySendNftResource_ValidCapability() { + let acct = getNewAccount() + setupExampleNft(acct: acct) + + trySendNft(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Deposit + Test.assertEqual(acct.address, event.to!) +} + +pub fun testTrySendNftResource_InvalidCapability() { + let acct = getNewAccount() + trySendNft(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(event.redeemer, acct.address) + Test.assertEqual(exampleNftIdentifier(), event.type.identifier) +} + +pub fun testTrySendFtResource_ValidCapability() { + let acct = getNewAccount() + setupExampleToken(acct: acct) + + trySendFt(acct, 1.0) + let event = Test.eventsOfType(Type()).removeLast() as! ExampleToken.TokensDeposited + Test.assertEqual(acct.address, event.to!) +} + +pub fun testTrySendFtResource_InvalidCapability() { + let acct = getNewAccount() + + trySendFt(acct, 1.0) + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(event.redeemer, acct.address) + 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()).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()).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) +} + +pub fun testBorrowAllTickets() { + let acct = getNewAccount() + let amount = 5.0 + trySendFt(acct, amount) + let id = trySendNft(acct) + + let tickets = scriptExecutor("lost-and-found/borrow_all_tickets.cdc", [acct.address])! as! [LostAndFoundHelper.Ticket] + Test.assertEqual(2, tickets.length) + + // there should be one nft and one ft ticket + var nftID: UInt64? = nil + var foundFt = false + + for ticket in tickets { + switch ticket.typeIdentifier { + case exampleNftIdentifier(): + nftID = ticket.ticketID + break + case exampleTokenIdentifier(): + foundFt = true + break + } + } + + Test.assertEqual(id, nftID!) + Test.assertEqual(true, foundFt) +} + +pub fun testBorrowTicketsByType_Nft() { + let acct = getNewAccount() + let id = trySendNft(acct) + + let tickets = scriptExecutor("example-nft/borrow_all_tickets.cdc", [acct.address])! as! [LostAndFoundHelper.Ticket] + Test.assertEqual(1, tickets.length) + Test.assertEqual(id, tickets[0].ticketID!) +} + +pub fun testBorrowTicketsByType_Ft() { + let acct = getNewAccount() + let amount = 5.0 + trySendFt(acct, amount) + + let tickets = scriptExecutor("example-token/borrow_all_tickets.cdc", [acct.address])! as! [LostAndFoundHelper.Ticket] + Test.assertEqual(1, tickets.length) +} + +pub fun testCheckTicketItem() { + let acct = getNewAccount() + trySendNft(acct) + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + + let res = scriptExecutor("lost-and-found/check_ticket_item.cdc", [acct.address, event.ticketID, exampleNftIdentifier()])! as! Bool + Test.assertEqual(true, res) +} + +pub fun testGetTicketFungibleTokenBalance() { + let acct = getNewAccount() + let amount = 5.0 + trySendFt(acct, amount) + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + + let balance = scriptExecutor("lost-and-found/get_ticket_ft_balance.cdc", [acct.address, event.ticketID, exampleTokenIdentifier()])! as! UFix64 + Test.assertEqual(amount, balance) +} + +pub fun testGetShelfOwner() { + let acct = getNewAccount() + trySendNft(acct) + + let owner = scriptExecutor("lost-and-found/get_shelf_owner.cdc", [acct.address])! as! Address + Test.assertEqual(lostAndFoundAccount.address, owner) +} + +pub fun testShelfHasType() { + let acct = getNewAccount() + trySendNft(acct) + let hasExampleNFT = scriptExecutor("lost-and-found/shelf_has_type.cdc", [acct.address, exampleNftIdentifier()])! as! Bool + Test.assertEqual(true, hasExampleNFT) + + let hasExampleToken = scriptExecutor("lost-and-found/shelf_has_type.cdc", [acct.address, exampleTokenIdentifier()])! as! Bool + Test.assertEqual(false, hasExampleToken) +} + +pub fun testDepositor_DepositNft() { + let acct = getNewAccount() + + mintAndSendNftWithDepositor(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(event.redeemer, acct.address) + Test.assertEqual(exampleNftIdentifier(), event.type.identifier) +} + +pub fun testDepositor_DepositFt() { + let acct = getNewAccount() + let amount = 5.0 + mintAndSendExampleTokensWithDepositor(acct, amount) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(event.redeemer, acct.address) + Test.assertEqual(exampleTokenIdentifier(), event.type.identifier) +} + +pub fun testDepositor_trySendNft_ValidCapability() { + let acct = getNewAccount() + setupExampleNft(acct: acct) + + let nftID = trySendNftWithDepositor(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Deposit + Test.assertEqual(acct.address, event.to!) + Test.assertEqual(nftID, event.id) +} + +pub fun testDepositor_trySendNft_InvalidCapability() { + let acct = getNewAccount() + + let nftID = trySendNftWithDepositor(acct) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(acct.address, event.redeemer) + Test.assertEqual(exampleNftIdentifier(), event.type.identifier) +} + +pub fun testDepositor_trySendFt_ValidCapability() { + let acct = getNewAccount() + setupExampleToken(acct: acct) + let amount = 5.0 + + trySendFtWithDepositor(acct, amount) + + let event = Test.eventsOfType(Type()).removeLast() as! ExampleToken.TokensDeposited + Test.assertEqual(acct.address, event.to!) + Test.assertEqual(amount, event.amount) +} + +pub fun testDepositor_trySendFt_InvalidCapability() { + let acct = getNewAccount() + let amount = 5.0 + + trySendFtWithDepositor(acct, amount) + + let event = Test.eventsOfType(Type()).removeLast() as! LostAndFound.TicketDeposited + Test.assertEqual(acct.address, event.redeemer) + Test.assertEqual(exampleTokenIdentifier(), event.type.identifier) +} + +pub fun mintAndSendNft(_ acct: Test.Account): UInt64 { + txExecutor("example-nft/mint_and_deposit_example_nft.cdc", [exampleNftAccount], [acct.address]) + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Mint + + return event.id +} + +pub fun trySendNft(_ acct: Test.Account): UInt64 { + txExecutor("example-nft/try_send_example_nft.cdc", [exampleNftAccount], [acct.address]) + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Mint + + return event.id +} + +pub fun trySendFt(_ acct: Test.Account, _ amount: UFix64) { + txExecutor("example-token/try_send_example_token.cdc", [exampleTokenAccount], [acct.address, amount]) +} + +pub fun mintAndSendNftWithDepositor(_ to: Test.Account): UInt64 { + txExecutor("example-nft/mint_and_deposit_with_depositor.cdc", [exampleNftAccount], [to.address]) + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Mint + + return event.id +} + +pub fun mintAndSendExampleTokensWithDepositor(_ to: Test.Account, _ amount: UFix64) { + txExecutor("example-token/deposit_example_token_with_depositor.cdc", [exampleTokenAccount], [to.address, amount]) +} + +pub fun trySendNftWithDepositor(_ to: Test.Account): UInt64 { + txExecutor("example-nft/try_send_example_nft_with_depositor.cdc", [exampleNftAccount], [to.address]) + let event = Test.eventsOfType(Type()).removeLast() as! ExampleNFT.Mint + + return event.id +} + +pub fun trySendFtWithDepositor(_ to: Test.Account, _ amount: UFix64) { + txExecutor("example-token/try_send_example_token_depositor.cdc", [exampleTokenAccount], [to.address, amount]) } \ No newline at end of file diff --git a/tests/test_helpers.cdc b/tests/test_helpers.cdc index 6c499fc..3e421e8 100644 --- a/tests/test_helpers.cdc +++ b/tests/test_helpers.cdc @@ -1,8 +1,39 @@ import Test +import "ExampleNFT" +import "ExampleToken" + +pub let lowBalanceThreshold = 1.0 + +// the cadence testing framework allocates 4 addresses for system acounts, +// and 10 pre-created accounts for us to use for deployments: +pub let Account0x1 = Address(0x0000000000000001) +pub let Account0x2 = Address(0x0000000000000002) +pub let Account0x3 = Address(0x0000000000000003) +pub let Account0x4 = Address(0x0000000000000004) +pub let Account0x5 = Address(0x0000000000000005) +pub let Account0x6 = Address(0x0000000000000006) +pub let Account0x7 = Address(0x0000000000000007) +pub let Account0x8 = Address(0x0000000000000008) +pub let Account0x9 = Address(0x0000000000000009) +pub let Account0xa = Address(0x000000000000000a) +pub let Account0xb = Address(0x000000000000000b) +pub let Account0xc = Address(0x000000000000000c) +pub let Account0xd = Address(0x000000000000000d) +pub let Account0xe = Address(0x000000000000000e) + +pub let lostAndFoundAccount = Test.getAccount(Account0x5) +pub let exampleNftAccount = Test.getAccount(Account0x6) +pub let exampleTokenAccount = Test.getAccount(Account0x7) + pub fun scriptExecutor(_ scriptName: String, _ arguments: [AnyStruct]): AnyStruct? { let scriptCode = loadCode(scriptName, "scripts") let scriptResult = Test.executeScript(scriptCode, arguments) + + if scriptResult.error != nil { + panic(scriptResult.error!.message) + } + return scriptResult.returnValue } @@ -38,6 +69,7 @@ pub fun deployAll() { deploy("ExampleToken", "../contracts/standard/ExampleToken.cdc", []) deploy("FeeEstimator", "../contracts/FeeEstimator.cdc", []) deploy("LostAndFound", "../contracts/LostAndFound.cdc", []) + deploy("LostAndFoundHelper", "../contracts/LostAndFoundHelper.cdc", []) } pub fun deploy(_ name: String, _ path: String, _ arguments: [AnyStruct]) { @@ -45,19 +77,92 @@ pub fun deploy(_ name: String, _ path: String, _ arguments: [AnyStruct]) { Test.expect(err, Test.beNil()) } -// the cadence testing framework allocates 4 addresses for system acounts, -// and 10 pre-created accounts for us to use for deployments: -pub let Account0x1 = Address(0x0000000000000001) -pub let Account0x2 = Address(0x0000000000000002) -pub let Account0x3 = Address(0x0000000000000003) -pub let Account0x4 = Address(0x0000000000000004) -pub let Account0x5 = Address(0x0000000000000005) -pub let Account0x6 = Address(0x0000000000000006) -pub let Account0x7 = Address(0x0000000000000007) -pub let Account0x8 = Address(0x0000000000000008) -pub let Account0x9 = Address(0x0000000000000009) -pub let Account0xa = Address(0x000000000000000a) -pub let Account0xb = Address(0x000000000000000b) -pub let Account0xc = Address(0x000000000000000c) -pub let Account0xd = Address(0x000000000000000d) -pub let Account0xe = Address(0x000000000000000e) \ No newline at end of file +// Example NFT constants +pub let exampleNftStoragePath = /storage/exampleNFTCollection +pub let exampleNftPublicPath = /public/exampleNFTCollection +pub let exampleNftProviderPath = /private/exampleNFTCollection + +// Example Token constants +pub let exampleTokenStoragePath = /storage/exampleTokenVault +pub let exampleTokenReceiverPath = /public/exampleTokenReceiver +pub let exampleTokenProviderPath = /private/exampleTokenProvider +pub let exampleTokenBalancePath = /public/exampleTokenBalance + +pub fun exampleNftIdentifier(): String { + return Type<@ExampleNFT.NFT>().identifier +} + +pub fun exampleTokenIdentifier(): String { + return Type<@ExampleToken.Vault>().identifier +} + +pub fun getNewAccount(): Test.Account { + let acct = Test.createAccount() + return acct +} + +pub fun setupExampleToken(acct: Test.Account) { + txExecutor("example-token/setup.cdc", [acct], []) +} + +pub fun setupExampleNft(acct: Test.Account) { + txExecutor("example-nft/setup.cdc", [acct], []) +} + +pub fun mintExampleNfts(_ acct: Test.Account, _ num: Int): [UInt64] { + let txRes = txExecutor("example-nft/mint_example_nft.cdc", [exampleNftAccount], [acct.address, num]) + let events = Test.eventsOfType(Type()) + + let ids: [UInt64] = [] + while ids.length < num { + let event = events.removeLast() as! ExampleNFT.Deposit + ids.append(event.id) + } + + return ids +} + +pub fun mintExampleNftByID(_ acct: Test.Account, _ id: UInt64): UInt64 { + post { + result == id + } + + let txRes = txExecutor("example-nft/mint_example_nft_with_id.cdc", [exampleNftAccount], [acct.address, id]) + let events = Test.eventsOfType(Type()) + let event = events.removeLast() as! ExampleNFT.Deposit + return event.id +} + +pub fun mintExampleTokens(_ acct: Test.Account, _ amount: UFix64) { + txExecutor("example-token/mint.cdc", [exampleTokenAccount], [acct.address, amount]) +} + +pub fun mintFlow(_ receiver: Test.Account, _ amount: UFix64) { + let code = loadCode("flow/mint_flow.cdc", "transactions") + let tx = Test.Transaction( + code: code, + authorizers: [Test.serviceAccount().address], + signers: [], + arguments: [receiver.address, amount] + ) + let txResult = Test.executeTransaction(tx) + if txResult.error != nil { + panic(txResult.error!.message) + } +} + +pub fun initializeDepositor(_ acct: Test.Account) { + txExecutor("depositor/setup_depositor.cdc", [acct], [lowBalanceThreshold]) + mintFlow(acct, lowBalanceThreshold + 1.0) + txExecutor("depositor/add_flow_tokens.cdc", [acct], [lowBalanceThreshold]) +} + +pub fun initializeDepositorWithoutBalance(_ acct: Test.Account) { + txExecutor("depositor/setup_depositor.cdc", [acct], [lowBalanceThreshold]) +} + +pub fun getNewDepositor(): Test.Account { + let acct = getNewAccount() + initializeDepositor(acct) + return acct +} \ No newline at end of file diff --git a/transactions/clear_all_tickets.cdc b/transactions/clear_all_tickets.cdc index 4ae03fa..26bcd72 100644 --- a/transactions/clear_all_tickets.cdc +++ b/transactions/clear_all_tickets.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../contracts/FlowToken.cdc" -import FungibleToken from "../contracts/FungibleToken.cdc" -import NonFungibleToken from "../contracts/NonFungibleToken.cdc" -import ExampleToken from "../contracts/ExampleToken.cdc" -import ExampleNFT from "../contracts/ExampleNFT.cdc" +import "FlowToken" +import "FungibleToken" +import "NonFungibleToken" +import "ExampleToken" +import "ExampleNFT" -import LostAndFound from "../contracts/LostAndFound.cdc" +import "LostAndFound" transaction { diff --git a/transactions/Depositor/add_flow_tokens.cdc b/transactions/depositor/add_flow_tokens.cdc similarity index 70% rename from transactions/Depositor/add_flow_tokens.cdc rename to transactions/depositor/add_flow_tokens.cdc index bdfad94..e87b41a 100644 --- a/transactions/Depositor/add_flow_tokens.cdc +++ b/transactions/depositor/add_flow_tokens.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(amount: UFix64) { diff --git a/transactions/Depositor/add_flow_tokens_public.cdc b/transactions/depositor/add_flow_tokens_public.cdc similarity index 72% rename from transactions/Depositor/add_flow_tokens_public.cdc rename to transactions/depositor/add_flow_tokens_public.cdc index 341e58b..0a8d1ca 100644 --- a/transactions/Depositor/add_flow_tokens_public.cdc +++ b/transactions/depositor/add_flow_tokens_public.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(addr: Address, amount: UFix64) { diff --git a/transactions/Depositor/destroy.cdc b/transactions/depositor/destroy.cdc similarity index 79% rename from transactions/Depositor/destroy.cdc rename to transactions/depositor/destroy.cdc index 02acb12..8ffd478 100644 --- a/transactions/Depositor/destroy.cdc +++ b/transactions/depositor/destroy.cdc @@ -1,4 +1,4 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction { prepare(acct: AuthAccount) { diff --git a/transactions/Depositor/set_threshold.cdc b/transactions/depositor/set_threshold.cdc similarity index 63% rename from transactions/Depositor/set_threshold.cdc rename to transactions/depositor/set_threshold.cdc index a2dc385..828922b 100644 --- a/transactions/Depositor/set_threshold.cdc +++ b/transactions/depositor/set_threshold.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(newThreshold: UFix64?) { let lfDepositor: &LostAndFound.Depositor diff --git a/transactions/Depositor/setup.cdc b/transactions/depositor/setup_depositor.cdc similarity index 79% rename from transactions/Depositor/setup.cdc rename to transactions/depositor/setup_depositor.cdc index 68d9020..a90ed48 100644 --- a/transactions/Depositor/setup.cdc +++ b/transactions/depositor/setup_depositor.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(lowBalanceThreshold: UFix64?) { diff --git a/transactions/Depositor/withdraw_below_threshold.cdc b/transactions/depositor/withdraw_below_threshold.cdc similarity index 87% rename from transactions/Depositor/withdraw_below_threshold.cdc rename to transactions/depositor/withdraw_below_threshold.cdc index f55d5e0..4b6c1fd 100644 --- a/transactions/Depositor/withdraw_below_threshold.cdc +++ b/transactions/depositor/withdraw_below_threshold.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(lowBalanceThreshold: UFix64) { diff --git a/transactions/Depositor/withdraw_to_threshold.cdc b/transactions/depositor/withdraw_to_threshold.cdc similarity index 86% rename from transactions/Depositor/withdraw_to_threshold.cdc rename to transactions/depositor/withdraw_to_threshold.cdc index 6f243b6..a28cc41 100644 --- a/transactions/Depositor/withdraw_to_threshold.cdc +++ b/transactions/depositor/withdraw_to_threshold.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(lowBalanceThreshold: UFix64) { diff --git a/transactions/Depositor/withdraw_tokens.cdc b/transactions/depositor/withdraw_tokens.cdc similarity index 72% rename from transactions/Depositor/withdraw_tokens.cdc rename to transactions/depositor/withdraw_tokens.cdc index 10c4fad..2c94b61 100644 --- a/transactions/Depositor/withdraw_tokens.cdc +++ b/transactions/depositor/withdraw_tokens.cdc @@ -1,6 +1,6 @@ -import LostAndFound from "../../contracts/LostAndFound.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import FlowToken from "../../contracts/FlowToken.cdc" +import "LostAndFound" +import "FungibleToken" +import "FlowToken" transaction(amount: UFix64) { diff --git a/transactions/ExampleNFT/destroy_example_nft_storage.cdc b/transactions/example-nft/destroy_example_nft_storage.cdc similarity index 56% rename from transactions/ExampleNFT/destroy_example_nft_storage.cdc rename to transactions/example-nft/destroy_example_nft_storage.cdc index 4b61e79..572620d 100644 --- a/transactions/ExampleNFT/destroy_example_nft_storage.cdc +++ b/transactions/example-nft/destroy_example_nft_storage.cdc @@ -1,6 +1,6 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" transaction { prepare(signer: AuthAccount) { diff --git a/transactions/ExampleNFT/mint_and_deposit_example_nft.cdc b/transactions/example-nft/mint_and_deposit_example_nft.cdc similarity index 76% rename from transactions/ExampleNFT/mint_and_deposit_example_nft.cdc rename to transactions/example-nft/mint_and_deposit_example_nft.cdc index db8f0b7..d02c1f0 100644 --- a/transactions/ExampleNFT/mint_and_deposit_example_nft.cdc +++ b/transactions/example-nft/mint_and_deposit_example_nft.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address) { // local variable for storing the minter reference @@ -33,16 +33,18 @@ transaction(recipient: Address) { } execute { - let token <- self.minter.mintAndReturnNFT(name: "testname", description: "descr", thumbnail: "image.html", royalties: []) + let cap: Capability<&AnyResource{NonFungibleToken.CollectionPublic}> = getAccount(recipient).getCapability<&{NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath) + + let token <- self.minter.mint(name: "some test nft", description: "desc", thumbnail: "image.png") let display = token.resolveView(Type()) as! MetadataViews.Display? let memo = "test memo" let depositEstimate <- LostAndFound.estimateDeposit(redeemer: recipient, item: <-token, memo: memo, display: display) let storageFee <- self.flowProvider.borrow()!.withdraw(amount: depositEstimate.storageFee) let resource <- depositEstimate.withdraw() - LostAndFound.deposit( - redeemer: recipient, - item: <-resource, + LostAndFound.trySendResource( + resource: <-resource, + cap: cap, memo: memo, display: display, storagePayment: &storageFee as &FungibleToken.Vault, diff --git a/transactions/ExampleNFT/mint_and_deposit_example_nfts.cdc b/transactions/example-nft/mint_and_deposit_example_nfts.cdc similarity index 78% rename from transactions/ExampleNFT/mint_and_deposit_example_nfts.cdc rename to transactions/example-nft/mint_and_deposit_example_nfts.cdc index e646809..f43bd27 100644 --- a/transactions/ExampleNFT/mint_and_deposit_example_nfts.cdc +++ b/transactions/example-nft/mint_and_deposit_example_nfts.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address, numToMint: Int) { // local variable for storing the minter reference @@ -37,7 +37,7 @@ transaction(recipient: Address, numToMint: Int) { while numMinted < numToMint { numMinted = numMinted + 1 - let token <- self.minter.mintAndReturnNFT(name: "testname", description: "descr", thumbnail: "image.html", royalties: []) as! @ExampleNFT.NFT + let token <- self.minter.mint(name: "testname", description: "descr", thumbnail: "image.html") let display = token.resolveView(Type()) as! MetadataViews.Display? let memo = "test memo" diff --git a/transactions/ExampleNFT/mint_and_deposit_with_depositor.cdc b/transactions/example-nft/mint_and_deposit_with_depositor.cdc similarity index 63% rename from transactions/ExampleNFT/mint_and_deposit_with_depositor.cdc rename to transactions/example-nft/mint_and_deposit_with_depositor.cdc index 18b0cb0..40c302d 100644 --- a/transactions/ExampleNFT/mint_and_deposit_with_depositor.cdc +++ b/transactions/example-nft/mint_and_deposit_with_depositor.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address) { // local variable for storing the minter reference @@ -19,7 +19,7 @@ transaction(recipient: Address) { } execute { - let token <- self.minter.mintAndReturnNFT(name: "testname", description: "descr", thumbnail: "image.html", royalties: []) + let token <- self.minter.mint(name: "testname", description: "descr", thumbnail: "image.html") let display = token.resolveView(Type()) as! MetadataViews.Display? let memo = "test memo" diff --git a/transactions/example-nft/mint_example_nft.cdc b/transactions/example-nft/mint_example_nft.cdc new file mode 100644 index 0000000..9e801ac --- /dev/null +++ b/transactions/example-nft/mint_example_nft.cdc @@ -0,0 +1,25 @@ +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" + +transaction(recipient: Address, num: Int) { + // local variable for storing the minter reference + let minter: &ExampleNFT.NFTMinter + + prepare(acct: AuthAccount) { + // borrow a reference to the NFTMinter resource in storage + self.minter = acct.borrow<&ExampleNFT.NFTMinter>(from: /storage/exampleNFTMinter) + ?? panic("Could not borrow a reference to the NFT minter") + } + + execute { + let receiver = getAccount(recipient).getCapability<&{NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath).borrow()! + + var count = 0 + while count < num { + count = count + 1 + self.minter.mintNFT(recipient: receiver, name: "testname", description: "descr", thumbnail: "image.html", royaltyReceipient: self.minter.owner!.address) + } + } +} diff --git a/transactions/ExampleNFT/redeem_example_nft_all.cdc b/transactions/example-nft/redeem_example_nft_all.cdc similarity index 84% rename from transactions/ExampleNFT/redeem_example_nft_all.cdc rename to transactions/example-nft/redeem_example_nft_all.cdc index 5a54657..fa2662a 100644 --- a/transactions/ExampleNFT/redeem_example_nft_all.cdc +++ b/transactions/example-nft/redeem_example_nft_all.cdc @@ -1,9 +1,9 @@ -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" +import "ExampleNFT" +import "NonFungibleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" -transaction() { +transaction { let receiver: Capability<&{NonFungibleToken.CollectionPublic}> let redeemer: Address diff --git a/transactions/example-nft/setup.cdc b/transactions/example-nft/setup.cdc new file mode 100644 index 0000000..5149570 --- /dev/null +++ b/transactions/example-nft/setup.cdc @@ -0,0 +1,31 @@ +import "NonFungibleToken" +import "ExampleNFT" +import "MetadataViews" + +transaction { + prepare(signer: AuthAccount) { + // Return early if the account already stores a ExampleToken Vault + if signer.borrow<&ExampleNFT.Collection>(from: ExampleNFT.CollectionStoragePath) == nil { + // Create a new ExampleToken Vault and put it in storage + signer.save( + <-ExampleNFT.createEmptyCollection(), + to: ExampleNFT.CollectionStoragePath + ) + } + + signer.unlink(ExampleNFT.CollectionPublicPath) + signer.unlink(/private/exampleNFTCollection) + + // Create a public capability to the Vault that only exposes + // the balance field through the Balance interface + signer.link<&ExampleNFT.Collection{NonFungibleToken.CollectionPublic, MetadataViews.ResolverCollection}>( + ExampleNFT.CollectionPublicPath, + target: ExampleNFT.CollectionStoragePath + ) + + signer.link<&ExampleNFT.Collection{NonFungibleToken.CollectionPublic, NonFungibleToken.Provider}>( + /private/exampleNFTCollection, + target: ExampleNFT.CollectionStoragePath + ) + } +} \ No newline at end of file diff --git a/transactions/ExampleNFT/setup_account_example_nft.cdc b/transactions/example-nft/setup_account_example_nft.cdc similarity index 81% rename from transactions/ExampleNFT/setup_account_example_nft.cdc rename to transactions/example-nft/setup_account_example_nft.cdc index bdf0b41..04a777e 100644 --- a/transactions/ExampleNFT/setup_account_example_nft.cdc +++ b/transactions/example-nft/setup_account_example_nft.cdc @@ -1,6 +1,6 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" +import "FlowToken" +import "NonFungibleToken" +import "ExampleNFT" transaction { diff --git a/transactions/ExampleNFT/try_send_example_nft.cdc b/transactions/example-nft/try_send_example_nft.cdc similarity index 80% rename from transactions/ExampleNFT/try_send_example_nft.cdc rename to transactions/example-nft/try_send_example_nft.cdc index cf0973e..16973c0 100644 --- a/transactions/ExampleNFT/try_send_example_nft.cdc +++ b/transactions/example-nft/try_send_example_nft.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address) { // local variable for storing the minter reference @@ -34,7 +34,8 @@ transaction(recipient: Address) { execute { let exampleNFTReceiver = getAccount(recipient).getCapability<&{NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath) - let token <- self.minter.mintAndReturnNFT(name: "testname", description: "descr", thumbnail: "image.html", royalties: []) as! @ExampleNFT.NFT + + let token <- self.minter.mint(name: "testname", description: "descr", thumbnail: "image.html") let display = token.resolveView(Type()) as! MetadataViews.Display? let memo = "test memo" diff --git a/transactions/ExampleNFT/try_send_example_nft_with_depositor.cdc b/transactions/example-nft/try_send_example_nft_with_depositor.cdc similarity index 67% rename from transactions/ExampleNFT/try_send_example_nft_with_depositor.cdc rename to transactions/example-nft/try_send_example_nft_with_depositor.cdc index 7d2b0d7..6058736 100644 --- a/transactions/ExampleNFT/try_send_example_nft_with_depositor.cdc +++ b/transactions/example-nft/try_send_example_nft_with_depositor.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address) { // local variable for storing the minter reference @@ -20,7 +20,7 @@ transaction(recipient: Address) { execute { let exampleNFTReceiver = getAccount(recipient).getCapability<&{NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath) - let token <- self.minter.mintAndReturnNFT(name: "testname", description: "descr", thumbnail: "image.html", royalties: []) + let token <- self.minter.mint(name: "testname", description: "descr", thumbnail: "image.html") let display = token.resolveView(Type()) as! MetadataViews.Display? let memo = "test memo" diff --git a/transactions/ExampleNFT/try_send_multiple_example_nft.cdc b/transactions/example-nft/try_send_multiple_example_nft.cdc similarity index 87% rename from transactions/ExampleNFT/try_send_multiple_example_nft.cdc rename to transactions/example-nft/try_send_multiple_example_nft.cdc index e800176..f0b4eae 100644 --- a/transactions/ExampleNFT/try_send_multiple_example_nft.cdc +++ b/transactions/example-nft/try_send_multiple_example_nft.cdc @@ -1,10 +1,10 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleNFT from "../../contracts/ExampleNFT.cdc" -import NonFungibleToken from "../../contracts/NonFungibleToken.cdc" -import MetadataViews from "../../contracts/MetadataViews.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleNFT" +import "NonFungibleToken" +import "MetadataViews" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address, numToMint: Int) { // local variable for storing the minter reference diff --git a/transactions/ExampleToken/deposit_example_token.cdc b/transactions/example-token/deposit_example_token.cdc similarity index 89% rename from transactions/ExampleToken/deposit_example_token.cdc rename to transactions/example-token/deposit_example_token.cdc index f5e59ab..abb51bc 100644 --- a/transactions/ExampleToken/deposit_example_token.cdc +++ b/transactions/example-token/deposit_example_token.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(redeemer: Address, amount: UFix64) { let tokenAdmin: &ExampleToken.Administrator diff --git a/transactions/example-token/deposit_example_token_with_depositor.cdc b/transactions/example-token/deposit_example_token_with_depositor.cdc new file mode 100644 index 0000000..8075dc9 --- /dev/null +++ b/transactions/example-token/deposit_example_token_with_depositor.cdc @@ -0,0 +1,25 @@ +import "FlowToken" +import "FungibleToken" +import "ExampleToken" + +import "LostAndFound" + +transaction(recipient: Address, amount: UFix64) { + let tokenAdmin: &ExampleToken.Administrator + let depositor: &LostAndFound.Depositor + + prepare(acct: AuthAccount) { + self.tokenAdmin = acct.borrow<&ExampleToken.Administrator>(from: /storage/exampleTokenAdmin) + ?? panic("acct is not the token admin") + self.depositor = acct.borrow<&LostAndFound.Depositor>(from: LostAndFound.DepositorStoragePath)! + } + + execute { + let minter <- self.tokenAdmin.createNewMinter(allowedAmount: amount) + let mintedVault <- minter.mintTokens(amount: amount) + let memo = "test memo" + self.depositor.deposit(redeemer: recipient, item: <- mintedVault, memo: memo, display: nil) + + destroy minter + } +} \ No newline at end of file diff --git a/transactions/ExampleToken/destroy_example_token_storage.cdc b/transactions/example-token/destroy_example_token_storage.cdc similarity index 53% rename from transactions/ExampleToken/destroy_example_token_storage.cdc rename to transactions/example-token/destroy_example_token_storage.cdc index c681f41..59ee594 100644 --- a/transactions/ExampleToken/destroy_example_token_storage.cdc +++ b/transactions/example-token/destroy_example_token_storage.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction { prepare(signer: AuthAccount) { diff --git a/transactions/ExampleToken/redeem_example_token_all.cdc b/transactions/example-token/redeem_example_token_all.cdc similarity index 81% rename from transactions/ExampleToken/redeem_example_token_all.cdc rename to transactions/example-token/redeem_example_token_all.cdc index 482234f..1f6fcd1 100644 --- a/transactions/ExampleToken/redeem_example_token_all.cdc +++ b/transactions/example-token/redeem_example_token_all.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction() { let receiver: Capability<&{FungibleToken.Receiver}> diff --git a/transactions/example-token/setup.cdc b/transactions/example-token/setup.cdc new file mode 100644 index 0000000..271e93b --- /dev/null +++ b/transactions/example-token/setup.cdc @@ -0,0 +1,23 @@ +import "FungibleToken" +import "ExampleToken" + +transaction { + prepare(acct: AuthAccount) { + if acct.borrow<&ExampleToken.Vault>(from: /storage/exampleTokenVault) == nil { + acct.save(<-ExampleToken.createEmptyVault(), to: /storage/exampleTokenVault) + } + + acct.link<&{FungibleToken.Receiver}>( + /public/exampleTokenReceiver, + target: /storage/exampleTokenVault + ) + + acct.link<&{FungibleToken.Balance}>( + /public/exampleTokenBalance, + target: /storage/exampleTokenVault + ) + + acct.link<&{FungibleToken.Provider, FungibleToken.Balance, FungibleToken.Receiver}>(/private/exampleTokenProvider, target: /storage/exampleTokenVault) + } +} + \ No newline at end of file diff --git a/transactions/ExampleToken/setup_account_ft.cdc b/transactions/example-token/setup_account_ft.cdc similarity index 81% rename from transactions/ExampleToken/setup_account_ft.cdc rename to transactions/example-token/setup_account_ft.cdc index d61117e..a11b056 100644 --- a/transactions/ExampleToken/setup_account_ft.cdc +++ b/transactions/example-token/setup_account_ft.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction { diff --git a/transactions/ExampleToken/try_send_example_token.cdc b/transactions/example-token/try_send_example_token.cdc similarity index 89% rename from transactions/ExampleToken/try_send_example_token.cdc rename to transactions/example-token/try_send_example_token.cdc index fc4f71f..ade1fd4 100644 --- a/transactions/ExampleToken/try_send_example_token.cdc +++ b/transactions/example-token/try_send_example_token.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address, amount: UFix64) { let tokenAdmin: &ExampleToken.Administrator diff --git a/transactions/ExampleToken/try_send_example_token_depositor.cdc b/transactions/example-token/try_send_example_token_depositor.cdc similarity index 80% rename from transactions/ExampleToken/try_send_example_token_depositor.cdc rename to transactions/example-token/try_send_example_token_depositor.cdc index 00c0908..00e0ca6 100644 --- a/transactions/ExampleToken/try_send_example_token_depositor.cdc +++ b/transactions/example-token/try_send_example_token_depositor.cdc @@ -1,8 +1,8 @@ -import FlowToken from "../../contracts/FlowToken.cdc" -import FungibleToken from "../../contracts/FungibleToken.cdc" -import ExampleToken from "../../contracts/ExampleToken.cdc" +import "FlowToken" +import "FungibleToken" +import "ExampleToken" -import LostAndFound from "../../contracts/LostAndFound.cdc" +import "LostAndFound" transaction(recipient: Address, amount: UFix64) { let tokenAdmin: &ExampleToken.Administrator diff --git a/transactions/flow/mint_flow.cdc b/transactions/flow/mint_flow.cdc new file mode 100644 index 0000000..a2c26cf --- /dev/null +++ b/transactions/flow/mint_flow.cdc @@ -0,0 +1,18 @@ +import "FungibleToken" +import "FlowToken" + +transaction(receiver: Address, amount: UFix64) { + prepare(account: AuthAccount) { + let flowVault = account.borrow<&FlowToken.Vault>( + from: /storage/flowTokenVault + ) ?? panic("Could not borrow BlpToken.Vault reference") + + let receiverRef = getAccount(receiver) + .getCapability(/public/flowTokenReceiver) + .borrow<&FlowToken.Vault{FungibleToken.Receiver}>() + ?? panic("Could not borrow FungibleToken.Receiver reference") + + let tokens <- flowVault.withdraw(amount: amount) + receiverRef.deposit(from: <- tokens) + } +} \ No newline at end of file