-
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 drawin from raffles
- Loading branch information
1 parent
0e2ed0a
commit 505808c
Showing
14 changed files
with
364 additions
and
46 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,42 @@ | ||
import "Raffles" | ||
|
||
pub contract RaffleSources { | ||
pub resource AddressRaffleSource: Raffles.RaffleSource { | ||
pub let addresses: [Address] | ||
|
||
pub fun getEntryAt(index: Int): AnyStruct { | ||
return self.addresses[index] | ||
} | ||
|
||
pub fun addEntry(_ v: AnyStruct) { | ||
let addr = v as! Address | ||
self.addresses.append(addr) | ||
} | ||
|
||
pub fun addEntries(_ v: [AnyStruct]) { | ||
let addrs = v as! [Address] | ||
self.addresses.appendAll(addrs) | ||
} | ||
|
||
pub fun getNumEntries(): Int { | ||
return self.addresses.length | ||
} | ||
|
||
pub fun getEntries(): [AnyStruct] { | ||
return self.addresses | ||
} | ||
|
||
init() { | ||
self.addresses = [] | ||
} | ||
} | ||
|
||
pub fun createRaffleSource(_ type: Type): @{Raffles.RaffleSource} { | ||
switch type { | ||
case Type<@AddressRaffleSource>(): | ||
return <- create AddressRaffleSource() | ||
} | ||
|
||
panic("raffle source type ".concat(type.identifier).concat(" is not valid")) | ||
} | ||
} |
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.