-
Notifications
You must be signed in to change notification settings - Fork 2
Access control tests #244
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
Merged
Merged
Access control tests #244
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c38635e
add security permission matrix doc
vishalchangrani 25fd067
docs: highlight EPosition over-grant risk in permission matrix
vishalchangrani 7a1ea97
docs: restructure matrix by actor to expose beta over-grant clearly
vishalchangrani 2780290
docs: clarify EPositionAdmin is user acting on own positions via storage
vishalchangrani 4265852
Merge branch 'main' into taras/177-access-control-test
mts1715 f9f728b
Add comprehensive entitlement/capability access-control test suite
mts1715 491193a
fix comments
mts1715 4a2ea5e
Merge remote-tracking branch 'origin/main' into taras/177-access-cont…
mts1715 9e0b53b
Merge remote-tracking branch 'origin/main' into taras/177-access-cont…
mts1715 bd0dc05
fix wrong path for capability EGovernance
mts1715 dee9360
move some scripts from the `helper` folder to appropriate paths
mts1715 1a0d372
Merge remote-tracking branch 'origin/main' into taras/177-access-cont…
mts1715 27dc3b5
typo fix
mts1715 ca275cf
fix pool_pause_test.cdc to change from direct pool storage borrow to …
mts1715 ff18746
fix false description statement in comments;
mts1715 9bfe703
fix comments "do not use in production" at transactions that can be u…
mts1715 63cfe76
remove doubled test scripts; add some check to test
mts1715 628fd86
add additional verification that the intended action did actually hap…
mts1715 7098d3c
added neg_* tests for Egovernance methods
mts1715 dcd8ddd
Merge remote-tracking branch 'origin/main' into taras/177-access-cont…
mts1715 218fe0f
hotfix after merge
mts1715 6dd9e24
Merge remote-tracking branch 'origin/main' into taras/177-access-cont…
mts1715 361eea0
move EGovernance neg tests to egovernance_neg/ and add without_auth v…
mts1715 6fd9946
Merge branch 'main' into taras/177-access-control-test
mts1715 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 hidden or 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 hidden or 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 "FlowALPv0" | ||
| import "FlowALPPositionResources" | ||
|
|
||
| /// Returns the maximum health for the given position. | ||
| /// | ||
| /// @param positionOwner: The account address that holds the PositionManager | ||
| /// @param pid: The position ID | ||
| access(all) | ||
| fun main(positionOwner: Address, pid: UInt64): UFix64 { | ||
| let manager = getAccount(positionOwner).capabilities | ||
| .borrow<&FlowALPPositionResources.PositionManager>(FlowALPv0.PositionPublicPath) | ||
| ?? panic("Could not borrow PositionManager from \(positionOwner) at \(FlowALPv0.PositionPublicPath)") | ||
| return manager.borrowPosition(pid: pid).getMaxHealth() | ||
| } |
This file contains hidden or 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 "FlowALPv0" | ||
| import "FlowALPPositionResources" | ||
|
|
||
| /// Returns the minimum health for the given position. | ||
| /// | ||
| /// @param positionOwner: The account address that holds the PositionManager | ||
| /// @param pid: The position ID | ||
| access(all) | ||
| fun main(positionOwner: Address, pid: UInt64): UFix64 { | ||
| let manager = getAccount(positionOwner).capabilities | ||
| .borrow<&FlowALPPositionResources.PositionManager>(FlowALPv0.PositionPublicPath) | ||
| ?? panic("Could not borrow PositionManager from \(positionOwner) at \(FlowALPv0.PositionPublicPath)") | ||
| return manager.borrowPosition(pid: pid).getMinHealth() | ||
| } |
This file contains hidden or 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 "FlowALPv0" | ||
| import "FlowALPPositionResources" | ||
|
|
||
| /// Returns the target health for the given position. | ||
| /// | ||
| /// @param positionOwner: The account address that holds the PositionManager | ||
| /// @param pid: The position ID | ||
| access(all) | ||
| fun main(positionOwner: Address, pid: UInt64): UFix64 { | ||
| let manager = getAccount(positionOwner).capabilities | ||
| .borrow<&FlowALPPositionResources.PositionManager>(FlowALPv0.PositionPublicPath) | ||
| ?? panic("Could not borrow PositionManager from \(positionOwner) at \(FlowALPv0.PositionPublicPath)") | ||
| return manager.borrowPosition(pid: pid).getTargetHealth() | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
22 changes: 0 additions & 22 deletions
22
cadence/tests/transactions/flow-alp/beta/claim_and_save_beta_cap.cdc
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
cadence/tests/transactions/flow-alp/beta/publish_beta_cap.cdc
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
cadence/tests/transactions/flow-alp/egovernance/add_supported_token.cdc
This file contains hidden or 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,38 @@ | ||
| import "FlowALPv0" | ||
| import "FlowALPModels" | ||
| import "FlowALPInterestRates" | ||
|
|
||
| /// TEST TRANSACTION - DO NOT USE IN PRODUCTION | ||
| /// | ||
| /// Verifies that auth(EGovernance) &Pool grants access to Pool.addSupportedToken. | ||
| /// Adds a token with a zero-rate interest curve (0% APY). | ||
| transaction( | ||
| tokenTypeIdentifier: String, | ||
| collateralFactor: UFix64, | ||
| borrowFactor: UFix64, | ||
| depositRate: UFix64, | ||
| depositCapacityCap: UFix64 | ||
| ) { | ||
| let tokenType: Type | ||
| let pool: auth(FlowALPModels.EGovernance) &FlowALPv0.Pool | ||
|
|
||
| prepare(signer: auth(BorrowValue) &Account) { | ||
| self.tokenType = CompositeType(tokenTypeIdentifier) | ||
| ?? panic("Invalid tokenTypeIdentifier \(tokenTypeIdentifier)") | ||
| let cap = signer.storage.borrow<&Capability<auth(FlowALPModels.EGovernance) &FlowALPv0.Pool>>( | ||
| from: FlowALPv0.PoolCapStoragePath | ||
| ) ?? panic("No EGovernance cap found") | ||
| self.pool = cap.borrow() ?? panic("Could not borrow Pool from EGovernance cap") | ||
| } | ||
|
|
||
| execute { | ||
| self.pool.addSupportedToken( | ||
| tokenType: self.tokenType, | ||
| collateralFactor: collateralFactor, | ||
| borrowFactor: borrowFactor, | ||
| interestCurve: FlowALPInterestRates.FixedCurve(yearlyRate: 0.0), | ||
| depositRate: depositRate, | ||
| depositCapacityCap: depositCapacityCap | ||
| ) | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
cadence/tests/transactions/flow-alp/egovernance/collect_insurance.cdc
This file contains hidden or 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 "FlowALPv0" | ||
| import "FlowALPModels" | ||
|
|
||
| /// Collects accrued insurance fees for the given token type. | ||
| /// Requires an EGovernance capability at PoolCapStoragePath. | ||
| transaction(tokenTypeIdentifier: String) { | ||
| let pool: auth(FlowALPModels.EGovernance) &FlowALPv0.Pool | ||
| let tokenType: Type | ||
|
|
||
| prepare(signer: auth(BorrowValue) &Account) { | ||
| self.tokenType = CompositeType(tokenTypeIdentifier) | ||
| ?? panic("Invalid tokenTypeIdentifier: \(tokenTypeIdentifier)") | ||
| let cap = signer.storage.borrow<&Capability<auth(FlowALPModels.EGovernance) &FlowALPv0.Pool>>( | ||
| from: FlowALPv0.PoolCapStoragePath | ||
| ) ?? panic("No EGovernance cap found") | ||
| self.pool = cap.borrow() ?? panic("Could not borrow Pool from EGovernance cap") | ||
| } | ||
|
|
||
| execute { | ||
| self.pool.collectInsurance(tokenType: self.tokenType) | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
cadence/tests/transactions/flow-alp/egovernance/collect_stability.cdc
This file contains hidden or 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 "FlowALPv0" | ||
| import "FlowALPModels" | ||
|
|
||
| /// Collects accrued stability fees for the given token type. | ||
| /// Requires an EGovernance capability at PoolCapStoragePath. | ||
| transaction(tokenTypeIdentifier: String) { | ||
| let pool: auth(FlowALPModels.EGovernance) &FlowALPv0.Pool | ||
| let tokenType: Type | ||
|
|
||
| prepare(signer: auth(BorrowValue) &Account) { | ||
| self.tokenType = CompositeType(tokenTypeIdentifier) | ||
| ?? panic("Invalid tokenTypeIdentifier: \(tokenTypeIdentifier)") | ||
| let cap = signer.storage.borrow<&Capability<auth(FlowALPModels.EGovernance) &FlowALPv0.Pool>>( | ||
| from: FlowALPv0.PoolCapStoragePath | ||
| ) ?? panic("No EGovernance cap found") | ||
| self.pool = cap.borrow() ?? panic("Could not borrow Pool from EGovernance cap") | ||
| } | ||
|
|
||
| execute { | ||
| self.pool.collectStability(tokenType: self.tokenType) | ||
| } | ||
| } |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
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.
We already have
./cadence/transactions/flow-alp/pool-governance/collect_insurance.cdc.I don't see an issue with having separate copies for the test transactions; in fact, it might be the correct approach, as transactions outside the test folder should adhere to stricter rules.
Just wanted to confirm this was a deliberate choice.
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.
cadence/transactions/flow-alp/pool-governance/collect_insurance.cdc: directly borrows the Pool from storage (for the pool admin)cadence/tests/transactions/flow-alp/egovernance/collect_insurance.cdc: borrows a Capability fromPoolCapStoragePath(for eGovernanceUser who only has a delegated capability, not direct storage access)Switching
cap_test.cdcto use the pool-governance version would breaktestEGovernance_CollectInsurancesinceeGovernanceUserdoesn't have the pool in their storage.