diff --git a/scripts/raffle/get_raffle_entries.cdc b/scripts/raffle/get_raffle_entries.cdc new file mode 100644 index 0000000..d6cc58f --- /dev/null +++ b/scripts/raffle/get_raffle_entries.cdc @@ -0,0 +1,11 @@ +import "FlowtyRaffles" +pub fun main(addr: Address, id: UInt64): [AnyStruct] { + let acct = getAuthAccount(addr) + let manager = acct.borrow<&FlowtyRaffles.Manager{FlowtyRaffles.ManagerPublic}>(from: FlowtyRaffles.ManagerStoragePath) + ?? panic("raffles manager not found") + let raffle = manager.borrowRafflePublic(id: id) + ?? panic("raffle not found") + let source: &AnyResource{FlowtyRaffles.RaffleSourcePublic} = raffle.borrowSourcePublic() ?? panic("source is invalid") + + return source.getEntries() +} \ No newline at end of file diff --git a/test/FlowtyWrapped_tests.cdc b/test/FlowtyWrapped_tests.cdc index babc4cd..fcfe558 100644 --- a/test/FlowtyWrapped_tests.cdc +++ b/test/FlowtyWrapped_tests.cdc @@ -4,6 +4,7 @@ import "test_helpers.cdc" import "FlowtyWrapped" import "MetadataViews" import "WrappedEditions" +import "FlowtyRaffles" pub let rafflesAcct = Test.getAccount(Address(0x0000000000000007)) pub let minterAccount = Test.getAccount(Address(0x0000000000000007)) @@ -29,8 +30,8 @@ pub fun setup() { // register a test wrapped edition let removeAfterReveal: Bool = true - let start: UInt64 = 0 - let end: UInt64 = 100 + let start: UInt64? = nil + let end: UInt64? = nil let baseImageUrl: String = "https://example.com/image/" let baseHtmlUrl: String = "QmVZv2s6sozWWb4dEcANaszqKWLQbieYJLysK7NGq3RGdJ" registerEdition(rafflesAcct: Test.getAccount(Address(0x0000000000000007)), removeAfterReveal: removeAfterReveal, start: start, end: end, baseImageUrl: baseImageUrl, baseHtmlUrl: baseHtmlUrl) @@ -203,7 +204,34 @@ pub fun testIpfsUrlNoName() { assert(ipfsUrl == "ipfs://QmVZv2s6sozWWb4dEcANaszqKWLQbieYJLysK7NGq3RGdJ?username=".concat(acct.address.toString()).concat("&raffleTickets=1"), message: "unexpected ipfs url") } -pub fun registerEdition(rafflesAcct: Test.Account, removeAfterReveal: Bool, start: UInt64, end: UInt64, baseImageUrl: String, baseHtmlUrl: String) { +pub fun testDrawRaffle() { + let acct = Test.createAccount() + let username: String = "user1" + + let editionName = "Flowty Wrapped 2023" + let createEvent = (Test.eventsOfType(Type()).removeLast() as! FlowtyRaffles.RaffleCreated) + + setupForMint(acct: acct, name: username) + let entries: AnyStruct = scriptExecutor("raffle/get_raffle_entries.cdc", [minterAccount.address, createEvent.raffleID]) + let castedEntries = entries! as! [AnyStruct] + + assert(castedEntries.length >= 1, message: "no entries") + assert(castedEntries.removeLast() as! Address == acct.address) + + let drawing = drawFromRaffle(rafflesAcct, createEvent.raffleID) + + var winnerIsFromEntryPool = false + for e in castedEntries { + let c = (e as! Address).toString() + if c == drawing{ + winnerIsFromEntryPool = true + break + } + } + assert(winnerIsFromEntryPool) +} + +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) } @@ -231,4 +259,11 @@ pub fun setupForMint(acct: Test.Account, name: String) { let collections: [String] = [""] txExecutor("mint_flowty_wrapped.cdc", [minterAccount], [acct.address, name, ticket, totalNftsOwned, floatCount, favoriteCollections, collections], nil) +} + +pub fun drawFromRaffle(_ signer: Test.Account, _ id: UInt64): String { + txExecutor("raffle/draw_from_raffle.cdc", [signer], [id], nil) + + let drawingEvent = Test.eventsOfType(Type()).removeLast() as! FlowtyRaffles.RaffleReceiptRevealed + return drawingEvent.value ?? "" } \ No newline at end of file diff --git a/transactions/raffle/draw_from_raffle.cdc b/transactions/raffle/draw_from_raffle.cdc new file mode 100644 index 0000000..aa40151 --- /dev/null +++ b/transactions/raffle/draw_from_raffle.cdc @@ -0,0 +1,12 @@ +import "FlowtyRaffles" + +transaction(id: UInt64) { + prepare(acct: AuthAccount) { + let manager = acct.borrow<&FlowtyRaffles.Manager>(from: FlowtyRaffles.ManagerStoragePath) + ?? panic("raffles manager not found") + let receiptID = manager.commitDrawing(raffleID: id) + + let ref = manager as &FlowtyRaffles.Manager{FlowtyRaffles.ManagerPublic} + manager.revealDrawing(manager: ref, raffleID: id, receiptID: receiptID) + } +} \ No newline at end of file diff --git a/transactions/register_edition.cdc b/transactions/register_edition.cdc index 0b781c7..bf228a0 100644 --- a/transactions/register_edition.cdc +++ b/transactions/register_edition.cdc @@ -4,7 +4,7 @@ import "FlowtyRaffles" import "FlowtyRaffleSource" // flow transactions send ./transactions/register_edition.cdc false 1703035065 1705195052 "https://storage.googleapis.com/flowty-wrapped-2023-testnet/" QmcvXz8zZ8hZwgH95zVQ8ZEJUZ92oR9MVjCFVYePyCuvxB -n testnet --signer wrapped-testnet -transaction(removeAfterReveal: Bool, start: UInt64, end: UInt64, baseImageUrl: String, baseHtmlUrl: String) { +transaction(removeAfterReveal: Bool, start: UInt64?, end: UInt64?, baseImageUrl: String, baseHtmlUrl: String) { prepare(acct: AuthAccount) { let raffleManager = acct.borrow<&FlowtyRaffles.Manager>(from: FlowtyRaffles.ManagerStoragePath)! @@ -12,7 +12,7 @@ transaction(removeAfterReveal: Bool, start: UInt64, end: UInt64, baseImageUrl: S let source <- FlowtyRaffleSource.createRaffleSource(entryType: Type
(), removeAfterReveal: removeAfterReveal) // fill out raffle details. All we really care about is the start and end here - let details = FlowtyRaffles.Details(start: start, end: end, display: nil, externalURL: nil, commitBlocksAhead: 1) + let details = FlowtyRaffles.Details(start: start, end: end, display: nil, externalURL: nil, commitBlocksAhead: 0) // make the raffle, get its id to pass on to the edition let raffleID = raffleManager.createRaffle(source: <- source, details: details, revealers: [])