-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter remove all #145
Merged
Merged
filter remove all #145
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -331,6 +331,57 @@ pub fun testGetCapability_ManagerFilterAllowed() { | |
scriptExecutor("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
} | ||
|
||
pub fun testAllowlistFilterRemoveAllTypes() { | ||
let child = blockchain.createAccount() | ||
let parent = blockchain.createAccount() | ||
|
||
setupChildAndParent_FilterKindAll(child: child, parent: parent) | ||
|
||
setupNFTCollection(child) | ||
|
||
scriptExecutor("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
|
||
let filter = getTestAccount(FilterKindAllowList) | ||
setupFilter(filter, FilterKindAllowList) | ||
|
||
let nftIdentifier = buildTypeIdentifier(getTestAccount(exampleNFT), exampleNFT, "Collection") | ||
setManagerFilterOnChild(child: child, parent: parent, filterAddress: filter.address) | ||
|
||
addTypeToFilter(filter, FilterKindAllowList, nftIdentifier) | ||
|
||
scriptExecutor("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
|
||
removeAllFilterTypes(filter, FilterKindAllowList) | ||
|
||
let error = expectScriptFailure("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
assert(contains(error, "Capability is not allowed by this account's Parent"), message: "failed to find expected error message") | ||
} | ||
|
||
pub fun testDenyListFilterRemoveAllTypes() { | ||
let child = blockchain.createAccount() | ||
let parent = blockchain.createAccount() | ||
|
||
setupChildAndParent_FilterKindAll(child: child, parent: parent) | ||
|
||
setupNFTCollection(child) | ||
|
||
scriptExecutor("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
|
||
let filter = getTestAccount(FilterKindDenyList) | ||
setupFilter(filter, FilterKindDenyList) | ||
|
||
let nftIdentifier = buildTypeIdentifier(getTestAccount(exampleNFT), exampleNFT, "Collection") | ||
addTypeToFilter(filter, FilterKindDenyList, nftIdentifier) | ||
setManagerFilterOnChild(child: child, parent: parent, filterAddress: filter.address) | ||
|
||
let error = expectScriptFailure("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
assert(contains(error, "Capability is not allowed by this account's Parent"), message: "failed to find expected error message") | ||
|
||
|
||
removeAllFilterTypes(filter, FilterKindDenyList) | ||
scriptExecutor("hybrid-custody/get_nft_provider_capability.cdc", [parent.address, child.address]) | ||
} | ||
|
||
pub fun testGetCapability_ManagerFilterNotAllowed() { | ||
let child = blockchain.createAccount() | ||
let parent = blockchain.createAccount() | ||
|
@@ -914,6 +965,22 @@ pub fun addTypeToFilter(_ acct: Test.Account, _ kind: String, _ identifier: Stri | |
txExecutor(filePath, [acct], [identifier], nil, nil) | ||
} | ||
|
||
pub fun removeAllFilterTypes(_ acct: Test.Account, _ kind: String) { | ||
var filePath = "" | ||
switch kind { | ||
case FilterKindAllowList: | ||
filePath = "filter/allow/remove_all_types.cdc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the file needs to be renamed - |
||
break | ||
case FilterKindDenyList: | ||
filePath = "filter/deny/remove_all_types.cdc" | ||
break | ||
default: | ||
assert(false, message: "unknown filter kind given") | ||
} | ||
|
||
txExecutor(filePath, [acct], [], nil, nil) | ||
} | ||
|
||
pub fun addNFTCollectionToDelegator(child: Test.Account, parent: Test.Account, isPublic: Bool) { | ||
txExecutor("hybrid-custody/add_example_nft_collection_to_delegator.cdc", [child], [parent.address, isPublic], nil, 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,10 @@ | ||
import "CapabilityFilter" | ||
|
||
transaction() { | ||
prepare(acct: AuthAccount) { | ||
let filter = acct.borrow<&CapabilityFilter.AllowlistFilter>(from: CapabilityFilter.StoragePath) | ||
?? panic("filter does not exist") | ||
|
||
filter.removeAllTypes() | ||
} | ||
} |
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,10 @@ | ||
import "CapabilityFilter" | ||
|
||
transaction() { | ||
prepare(acct: AuthAccount) { | ||
let filter = acct.borrow<&CapabilityFilter.DenylistFilter>(from: CapabilityFilter.StoragePath) | ||
?? panic("filter does not exist") | ||
|
||
filter.removeAllTypes() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead make
deniedTypes
a var and just set it to an empty array?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will that be backward compatible change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the events might be nice to have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably have an event that says types cleared to make it more efficient. and lemme check if it's a backward compatible change, my gut says no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe changing
let
tovar
is an an upgradable change yes👍 Sure, totally fine to add events. That might require some discussion so if you need some way to remove types right now for testing purposes, I'd split them up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth it to do the let/var change if we want to iterate through every key to emit each event?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be helpful for each removed type to be included in its own event or could we emit an array of removed types? If the latter, I think we could use the same event for both removal operations and just emit the dict keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emitting an array is what I was thinking, yeah. It depends on what kinds of events you're thinking about @rrrkren. Is there any high-level thought on that yet that we can use to think through this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is what we are doing right now to reset filters:
I'd prefer to keep this PR as is if possible since it's just a sugared iterate remove all and doesn't require downstream event aggregations to change. Happy to discuss further on the single filter reset event as a follow up.