-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: velocity e2e test * chore: pass control_id instead of limit_it * test: velocity limits
- Loading branch information
1 parent
b25d00e
commit 1139d98
Showing
7 changed files
with
289 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mutation VelocityControlAddLimit($input: VelocityControlAddLimitInput!) { | ||
velocityControlAddLimit(input: $input) { | ||
velocityControl { | ||
limits { | ||
velocityLimitId | ||
} | ||
} | ||
} | ||
} |
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,7 @@ | ||
mutation VelocityControlAttach($input: VelocityControlAttachInput!) { | ||
velocityControlAttach(input: $input) { | ||
velocityControl { | ||
velocityControlId | ||
} | ||
} | ||
} |
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,7 @@ | ||
mutation VelocityControlCreate($input: VelocityControlCreateInput!) { | ||
velocityControlCreate(input: $input) { | ||
velocityControl { | ||
velocityControlId | ||
} | ||
} | ||
} |
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,7 @@ | ||
mutation VelocityLimitCreate($input: VelocityLimitCreateInput!) { | ||
velocityLimitCreate(input: $input) { | ||
velocityLimit { | ||
velocityLimitId | ||
} | ||
} | ||
} |
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,64 @@ | ||
mutation VelocityTxTemplateCreate( | ||
$templateId: UUID! | ||
$templateCode: String! | ||
$journalId: Expression! | ||
) { | ||
velocityTemplate: txTemplateCreate( | ||
input: { | ||
txTemplateId: $templateId | ||
code: $templateCode | ||
description: "Velocity transaction template." | ||
params: [ | ||
{ name: "recipient", type: UUID, description: "Recipient account ID." } | ||
{ name: "sender", type: UUID, description: "Sender account ID." } | ||
{ name: "journal_id", type: UUID, description: "Journal ID." } | ||
{ | ||
name: "amount" | ||
type: DECIMAL | ||
description: "Amount with decimal, e.g. `1.23`." | ||
} | ||
{ | ||
name: "currency" | ||
type: STRING | ||
description: "Currency used in the transaction." | ||
default: "'USD'" | ||
} | ||
{ | ||
name: "layer" | ||
type: STRING | ||
description: "Layer for the transaction." | ||
default: "'SETTLED'" | ||
} | ||
{ | ||
name: "effective" | ||
type: DATE | ||
description: "Effective date for transaction." | ||
default: "date()" | ||
} | ||
] | ||
transaction: { journalId: $journalId, effective: "params.effective" } | ||
entries: [ | ||
{ | ||
accountId: "params.sender" | ||
units: "params.amount" | ||
currency: "params.currency" | ||
entryType: "'TEST_DR'" | ||
direction: "DEBIT" | ||
layer: "params.layer" | ||
} | ||
{ | ||
accountId: "params.recipient" | ||
units: "params.amount" | ||
currency: "params.currency" | ||
entryType: "'TEST_CR'" | ||
direction: "CREDIT" | ||
layer: "params.layer" | ||
} | ||
] | ||
} | ||
) { | ||
txTemplate { | ||
txTemplateId | ||
} | ||
} | ||
} |
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,194 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "helpers" | ||
|
||
setup_file() { | ||
start_server | ||
} | ||
|
||
teardown_file() { | ||
stop_server | ||
} | ||
|
||
@test "cala: create velocity control and post transaction with limits" { | ||
journal_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg journal_id "$journal_id" \ | ||
'{ | ||
"input": { | ||
"journalId": $journal_id, | ||
"name": "General Ledger", | ||
} | ||
}' | ||
) | ||
exec_graphql 'journal-create' "$variables" | ||
output=$(graphql_output '.data.journalCreate.journal.journalId') | ||
[[ "$output" != "null" ]] || exit 1 | ||
|
||
# create accounts | ||
|
||
sender_account_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg sender_account_id "$sender_account_id" \ | ||
'{ | ||
"input": { | ||
"accountId": $sender_account_id, | ||
"name": "Sender - Checking", | ||
"code": ("SENDER.CHECKING-" + $sender_account_id), | ||
"normalBalanceType": "CREDIT" | ||
} | ||
}' | ||
) | ||
exec_graphql 'account-create' "$variables" | ||
output=$(graphql_output '.data.accountCreate.account.accountId') | ||
[[ "$output" != "null" ]] || exit 1 | ||
|
||
recipient_account_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg recipient_account_id "$recipient_account_id" \ | ||
'{ | ||
"input": { | ||
"accountId": $recipient_account_id, | ||
"name": "Recipient - Checking", | ||
"code": ("RECIPIENT.CHECKING-" + $recipient_account_id), | ||
"normalBalanceType": "DEBIT" | ||
} | ||
}' | ||
) | ||
exec_graphql 'account-create' "$variables" | ||
output=$(graphql_output '.data.accountCreate.account.accountId') | ||
[[ "$output" != "null" ]] || exit 1 | ||
|
||
# create velocity limits | ||
withdrawal_limit_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg velocityLimitId "$withdrawal_limit_id" \ | ||
'{ | ||
"input": { | ||
"velocityLimitId": $velocityLimitId, | ||
"name": ("Withdrawal-" + $velocityLimitId), | ||
"description": "Test withdrawal limit", | ||
"window": [], | ||
"currency": null, | ||
"limit": { | ||
"timestampSource": null, | ||
"balance": [{ | ||
"limitType": "AVAILABLE", | ||
"layer": "SETTLED", | ||
"amount": "params.withdrawal_limit", | ||
"normalBalanceType": "DEBIT", | ||
}] | ||
}, | ||
"params": [{ | ||
"name": "withdrawal_limit", | ||
"type": "DECIMAL", | ||
"default": null, | ||
"description": null | ||
}] | ||
} | ||
}' | ||
) | ||
exec_graphql 'velocity-limit-create' "$variables" | ||
velocity_limit_id=$(graphql_output '.data.velocityLimitCreate.velocityLimit.velocityLimitId') | ||
[[ "$velocity_limit_id" == "$withdrawal_limit_id" ]] || exit 1 | ||
|
||
# create velocity control | ||
control_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg control_id "$control_id" \ | ||
'{ | ||
"input": { | ||
"velocityControlId": $control_id, | ||
"name": ("Velocity Control-" + $control_id), | ||
"description": "Test velocity control", | ||
"enforcement": { | ||
"velocityEnforcementAction": "REJECT" | ||
} | ||
} | ||
}' | ||
) | ||
exec_graphql 'velocity-control-create' "$variables" | ||
velocity_control_id=$(graphql_output '.data.velocityControlCreate.velocityControl.velocityControlId') | ||
[[ "$velocity_control_id" == "$control_id" ]] || exit 1 | ||
|
||
# attach limits to control | ||
variables=$( | ||
jq -n \ | ||
--arg velocity_control_id "$control_id" \ | ||
--arg velocity_limit_id "$withdrawal_limit_id" \ | ||
'{ | ||
"input": { | ||
"velocityControlId": $velocity_control_id, | ||
"velocityLimitId": $velocity_limit_id | ||
} | ||
}' | ||
) | ||
exec_graphql 'velocity-control-add-limit' "$variables" | ||
n_limits=$(graphql_output '.data.velocityControlAddLimit.velocityControl.limits' | jq length) | ||
[[ $n_limits == 1 ]] || exit 1 | ||
|
||
# attach control to sender account | ||
limit="100.0" | ||
variables=$( | ||
jq -n \ | ||
--arg control_id "$control_id" \ | ||
--arg sender_account_id "$sender_account_id" \ | ||
--arg limit "$limit" \ | ||
'{ | ||
"input": { | ||
"velocityControlId": $control_id, | ||
"accountId": $sender_account_id, | ||
"params": { | ||
"withdrawal_limit": $limit, | ||
} | ||
} | ||
}' | ||
) | ||
exec_graphql 'velocity-control-attach' "$variables" | ||
velocity_control_id=$(graphql_output '.data.velocityControlAttach.velocityControl.velocityControlId') | ||
[[ "$velocity_control_id" != "null" ]] || exit 1 | ||
|
||
# create tx templates | ||
|
||
velocity_template_id=$(random_uuid) | ||
variables=$(jq -n \ | ||
--arg velocityTemplateId "$velocity_template_id" \ | ||
--arg journalId "$journal_id" \ | ||
'{ | ||
"templateId": $velocityTemplateId, | ||
"templateCode": ("VELOCITY-" + $velocityTemplateId), | ||
"journalId": ("uuid(\u0027" + $journalId + "\u0027)") | ||
}') | ||
exec_graphql 'velocity-tx-template-create' "$variables" | ||
|
||
# # post transaction | ||
overflow_limit="101.10" | ||
transaction_id=$(random_uuid) | ||
variables=$( | ||
jq -n \ | ||
--arg transaction_id "$transaction_id" \ | ||
--arg sender "$sender_account_id" \ | ||
--arg recipient "$recipient_account_id" \ | ||
--arg templateId "$velocity_template_id" \ | ||
--arg overflowLimit "$overflow_limit" \ | ||
'{ | ||
"input": { | ||
"transactionId": $transaction_id, | ||
"txTemplateCode": ("VELOCITY-" + $templateId), | ||
"params": { | ||
"sender": $sender, | ||
"recipient": $recipient, | ||
"amount": $overflowLimit, | ||
} | ||
} | ||
}' | ||
) | ||
exec_graphql 'transaction-post' "$variables" | ||
error=$(graphql_output '.errors[0].message') | ||
[[ "$error" == *"Enforcement: Velocity limit"* ]] || exit 1 | ||
} |
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