Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Jan 30, 2024
1 parent 6790c0e commit bc4a527
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 308 deletions.
53 changes: 53 additions & 0 deletions apps/authz/src/opa/rego/__test__/criteria/intent/amount_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

test_intentAmount {
amount = intentAmount(wildcard) with input as request
with data.entities as entities

amount == to_number(one_matic)

value = intentAmount("fiat:usd") with input as request
with data.entities as entities

value == to_number(one_matic_value)
}

test_checkIntentAmount {
checkIntentAmount({"currency": wildcard, "operator": "eq", "value": one_matic}) with input as request
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "neq", "value": ten_matic}) with input as request
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "gt", "value": half_matic}) with input as request
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "lt", "value": ten_matic}) with input as request
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "gte", "value": one_matic}) with input as request
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "lte", "value": one_matic}) with input as request
with data.entities as entities
}

test_checkTokenValue {
checkIntentAmount({"currency": "fiat:usd", "operator": "eq", "value": one_matic_value}) with input as request
with data.entities as entities

checkIntentAmount({"currency": "fiat:usd", "operator": "neq", "value": ten_matic_value}) with input as request
with data.entities as entities

checkIntentAmount({"currency": "fiat:usd", "operator": "gt", "value": half_matic_value}) with input as request
with data.entities as entities

checkIntentAmount({"currency": "fiat:usd", "operator": "lt", "value": ten_matic_value}) with input as request
with data.entities as entities

checkIntentAmount({"currency": "fiat:usd", "operator": "gte", "value": one_matic_value}) with input as request
with data.entities as entities

checkIntentAmount({"currency": "fiat:usd", "operator": "lte", "value": one_matic_value}) with input as request
with data.entities as entities
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ test_contractCall {
checkDestinationAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as contractCallRequest
with data.entities as entities

checkContractAddress({"eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as contractCallRequest
checkIntentContractAddress({"eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as contractCallRequest
with data.entities as entities

checkContractHexSignatures({"0x12345"}) with input as contractCallRequest
checkIntentHexSignature({"0x12345"}) with input as contractCallRequest
with data.entities as entities
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package main

test_wildcardDestination {
checkDestinationAddress(wildcard)
checkDestinationClassification(wildcard)
}

test_destination {
res = destination with input as request
with data.entities as entities
Expand All @@ -22,3 +17,8 @@ test_destination {
checkDestinationClassification({"internal"}) with input as request
with data.entities as entities
}

test_wildcardDestination {
checkDestinationAddress(wildcard)
checkDestinationClassification(wildcard)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ test_checkSignMessage {
checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signMessageRequest
with data.entities as entities

signMessageEquals("Hello world!") with input as signMessageRequest
checkIntentMessage("equals", "Hello world!") with input as signMessageRequest
with data.entities as entities

signMessageContains("Hello") with input as signMessageRequest
checkIntentMessage("contains", "Hello") with input as signMessageRequest
with data.entities as entities
}

Expand All @@ -39,68 +39,20 @@ test_checkSignRawPayload {
checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signRawPayloadRequest
with data.entities as entities

signRawPayloadEquals("Hello world!") with input as signRawPayloadRequest
checkIntentPayload("equals", "Hello world!") with input as signRawPayloadRequest
with data.entities as entities

signRawPayloadContains("Hello") with input as signRawPayloadRequest
checkIntentPayload("contains", "Hello") with input as signRawPayloadRequest
with data.entities as entities
}

test_checkSignTypedData {
typedData = {
"account": "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": 1,
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
"types": {
"Person": [
{
"name": "name",
"type": "string",
},
{
"name": "wallet",
"type": "address",
},
],
"Mail": [
{
"name": "from",
"type": "Person",
},
{
"name": "to",
"type": "Person",
},
{
"name": "contents",
"type": "string",
},
],
},
"primaryType": "Mail",
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
"contents": "Hello, Bob!",
},
}

signTypedDataRequest = {
"action": "signTransaction",
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "signTypedData",
"typedData": typedData,
"typedData": {},
},
}

Expand All @@ -109,7 +61,4 @@ test_checkSignTypedData {

checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signTypedDataRequest
with data.entities as entities

signTypedDataEquals(typedData) with input as signTypedDataRequest
with data.entities as entities
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package main

test_wildcardSource {
checkSourceAccountType(wildcard)
checkSourceAddress(wildcard)
checkSourceClassification(wildcard)
}

test_source {
res = source with input as request
with data.entities as entities
Expand All @@ -26,3 +20,9 @@ test_source {
checkSourceClassification({"wallet"}) with input as request
with data.entities as entities
}

test_wildcardSource {
checkSourceAccountType(wildcard)
checkSourceAddress(wildcard)
checkSourceClassification(wildcard)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ test_tokenAllowance {
checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as tokenAllowanceRequest
with data.entities as entities

checkTokenSpenderAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as tokenAllowanceRequest
checkIntentSpenderAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as tokenAllowanceRequest
with data.entities as entities

checkTokenAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as tokenAllowanceRequest
checkIntentTokenAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as tokenAllowanceRequest
with data.entities as entities

checkTokenAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as tokenAllowanceRequest
checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as tokenAllowanceRequest
with data.entities as entities
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test_transferERC721 {
checkDestinationAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc721Request
with data.entities as entities

checkContractAddress({"eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as erc721Request
checkIntentContractAddress({"eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as erc721Request
with data.entities as entities

checkERC721TokenId({"eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173"}) with input as erc721Request
Expand Down Expand Up @@ -62,7 +62,7 @@ test_transferERC1155 {
checkDestinationAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc1155Request
with data.entities as entities

checkContractAddress({"eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as erc1155Request
checkIntentContractAddress({"eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4"}) with input as erc1155Request
with data.entities as entities

checkERC1155TokenId({"eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173"}) with input as erc1155Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test_transferNative {
checkDestinationAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as nativeRequest
with data.entities as entities

checkTokenAddress({"eip155:137/slip44/966"}) with input as nativeRequest
checkIntentTokenAddress({"eip155:137/slip44/966"}) with input as nativeRequest
with data.entities as entities

checkTokenAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as nativeRequest
checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as nativeRequest
with data.entities as entities
}

Expand All @@ -49,9 +49,9 @@ test_transferERC20 {
checkDestinationAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as erc20Request
with data.entities as entities

checkContractAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as erc20Request
checkIntentContractAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as erc20Request
with data.entities as entities

checkTokenAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as erc20Request
checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as erc20Request
with data.entities as entities
}
24 changes: 11 additions & 13 deletions apps/authz/src/opa/rego/__test__/criteria/principal_test.rego
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
package main

test_wildcardPrincipal {
checkPrincipalId(wildcard)
checkPrincipalRole(wildcard)
checkPrincipalGroups(wildcard)
}

test_principalGroups {
groups = principalGroups with input as request
test_principal {
user = principal with input as request
with data.entities as entities

groups == {"test-user-group-one-uid", "test-user-group-two-uid"}
}
user == {"uid": "test-bob-uid", "role": "root"}

test_principal {
res = principal with input as request
groups = principalGroups with input as request
with data.entities as entities

res == {"uid": "test-bob-uid", "role": "root"}
groups == {"test-user-group-one-uid", "test-user-group-two-uid"}

isPrincipalRootUser with input as request
with data.entities as entities
Expand All @@ -34,3 +26,9 @@ test_principal {
checkPrincipalGroups({"test-user-group-one-uid"}) with input as request
with data.entities as entities
}

test_wildcardPrincipal {
checkPrincipalId(wildcard)
checkPrincipalRole(wildcard)
checkPrincipalGroups(wildcard)
}
42 changes: 19 additions & 23 deletions apps/authz/src/opa/rego/__test__/criteria/resource_test.rego
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
package main

test_checkTransferResourceIntegrity {
test_resource {
checkTransferResourceIntegrity with input as request
with data.entities as entities
}

test_walletGroups {
groups = walletGroups with input as request
wallet = resource with input as request
with data.entities as entities

groups == {"test-wallet-group-one-uid"}
}
wallet == {
"uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-bar-uid"],
}

test_getWalletGroups {
getWalletGroups({"test-wallet-group-one-uid"}) with input as request
groups = walletGroups with input as request
with data.entities as entities
}

test_wildcardResource {
checkWalletId(wildcard)
checkWalletGroups(wildcard)
checkWalletChainId(wildcard)
checkWalletAssignees(wildcard)
}
groups == {"test-wallet-group-one-uid"}

test_resource {
res = resource with input as request
walletGroupsById = getWalletGroups("eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e") with input as request
with data.entities as entities

res == {
"uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-bar-uid"],
}
walletGroupsById == {"test-wallet-group-one-uid"}

checkWalletId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as request
with data.entities as entities
Expand All @@ -47,3 +36,10 @@ test_resource {
checkWalletAssignees({"test-bob-uid"}) with input as request
with data.entities as entities
}

test_wildcardResource {
checkWalletId(wildcard)
checkWalletGroups(wildcard)
checkWalletChainId(wildcard)
checkWalletAssignees(wildcard)
}
Loading

0 comments on commit bc4a527

Please sign in to comment.