-
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 test to validate access to child account tokens
- Loading branch information
1 parent
9d8a2d2
commit d5e6fe5
Showing
6 changed files
with
110 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import "FungibleToken" | ||
|
||
access(all) fun main(addr: Address, path: StoragePath): UInt64 { | ||
let acct = getAuthAccount<auth(Capabilities) &Account>(addr) | ||
|
||
let type = Type<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>() | ||
for controller in acct.capabilities.storage.getControllers(forPath: path) { | ||
if controller.borrowType.isSubtype(of: type) { | ||
return controller.capabilityID | ||
} | ||
} | ||
|
||
panic("no withdraw capability ID found") | ||
} |
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 |
---|---|---|
@@ -1,13 +1,43 @@ | ||
import "ContractManager" | ||
import "FlowToken" | ||
import "FungibleToken" | ||
import "HybridCustody" | ||
import "ViewResolver" | ||
|
||
transaction(flowTokenAmount: UFix64) { | ||
prepare(acct: auth(Storage, Capabilities) &Account) { | ||
prepare(acct: auth(Storage, Capabilities, Inbox) &Account) { | ||
let v = acct.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)! | ||
let tokens <- v.withdraw(amount: flowTokenAmount) as! @FlowToken.Vault | ||
|
||
acct.storage.save(<- ContractManager.createManager(tokens: <-tokens, defaultRouterAddress: acct.address), to: ContractManager.StoragePath) | ||
acct.storage.borrow<auth(ContractManager.Manage) &ContractManager.Manager>(from: ContractManager.StoragePath)!.onSave() | ||
let contractManager = acct.storage.borrow<auth(ContractManager.Manage) &ContractManager.Manager>(from: ContractManager.StoragePath)! | ||
contractManager.onSave() | ||
|
||
// there is a published hybrid custody capability to redeem | ||
if acct.storage.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) == nil { | ||
let m <- HybridCustody.createManager(filter: nil) | ||
acct.storage.save(<- m, to: HybridCustody.ManagerStoragePath) | ||
|
||
for c in acct.capabilities.storage.getControllers(forPath: HybridCustody.ManagerStoragePath) { | ||
c.delete() | ||
} | ||
|
||
acct.capabilities.unpublish(HybridCustody.ManagerPublicPath) | ||
|
||
acct.capabilities.publish( | ||
acct.capabilities.storage.issue<&{HybridCustody.ManagerPublic}>(HybridCustody.ManagerStoragePath), | ||
at: HybridCustody.ManagerPublicPath | ||
) | ||
|
||
acct.capabilities.storage.issue<auth(HybridCustody.Manage) &{HybridCustody.ManagerPrivate, HybridCustody.ManagerPublic}>(HybridCustody.ManagerStoragePath) | ||
} | ||
|
||
let inboxName = HybridCustody.getChildAccountIdentifier(acct.address) | ||
let cap = acct.inbox.claim<auth(HybridCustody.Child) &{HybridCustody.AccountPrivate, HybridCustody.AccountPublic, ViewResolver.Resolver}>(inboxName, provider: contractManager.getAccount().address) | ||
?? panic("child account cap not found") | ||
|
||
let manager = acct.storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) | ||
?? panic("manager no found") | ||
manager.addAccount(cap: cap) | ||
} | ||
} |
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,31 @@ | ||
import "FlowToken" | ||
import "FungibleToken" | ||
import "HybridCustody" | ||
import "ContractManager" | ||
import "FungibleTokenMetadataViews" | ||
|
||
transaction(amount: UFix64, controllerID: UInt64) { | ||
prepare(acct: auth(Storage, Capabilities) &Account) { | ||
let contractManager = acct.storage.borrow<auth(ContractManager.Manage) &ContractManager.Manager>(from: ContractManager.StoragePath) | ||
?? panic("contract manager not found") | ||
|
||
let manager = acct.storage.borrow<auth(HybridCustody.Manage) &HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath) | ||
?? panic("hybrid custody manager not found") | ||
|
||
let child = manager.borrowAccount(addr: contractManager.getAccount().address) | ||
?? panic("child account not found") | ||
|
||
let cap = child.getCapability(controllerID: controllerID, type: Type<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}>()) ?? panic("capability count not be borrowed") | ||
let providerCap = cap as! Capability<auth(FungibleToken.Withdraw) &{FungibleToken.Provider}> | ||
let vault = providerCap.borrow() ?? panic("vault count not be borrowed") | ||
let tokens <- vault.withdraw(amount: amount) | ||
|
||
let ftVaultData = tokens.resolveView(Type<FungibleTokenMetadataViews.FTVaultData>())! as! FungibleTokenMetadataViews.FTVaultData | ||
|
||
if acct.storage.type(at: ftVaultData.storagePath) == nil { | ||
acct.storage.save(<- ftVaultData.createEmptyVault(), to: ftVaultData.storagePath) | ||
} | ||
|
||
acct.storage.borrow<&{FungibleToken.Vault}>(from: ftVaultData.storagePath)!.deposit(from: <-tokens) | ||
} | ||
} |
Empty file.