-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
7 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
48 changes: 48 additions & 0 deletions
48
apps/authz/src/opa/rego/__test__/criteria/intent/permit_test.rego
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,48 @@ | ||
package main | ||
|
||
test_permit { | ||
permitRequest = { | ||
"action": "signTransaction", | ||
"intent": { | ||
"type": "permit", | ||
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", | ||
"spender": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", | ||
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174", | ||
"amount": "1000000000000000000", | ||
"deadline": "1634025600", # in ms | ||
}, | ||
} | ||
|
||
checkIntentType({"permit", "permit2"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkIntentSpenderAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkIntentTokenAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "eq", "value": "1634025600"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "neq", "value": "111111111"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "lte", "value": "1634025600"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "gte", "value": "1634025600"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "lt", "value": "16340256000"}) with input as permitRequest | ||
with data.entities as entities | ||
|
||
checkPermitDeadline({"operator": "gt", "value": "163402560"}) with input as permitRequest | ||
with data.entities as entities | ||
} |
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,36 @@ | ||
package main | ||
|
||
import future.keywords.in | ||
|
||
# convert ms to ns | ||
permitDeadlineMs = to_number(input.intent.deadline) | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "eq" | ||
permitDeadlineMs == to_number(condition.value) | ||
} | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "neq" | ||
permitDeadlineMs != to_number(condition.value) | ||
} | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "lte" | ||
permitDeadlineMs <= to_number(condition.value) | ||
} | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "gte" | ||
permitDeadlineMs >= to_number(condition.value) | ||
} | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "lt" | ||
permitDeadlineMs < to_number(condition.value) | ||
} | ||
|
||
checkPermitDeadline(condition) { | ||
condition.operator == "gt" | ||
permitDeadlineMs > to_number(condition.value) | ||
} |