Skip to content

Commit

Permalink
Evaluation is responsible to enforce casing (#550)
Browse files Browse the repository at this point in the history
* utils for case insentivity, modified test data and first passing test

* renamed util for case insensitive find, more tests passing

* added missing bracket

* fixed rebasing issue

* added entity querying package

* removed unused code, added comments

* added lowercase where needed

* fixed import path for resources in e2e tests

* access to entity only go through to query lib

* remove entityInput file, corrected comments over get.account query
  • Loading branch information
Ptroger authored Oct 3, 2024
1 parent 8e84c23 commit a0ec7dd
Show file tree
Hide file tree
Showing 38 changed files with 807 additions and 289 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
package main

test_approversRoles {
roles = approversRoles with input as requestWithEip1559Transaction with data.entities as entities
roles == {"root", "member", "admin"}
}

test_approversGroups {
groups = approversGroups with input as requestWithEip1559Transaction with data.entities as entities
groups == {"test-user-group-one-uid", "test-user-group-two-uid"}
}

test_checkApprovalByUserId {
requiredApproval = {
"approvalCount": 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package main

import data.armory.lib.chainAccount.build

test_source {
res = getIntentSourceChainAccount(input.intent) with input as requestWithEip1559Transaction with data.entities as entities
res = build.intentSourceChainAccount(input.intent) with input as requestWithEip1559Transaction with data.entities as entities

res == {
"id": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
expected := {
"id": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"chainId": 137,
"classification": "managed",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-foo-uid", "test-bar-uid"],
"accountGroups": {"test-account-group-one-uid"},
"assignees": ["test-bOb-uid", "test-alicE-uid", "test-foo-uid", "test-bar-uid"],
"groups": {"test-account-group-ONE-uid"},
}

expected == res

checkSourceId({"eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as requestWithEip1559Transaction with data.entities as entities
checkSourceAddress({"0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as requestWithEip1559Transaction with data.entities as entities
checkSourceAccountType({"eoa"}) with input as requestWithEip1559Transaction with data.entities as entities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import data.armory.entities.get

test_principal {
user = principal with input as requestWithEip1559Transaction with data.entities as entities
user == {"id": "test-bob-uid", "role": "root"}
user = get.user(input.principal.userId) with input as requestWithEip1559Transaction with data.entities as entities

groups = principalGroups with input as requestWithEip1559Transaction with data.entities as entities
groups == {"test-user-group-one-uid", "test-user-group-two-uid"}
user == {"id": "test-BOB-uid", "role": "root", "groups": {"test-USER-group-one-uid", "test-USER-group-two-uid"}}

checkPrincipalId({"test-bob-uid", "test-alice-uid"}) with input as requestWithEip1559Transaction with data.entities as entities
checkPrincipalRole({"root", "admin"}) with input as requestWithEip1559Transaction with data.entities as entities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package main

import data.armory.entities.get

test_resource {
account = resource with input as requestWithEip1559Transaction with data.entities as entities
account == {
"id": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
account = get.account(input.resource.uid) with input as requestWithEip1559Transaction with data.entities as entities

expected := {
"id": "eip155:eoa:0xDDcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208F219a6e6af072f2cfdc615b2c1805f98e",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-foo-uid", "test-bar-uid"],
"assignees": ["test-bOb-uid", "test-alicE-uid", "test-foo-uid", "test-bar-uid"],
"groups": {"test-account-group-ONE-uid"},
}
account == expected

groups = accountGroups with input as requestWithEip1559Transaction with data.entities as entities
groups == {"test-account-group-one-uid"}

accountGroupsById = getAccountGroups("eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e") with input as requestWithEip1559Transaction with data.entities as entities
accountGroupsById == {"test-account-group-one-uid"}

checkAccountId({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountAddress({"0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountId({"eip155:eoa:0xdDcF208f219a6e6af072f2cfdc615b2c1805F98E"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountAddress({"0xdDCf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountType({"eoa"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountGroup({"test-account-group-one-uid"}) with input as requestWithEip1559Transaction with data.entities as entities
checkAccountGroup({"teST-account-groUp-one-uid"}) with input as requestWithEip1559Transaction with data.entities as entities
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ tenHoursAgo = (nowSeconds - ((10 * 60) * 60)) * 1000 # in ms

nineHoursAgo = (nowSeconds - ((9 * 60) * 60)) * 1000 # in ms

principalReq = {"userId": "test-bob-uid"}
principalReq = {"userId": "test-bob-Uid"}

resourceReq = {"uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}
resourceReq = {"uid": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98E"}

transactionRequestEIP1559 = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7A3",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
Expand All @@ -38,30 +38,30 @@ transactionRequestEIP1559 = {
}

transactionRequestLegacy = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7A3",
"chainId": 137,
"gas": "21000",
"gasPrice": "20000000000",
"value": "0xde0b6b3a7640000",
"value": "0xde0b6b3A7640000",
"data": "0x00000000",
"nonce": 192,
"type": "0",
}

intentReq = {
"type": "transferERC20",
"from": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"from": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7A3",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aA84174",
"amount": "1000000000000000000", # 1 USDC
}

approvalsReq = [
{"userId": "test-bob-uid"},
{"userId": "test-alice-uid"},
{"userId": "test-foo-uid"},
{"userId": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43"},
{"userId": "test-bob-uiD"},
{"userId": "test-alice-uiD"},
{"userId": "test-foo-uiD"},
{"userId": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2A43"},
]

feedsReq = [
Expand Down Expand Up @@ -143,82 +143,82 @@ requestWithLegacyTransaction = {
entities = {
"addressBook": {
"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3": {
"id": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"address": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"id": "eip155:137:0xA45E21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"address": "0xa45e21E9370Ba031c5e1f47dedca74a7ce2ed7a3",
"chainId": 137,
"classification": "internal",
},
"eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": {
"id": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"id": "eip155:137:0xDDcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddCF208f219a6e6af072f2cfdc615b2c1805f98e",
"chainId": 137,
"classification": "managed",
},
"eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": {
"id": "eip155:1:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"id": "eip155:1:0xDDCf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208F219a6e6af072f2cfdc615b2c1805f98e",
"chainId": 1,
"classification": "managed",
},
},
"tokens": {"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174": {
"id": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"address": "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"id": "eip155:137/erc20:0x2791bCA1f2de4661ed88a30c99a7a9449aa84174",
"address": "0x2791bca1f2de4661ED88a30c99a7a9449aa84174",
"symbol": "USDC",
"chainId": 137,
"decimals": 6,
}},
"users": {
"test-bob-uid": {
"id": "test-bob-uid",
"id": "test-BOB-uid",
"role": "root",
},
"test-alice-uid": {
"id": "test-alice-uid",
"id": "test-Alice-uid",
"role": "member",
},
"test-bar-uid": {
"id": "test-bar-uid",
"id": "test-Bar-uid",
"role": "admin",
},
"test-foo-uid": {
"id": "test-foo-uid",
"id": "test-Foo-uid",
"role": "admin",
},
"0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43": {
"id": "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43",
"id": "0xAAA8ee1cbaa1856f4550c6fc24abb16c5c9b2a43",
"role": "admin",
},
},
"userGroups": {
"test-user-group-one-uid": {
"id": "test-user-group-one-uid",
"id": "test-USER-group-one-uid",
"name": "dev",
"users": ["test-bob-uid", "test-bar-uid"],
"users": ["test-Bob-uid", "test-Bar-uid"],
},
"test-user-group-two-uid": {
"id": "test-user-group-two-uid",
"id": "test-USER-group-two-uid",
"name": "finance",
"users": ["test-bob-uid", "test-bar-uid"],
"users": ["tesT-Bob-uid", "test-bar-uid"],
},
},
"accounts": {
"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e": {
"id": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"id": "eip155:eoa:0xDDcf208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xddcf208F219a6e6af072f2cfdc615b2c1805f98e",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-foo-uid", "test-bar-uid"],
"assignees": ["test-bOb-uid", "test-alicE-uid", "test-foo-uid", "test-bar-uid"],
},
"eip155:eoa:0xbbbb208f219a6e6af072f2cfdc615b2c1805f98e": {
"id": "eip155:eoa:0xbbbb208f219a6e6af072f2cfdc615b2c1805f98e",
"address": "0xbbbb208f219a6e6af072f2cfdc615b2c1805f98e",
"id": "eip155:eoa:0xbbbb208f219a6e6af072F2cfdc615b2c1805f98e",
"address": "0xbbbb208f219a6e6af072f2cfdC615b2c1805f98e",
"accountType": "eoa",
"assignees": ["test-bob-uid", "test-alice-uid", "test-foo-uid", "test-bar-uid", "0xaaa8ee1cbaa1856f4550c6fc24abb16c5c9b2a43"],
"assignees": ["test-Bob-uid", "test-alicE-uid", "test-foo-uid", "test-bar-uid", "0xAAA8ee1cbaa1856f4550c6fc24abb16c5c9b2a43"],
},
},
"accountGroups": {"test-account-group-one-uid": {
"id": "test-account-group-one-uid",
"id": "test-account-group-ONE-uid",
"name": "dev",
"accounts": ["eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", "eip155:eoa:0xbbbb208f219a6e6af072f2cfdc615b2c1805f98e"],
"accounts": ["eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", "eip155:eoa:0xbbBB208f219a6e6af072f2cfdc615b2c1805f98e"],
}},
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ permit[{"policyId": "approvalByUserGroups"}] = reason {
checkIntentAmount(transferValueCondition)

approvals = checkApprovals(approvalsRequired)

reason = {
"type": "permit",
"policyId": "approvalByUserGroups",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_approvalByUserGroups {

res = permit[{"policyId": "approvalByUserGroups"}] with input as approvalByUserGroupsReq with data.entities as entities

res == {
expected := {
"approvalsMissing": [],
"approvalsSatisfied": [{
"approvalCount": 2,
Expand All @@ -46,6 +46,7 @@ test_approvalByUserGroups {
"policyId": "approvalByUserGroups",
"type": "permit",
}
res == expected
}

test_approvalByUserRoles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ forbid[{"policyId": "spendingLimitByUserGroup"}] = reason {
},
"filters": {"userGroups": {"test-user-group-one-uid"}},
})

reason = {
"type": "forbid",
"policyId": "spendingLimitByUserGroup",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package main

import data.armory.lib.chainAccount.build.extractAddressFromAccountId

test_transformIntentToTransferObject {
res = transformIntentToTransferObject(input.intent) with input as requestWithEip1559Transaction with data.entities as entities

res == {
expected := {
"amount": "1000000000000000000",
"chainId": 137,
"from": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"initiatedBy": "test-bob-uid",
"from": "eip155:137:0xddcf208f219a6e6af072f2cfdc615b2c1805f98E",
"initiatedBy": "test-bob-Uid",
"rates": {"fiat:eur": "1.10", "fiat:usd": "0.99"},
"resourceId": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"resourceId": "eip155:eoa:0xDDcf208f219a6e6af072f2cfdc615b2c1805f98e",
"timestamp": nowSeconds * 1000,
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7A3",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aA84174",
}
res == expected
}

test_parseUnits {
Expand Down
Loading

0 comments on commit a0ec7dd

Please sign in to comment.