-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for creating, adding to, and drawing from raffles (#4)
* add tests for creating, adding to, and drawin from raffles * move to generic raffle source
- Loading branch information
1 parent
0e2ed0a
commit 352fb54
Showing
13 changed files
with
370 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import "Raffles" | ||
|
||
pub contract RaffleSources { | ||
pub resource GenericRaffleSource: Raffles.RaffleSource { | ||
pub let entries: [AnyStruct] | ||
pub let entryType: Type | ||
|
||
pub fun getEntryType(): Type { | ||
return self.entryType | ||
} | ||
|
||
pub fun getEntryAt(index: Int): AnyStruct { | ||
return self.entries[index] | ||
} | ||
|
||
pub fun addEntry(_ v: AnyStruct) { | ||
pre { | ||
v.getType() == self.entryType: "incorrect entry type" | ||
} | ||
|
||
self.entries.append(v) | ||
} | ||
|
||
pub fun addEntries(_ v: [AnyStruct]) { | ||
pre { | ||
VariableSizedArrayType(self.entryType) == v.getType(): "incorrect array type" | ||
} | ||
|
||
self.entries.appendAll(v) | ||
} | ||
|
||
pub fun getNumEntries(): Int { | ||
return self.entries.length | ||
} | ||
|
||
pub fun getEntries(): [AnyStruct] { | ||
return self.entries | ||
} | ||
|
||
init(_ entryType: Type) { | ||
self.entries = [] | ||
self.entryType = entryType | ||
} | ||
} | ||
|
||
pub fun createRaffleSource(_ type: Type): @GenericRaffleSource { | ||
return <- create GenericRaffleSource(type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import "Raffles" | ||
|
||
pub fun main(addr: Address, id: UInt64): Int { | ||
let acct = getAuthAccount(addr) | ||
let manager = acct.borrow<&Raffles.Manager{Raffles.ManagerPublic}>(from: Raffles.ManagerStoragePath) | ||
?? panic("raffles manager not found") | ||
let raffle = manager.borrowRafflePublic(id: id) | ||
?? panic("raffle not found") | ||
|
||
return raffle.getNumEntries() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import "Raffles" | ||
|
||
pub fun main(addr: Address, id: UInt64): Raffles.Details? { | ||
let acct = getAuthAccount(addr) | ||
let manager = acct.borrow<&Raffles.Manager>(from: Raffles.ManagerStoragePath) | ||
?? panic("raffles manager not found") | ||
|
||
if let raffle = manager.borrowRafflePublic(id: id) { | ||
return raffle.getDetails() | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import "Raffles" | ||
|
||
pub fun main(addr: Address, id: UInt64): [AnyStruct] { | ||
let acct = getAuthAccount(addr) | ||
let manager = acct.borrow<&Raffles.Manager{Raffles.ManagerPublic}>(from: Raffles.ManagerStoragePath) | ||
?? panic("raffles manager not found") | ||
let raffle = manager.borrowRafflePublic(id: id) | ||
?? panic("raffle not found") | ||
|
||
return raffle.getEntries() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "Raffles" | ||
|
||
pub fun main(addr: Address, path: StoragePath): String { | ||
let acct = getAuthAccount(addr) | ||
let source = acct.borrow<&{Raffles.RaffleSource}>(from: path) | ||
return source!.getType().identifier | ||
} |
Oops, something went wrong.