-
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 some basic tests for getting drop details (#2)
- Loading branch information
1 parent
7e62ce0
commit b718159
Showing
10 changed files
with
329 additions
and
25 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
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,17 @@ | ||
import "FlowtyDrops" | ||
import "ViewResolver" | ||
|
||
pub fun main(contractAddress: Address, contractName: String, dropID: UInt64): FlowtyDrops.DropDetails { | ||
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName) | ||
?? panic("contract does not implement ViewResolver interface") | ||
|
||
let dropResolver = resolver.resolveView(Type<FlowtyDrops.DropResolver>())! as! FlowtyDrops.DropResolver | ||
|
||
let container = dropResolver.borrowContainer() | ||
?? panic("drop container not found") | ||
|
||
let drop = container.borrowDropPublic(id: dropID) | ||
?? panic("drop not found") | ||
|
||
return drop.getDetails() | ||
} |
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,22 @@ | ||
import "FlowtyDrops" | ||
import "ViewResolver" | ||
|
||
pub fun main(contractAddress: Address, contractName: String): [UInt64] { | ||
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName) | ||
if resolver == nil { | ||
return [] | ||
} | ||
|
||
let tmp = resolver!.resolveView(Type<FlowtyDrops.DropResolver>()) | ||
if tmp == nil { | ||
return [] | ||
} | ||
|
||
let dropResolver = tmp! as! FlowtyDrops.DropResolver | ||
|
||
if let dropContainer = dropResolver.borrowContainer() { | ||
return dropContainer.getIDs() | ||
} | ||
|
||
return [] | ||
} |
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,20 @@ | ||
import "FlowtyDrops" | ||
import "ViewResolver" | ||
|
||
pub fun main(contractAddress: Address, contractName: String, dropID: UInt64, phaseIndex: Int, minter: Address, numToMint: Int, paymentIdentifier: String): UFix64? { | ||
let paymentTokenType = CompositeType(paymentIdentifier)! | ||
|
||
let resolver = getAccount(contractAddress).contracts.borrow<&ViewResolver>(name: contractName) | ||
?? panic("contract does not implement ViewResolver interface") | ||
|
||
let dropResolver = resolver.resolveView(Type<FlowtyDrops.DropResolver>())! as! FlowtyDrops.DropResolver | ||
|
||
let container = dropResolver.borrowContainer() | ||
?? panic("drop container not found") | ||
|
||
let drop = container.borrowDropPublic(id: dropID) | ||
?? panic("drop not found") | ||
|
||
let phase = drop.borrowPhase(index: phaseIndex) | ||
return phase.getDetails().pricer.getPrice(num: numToMint, paymentTokenType: paymentTokenType, minter: minter) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,63 @@ | ||
import Test | ||
import "test_helpers.cdc" | ||
import "FlowToken" | ||
import "FlowtyDrops" | ||
|
||
pub let defaultEndlessOpenEditionName = "Default Endless Open Edition" | ||
|
||
pub fun setup() { | ||
deployAll() | ||
} | ||
|
||
pub fun afterEach() { | ||
txExecutor("drops/remove_all_drops.cdc", [openEditionAccount], [], nil, nil) | ||
} | ||
|
||
pub fun testImports() { | ||
Test.assert(scriptExecutor("import_all.cdc", [])! as! Bool, message: "failed to import all") | ||
} | ||
|
||
pub fun test_OpenEditionNFT_getPrice() { | ||
let minter = Test.createAccount() | ||
|
||
let dropID = createDefaultEndlessOpenEditionDrop() | ||
let price = getPriceAtPhase( | ||
contractAddress: openEditionAccount.address, contractName: "OpenEditionNFT", dropID: dropID, phaseIndex: 0, minter: minter.address, numToMint: 1, paymentIdentifier: Type<@FlowToken.Vault>().identifier | ||
) | ||
Test.assertEqual(1.0, price) | ||
|
||
let priceMultiple = getPriceAtPhase( | ||
contractAddress: openEditionAccount.address, contractName: "OpenEditionNFT", dropID: dropID, phaseIndex: 0, minter: minter.address, numToMint: 10, paymentIdentifier: Type<@FlowToken.Vault>().identifier | ||
) | ||
Test.assertEqual(10.0, priceMultiple) | ||
} | ||
|
||
pub fun test_OpenEditionNFT_getDetails() { | ||
let dropID = createDefaultEndlessOpenEditionDrop() | ||
let details = getDropDetails(contractAddress: openEditionAccount.address, contractName: "OpenEditionNFT", dropID: dropID) | ||
Test.assertEqual(details.display.name, defaultEndlessOpenEditionName) | ||
} | ||
|
||
// ------------------------------------------------------------------------ | ||
// Helper functions section | ||
pub fun createDefaultEndlessOpenEditionDrop(): UInt64 { | ||
return createEndlessOpenEditionDrop( | ||
acct: openEditionAccount, | ||
name: "Default Endless Open Edition", | ||
description: "This is a placeholder description", | ||
ipfsCid: "1234", | ||
ipfsPath: nil, | ||
price: 1.0, | ||
paymentIdentifier: Type<@FlowToken.Vault>().identifier, | ||
minterPrivatePath: FlowtyDrops.MinterPrivatePath | ||
) | ||
} | ||
|
||
pub fun getPriceAtPhase(contractAddress: Address, contractName: String, dropID: UInt64, phaseIndex: Int, minter: Address, numToMint: Int, paymentIdentifier: String): UFix64 { | ||
return scriptExecutor("get_price_at_phase.cdc", [contractAddress, contractName, dropID, phaseIndex, minter, numToMint, paymentIdentifier])! as! UFix64 | ||
} | ||
|
||
pub fun getDropDetails(contractAddress: Address, contractName: String, dropID: UInt64): FlowtyDrops.DropDetails { | ||
return scriptExecutor("get_drop_details.cdc", [contractAddress, contractName, dropID])! as! FlowtyDrops.DropDetails | ||
} |
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
Oops, something went wrong.