Skip to content

Commit

Permalink
account format (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Jun 24, 2019
1 parent 43ac685 commit 77f689b
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 102 deletions.
6 changes: 6 additions & 0 deletions bbtest/features/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Feature: REST
"""
{
"name": "A",
"format": "test",
"currency": "XXX",
"isBalanceCheck": false
}
Expand All @@ -80,6 +81,7 @@ Feature: REST
"""
{
"name": "yyy",
"format": "test",
"currency": "XXX",
"isBalanceCheck": false
}
Expand All @@ -93,6 +95,7 @@ Feature: REST
"""
{
"name": "yyy",
"format": "test",
"currency": "XXX",
"isBalanceCheck": false
}
Expand All @@ -106,6 +109,7 @@ Feature: REST
"""
{
"name": "B",
"format": "test",
"currency": "XXX",
"isBalanceCheck": false
}
Expand All @@ -125,6 +129,7 @@ Feature: REST
"""
{
"name": "xxx",
"format": "test",
"currency": "XXX",
"isBalanceCheck": false
}
Expand All @@ -135,6 +140,7 @@ Feature: REST
Then curl responds with 200
"""
{
"format": "TEST",
"currency": "XXX",
"balance": "0",
"blocking": "0",
Expand Down
2 changes: 2 additions & 0 deletions bbtest/features/journal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Feature: Persistent journal
"promiseBuffer": [],
"accountName": "Euro",
"isBalanceCheck": false,
"format": "TEST",
"currency": "EUR"
}
"""
Expand All @@ -32,6 +33,7 @@ Feature: Persistent journal
"promiseBuffer": [],
"accountName": "Ripple",
"isBalanceCheck": true,
"format": "TEST",
"currency": "XRP"
}
"""
Expand Down
10 changes: 5 additions & 5 deletions bbtest/features/messaging.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ Feature: Messaging behaviour
Given tenant MSG1 is onbdoarded
And lake is empty

When lake recieves "VaultUnit/MSG1 VaultRest account_name_1 req_id_1 NA EUR f"
When lake recieves "VaultUnit/MSG1 VaultRest account_name_1 req_id_1 NA test EUR f"
Then lake responds with "VaultRest VaultUnit/MSG1 req_id_1 account_name_1 AN"

Scenario: get balance
Given tenant MSG2 is onbdoarded
And lake is empty

When lake recieves "VaultUnit/MSG2 VaultRest account_name_3 req_id_3 NA EUR f"
When lake recieves "VaultUnit/MSG2 VaultRest account_name_3 req_id_3 NA test EUR f"
Then lake responds with "VaultRest VaultUnit/MSG2 req_id_3 account_name_3 AN"

When lake recieves "VaultUnit/MSG2 VaultRest account_name_3 req_id_3 GS"
Then lake responds with "VaultRest VaultUnit/MSG2 req_id_3 account_name_3 S0 EUR f 0 0"
Then lake responds with "VaultRest VaultUnit/MSG2 req_id_3 account_name_3 S0 TEST EUR f 0 0"

When lake recieves "VaultUnit/MSG2 VaultRest account_name_4 req_id_3 GS"
Then lake responds with "VaultRest VaultUnit/MSG2 req_id_3 account_name_4 S1"
Expand All @@ -24,7 +24,7 @@ Feature: Messaging behaviour
Given tenant MSG3 is onbdoarded
And lake is empty

When lake recieves "VaultUnit/MSG3 VaultRest account_name_2 req_id_2 NA EUR f"
And lake recieves "VaultUnit/MSG3 VaultRest account_name_2 req_id_2 NA EUR f"
When lake recieves "VaultUnit/MSG3 VaultRest account_name_2 req_id_2 NA test EUR f"
And lake recieves "VaultUnit/MSG3 VaultRest account_name_2 req_id_2 NA test EUR f"
Then lake responds with "VaultRest VaultUnit/MSG3 req_id_2 account_name_2 AN"
And lake responds with "VaultRest VaultUnit/MSG3 req_id_2 account_name_2 EE"
10 changes: 6 additions & 4 deletions bbtest/helpers/journal_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def self.account_snapshot(tenant, account, version)
lines = data.split("\n").map(&:strip)

{
:balance_check => lines[0][0] != 'F',
:currency => lines[0][1..3],
:balance_check => lines[0][lines[0].length-1..-1] != "F",
:format => lines[0][4...-2],
:currency => lines[0][0..2],
:account_name => account,
:version => version.to_i,
:balance => '%g' % BigDecimal.new(lines[1]).to_s('F'),
Expand All @@ -40,8 +41,9 @@ def self.account_latest_snapshot(tenant, account)
lines = data.split("\n").map(&:strip)

{
:balance_check => lines[0][0] != 'F',
:currency => lines[0][1..3],
:balance_check => lines[0][lines[0].length-1..-1] != "F",
:format => lines[0][4...-2],
:currency => lines[0][0..2],
:account_name => account,
:version => snapshots[0].to_i,
:balance => '%g' % BigDecimal.new(lines[1]).to_s('F'),
Expand Down
3 changes: 3 additions & 0 deletions bbtest/steps/account_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
expected_response = {
balance: "0",
blocking: "0",
format: meta[:format],
currency: meta[:currency],
isBalanceCheck: (snapshot[:activity] || false)
}.to_json
Expand All @@ -33,6 +34,7 @@

payload = {
name: account,
format: 'test',
currency: currency,
isBalanceCheck: activity
}.to_json
Expand All @@ -44,6 +46,7 @@

@accounts[account] = {
:currency => currency,
:format => 'test',
:activity => activity,
:balance => '%g' % BigDecimal.new(0).to_s('F'),
:promised => '%g' % BigDecimal.new(0).to_s('F'),
Expand Down
2 changes: 2 additions & 0 deletions bbtest/steps/journal_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
step "snapshot :account version :count should be" do |account, version, expectation|
(tenant, account) = account.split('/')
actual = JournalHelper.account_snapshot(tenant, account, version)

expectation = JSON.parse(expectation)

expect(actual[:version]).to eq(expectation["version"])
expect(actual[:balance]).to eq(expectation["balance"])
expect(actual[:format]).to eq(expectation["format"])
expect(actual[:promised]).to eq(expectation["promised"])
expect(actual[:account_name]).to eq(expectation["accountName"])
expect(actual[:balance_check]).to eq(expectation["isBalanceCheck"])
Expand Down
2 changes: 1 addition & 1 deletion packaging/debian_amd64/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: vault
Version: 1.2.7+master
Version: 1.2.7+account-format
Section: misc
Priority: extra
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion services/vault-rest/actor/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func CreateAccount(sys *ActorSystem, tenant string, account model.Account) (resu
ch <- context.Data
})

sys.SendRemote(CreateAccountMessage(tenant, envelope.Name, account.Name, account.Currency, account.IsBalanceCheck))
sys.SendRemote(CreateAccountMessage(tenant, envelope.Name, account.Name, account.Format, account.Currency, account.IsBalanceCheck))

select {

Expand Down
9 changes: 5 additions & 4 deletions services/vault-rest/actor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ func ProcessRemoteMessage(s *ActorSystem) system.ProcessRemoteMessage {

case RespAccountState:
message = &model.Account{
Currency: parts[5],
IsBalanceCheck: parts[6] != "f",
Balance: parts[7],
Blocking: parts[8],
Format: parts[5],
Currency: parts[6],
IsBalanceCheck: parts[7] != "f",
Balance: parts[8],
Blocking: parts[9],
}

case RespAccountMissing:
Expand Down
6 changes: 3 additions & 3 deletions services/vault-rest/actor/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const (
)

// CreateAccountMessage is message for creation of new account
func CreateAccountMessage(tenant string, sender string, name string, currency string, isBalanceCheck bool) string {
func CreateAccountMessage(tenant string, sender string, name string, format string, currency string, isBalanceCheck bool) string {
if isBalanceCheck {
return "VaultUnit/" + tenant + " VaultRest " + name + " " + sender + " " + ReqCreateAccount + " " + currency + " t"
return "VaultUnit/" + tenant + " VaultRest " + name + " " + sender + " " + ReqCreateAccount + " " + format + " " + currency + " t"
}
return "VaultUnit/" + tenant + " VaultRest " + name + " " + sender + " " + ReqCreateAccount + " " + currency + " f"
return "VaultUnit/" + tenant + " VaultRest " + name + " " + sender + " " + ReqCreateAccount + " " + format + " " + currency + " f"
}

// GetAccountMessage is message for getting balance of account
Expand Down
6 changes: 6 additions & 0 deletions services/vault-rest/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type AccountMissing struct{}
// Account represents account
type Account struct {
Name string `json:"-"`
Format string `json:"format"`
Currency string `json:"currency"`
Balance string `json:"balance"`
Blocking string `json:"blocking"`
Expand All @@ -46,6 +47,7 @@ func (entity *Account) UnmarshalJSON(data []byte) error {
}
all := struct {
Name string `json:"name"`
Format string `json:"format"`
Currency string `json:"currency"`
IsBalanceCheck *bool `json:"isBalanceCheck"`
}{}
Expand All @@ -56,6 +58,9 @@ func (entity *Account) UnmarshalJSON(data []byte) error {
if all.Name == "" {
return fmt.Errorf("missing attribute \"name\"")
}
if all.Format == "" {
return fmt.Errorf("missing attribute \"format\"")
}
if all.Currency == "" {
return fmt.Errorf("missing attribute \"currency\"")
}
Expand All @@ -72,6 +77,7 @@ func (entity *Account) UnmarshalJSON(data []byte) error {
}

entity.Name = strings.Replace(all.Name, " ", "_", -1)
entity.Format = strings.Replace(all.Format, " ", "_", -1)
entity.Currency = all.Currency
return nil
}
Loading

0 comments on commit 77f689b

Please sign in to comment.